【功能优化】商城:价格计算时,返回可用 + 不可用的优惠劵

pull/95/MERGE
YunaiV 2024-09-07 12:06:10 +08:00
parent 735dc8c373
commit 9b6d1a9a97
4 changed files with 61 additions and 74 deletions

View File

@ -52,25 +52,38 @@
class="score-img" class="score-img"
/> />
<text class="item-value ss-m-r-24"> <text class="item-value ss-m-r-24">
{{ state.pointStatus ? state.orderInfo.totalPoint - state.orderInfo.usePoint : (state.orderInfo.totalPoint || 0) }} {{
state.pointStatus
? state.orderInfo.totalPoint - state.orderInfo.usePoint
: state.orderInfo.totalPoint || 0
}}
</text> </text>
<checkbox-group @change="changeIntegral"> <checkbox-group @change="changeIntegral">
<checkbox :checked='state.pointStatus' :disabled="!state.orderInfo.totalPoint || state.orderInfo.totalPoint <= 0" /> <checkbox
:checked="state.pointStatus"
:disabled="!state.orderInfo.totalPoint || state.orderInfo.totalPoint <= 0"
/>
</checkbox-group> </checkbox-group>
</view> </view>
</view> </view>
<!-- 快递配置时信息的展示 --> <!-- 快递配置时信息的展示 -->
<view class="order-item ss-flex ss-col-center ss-row-between" v-if='addressState.deliveryType === 1'> <view
class="order-item ss-flex ss-col-center ss-row-between"
v-if="addressState.deliveryType === 1"
>
<view class="item-title">运费</view> <view class="item-title">运费</view>
<view class="ss-flex ss-col-center"> <view class="ss-flex ss-col-center">
<text class="item-value ss-m-r-24" v-if="state.orderInfo.price.deliveryPrice > 0"> <text class="item-value ss-m-r-24" v-if="state.orderInfo.price.deliveryPrice > 0">
+{{ fen2yuan(state.orderInfo.price.deliveryPrice) }} +{{ fen2yuan(state.orderInfo.price.deliveryPrice) }}
</text> </text>
<view class='item-value ss-m-r-24' v-else></view> <view class="item-value ss-m-r-24" v-else></view>
</view> </view>
</view> </view>
<!-- 门店自提时需要填写姓名和手机号 --> <!-- 门店自提时需要填写姓名和手机号 -->
<view class="order-item ss-flex ss-col-center ss-row-between" v-if='addressState.deliveryType === 2'> <view
class="order-item ss-flex ss-col-center ss-row-between"
v-if="addressState.deliveryType === 2"
>
<view class="item-title">联系人</view> <view class="item-title">联系人</view>
<view class="ss-flex ss-col-center"> <view class="ss-flex ss-col-center">
<uni-easyinput <uni-easyinput
@ -82,7 +95,10 @@
/> />
</view> </view>
</view> </view>
<view class="order-item ss-flex ss-col-center ss-row-between" v-if='addressState.deliveryType === 2'> <view
class="order-item ss-flex ss-col-center ss-row-between"
v-if="addressState.deliveryType === 2"
>
<view class="item-title">联系电话</view> <view class="item-title">联系电话</view>
<view class="ss-flex ss-col-center"> <view class="ss-flex ss-col-center">
<uni-easyinput <uni-easyinput
@ -190,7 +206,6 @@
import AddressSelection from '@/pages/order/addressSelection.vue'; import AddressSelection from '@/pages/order/addressSelection.vue';
import sheep from '@/sheep'; import sheep from '@/sheep';
import OrderApi from '@/sheep/api/trade/order'; import OrderApi from '@/sheep/api/trade/order';
import CouponApi from '@/sheep/api/promotion/coupon';
import { fen2yuan } from '@/sheep/hooks/useGoods'; import { fen2yuan } from '@/sheep/hooks/useGoods';
const state = reactive({ const state = reactive({
@ -266,9 +281,9 @@
remark: state.orderPayload.remark, remark: state.orderPayload.remark,
deliveryType: addressState.value.deliveryType, deliveryType: addressState.value.deliveryType,
addressId: addressState.value.addressInfo.id, // addressId: addressState.value.addressInfo.id, //
pickUpStoreId: addressState.value.pickUpInfo.id,// pickUpStoreId: addressState.value.pickUpInfo.id, //
receiverName: addressState.value.receiverName,// receiverName: addressState.value.receiverName, //
receiverMobile: addressState.value.receiverMobile,// receiverMobile: addressState.value.receiverMobile, //
pointStatus: state.pointStatus, pointStatus: state.pointStatus,
combinationActivityId: state.orderPayload.combinationActivityId, combinationActivityId: state.orderPayload.combinationActivityId,
combinationHeadId: state.orderPayload.combinationHeadId, combinationHeadId: state.orderPayload.combinationHeadId,
@ -296,9 +311,9 @@
couponId: state.orderPayload.couponId, couponId: state.orderPayload.couponId,
deliveryType: addressState.value.deliveryType, deliveryType: addressState.value.deliveryType,
addressId: addressState.value.addressInfo.id, // addressId: addressState.value.addressInfo.id, //
pickUpStoreId: addressState.value.pickUpInfo.id,// pickUpStoreId: addressState.value.pickUpInfo.id, //
receiverName: addressState.value.receiverName,// receiverName: addressState.value.receiverName, //
receiverMobile: addressState.value.receiverMobile,// receiverMobile: addressState.value.receiverMobile, //
pointStatus: state.pointStatus, pointStatus: state.pointStatus,
combinationActivityId: state.orderPayload.combinationActivityId, combinationActivityId: state.orderPayload.combinationActivityId,
combinationHeadId: state.orderPayload.combinationHeadId, combinationHeadId: state.orderPayload.combinationHeadId,
@ -308,25 +323,13 @@
return; return;
} }
state.orderInfo = data; state.orderInfo = data;
state.couponInfo = data.coupons;
// //
if (state.orderInfo.address) { if (state.orderInfo.address) {
addressState.value.addressInfo = state.orderInfo.address; addressState.value.addressInfo = state.orderInfo.address;
} }
} }
//
async function getCoupons() {
const { code, data } = await CouponApi.getMatchCouponList(
state.orderInfo.price.payPrice,
state.orderInfo.items.map((item) => item.spuId),
state.orderPayload.items.map((item) => item.skuId),
state.orderPayload.items.map((item) => item.categoryId),
);
if (code === 0) {
state.couponInfo = data;
}
}
onLoad(async (options) => { onLoad(async (options) => {
if (!options.data) { if (!options.data) {
sheep.$helper.toast('参数不正确,请检查!'); sheep.$helper.toast('参数不正确,请检查!');
@ -334,13 +337,15 @@
} }
state.orderPayload = JSON.parse(options.data); state.orderPayload = JSON.parse(options.data);
await getOrderInfo(); await getOrderInfo();
await getCoupons();
}); });
// 使 watch // 使 watch
watch(addressState, async (newAddress, oldAddress) => { watch(addressState, async (newAddress, oldAddress) => {
// //
if (newAddress.addressInfo.id !== oldAddress.addressInfo.id || newAddress.deliveryType !== oldAddress.deliveryType) { if (
newAddress.addressInfo.id !== oldAddress.addressInfo.id ||
newAddress.deliveryType !== oldAddress.deliveryType
) {
await getOrderInfo(); await getOrderInfo();
} }
}); });

