完成优惠券页面

This commit is contained in:
gyq 2025-11-21 16:03:04 +08:00
parent e6212251e3
commit df8a700aec
14 changed files with 1069 additions and 64 deletions

View File

@ -184,11 +184,14 @@ onLaunch(() => {
width: 180upx;
font-size: 28upx;
color: #666;
display: flex;
justify-content: flex-end;
}
.info {
flex: 1;
font-size: 28upx;
color: #333;
padding-left: 28upx;
}
}
}
@ -201,5 +204,8 @@ onLaunch(() => {
border-radius: 20upx;
padding: 0 28upx 14upx;
margin-bottom: 28upx;
:deep(.u-form-item__body__left__content__label.data-v-b4fd400b) {
font-weight: bold;
}
}
</style>

View File

@ -2,7 +2,8 @@
<template>
<view class="item">
<view class="header">
<text class="title">{{ item.title }}</text>
<text class="title" v-if="item.couponType == 5">消费赠券</text>
<text v-else>{{ item.title }}</text>
<text class="id">ID:83713</text>
</view>
<view class="content">
@ -16,14 +17,23 @@
</text>
<text class="title">总发放</text>
</view>
<view class="item">
<view class="item" v-if="item.couponType == 5">
<text class="info">{{ item.giftNum }}</text>
<text class="title">已领取</text>
</view>
<view class="item">
<text class="info">{{ item.useNum }}</text>
<text class="title">已使用</text>
<view class="title">
<text class="t">已赠送</text>
<text class="l" @click="toDetail(item)">详情</text>
</view>
</view>
<template v-else>
<view class="item">
<text class="info">{{ item.giftNum }}</text>
<text class="title">已领取</text>
</view>
<view class="item">
<text class="info">{{ item.useNum }}</text>
<text class="title">已使用</text>
</view>
</template>
<view class="item">
<text class="info">
<template v-if="item.giveNum == -10086">无限</template>
@ -44,6 +54,8 @@
</template>
<script setup>
import go from '@/commons/utils/go.js';
const props = defineProps({
item: {
type: Object,
@ -52,6 +64,11 @@ const props = defineProps({
});
const emits = defineEmits(['delete', 'editor']);
//
function toDetail(item) {
go.to('PAGES_COUPON_GET_DETAIL', { couponId: item.couponGiftList[0].couponId });
}
</script>
<style scoped lang="scss">
@ -100,6 +117,16 @@ const emits = defineEmits(['delete', 'editor']);
.title {
font-size: 24upx;
color: #999;
display: flex;
gap: 28upx;
.t {
font-size: 24upx;
color: #999;
}
.l {
font-size: 24upx;
color: #318afe;
}
}
}
}

View File

@ -17,7 +17,7 @@ import { ref, onMounted, nextTick, getCurrentInstance } from 'vue';
const props = defineProps({
confirmText: {
type: String,
default: '添加'
default: '保存'
},
showCancel: {
type: Boolean,

View File

@ -0,0 +1,190 @@
<template>
<view class="">
<view @click="show = true">
<slot v-if="$slots.default"></slot>
<view v-else class="choose-goods u-flex u-row-between">
<text class="color-999" v-if="!modelValue">请选择商品</text>
<text class="color-333 u-m-r-32 u-line-1" v-else>{{ goodsName }}</text>
<up-icon size="14" name="arrow-down"></up-icon>
</view>
</view>
<up-popup :show="show" :round="20" mode="bottom">
<view class="">
<view class="top u-flex u-row-between">
<text class="font-bold u-font-32 color-333">{{ title }}</text>
<up-icon size="18" name="close" @click="show = false"></up-icon>
</view>
<scroll-view :scroll-y="true" style="max-height: 50vh" @scroll="scroll" :scroll-top="scrollTop">
<view v-for="(item, index) in list" :key="index" class="item" @click="itemClick(item)" :class="[selGoods && selGoods.id == item.id ? 'selected' : '']">
<view class="u-flex u-row-between">
<view class="u-flex gap-20">
<!-- <view class="u-flex" @click.stop="preview(item)">
<up-image :src="item.coverImg" width="80rpx" height="80rpx"></up-image>
</view> -->
<text class="u-font-32 color-333">{{ item.title }}</text>
</view>
<!-- <text class="u-font-32 color-red u-p-l-30">¥{{ item.lowPrice }}</text> -->
</view>
</view>
</scroll-view>
<view class="bottom">
<view class="btn cancel" @click="close">{{ cancelText }}</view>
<view class="btn success" @click="confirm">{{ confirmText }}</view>
</view>
</view>
</up-popup>
</view>
</template>
<script setup>
import { ref, onMounted, watch } from 'vue';
import { couponPage } from '@/http/api/market/index.js';
const show = ref(false);
const modelValue = defineModel({
type: String,
default: ''
});
const goodsName = defineModel('goodsName', {
type: String,
default: ''
});
const props = defineProps({
title: {
type: String,
default: '选择优惠券'
},
confirmText: {
type: String,
default: '确认'
},
cancelText: {
type: String,
default: '取消'
}
});
const selGoods = ref('');
function itemClick(item) {
if (selGoods.value && selGoods.value.id == item.id) {
selGoods.value = '';
return;
}
selGoods.value = item;
}
const list = ref([]);
const scrollTop = ref(0);
function scroll(e) {
scrollTop.value = e.detail.scrollTop;
}
function preview(item) {
uni.previewImage({
urls: item.images || [item.coverImg]
});
}
watch(
() => modelValue.value,
(newVal, oldVal) => {
console.log(newVal, oldVal);
selGoods.value = list.value.find((item) => item.id == newVal);
console.log(selGoods.value);
if (selGoods.value) {
goodsName.value = selGoods.value.title;
}
}
);
watch(
() => list.value.length,
(newVal, oldVal) => {
selGoods.value = list.value.find((item) => item.id == modelValue.value);
console.log(selGoods.value);
if (selGoods.value) {
modelValue.value = selGoods.value.id;
goodsName.value = selGoods.value.title;
}
}
);
function close() {
show.value = false;
}
function confirm() {
if (!selGoods.value) {
uni.showToast({
title: '请选择优惠券',
icon: 'none'
});
return;
}
modelValue.value = selGoods.value.id;
show.value = false;
}
const emits = defineEmits(['load']);
onMounted(() => {
couponPage({ page: 1, size: 500 }).then((res) => {
list.value = res.records;
emits('load', list.value);
});
});
</script>
<style lang="scss">
.popup-content {
background: #fff;
width: 640rpx;
border-radius: 18rpx;
}
.top {
padding: 40rpx 48rpx;
border-bottom: 1px solid #d9d9d9;
}
.bottom {
padding: 48rpx 52rpx;
display: flex;
justify-content: space-between;
border-top: 1px solid #d9d9d9;
gap: 50rpx;
.btn {
flex: 1;
text-align: center;
padding: 18rpx 60rpx;
border-radius: 100rpx;
font-size: 32rpx;
border: 2rpx solid transparent;
&.success {
background-color: $my-main-color;
color: #fff;
}
&.cancel {
border-color: #d9d9d9;
box-shadow: 0 4rpx 0 0 #00000005;
}
}
}
.item {
padding: 10rpx 30rpx;
border: 1px solid #d9d9d9;
margin: 10rpx;
border-radius: 8rpx;
transition: all 0.3s ease-in-out;
box-shadow: 0 0 10px transparent;
&.selected {
border-color: $my-main-color;
box-shadow: 0 0 10px $my-main-color;
}
}
.choose-goods {
display: flex;
padding: 24rpx;
align-items: center;
border-radius: 8rpx;
border: 2rpx solid #d9d9d9;
background: #fff;
font-size: 28rpx;
font-weight: 400;
}
</style>

View File

@ -1,7 +1,7 @@
<template>
<view class="my-select-goods">
<view class="radio-wrap">
<u-radio-group v-model="foodType">
<u-radio-group v-model="foodType" @change="foodTypeChange">
<u-radio v-for="item in radioList" :key="item.value" :label="item.label" :name="item.value" :customStyle="customStyle"></u-radio>
</u-radio-group>
</view>
@ -90,6 +90,12 @@ const radioList = ref([
}
]);
const emits = defineEmits('foodTypeChange');
function foodTypeChange(e) {
console.log('foodTypeChange', e);
emits('foodTypeChange', e);
}
const foodType = defineModel('foodType', {
type: [Number, String],
default: 1

View File

@ -63,7 +63,7 @@ export function couponAdd(data) {
/**
* 优惠券-删除
* @param {Object} params
* @param id
*/
export function couponDel(id) {
return request({
@ -74,11 +74,82 @@ export function couponDel(id) {
/**
* 优惠券-详情
* @param {Object} params
* @param id
*/
export function couponDetail(id) {
return request({
url: `${urlType}/admin/coupon/${id}`,
method: "GET"
});
}
/**
* 消费赠券-添加
* @param {Object} data
*/
export function couponPost(data) {
return request({
url: `${urlType}/admin/consumerCoupon/addConsumerCoupon`,
method: 'post',
data
});
}
/**
* 消费赠券-更新
* @param {Object} data
*/
export function updateConsumerCouponById(data) {
return request({
url: `${urlType}/admin/consumerCoupon/updateConsumerCouponById`,
method: 'put',
data
});
}
/**
* 消费赠券-分页
* @param {Object} data
*/
export function getConsumerCouponPage(params) {
return request({
url: `${urlType}/admin/consumerCoupon/getConsumerCouponPage`,
method: 'get',
params
});
}
/**
* 消费赠券-删除
* @param {Object} data
*/
export function deleteConsumerCoupon(id) {
return request({
url: `${urlType}/admin/consumerCoupon/deleteConsumerCoupon?id=${id}`,
method: 'DELETE',
});
}
/**
* 消费赠券-详情
* @param {Object} data
*/
export function getConsumerCouponById(params) {
return request({
url: `${urlType}/admin/consumerCoupon/getConsumerCouponById`,
method: 'get',
params
});
}
/**
* 优惠券列表/已领取详情
* @param {Object} data
*/
export function couponGetRecord(params) {
return request({
url: `${urlType}/admin/coupon/record`,
method: 'get',
params
});
}

View File

@ -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>

View File

@ -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);

View 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>

View File

@ -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. ScrollViewref
uni.createSelectorQuery()
.select('.tabs-wrap')
.boundingClientRect((scrollViewRect) => {
if (!scrollViewRect) return;
const viewWidth = scrollViewRect.width; // ScrollViewpx
const viewHalfWidth = viewWidth / 2; // ScrollViewpx
// 2. TabDOM
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; // Tabpx
leftTotalWidth += 28 * (uni.getSystemInfoSync().windowWidth / 750); // Tabmargin-left28rpxpx
}
// 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>

View File

@ -238,7 +238,6 @@ function submitHandle() {
data.useStartTime = convertTimeFormat(form.value.useStartTime);
data.useEndTime = convertTimeFormat(form.value.useEndTime);
}
uni.showLoading({
title: '提交中...',
mask: true

View File

@ -16,15 +16,14 @@ export const emunList = {
label: '第二件半价券',
value: 4,
},
{
label: '消费送券',
value: 5,
},
{
label: '买一送一券',
value: 6,
},
{
label: '消费送券',
value: 5,
},
{
label: '固定价格券',
value: 7,

View File

@ -649,7 +649,14 @@
"pageId": "PAGES_EXCHANGE_COUPON",
"path": "exchangeCoupon/index",
"style": {
"navigationBarTitleText": "优惠券"
"navigationBarTitleText": "优惠券管理"
}
},
{
"pageId": "PAGES_COUPON_GET_DETAIL",
"path": "exchangeCoupon/getDetail",
"style": {
"navigationBarTitleText": "领取详情"
}
},
{

View File

@ -58,7 +58,7 @@ const menuList = ref([
{
title: '新客立减',
icon: '',
pageUrl: 'PAGES_MARKET_NEW_USER_DISCOUNT',
pageUrl: 'PAGES_ORDER_INDEX',
intro: '首单下单减免金额'
},
{
@ -100,7 +100,7 @@ const menuList = ref([
{
title: '点餐智能推荐',
icon: '',
pageUrl: 'PAGES_MARKET_ORDER_RECOMMENDATION',
pageUrl: '',
intro: '进入点单页X秒未点自动推荐商品此推荐设置启用即生效'
},
{
@ -150,7 +150,7 @@ const menuList = ref([
title: '商品兑换券',
intro: '批量设置商品折扣',
query: {
coupon_type: 2
couponType: 2
}
}
]