完成优惠券页面
This commit is contained in:
@@ -2,38 +2,315 @@
|
||||
<view class="container">
|
||||
<u-form ref="formRef" label-position="top" labelWidth="200" :model="form" :rules="rules">
|
||||
<view class="u-form-card">
|
||||
<u-form-item label="赠券门槛">
|
||||
<u-input placeholder="请输入内容" v-model="form.fullAmount">
|
||||
<template v-slot:prefix>满</template>
|
||||
<template v-slot:suffix>可用</template>
|
||||
<u-form-item label="赠券门槛" prop="fullAmount">
|
||||
<view class="center">
|
||||
<view class="ipt">
|
||||
<u-input placeholder="请输入内容" v-model="form.fullAmount" input-align="center" :maxlength="5" @change="fullAmountInput">
|
||||
<template v-slot:prefix>满</template>
|
||||
<template v-slot:suffix>可用</template>
|
||||
</u-input>
|
||||
</view>
|
||||
<div class="tips-icon" @click="showTipsHandle">
|
||||
<u-icon name="question-circle-fill" size="22" color="#999"></u-icon>
|
||||
</div>
|
||||
</view>
|
||||
</u-form-item>
|
||||
<u-form-item label="优惠券" prop="couponGiftList">
|
||||
<my-select-coupon v-model="couponGiftList" @load="couponLoad"></my-select-coupon>
|
||||
</u-form-item>
|
||||
</view>
|
||||
<view class="u-form-card">
|
||||
<u-form-item label="可使用类型" prop="useType">
|
||||
<my-dine-types v-model="form.useType"></my-dine-types>
|
||||
</u-form-item>
|
||||
</view>
|
||||
<view class="u-form-card">
|
||||
<u-form-item label="总发放数量" prop="giveNum">
|
||||
<view class="column">
|
||||
<view class="center">
|
||||
<u-switch v-model="infiniteGiveNum" @change="infiniteGiveNumChange"></u-switch>
|
||||
<text class="tips">关闭则为无限制</text>
|
||||
</view>
|
||||
<view class="center" v-if="infiniteGiveNum">
|
||||
<view class="ipt">
|
||||
<u-input placeholder="请输入总发放数量" :maxlength="5" v-model="form.giveNum" @change="giveNumInput">
|
||||
<template v-slot:suffix>张</template>
|
||||
</u-input>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
<u-form-item label="每次赠送" prop="couponGiveNum">
|
||||
<u-input placeholder="赠送数量" :maxlength="5" v-model="couponGiveNum" @change="couponGiveNumInput">
|
||||
<template v-slot:suffix>张</template>
|
||||
</u-input>
|
||||
</u-form-item>
|
||||
<u-form-item label="每人限量" prop="getLimit">
|
||||
<view class="column">
|
||||
<view class="center">
|
||||
<u-switch v-model="infiniteGetLimit" @change="infiniteGetLimitChange"></u-switch>
|
||||
<text class="tips">关闭则为无限制</text>
|
||||
</view>
|
||||
<view class="center" v-if="infiniteGetLimit">
|
||||
<view class="ipt">
|
||||
<u-input placeholder="请输入每人限量" :maxlength="5" v-model="form.getLimit" @change="getLimitInput">
|
||||
<template v-slot:suffix>张</template>
|
||||
</u-input>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</u-form-item>
|
||||
</view>
|
||||
</u-form>
|
||||
<my-footer-btn @confirm="submitHandle" v-if="(shopInfo.isHeadShop && shopInfo.shopType != 'only') || !form.syncId"></my-footer-btn>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { filterNumberInput } from '@/utils/index.js';
|
||||
import { couponPost, updateConsumerCouponById, getConsumerCouponById } from '@/http/api/market/index.js';
|
||||
|
||||
const shopInfo = ref({});
|
||||
|
||||
const formRef = ref(null);
|
||||
|
||||
const couponGiftList = ref('');
|
||||
const form = ref({
|
||||
id: '',
|
||||
shopId: '',
|
||||
couponType: 1, // 1-满减券,2-商品兑换券,3-折扣券,4-第二件半价券,5-消费送券,6-买一送一券,7-固定价格券,8-免配送费券
|
||||
fullAmount: '', // 使用门槛:满多少金额
|
||||
couponGiftList: [], // 优惠券,目前单选
|
||||
useType: ['dine'], // 可使用类型:dine堂食/pickup自取/deliv配送/express快递
|
||||
useType: ['dine-in'], // 堂食 dine-in 外带 take-out 外卖 take-away 配送 post
|
||||
giveNum: '', // 总发放数量,-10086为不限量
|
||||
getLimit: '' // 每人领取限量,-10086为不限量
|
||||
});
|
||||
|
||||
const couponList = ref([]);
|
||||
|
||||
// 成功加载优惠券
|
||||
function couponLoad(res) {
|
||||
couponList.value = res;
|
||||
}
|
||||
|
||||
function showTipsHandle() {
|
||||
uni.showModal({
|
||||
title: '注意',
|
||||
content: '每单消费满此金额后赠送',
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
// 开始提交
|
||||
function submitHandle() {
|
||||
console.log('前置form', form.value);
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(async (res) => {
|
||||
try {
|
||||
form.value.shopId = shopInfo.value.id;
|
||||
form.value.useType = JSON.stringify(form.value.useType);
|
||||
let item = couponList.value.find((item) => item.id == couponGiftList.value);
|
||||
form.value.couponGiftList = [
|
||||
{
|
||||
couponName: item.title,
|
||||
couponId: item.id,
|
||||
num: couponGiveNum.value
|
||||
}
|
||||
];
|
||||
console.log('终极form', form.value);
|
||||
uni.showLoading({
|
||||
title: '加载中...',
|
||||
mask: true
|
||||
});
|
||||
if (form.value.id) {
|
||||
await updateConsumerCouponById(form.value);
|
||||
} else {
|
||||
await couponPost(form.value);
|
||||
}
|
||||
uni.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'none'
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.navigateBack();
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 500);
|
||||
})
|
||||
.catch((res) => {});
|
||||
}
|
||||
|
||||
const rules = ref({
|
||||
fullAmount: [
|
||||
{
|
||||
required: true,
|
||||
trigger: ['blur'],
|
||||
message: '请输入使用门槛',
|
||||
validator: (rule, value, callback) => {
|
||||
if (form.value.fullAmount < 0 || form.value.fullAmount === '') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
couponGiftList: [
|
||||
{
|
||||
required: true,
|
||||
trigger: ['change'],
|
||||
message: '请选择优惠券',
|
||||
validator: (rule, value, callback) => {
|
||||
if (couponGiftList.value === '') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
useType: [
|
||||
{
|
||||
required: true,
|
||||
trigger: ['change'],
|
||||
message: '请选择可使用类型',
|
||||
validator: (rule, value, callback) => {
|
||||
if (form.value.useType.length == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
giveNum: [
|
||||
{
|
||||
trigger: ['blur'],
|
||||
message: '请输入总发放数量',
|
||||
validator: (rule, value, callback) => {
|
||||
if (infiniteGiveNum.value && form.value.giveNum === '') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
couponGiveNum: [
|
||||
{
|
||||
trigger: ['blur'],
|
||||
message: '请输入赠送数量',
|
||||
validator: (rule, value, callback) => {
|
||||
if (couponGiveNum.value.giveNum === '') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
getLimit: [
|
||||
{
|
||||
trigger: ['blur'],
|
||||
message: '请输入每人限量',
|
||||
validator: (rule, value, callback) => {
|
||||
if (infiniteGetLimit.value && form.value.getLimit === '') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const inputTime = 50;
|
||||
function fullAmountInput(e) {
|
||||
setTimeout(() => {
|
||||
form.value.fullAmount = filterNumberInput(e);
|
||||
}, inputTime);
|
||||
}
|
||||
|
||||
const infiniteNum = -10086; // 无限
|
||||
const infiniteGiveNum = ref(true);
|
||||
function infiniteGiveNumChange(e) {
|
||||
if (!e) {
|
||||
form.value.giveNum = infiniteNum;
|
||||
} else {
|
||||
form.value.giveNum = '';
|
||||
}
|
||||
}
|
||||
|
||||
function giveNumInput(e) {
|
||||
setTimeout(() => {
|
||||
form.value.giveNum = filterNumberInput(e, 1);
|
||||
}, inputTime);
|
||||
}
|
||||
|
||||
// 优惠券赠送数量
|
||||
const couponGiveNum = ref(1);
|
||||
function couponGiveNumInput(e) {
|
||||
setTimeout(() => {
|
||||
couponGiveNum.value = filterNumberInput(e, 1);
|
||||
}, inputTime);
|
||||
}
|
||||
|
||||
const infiniteGetLimit = ref(true);
|
||||
function getLimitInput(e) {
|
||||
setTimeout(() => {
|
||||
form.value.getLimit = filterNumberInput(e);
|
||||
}, inputTime);
|
||||
}
|
||||
function infiniteGetLimitChange(e) {
|
||||
if (!e) {
|
||||
form.value.getLimit = infiniteNum;
|
||||
} else {
|
||||
form.value.getLimit = '';
|
||||
}
|
||||
}
|
||||
|
||||
const id = ref('');
|
||||
async function getConsumerCouponByIdAjax() {
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '加载中...',
|
||||
mask: true
|
||||
});
|
||||
const res = await getConsumerCouponById({ id: id.value });
|
||||
couponGiftList.value = res.couponGiftList[0].couponId;
|
||||
res.useType = JSON.parse(res.useType);
|
||||
if (res.giveNum == infiniteNum) {
|
||||
infiniteGiveNum.value = false;
|
||||
}
|
||||
|
||||
if (res.getLimit == infiniteNum) {
|
||||
infiniteGetLimit.value = false;
|
||||
}
|
||||
|
||||
form.value = res;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
shopInfo.value = uni.getStorageSync('shopInfo');
|
||||
if (options.id) {
|
||||
id.value = options.id;
|
||||
uni.setNavigationBarTitle({
|
||||
title: '编辑消费赠券'
|
||||
});
|
||||
getConsumerCouponByIdAjax();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -46,4 +323,21 @@ page {
|
||||
.container {
|
||||
padding: 28upx;
|
||||
}
|
||||
.center {
|
||||
display: flex;
|
||||
gap: 28upx;
|
||||
align-items: center;
|
||||
.ipt {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
.tips {
|
||||
font-size: 28upx;
|
||||
color: #999;
|
||||
}
|
||||
.column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20upx;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</u-input>
|
||||
</u-form-item>
|
||||
<u-form-item label="可用商品" prop="foods">
|
||||
<my-select-goods v-model="form.foods" v-model:foodType="form.goodsType"></my-select-goods>
|
||||
<my-select-goods v-model="form.foods" v-model:foodType="form.goodsType" @foodTypeChange="goodsTypeChange"></my-select-goods>
|
||||
</u-form-item>
|
||||
<u-form-item label="使用规则">
|
||||
<u-radio-group v-model="form.useRule" placement="column">
|
||||
@@ -55,14 +55,14 @@
|
||||
</u-input>
|
||||
</u-form-item>
|
||||
<u-form-item label="可抵扣最大金额" prop="maxDiscountAmount">
|
||||
<u-input placeholder="请输入" v-model="form.maxDiscountAmount" :maxlength="8" input-align="center" @change="maxDiscountAmountInput">
|
||||
<template v-slot:prefix>可用</template>
|
||||
<u-input placeholder="请输入内容" v-model="form.maxDiscountAmount" :maxlength="8" input-align="center" @change="maxDiscountAmountInput">
|
||||
<template v-slot:prefix>元</template>
|
||||
</u-input>
|
||||
</u-form-item>
|
||||
</view>
|
||||
<view v-if="form.couponType == 4 || form.couponType == 6">
|
||||
<u-form-item label="可用商品" prop="foods">
|
||||
<my-select-goods v-model="form.foods" v-model:foodType="form.goodsType"></my-select-goods>
|
||||
<my-select-goods v-model="form.foods" v-model:foodType="form.goodsType" @foodTypeChange="goodsTypeChange"></my-select-goods>
|
||||
</u-form-item>
|
||||
<u-form-item label="使用规则">
|
||||
<u-radio-group v-model="form.useRule" placement="column">
|
||||
@@ -76,7 +76,7 @@
|
||||
<my-shop-select-w v-model:useType="form.useShopType" v-model:selShops="form.useShops"></my-shop-select-w>
|
||||
</u-form-item>
|
||||
<u-form-item label="可用商品" v-if="form.couponType != 2 && form.couponType != 4 && form.couponType != 6" prop="foods">
|
||||
<my-select-goods v-model="form.foods" v-model:foodType="form.goodsType"></my-select-goods>
|
||||
<my-select-goods v-model="form.foods" v-model:foodType="form.goodsType" @foodTypeChange="goodsTypeChange"></my-select-goods>
|
||||
</u-form-item>
|
||||
<u-form-item label="可使用类型" prop="useType">
|
||||
<my-dine-types v-model="form.useType"></my-dine-types>
|
||||
@@ -193,7 +193,7 @@
|
||||
</u-form-item>
|
||||
</view>
|
||||
</u-form>
|
||||
<my-footer-btn @confirm="submitHandle" confirmText="保存" v-if="(shopInfo.isHeadShop && shopInfo.shopType != 'only') || !form.syncId"></my-footer-btn>
|
||||
<my-footer-btn @confirm="submitHandle" v-if="(shopInfo.isHeadShop && shopInfo.shopType != 'only') || !form.syncId"></my-footer-btn>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -253,6 +253,13 @@ const form = ref({
|
||||
otherCouponShare: 1 // 与其它优惠共享:0-否,1-是
|
||||
});
|
||||
|
||||
function goodsTypeChange(e) {
|
||||
console.log('goodsTypeChange===', e);
|
||||
if (e == 1) {
|
||||
form.value.foods = '';
|
||||
}
|
||||
}
|
||||
|
||||
const rules = ref({
|
||||
title: [
|
||||
{
|
||||
@@ -698,6 +705,8 @@ async function couponDetailAjax() {
|
||||
|
||||
if (form.value.useLimit == infiniteNum) {
|
||||
infiniteUseLimit.value = true;
|
||||
} else {
|
||||
infiniteUseLimit.value = false;
|
||||
}
|
||||
|
||||
console.log('最终获取到的form', form.value);
|
||||
|
||||
311
pageMarket/exchangeCoupon/getDetail.vue
Normal file
311
pageMarket/exchangeCoupon/getDetail.vue
Normal file
@@ -0,0 +1,311 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="search-header-wrap">
|
||||
<view class="search-header">
|
||||
<div class="row">
|
||||
<view class="ipt" @click="showStatusSheet = true">
|
||||
<u-input suffix-icon="arrow-down" readonly placeholder="全部" :customStyle="inputStyle" v-model="statusValue"></u-input>
|
||||
</view>
|
||||
<view class="ipt" style="flex: 1.5" @click="showTime = true">
|
||||
<u-input suffix-icon="arrow-right" readonly placeholder="请选择日期" :customStyle="inputStyle" v-model="timeVlaue"></u-input>
|
||||
</view>
|
||||
</div>
|
||||
<div class="row" style="margin-top: 10px">
|
||||
<view class="ipt">
|
||||
<u-input prefix-icon="search" shape="circle" placeholder="用户昵称/用户ID" :customStyle="inputStyle"></u-input>
|
||||
</view>
|
||||
<div class="btn" style="width: 80px">
|
||||
<u-button shape="circle" type="primary" :customStyle="inputStyle" @click="resetGetTabdleData">搜索</u-button>
|
||||
</div>
|
||||
</div>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list">
|
||||
<view class="item" v-for="item in tableData.list" :key="item.id">
|
||||
<view class="header">
|
||||
<view class="user-info">
|
||||
<u-image :src="item.headImg" width="40px" height="40px"></u-image>
|
||||
<view class="info">
|
||||
<view class="id">
|
||||
<text class="t">ID:{{ item.id }}</text>
|
||||
</view>
|
||||
<view class="name">
|
||||
<text class="t">{{ item.nickName }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="status">
|
||||
<u-tag :type="getStatus(item.status).type">{{ getStatus(item.status).label }}</u-tag>
|
||||
</view>
|
||||
</view>
|
||||
<view class="content">
|
||||
<view class="row">
|
||||
<text class="title">领取时间</text>
|
||||
<text class="b">领取时间</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="title">使用时间</text>
|
||||
<text class="b">-</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="title">获得来源</text>
|
||||
<text class="b">-</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="title">使用门店</text>
|
||||
<text class="b">-</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="title">优惠金额</text>
|
||||
<text class="b">-</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- <view class="footer-wrap">
|
||||
<view class="btn">
|
||||
<u-button shape="circle">删除</u-button>
|
||||
</view>
|
||||
</view> -->
|
||||
</view>
|
||||
<u-loadmore :status="tableData.listStatus"></u-loadmore>
|
||||
</view>
|
||||
<u-action-sheet
|
||||
title="领取状态"
|
||||
:show="showStatusSheet"
|
||||
:actions="statusSheetList"
|
||||
closeOnClickOverlay
|
||||
@close="showStatusSheet = false"
|
||||
:round="20"
|
||||
safeAreaInsetBottom
|
||||
cancelText="取消"
|
||||
@select="selectStatus"
|
||||
></u-action-sheet>
|
||||
<u-datetime-picker
|
||||
title="开始时间"
|
||||
:round="20"
|
||||
:show="showTime"
|
||||
:minDate="minDate"
|
||||
:maxDate="maxDate"
|
||||
mode="date"
|
||||
closeOnClickOverlay
|
||||
@cancel="showTime = false"
|
||||
@close="showTime = false"
|
||||
@confirm="selectTime"
|
||||
></u-datetime-picker>
|
||||
<u-datetime-picker
|
||||
title="结束时间"
|
||||
:round="20"
|
||||
:show="showTime2"
|
||||
:minDate="dayjs(tableData.startTime || new Date()).valueOf()"
|
||||
:maxDate="maxDate"
|
||||
mode="date"
|
||||
closeOnClickOverlay
|
||||
@cancel="showTime2 = false"
|
||||
@close="showTime2 = false"
|
||||
@confirm="selectTime2"
|
||||
></u-datetime-picker>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import dayjs from 'dayjs';
|
||||
import { reactive, ref } from 'vue';
|
||||
import { onLoad, onReachBottom } from '@dcloudio/uni-app';
|
||||
import { couponGetRecord } from '@/http/api/market/index.js';
|
||||
|
||||
const inputStyle = {
|
||||
height: '35px'
|
||||
};
|
||||
|
||||
const shopInfo = ref({});
|
||||
|
||||
const statusValue = ref('');
|
||||
const showStatusSheet = ref(false);
|
||||
const statusSheetList = ref([
|
||||
{
|
||||
value: '',
|
||||
name: '全部'
|
||||
},
|
||||
{
|
||||
value: 0,
|
||||
name: '未使用',
|
||||
type: 'warning'
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
name: '已使用',
|
||||
type: 'primary'
|
||||
},
|
||||
{
|
||||
value: 2,
|
||||
name: '已过期',
|
||||
type: 'error'
|
||||
}
|
||||
]);
|
||||
|
||||
// 获取状态参数
|
||||
function getStatus(val) {
|
||||
let obj = statusSheetList.value.find(val.value == val);
|
||||
if (obj) {
|
||||
return obj;
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
// 选择状态
|
||||
function selectStatus(e) {
|
||||
console.log(e);
|
||||
if (e.value === '') {
|
||||
statusValue.value = '';
|
||||
} else {
|
||||
statusValue.value = e.name;
|
||||
}
|
||||
tableData.status = e.value;
|
||||
resetGetTabdleData();
|
||||
}
|
||||
|
||||
const showTime = ref(false);
|
||||
const minDate = ref(dayjs().add(-3, 'year').valueOf());
|
||||
const maxDate = ref(dayjs().valueOf());
|
||||
|
||||
// 选择日期范围
|
||||
const timeVlaue = ref('');
|
||||
function selectTime(e) {
|
||||
tableData.startTime = dayjs(e.value).format('YYYY-MM-DD 00:00:00');
|
||||
showTime.value = false;
|
||||
showTime2.value = true;
|
||||
}
|
||||
|
||||
const showTime2 = ref(false);
|
||||
function selectTime2(e) {
|
||||
tableData.endTime = dayjs(e.value).format('YYYY-MM-DD 23:59:59');
|
||||
showTime2.value = false;
|
||||
timeVlaue.value = `${tableData.startTime} - ${tableData.endTime}`;
|
||||
resetGetTabdleData();
|
||||
}
|
||||
|
||||
// 重置获取列表数据
|
||||
function resetGetTabdleData() {
|
||||
tableData.page = 1;
|
||||
tableData.listStatus = 'loading';
|
||||
couponGetRecordAjax();
|
||||
}
|
||||
|
||||
const tableData = reactive({
|
||||
couponId: '',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
status: '',
|
||||
listStatus: 'loading',
|
||||
page: 1,
|
||||
size: 10,
|
||||
list: []
|
||||
});
|
||||
|
||||
onReachBottom(() => {
|
||||
if (tableData.listStatus != 'nomore') {
|
||||
tableData.page++;
|
||||
couponGetRecordAjax();
|
||||
}
|
||||
});
|
||||
|
||||
// 获取已领取优惠券详情列表
|
||||
async function couponGetRecordAjax() {
|
||||
try {
|
||||
const res = await couponGetRecord({
|
||||
startTime: tableData.startTime,
|
||||
endTime: tableData.endTime,
|
||||
shopId: shopInfo.value.id,
|
||||
userId: '',
|
||||
couponId: tableData.couponId,
|
||||
source: '',
|
||||
status: tableData.status,
|
||||
page: tableData.page,
|
||||
size: tableData.size
|
||||
});
|
||||
|
||||
if (tableData.page == 1) {
|
||||
tableData.list = res.records;
|
||||
} else {
|
||||
tableData.list.push(...res.records);
|
||||
}
|
||||
|
||||
if (res.pageNumber >= res.totalPage) {
|
||||
tableData.listStatus = 'nomore';
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
shopInfo.value = uni.getStorageSync('shopInfo');
|
||||
tableData.couponId = options.couponId;
|
||||
couponGetRecordAjax();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
page {
|
||||
background-color: #f7f7f7;
|
||||
}
|
||||
</style>
|
||||
<style scoped lang="scss">
|
||||
.search-header-wrap {
|
||||
$height: 100px;
|
||||
width: 100%;
|
||||
height: $height;
|
||||
.search-header {
|
||||
width: 100%;
|
||||
height: $height;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
background-color: #fff;
|
||||
padding: 10px 14px;
|
||||
.row {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
}
|
||||
.ipt {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
.list {
|
||||
padding: 28upx;
|
||||
.item {
|
||||
padding: 28upx;
|
||||
border-radius: 20upx;
|
||||
background-color: #fff;
|
||||
&:not(:first-child) {
|
||||
margin-top: 28upx;
|
||||
}
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
.user-info {
|
||||
display: flex;
|
||||
.info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
}
|
||||
.content {
|
||||
padding: 28upx;
|
||||
.row {
|
||||
}
|
||||
}
|
||||
.footer-wrap {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
.btn {
|
||||
width: 200upx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,8 +2,15 @@
|
||||
<view class="container">
|
||||
<view class="header-wrap">
|
||||
<view class="fixed-header-wrap">
|
||||
<scroll-view scroll-x direction="horizontal" class="tabs-wrap">
|
||||
<view class="item" :class="{ active: couponType == item.value }" v-for="item in emunList.couponTypes" :key="item.value" @click="changeType(item.value)">
|
||||
<scroll-view scroll-x direction="horizontal" class="tabs-wrap" :scroll-left="scrollLeft" scroll-with-animation>
|
||||
<view
|
||||
class="item"
|
||||
:class="{ active: couponType == item.value }"
|
||||
v-for="(item, index) in emunList.couponTypes"
|
||||
:key="index"
|
||||
:data-index="index"
|
||||
@click="changeType(item.value, index)"
|
||||
>
|
||||
<div class="item-flex">
|
||||
<text class="t">{{ item.label }}</text>
|
||||
</div>
|
||||
@@ -95,18 +102,69 @@
|
||||
|
||||
<script setup>
|
||||
import dayjs from 'dayjs';
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ref, reactive, nextTick, getCurrentInstance } from 'vue';
|
||||
import go from '@/commons/utils/go.js';
|
||||
import { couponPage, couponDel } from '@/http/api/market/index.js';
|
||||
import { couponPage, couponDel, getConsumerCouponPage, deleteConsumerCoupon } from '@/http/api/market/index.js';
|
||||
import { onLoad, onShow, onReachBottom } from '@dcloudio/uni-app';
|
||||
import { getEmunListLabel, emunList } from '../utils/couponUtils.js';
|
||||
|
||||
const instance = getCurrentInstance();
|
||||
const couponType = ref(1); // 当前选中的优惠券类型
|
||||
const scrollLeft = ref(0); // scroll-view的滚动距离
|
||||
|
||||
// 切换类型
|
||||
function changeType(type) {
|
||||
function changeType(type, index) {
|
||||
couponType.value = type;
|
||||
resetGetData();
|
||||
calculateCenterScroll(index);
|
||||
}
|
||||
|
||||
// item居中
|
||||
const calculateCenterScroll = (activeIndex) => {
|
||||
// 1. 查询ScrollView的可视宽度(全局查询,无需ref)
|
||||
uni.createSelectorQuery()
|
||||
.select('.tabs-wrap')
|
||||
.boundingClientRect((scrollViewRect) => {
|
||||
if (!scrollViewRect) return;
|
||||
const viewWidth = scrollViewRect.width; // ScrollView可视宽度(px)
|
||||
const viewHalfWidth = viewWidth / 2; // ScrollView中心位置(px)
|
||||
|
||||
// 2. 查询所有Tab项的DOM信息(计算选中项左侧总宽度)
|
||||
uni.createSelectorQuery()
|
||||
.selectAll('.item')
|
||||
.boundingClientRect((tabItemsRect) => {
|
||||
if (!tabItemsRect || tabItemsRect.length === 0) return;
|
||||
|
||||
// 3. 计算选中项左侧所有Tab的宽度总和
|
||||
let leftTotalWidth = 0;
|
||||
for (let i = 0; i < activeIndex; i++) {
|
||||
leftTotalWidth += tabItemsRect[i].width; // 累加左侧Tab宽度(px)
|
||||
leftTotalWidth += 28 * (uni.getSystemInfoSync().windowWidth / 750); // 累加左侧Tab的margin-left(28rpx转px)
|
||||
}
|
||||
|
||||
// 4. 获取选中项自身的宽度和位置
|
||||
const activeItemRect = tabItemsRect[activeIndex];
|
||||
const itemHalfWidth = activeItemRect.width / 2; // 选中项中心位置(px)
|
||||
|
||||
// 5. 计算最终滚动距离(核心公式)
|
||||
let targetScrollLeft = leftTotalWidth + itemHalfWidth - viewHalfWidth;
|
||||
|
||||
// 6. 边界处理:不小于0,不超过最大滚动距离
|
||||
uni.createSelectorQuery()
|
||||
.select('.tabs-wrap')
|
||||
.scrollOffset((scrollOffset) => {
|
||||
const maxScrollLeft = scrollOffset.scrollWidth - viewWidth; // 最大滚动距离
|
||||
targetScrollLeft = Math.max(0, Math.min(targetScrollLeft, maxScrollLeft));
|
||||
scrollLeft.value = targetScrollLeft; // 赋值滚动距离
|
||||
console.log('最终滚动距离:', targetScrollLeft);
|
||||
})
|
||||
.exec();
|
||||
})
|
||||
.exec();
|
||||
})
|
||||
.exec();
|
||||
};
|
||||
|
||||
// 搜索
|
||||
function searchHandle() {
|
||||
resetGetData();
|
||||
@@ -133,26 +191,32 @@ function deleteHandle(item) {
|
||||
console.log('del', item);
|
||||
uni.showModal({
|
||||
title: '注意',
|
||||
content: `确定要删除${item.title}优惠券吗?`,
|
||||
content: `确定要删除${item.title || '该'}优惠券吗?`,
|
||||
success: async (res) => {
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '删除中...',
|
||||
mask: true
|
||||
});
|
||||
await couponDel(item.id);
|
||||
uni.showToast({
|
||||
title: '已删除',
|
||||
icon: 'none'
|
||||
});
|
||||
let index = tableData.list.findIndex((val) => val.id == item.id);
|
||||
tableData.list.splice(index, 1);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
if (res.confirm) {
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '删除中...',
|
||||
mask: true
|
||||
});
|
||||
if (couponType.value == 5) {
|
||||
await deleteConsumerCoupon(item.id);
|
||||
} else {
|
||||
await couponDel(item.id);
|
||||
}
|
||||
uni.showToast({
|
||||
title: '已删除',
|
||||
icon: 'none'
|
||||
});
|
||||
let index = tableData.list.findIndex((val) => val.id == item.id);
|
||||
tableData.list.splice(index, 1);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 500);
|
||||
}
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -160,14 +224,20 @@ function deleteHandle(item) {
|
||||
// 编辑
|
||||
function editorHandle(item) {
|
||||
console.log('editor', item);
|
||||
go.to('PAGES_ADD_COUPON', {
|
||||
couponType: item.couponType,
|
||||
id: item.id
|
||||
});
|
||||
if (couponType.value == 5) {
|
||||
go.to('PAGES_ADD_CONSUME_COUPON', {
|
||||
couponType: item.couponType,
|
||||
id: item.id
|
||||
});
|
||||
} else {
|
||||
go.to('PAGES_ADD_COUPON', {
|
||||
couponType: item.couponType,
|
||||
id: item.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 获取优惠券
|
||||
const couponType = ref(1);
|
||||
const tableData = reactive({
|
||||
query: '',
|
||||
status: 'loading',
|
||||
@@ -178,12 +248,22 @@ const tableData = reactive({
|
||||
async function couponPageAjax() {
|
||||
try {
|
||||
tableData.status = 'loading';
|
||||
const res = await couponPage({
|
||||
let res = null;
|
||||
let params = {
|
||||
couponType: couponType.value,
|
||||
title: tableData.query,
|
||||
page: tableData.page,
|
||||
size: tableData.size
|
||||
});
|
||||
};
|
||||
|
||||
if (couponType.value == 5) {
|
||||
res = await getConsumerCouponPage(params);
|
||||
res.records.map((item) => {
|
||||
item.couponType = 5;
|
||||
});
|
||||
} else {
|
||||
res = await couponPage(params);
|
||||
}
|
||||
|
||||
if (tableData.page == 1) {
|
||||
tableData.list = res.records;
|
||||
@@ -210,7 +290,13 @@ onShow(() => {
|
||||
});
|
||||
|
||||
onLoad((options) => {
|
||||
couponType.value = options.coupon_type;
|
||||
couponType.value = options.couponType;
|
||||
const index = emunList.couponTypes.findIndex((item) => item.value == couponType.value);
|
||||
setTimeout(() => {
|
||||
if (index !== -1) {
|
||||
calculateCenterScroll(index);
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -238,7 +238,6 @@ function submitHandle() {
|
||||
data.useStartTime = convertTimeFormat(form.value.useStartTime);
|
||||
data.useEndTime = convertTimeFormat(form.value.useEndTime);
|
||||
}
|
||||
|
||||
uni.showLoading({
|
||||
title: '提交中...',
|
||||
mask: true
|
||||
|
||||
@@ -16,15 +16,14 @@ export const emunList = {
|
||||
label: '第二件半价券',
|
||||
value: 4,
|
||||
},
|
||||
{
|
||||
label: '消费送券',
|
||||
value: 5,
|
||||
},
|
||||
|
||||
{
|
||||
label: '买一送一券',
|
||||
value: 6,
|
||||
},
|
||||
{
|
||||
label: '消费送券',
|
||||
value: 5,
|
||||
},
|
||||
{
|
||||
label: '固定价格券',
|
||||
value: 7,
|
||||
|
||||
Reference in New Issue
Block a user