View File

@ -79,23 +79,6 @@ const CouponApi = {
}, },
}); });
}, },
// 获得匹配指定商品的优惠劵列表
getMatchCouponList: (price, spuIds, skuIds, categoryIds) => {
return request({
url: '/promotion/coupon/match-list',
method: 'GET',
params: {
price,
spuIds: spuIds.join(','),
skuIds: skuIds.join(','),
categoryIds: categoryIds.join(','),
},
custom: {
showError: false,
showLoading: false, // 避免影响 settlementOrder 结算的结果
},
});
}
}; };
export default CouponApi; export default CouponApi;

View File

@ -37,30 +37,22 @@
<view class="ss-flex ss-row-between ss-m-t-16"> <view class="ss-flex ss-row-between ss-m-t-16">
<view <view
class="sellby-text" class="sellby-text"
:class=" isDisable ? 'disabled-color' : 'subtitle-color'" :class="isDisable ? 'disabled-color' : 'subtitle-color'"
v-if="data.validityType === 2" v-if="data.validityType === 2"
> >
有效期领取后 {{ data.fixedEndTerm }} 天内可用 有效期领取后 {{ data.fixedEndTerm }} 天内可用
</view> </view>
<view <view class="sellby-text" :class="isDisable ? 'disabled-color' : 'subtitle-color'" v-else>
class="sellby-text"
:class=" isDisable ? 'disabled-color' : 'subtitle-color'"
v-else
>
有效期: {{ sheep.$helper.timeFormat(data.validStartTime, 'yyyy-mm-dd') }} 有效期: {{ sheep.$helper.timeFormat(data.validStartTime, 'yyyy-mm-dd') }}
{{ sheep.$helper.timeFormat(data.validEndTime, 'yyyy-mm-dd') }} {{ sheep.$helper.timeFormat(data.validEndTime, 'yyyy-mm-dd') }}
</view> </view>
<view <view class="value-enough" :class="isDisable ? 'disabled-color' : 'subtitle-color'">
class="value-enough"
:class="isDisable ? 'disabled-color' : 'subtitle-color'"
>
{{ fen2yuan(data.usePrice) }} 可用 {{ fen2yuan(data.usePrice) }} 可用
</view> </view>
</view> </view>
</view> </view>
</view> </view>
<!-- TODO 芋艿可优化增加优惠劵的描述 -->
<view class="desc ss-flex ss-row-between"> <view class="desc ss-flex ss-row-between">
<view> <view>
<view class="desc-title">{{ data.description }}</view> <view class="desc-title">{{ data.description }}</view>
@ -76,12 +68,10 @@
</template> </template>
<script setup> <script setup>
import { computed, reactive } from 'vue'; import { computed } from 'vue';
import { fen2yuan } from '../../hooks/useGoods'; import { fen2yuan } from '../../hooks/useGoods';
import sheep from '../../index'; import sheep from '../../index';
const state = reactive({});
const isDisable = computed(() => { const isDisable = computed(() => {
if (props.type === 'coupon') { if (props.type === 'coupon') {
return false; return false;
@ -202,4 +192,4 @@
.price-text { .price-text {
color: #ff0000; color: #ff0000;
} }
</style> </style>

View File

@ -1,19 +1,28 @@
<!-- 订单确认的优惠劵选择弹窗 --> <!-- 订单确认的优惠劵选择弹窗 -->
<template> <template>
<su-popup :show="show" type="bottom" round="20" @close="emits('close')" showClose backgroundColor="#f2f2f2"> <su-popup
:show="show"
type="bottom"
round="20"
@close="emits('close')"
showClose
backgroundColor="#f2f2f2"
>
<view class="model-box"> <view class="model-box">
<view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠券</view> <view class="title ss-m-t-16 ss-m-l-20 ss-flex">优惠券</view>
<scroll-view class="model-content" scroll-y :scroll-with-animation="false" :enable-back-to-top="true"> <scroll-view
class="model-content"
scroll-y
:scroll-with-animation="false"
:enable-back-to-top="true"
>
<!--可使用的优惠券区域--> <!--可使用的优惠券区域-->
<view class="subtitle ss-m-l-20">可使用优惠券</view> <view class="subtitle ss-m-l-20">可使用优惠券</view>
<view v-for="(item, index) in state.couponInfo.filter(coupon => coupon.match)" :key="index"> <view
v-for="(item, index) in state.couponInfo.filter((coupon) => coupon.match)"
:key="index"
>
<s-coupon-list :data="item" type="user" :disabled="false"> <s-coupon-list :data="item" type="user" :disabled="false">
<template v-slot:reason>
<view class="ss-flex ss-m-t-24">
<view class="reason-title">可用原因</view>
<view class="reason-desc">{{ item.description || '已达到使用门槛' }}</view>
</view>
</template>
<template #default> <template #default>
<label class="ss-flex ss-col-center" @tap="radioChange(item.id)"> <label class="ss-flex ss-col-center" @tap="radioChange(item.id)">
<radio <radio
@ -28,12 +37,12 @@
</view> </view>
<!--不可使用的优惠券区域--> <!--不可使用的优惠券区域-->
<view class="subtitle ss-m-t-40 ss-m-l-20">不可使用优惠券</view> <view class="subtitle ss-m-t-40 ss-m-l-20">不可使用优惠券</view>
<view v-for="item in state.couponInfo.filter(coupon => !coupon.match)" :key="item.id"> <view v-for="item in state.couponInfo.filter((coupon) => !coupon.match)" :key="item.id">
<s-coupon-list :data="item" type="user" :disabled="true"> <s-coupon-list :data="item" type="user" :disabled="true">
<template v-slot:reason> <template v-slot:reason>
<view class="ss-flex ss-m-t-24"> <view class="ss-flex ss-m-t-24">
<view class="reason-title"> 不可用原因</view> <view class="reason-title"> 不可用原因</view>
<view class="reason-desc">{{ item.description || '未达到使用门槛' }}</view> <view class="reason-desc">{{ item.mismatchReason || '未达到使用门槛' }}</view>
</view> </view>
</template> </template>
</s-coupon-list> </s-coupon-list>
@ -49,10 +58,10 @@
import { computed, reactive } from 'vue'; import { computed, reactive } from 'vue';
const props = defineProps({ const props = defineProps({
modelValue: { // modelValue: {
//
type: Object, type: Object,
default() { default() {},
},
}, },
show: { show: {
type: Boolean, type: Boolean,