优化订单优惠券详情显示问题

This commit is contained in:
gyq
2025-09-29 17:02:16 +08:00
parent fd86132f5d
commit a05d14e2b4

View File

@@ -17,17 +17,17 @@
</view> --> </view> -->
<view class="status-wrap"> <view class="status-wrap">
<view class="item" :class="{ active: querForm.statusActiveIndex == 0 }" @click="tabChange(0)"> <view class="item" :class="{ active: querForm.statusActiveIndex == 0 }" @click="tabChange(0)">
<text class="t">商品兑换券 {{returnSelNumber(0)}}</text> <text class="t">商品兑换券 {{ returnSelNumber(0) }}</text>
</view> </view>
<view class="item" :class="{ active: querForm.statusActiveIndex == 1 }" @click="tabChange(1)"> <view class="item" :class="{ active: querForm.statusActiveIndex == 1 }" @click="tabChange(1)">
<text class="t">折扣优惠券{{returnSelNumber(1)}}</text> <text class="t">折扣优惠券{{ returnSelNumber(1) }}</text>
</view> </view>
<view class="icon-wrap" <view class="icon-wrap" :style="{ width: `${100 / statusList.length}%`, left: `${(100 / statusList.length) * querForm.statusActiveIndex}%` }">
:style="{ width: `${100 / statusList.length}%`, left: `${(100 / statusList.length) * querForm.statusActiveIndex}%` }"> <image
<image class="active-icon" class="active-icon"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAMCAYAAAB4MH11AAACKUlEQVR4AaRTS2sTURT+MpkxUzNtRpuYpBsrqbgQH6BYRHGllloQN+5cuNeV6MKfoj9BwYUgIsXHRqE+SluliFLbBqmENJNMMpMm87qecw1NglJse+HMPeee833nce8oIgpFq7wsGt/fCb9eFrtdfmNd1L+9Jc4Vog6E4jcqqM0/R+3zNOwv09jtshdfSx7mDJwKqAMfIvAAEaFVWkLgWjvOEbVdtNa+Epf4wxmFUNTkfqiDGUkqogDu8icKiKS9nQ9jnR8fqM5AwuJJE/G9JhRF05E8dAqIKeDlrsyiWVxg9f+Fum+uzsFZmtnEGIVxKHsGIFn1bAF6ZlQ6I28D9uIrmYSrkodbfETgw6GubZo9Yzk0kR4Fc7IuE8QUFebJKSTSB/kM4UYd1scnKL18QInm4Vk/6W6qiNoOwpZDuoX2elFWXHrzELW5Z+RzJVbPHca+09doIKq0ZQLW+C44iWbm2ZQSNMqozj5F5f1jWCSVGd4fwerstYUXCOplGcsfxponJqHS7Nlm2UyAWAza0AFkzt1A6uhFqEYaoHsR9BLCpg2vukZVr5IU4dV+yU7oRikkTrHDMI9PIHPhJrhQ9Kxugs6hkkhi8Mh5DI9flyCep6ImOt7uxnF6dgypYxMy1hg7S0/yH3FdSL+mpbIw6CVwVSNX7yM/eQfZS7eQu3wb+St3MTJ1D2nq1iicgZbK9YN7rL866PH1qfGBIWj0v/Do4rrR59vK+A0AAP//GfTndQAAAAZJREFUAwCu+SjIaSGpLwAAAABJRU5ErkJggg=="> src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAMCAYAAAB4MH11AAACKUlEQVR4AaRTS2sTURT+MpkxUzNtRpuYpBsrqbgQH6BYRHGllloQN+5cuNeV6MKfoj9BwYUgIsXHRqE+SluliFLbBqmENJNMMpMm87qecw1NglJse+HMPeee833nce8oIgpFq7wsGt/fCb9eFrtdfmNd1L+9Jc4Vog6E4jcqqM0/R+3zNOwv09jtshdfSx7mDJwKqAMfIvAAEaFVWkLgWjvOEbVdtNa+Epf4wxmFUNTkfqiDGUkqogDu8icKiKS9nQ9jnR8fqM5AwuJJE/G9JhRF05E8dAqIKeDlrsyiWVxg9f+Fum+uzsFZmtnEGIVxKHsGIFn1bAF6ZlQ6I28D9uIrmYSrkodbfETgw6GubZo9Yzk0kR4Fc7IuE8QUFebJKSTSB/kM4UYd1scnKL18QInm4Vk/6W6qiNoOwpZDuoX2elFWXHrzELW5Z+RzJVbPHca+09doIKq0ZQLW+C44iWbm2ZQSNMqozj5F5f1jWCSVGd4fwerstYUXCOplGcsfxponJqHS7Nlm2UyAWAza0AFkzt1A6uhFqEYaoHsR9BLCpg2vukZVr5IU4dV+yU7oRikkTrHDMI9PIHPhJrhQ9Kxugs6hkkhi8Mh5DI9flyCep6ImOt7uxnF6dgypYxMy1hg7S0/yH3FdSL+mpbIw6CVwVSNX7yM/eQfZS7eQu3wb+St3MTJ1D2nq1iicgZbK9YN7rL866PH1qfGBIWj0v/Do4rrR59vK+A0AAP//GfTndQAAAAZJREFUAwCu+SjIaSGpLwAAAABJRU5ErkJggg=="
</image> ></image>
</view> </view>
</view> </view>
</view> </view>
@@ -37,7 +37,7 @@
</view> </view>
<view class="title-wrap"> <view class="title-wrap">
<text class="t">可用红包</text> <text class="t">可用红包</text>
<text class="n">{{list.canUseCoupons.length}}</text> <text class="n">{{ list.canUseCoupons.length }}</text>
</view> </view>
<view class="item" v-for="item in list.canUseCoupons" :key="item.id" @click="changeSelCoupon(item)"> <view class="item" v-for="item in list.canUseCoupons" :key="item.id" @click="changeSelCoupon(item)">
<view class="top"> <view class="top">
@@ -49,8 +49,7 @@
<text class="t">{{ item.name }}</text> <text class="t">{{ item.name }}</text>
</view> </view>
<view class="view time"> <view class="view time">
<text class="t">{{ dayjs(item.effectStartTime).format('YYYY.M.D') }} - <text class="t">{{ dayjs(item.effectStartTime).format('YYYY.M.D') }} - {{ dayjs(item.effectEndTime).format('YYYY.M.D') }}</text>
{{ dayjs(item.effectEndTime).format('YYYY.M.D') }}</text>
</view> </view>
</view> </view>
<view class="btn"> <view class="btn">
@@ -58,12 +57,10 @@
<up-icon name="checkmark-circle-fill" size="24" color="#FF3232"></up-icon> <up-icon name="checkmark-circle-fill" size="24" color="#FF3232"></up-icon>
</view> </view>
<view class="round" v-else></view> <view class="round" v-else></view>
</view> </view>
</view> </view>
<view class="btm"> <view class="btm">
<view class="left">1可适用门店{{ item.useShops }} <view class="left">1可适用门店{{ item.useShops }} 2可适用商品{{ item.foods }}3可使用类型{{ convertValuesToLabels(item.useType) }}</view>
2可适用商品{{ item.foods }}3可使用类型{{ convertValuesToLabels(item.useType) }}</view>
<view class="right" @click.stop="showDetailHandle(item)"> <view class="right" @click.stop="showDetailHandle(item)">
<text class="t">查看详情</text> <text class="t">查看详情</text>
</view> </view>
@@ -71,7 +68,7 @@
</view> </view>
<view class="title-wrap"> <view class="title-wrap">
<text class="t">不可用红包</text> <text class="t">不可用红包</text>
<text class="n">{{list.noCanUseCoupons.length}}</text> <text class="n">{{ list.noCanUseCoupons.length }}</text>
</view> </view>
<view class="item disabled" v-for="item in list.noCanUseCoupons" :key="item.id"> <view class="item disabled" v-for="item in list.noCanUseCoupons" :key="item.id">
<view class="top"> <view class="top">
@@ -83,8 +80,7 @@
<text class="t">{{ item.name }}</text> <text class="t">{{ item.name }}</text>
</view> </view>
<view class="view time"> <view class="view time">
<text class="t">{{ dayjs(item.effectStartTime).format('YYYY.M.D') }} - <text class="t">{{ dayjs(item.effectStartTime).format('YYYY.M.D') }} - {{ dayjs(item.effectEndTime).format('YYYY.M.D') }}</text>
{{ dayjs(item.effectEndTime).format('YYYY.M.D') }}</text>
</view> </view>
</view> </view>
<view class="btn"> <view class="btn">
@@ -98,7 +94,7 @@
</view> --> </view> -->
<view class="error"> <view class="error">
<text class="t t1">不可用原因</text> <text class="t t1">不可用原因</text>
<text class="t t2">{{returnNoUseRestrictions(item) }}</text> <text class="t t2">{{ returnNoUseRestrictions(item) }}</text>
</view> </view>
</view> </view>
</view> </view>
@@ -125,9 +121,7 @@
</view> </view>
<scroll-view class="popup-list" direction="vertical"> <scroll-view class="popup-list" direction="vertical">
<view class="ul"> <view class="ul">
<view class="li" v-for="(item, index) in selectListItemDetails" :key="index"> <view class="li" v-for="(item, index) in selectListItemDetails" :key="index">{{ index + 1 }}{{ item }}</view>
{{ index + 1 }}{{ item }}
</view>
</view> </view>
</scroll-view> </scroll-view>
</view> </view>
@@ -136,59 +130,38 @@
</template> </template>
<script setup> <script setup>
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { import { ref, reactive, onMounted, computed, watch } from 'vue';
ref, import { onLoad, onReady, onShow, onPageScroll, onReachBottom, onBackPress } from '@dcloudio/uni-app';
reactive, import { APIcouponfindByUserId, APIfindCoupon, getCouponShops } from '@/common/api/member.js';
onMounted, import { findCoupon } from '@/common/api/market/coupon.js';
computed, import couponIcon from '@/pages/user/components/coupon-icon.vue';
watch import * as UTILS from '@/utils/goods-utils.js';
} from 'vue'; import { useCartsStore } from '@/stores/carts.js';
import { const cartStore = useCartsStore();
onLoad,
onReady,
onShow,
onPageScroll,
onReachBottom,
onBackPress
} from '@dcloudio/uni-app';
import {
APIcouponfindByUserId,
APIfindCoupon,
getCouponShops
} from '@/common/api/member.js';
import {
findCoupon
} from '@/common/api/market/coupon.js';
import couponIcon from '@/pages/user/components/coupon-icon.vue';
import * as UTILS from '@/utils/goods-utils.js'
import {
useCartsStore
} from '@/stores/carts.js';
const cartStore = useCartsStore()
//返回不可用原因
//返回不可用原因 function returnNoUseRestrictions(item) {
function returnNoUseRestrictions(item) {
if (item.noUseRestrictions) { if (item.noUseRestrictions) {
return item.noUseRestrictions return item.noUseRestrictions;
} }
if (item.canuseResult) { if (item.canuseResult) {
return item.canuseResult.reason return item.canuseResult.reason;
}
return ''
} }
return '';
}
const show = ref(false); const show = ref(false);
const querForm = ref({ const querForm = ref({
searchValue: '', searchValue: '',
shopId: '', shopId: '',
shopName: '', shopName: '',
statusActiveIndex: 0 statusActiveIndex: 0
}); });
const statusList = ref([{ const statusList = ref([
{
value: 0, value: 0,
label: '商品兑换券', label: '商品兑换券',
bg: '#333333', bg: '#333333',
@@ -200,31 +173,48 @@
bg: '#F8F8F8', bg: '#F8F8F8',
color: '#999999' color: '#999999'
} }
]); ]);
const list = reactive({ const list = reactive({
page: 1, page: 1,
size: 10, size: 10,
status: 'nomore', status: 'nomore',
data: [], data: [],
noCanUseCoupons: [], noCanUseCoupons: [],
canUseCoupons: [] canUseCoupons: []
}); });
const showDetail = ref(false);
const selectListItem = ref('');
const selectListItemDetails = ref([]);
function showDetailHandle(item) {
const showDetail = ref(false);
const selectListItem = ref('');
const selectListItemDetails = ref([]);
function showDetailHandle(item) {
showDetail.value = true; showDetail.value = true;
// 1. 定义每个规则的独立描述仅“其他优惠券”需判断item.type
const ruleList = [];
// 规则1限时折扣同享始终显示
const discountRule = item.discountShare ? '与限时折扣同享' : '不与限时折扣同享';
ruleList.push(discountRule);
// 规则2会员价/会员折扣同享(始终显示)
const vipRule = item.vipPriceShare ? '与会员价/会员折扣同享' : '不与会员价/会员折扣同享';
ruleList.push(vipRule);
// 规则3其他优惠券同享仅item.type=2时显示
if (item.type === 2) {
const otherCouponRule = item.otherCouponShare ? '与其他优惠券同享' : '不与其他优惠券同享';
ruleList.push(otherCouponRule);
}
const shareRuleText = `${ruleList.join('、')}`;
selectListItemDetails.value = [ selectListItemDetails.value = [
`可适用门店:${item.useShops}`, `可适用门店:${item.useShops}`,
`可适用商品:${item.foods}`, `可适用商品:${item.foods}`,
`可使用类型:${convertValuesToLabels(item.useType)}`, `可使用类型:${convertValuesToLabels(item.useType)}`,
`可用时间段:${item.useTimeType == 'all' ? '全段时间可用' : `${item.useStartTime} - ${item.useEndTime}`}`, `可用时间段:${item.useTimeType == 'all' ? '全段时间可用' : `${item.useStartTime} - ${item.useEndTime}`}`,
`限量规则:每人限领${item.getLimit == -10086 ? `无限张` : `${item.getLimit}`},每日最多可使用${item.useLimit == -10086 ? `无限张` : `${item.useLimit}`}`, `限量规则:每人限领${item.getLimit == -10086 ? `无限张` : `${item.getLimit}`},每日最多可使用${item.useLimit == -10086 ? `无限张` : `${item.useLimit}`}`,
`同享规则:${item.vipPriceShare ? '与限时折扣同享、与会员价同享' : '不与限时折扣同享、与会员价同享'}`, `同享规则:${shareRuleText}`,
`其它说明:${item.ruleDetails || '无'}` `其它说明:${item.ruleDetails || '无'}`
]; ];
@@ -235,104 +225,103 @@
if (item.type == 3) { if (item.type == 3) {
selectListItemDetails.value.unshift(`最高抵扣${item.maxDiscountAmount}`); selectListItemDetails.value.unshift(`最高抵扣${item.maxDiscountAmount}`);
} }
} }
function returnSelNumber(index) { function returnSelNumber(index) {
if (index) { if (index) {
if (couponSel.value.id) { if (couponSel.value.id) {
return '(1)' return '(1)';
} else { } else {
return '(0)' return '(0)';
} }
} else { } else {
if (goodsCouponSel.value.id) { if (goodsCouponSel.value.id) {
return '(1)' return '(1)';
} else { } else {
return '(0)' return '(0)';
} }
} }
} }
// 搜索 // 搜索
function searchHandle() { function searchHandle() {
list.page = 1; list.page = 1;
list.status = 'nomore'; list.status = 'nomore';
getCouponList(); getCouponList();
} }
// 切换类型 // 切换类型
function tabChange(index) { function tabChange(index) {
querForm.value.statusActiveIndex = index; querForm.value.statusActiveIndex = index;
list.page = 1; list.page = 1;
list.status = 'nomore'; list.status = 'nomore';
getCouponList(); getCouponList();
} }
function changeSelCoupon(item) { function changeSelCoupon(item) {
if (querForm.value.statusActiveIndex) { if (querForm.value.statusActiveIndex) {
if (couponSel.value.id == item.id) { if (couponSel.value.id == item.id) {
couponSel.value = { couponSel.value = {
id: '' id: ''
} };
} else { } else {
couponSel.value = item couponSel.value = item;
} }
} else { } else {
if (goodsCouponSel.value.id == item.id) { if (goodsCouponSel.value.id == item.id) {
goodsCouponSel.value = { goodsCouponSel.value = {
id: '' id: ''
} };
} else { } else {
goodsCouponSel.value = item goodsCouponSel.value = item;
}
} }
} }
}
const couponSel = ref({ const couponSel = ref({
id: '' id: ''
}) });
const goodsCouponSel = ref({ const goodsCouponSel = ref({
id: '' id: ''
}) });
const quansSelArr = computed(() => { const quansSelArr = computed(() => {
return [couponSel.value, goodsCouponSel.value].filter((v) => v.id); return [couponSel.value, goodsCouponSel.value].filter((v) => v.id);
}) });
function isActive(item) { function isActive(item) {
if (querForm.value.statusActiveIndex) { if (querForm.value.statusActiveIndex) {
return couponSel.value.id == item.id return couponSel.value.id == item.id;
} else { } else {
return goodsCouponSel.value.id == item.id return goodsCouponSel.value.id == item.id;
}
} }
}
// 获取优惠券列表 // 获取优惠券列表
async function getCouponList() { async function getCouponList() {
try { try {
uni.showLoading({ uni.showLoading({
title: '加载中...', title: '加载中...',
mask: true mask: true
}); });
const res = await findCoupon({ const res = await findCoupon({
shopUserId: uni.cache.get('shopUserInfo').id, shopUserId: uni.cache.get('shopUserInfo').id
}); });
let canUseGoodsCoupon = [];
let canUseDiscountCoupon = [];
let canUseGoodsCoupon = [] let noUseGoodsCoupon = [];
let canUseDiscountCoupon = [] let noUseDiscountCoupon = [];
const user = uni.cache.get('shopUserInfo');
let noUseGoodsCoupon = [] let shopInfo = uni.cache.get('shopInfo') || {};
let noUseDiscountCoupon = []
const user = uni.cache.get('shopUserInfo')
let shopInfo = uni.cache.get('shopInfo') || {}
if (!shopInfo.isMemberPrice) { if (!shopInfo.isMemberPrice) {
shopInfo = {} shopInfo = {};
} }
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0 const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
const dinnerType = cartStore.dinnerType const dinnerType = cartStore.dinnerType;
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user); const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
const shopId = uni.cache.get('shopId') const shopId = uni.cache.get('shopId');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
const coupon = res[i] const coupon = res[i];
const canuseResult = UTILS.returnCouponCanUse({ const canuseResult = UTILS.returnCouponCanUse({
canDikouGoodsArr, canDikouGoodsArr,
coupon, coupon,
@@ -340,101 +329,81 @@
user, user,
selCoupon: quansSelArr.value, selCoupon: quansSelArr.value,
shopInfo shopInfo
}) });
const { const { canUse, reason } = canuseResult;
canUse,
reason
} = canuseResult
if (coupon.type == 2) { if (coupon.type == 2) {
if (canUse || goodsCouponSel.value.id == coupon.id) { if (canUse || goodsCouponSel.value.id == coupon.id) {
canUseGoodsCoupon.push(coupon) canUseGoodsCoupon.push(coupon);
} else { } else {
noUseGoodsCoupon.push({ noUseGoodsCoupon.push({
...coupon, ...coupon,
canuseResult canuseResult
}) });
} }
} else { } else {
if (canUse || couponSel.value.id == coupon.id) { if (canUse || couponSel.value.id == coupon.id) {
canUseDiscountCoupon.push(coupon) canUseDiscountCoupon.push(coupon);
} else { } else {
noUseDiscountCoupon.push({ noUseDiscountCoupon.push({
...coupon, ...coupon,
canuseResult canuseResult
}) });
} }
} }
} }
//商品券 //商品券
canUseGoodsCoupon = canUseGoodsCoupon.map(v => { canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount( const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
quansSelArr.value,
shopInfo
);
return { return {
...v, ...v,
discount, discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount, discountAmount: discount ? discount.discountPrice : v.discountAmount
}; };
}) });
//非商品券 //非商品券
canUseDiscountCoupon = canUseDiscountCoupon.map(v => { canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount( const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo);
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
quansSelArr.value,
shopInfo
);
return { return {
...v, ...v,
discount, discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount, discountAmount: discount ? discount.discountPrice : v.discountAmount
} };
}) });
if (querForm.value.statusActiveIndex == 0) { if (querForm.value.statusActiveIndex == 0) {
list.noCanUseCoupons = noUseGoodsCoupon list.noCanUseCoupons = noUseGoodsCoupon;
list.canUseCoupons = canUseGoodsCoupon list.canUseCoupons = canUseGoodsCoupon;
} else { } else {
list.noCanUseCoupons = noUseDiscountCoupon list.noCanUseCoupons = noUseDiscountCoupon;
list.canUseCoupons = canUseDiscountCoupon list.canUseCoupons = canUseDiscountCoupon;
} }
console.log('canUseGoodsCoupon', canUseGoodsCoupon); console.log('canUseGoodsCoupon', canUseGoodsCoupon);
console.log('noUseGoodsCoupon', noUseGoodsCoupon); console.log('noUseGoodsCoupon', noUseGoodsCoupon);
console.log('canUseDiscountCoupon', canUseDiscountCoupon); console.log('canUseDiscountCoupon', canUseDiscountCoupon);
console.log('noUseDiscountCoupon', noUseDiscountCoupon); console.log('noUseDiscountCoupon', noUseDiscountCoupon);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
uni.hideLoading(); uni.hideLoading();
} }
// 店铺列表滚动到底部了 // 店铺列表滚动到底部了
function scrollBottom() { function scrollBottom() {
console.log('店铺列表滚动到底部了'); console.log('店铺列表滚动到底部了');
} }
/** /**
* 将value数组字符串转换为对应的label拼接字符串 * 将value数组字符串转换为对应的label拼接字符串
* @param {Array} options - 包含value和label的选项数组格式如[{value: 'xxx', label: 'xxx'}, ...] * @param {Array} options - 包含value和label的选项数组格式如[{value: 'xxx', label: 'xxx'}, ...]
* @param {string} valueStr - 包含value的数组字符串格式如'["dine","pickup"]' * @param {string} valueStr - 包含value的数组字符串格式如'["dine","pickup"]'
* @param {string} separator - 标签拼接分隔符,默认值为'、' * @param {string} separator - 标签拼接分隔符,默认值为'、'
* @returns {string} 拼接后的label字符串如"堂食、自取" * @returns {string} 拼接后的label字符串如"堂食、自取"
*/ */
function convertValuesToLabels(valueStr, options, separator = '、') { function convertValuesToLabels(valueStr, options, separator = '、') {
try { try {
options = [{ options = [
{
value: 'dine', value: 'dine',
label: '堂食' label: '堂食'
}, },
@@ -482,102 +451,91 @@
console.error('转换失败:', error.message); console.error('转换失败:', error.message);
return ''; // 出错时返回空字符串 return ''; // 出错时返回空字符串
} }
} }
// 选择店铺 // 选择店铺
function selectShopHandle(item) { function selectShopHandle(item) {
querForm.value.shopId = item.shopId; querForm.value.shopId = item.shopId;
querForm.value.shopName = item.shopName; querForm.value.shopName = item.shopName;
list.page = 1; list.page = 1;
show.value = false; show.value = false;
getCouponList(); getCouponList();
} }
// 获取当前店铺会员信息 // 获取当前店铺会员信息
const shopList = ref([]); const shopList = ref([]);
async function getCouponShopsAjax() { async function getCouponShopsAjax() {
try { try {
const res = await getCouponShops(); const res = await getCouponShops();
shopList.value = res; shopList.value = res;
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
} }
onShow(() => { onShow(() => {
const couponArr = cartStore.backendCoupons.filter(v => v.type != 2) const couponArr = cartStore.backendCoupons.filter((v) => v.type != 2);
const goodsCouponArr = cartStore.backendCoupons.filter(v => v.type == 2) const goodsCouponArr = cartStore.backendCoupons.filter((v) => v.type == 2);
if (couponArr.length) { if (couponArr.length) {
couponSel.value = couponArr[0] couponSel.value = couponArr[0];
} }
if (goodsCouponArr.length) { if (goodsCouponArr.length) {
goodsCouponSel.value = goodsCouponArr[0] goodsCouponSel.value = goodsCouponArr[0];
} }
getCouponList(); getCouponList();
}); });
onLoad(() => { onLoad(() => {
getCouponShopsAjax(); getCouponShopsAjax();
}); });
watch(() => quansSelArr.value, (newval) => { watch(
const user = uni.cache.get('shopUserInfo') () => quansSelArr.value,
let shopInfo = uni.cache.get('shopInfo') || {} (newval) => {
const user = uni.cache.get('shopUserInfo');
let shopInfo = uni.cache.get('shopInfo') || {};
if (!shopInfo.isMemberPrice) { if (!shopInfo.isMemberPrice) {
shopInfo = {} shopInfo = {};
} }
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0 const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
const dinnerType = cartStore.dinnerType const dinnerType = cartStore.dinnerType;
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user); const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
const shopId = uni.cache.get('shopId') const shopId = uni.cache.get('shopId');
let goodsCoupon = newval.filter(v => v.type == 2) let goodsCoupon = newval.filter((v) => v.type == 2);
let otherCoupon = newval.filter(v => v.type != 2) let otherCoupon = newval.filter((v) => v.type != 2);
goodsCoupon = goodsCoupon.map(v => { goodsCoupon = goodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount( const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, [], shopInfo);
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
[],
shopInfo
);
return { return {
...v, ...v,
discount, discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount, discountAmount: discount ? discount.discountPrice : v.discountAmount
} };
}) });
otherCoupon = otherCoupon.map(v => { otherCoupon = otherCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount( const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, goodsCoupon, shopInfo);
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
goodsCoupon,
shopInfo
);
return { return {
...v, ...v,
discount, discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount, discountAmount: discount ? discount.discountPrice : v.discountAmount
} };
}) });
uni.$emit('selCoupon', [...goodsCoupon, ...otherCoupon]) uni.$emit('selCoupon', [...goodsCoupon, ...otherCoupon]);
}, { },
{
deep: true deep: true
}) }
);
</script> </script>
<style> <style>
page { page {
background-color: #f7f7f7; background-color: #f7f7f7;
} }
</style> </style>
<style scoped lang="scss"> <style scoped lang="scss">
.container { .container {
padding: 136upx 28upx 28upx; padding: 136upx 28upx 28upx;
} }
.header-wrap { .header-wrap {
width: 100%; width: 100%;
background-color: #fff; background-color: #fff;
position: fixed; position: fixed;
@@ -673,9 +631,9 @@
} }
} }
} }
} }
.list-wrap { .list-wrap {
padding-top: 28upx; padding-top: 28upx;
.tips { .tips {
@@ -846,9 +804,9 @@
} }
} }
} }
} }
.shoplist-popup { .shoplist-popup {
padding: 0 28upx 28upx; padding: 0 28upx 28upx;
.title { .title {
@@ -941,5 +899,5 @@
} }
} }
} }
} }
</style> </style>