fixed 优化购物车,渲染优惠券列表

This commit is contained in:
AERWEN\26795 2023-10-18 20:45:09 +08:00
parent f0e2b7ecfc
commit 6ab71eb4bf
13 changed files with 133 additions and 84 deletions

View File

@ -104,7 +104,20 @@ export async function genSettleDetail(params) {
success: true,
};
console.log(storeInfoList, '测试前端用店铺判断');
// 判断是否携带优惠券数据
const discountPrice = [];
console.log(couponList, '计算一下');
if (couponList && couponList.length > 0) {
couponList.forEach((coupon) => {
if (coupon.status === 'default') {
discountPrice.push({
shopGuid: coupon.shopGuid,
type: coupon.type,
value: coupon.value,
});
}
});
}
const storeGoodsList = []
// 将商品塞进对应的店铺
@ -118,8 +131,7 @@ export async function genSettleDetail(params) {
storeTotalDiscountAmount: 0,
storeTotalCouponAmount: 0,
couponList: [{
couponId: 11,
storeId: '1000',
}, ],
}
const storeGoodsRequestList = []
@ -129,26 +141,42 @@ export async function genSettleDetail(params) {
goodsRequestList.forEach(item => {
if (item.storeId === store.storeId) {
storeGoods.goodsCount += item.quantity
storeGoods.storeTotalAmount += item.quantity * item.price
storeGoodsRequestList.push(item)
// 计算店铺运费
if (userAddressReq) {
let data = {
GoodsRequestList: storeGoodsRequestList,
CustomerAddressGuid: userAddressReq.customerAddressGuid
}
getGoodsFreight(data).then((res) => {
if (res.code === 0) {
resp.data.abnormalDeliveryGoodsList = storeGoodsRequestList
}
storeGoods.deliveryFee = res.data
})
}
// 计算优惠券价格
let storeTotalCouponAmount = 0
if (discountPrice && discountPrice.length > 0) {
discountPrice.forEach(e => {
if (e.shopGuid === item.storeId) {
if (e.type === 1) {
storeTotalCouponAmount = e.value;
}
if (e.type === 2) {
storeTotalCouponAmount = (Number(storeGoods.storeTotalAmount) * e.value) / 10;
}
}
});
}
storeGoods.storeTotalCouponAmount = storeTotalCouponAmount;
storeGoods.storeTotalAmount += item.quantity * item.price + storeGoods.deliveryFee - storeTotalCouponAmount;
}
});
if (userAddressReq) {
let data = {
GoodsRequestList: storeGoodsRequestList,
CustomerAddressGuid: userAddressReq.customerAddressGuid
}
getGoodsFreight(data).then((res) => {
if (res.code === 0) {
resp.data.abnormalDeliveryGoodsList = storeGoodsRequestList
}
storeGoods.deliveryFee = res.data
storeGoods.storeTotalAmount += res.data
console.log(storeGoods.deliveryFee, '运费');
})
}
const list = transformGoodsDataToConfirmData(storeGoodsRequestList);
storeGoods.skuDetailVos = list
storeGoodsList.push(storeGoods)
@ -156,25 +184,11 @@ export async function genSettleDetail(params) {
console.log(storeGoodsList, '看看成果');
const list = transformGoodsDataToConfirmData(goodsRequestList);
console.log(list, '看看list');
// 获取购物车传递的商品数据
// resp.data.storeGoodsList[0].skuDetailVos = list;
// resp.data.storeGoodsList[1].skuDetailVos = list;
resp.data.storeGoodsList = storeGoodsList;
// 判断是否携带优惠券数据
const discountPrice = [];
if (couponList && couponList.length > 0) {
couponList.forEach((coupon) => {
if (coupon.status === 'default') {
discountPrice.push({
type: coupon.type,
value: coupon.value,
});
}
});
}
// 模拟计算场景
@ -207,8 +221,6 @@ export async function genSettleDetail(params) {
if (totalDeliveryFee) {
resp.data.totalPayAmount += resp.data.totalDeliveryFee
console.log(typeof (totalDeliveryFee), '类型是什么');
console.log(totalDeliveryFee, '这里呢');
}
list.forEach(item => {

View File

@ -28,7 +28,7 @@
</view>
<t-empty wx:if="{{couponList.length == 0}}" t-class="empty-cls" t-class-image="t-empty__image" image="https://tdesign.gtimg.com/miniprogram/images/empty1.png" description="暂无数据" />
</t-pull-down-refresh>
<view class="center-entry">
<!-- <view class="center-entry">
<view class="center-entry-btn" bind:tap="goCouponCenterHandle">
<view>领券中心</view>
<t-icon
@ -38,6 +38,6 @@
style="line-height: 28rpx;"
/>
</view>
</view>
</view> -->
</view>

View File

@ -7,7 +7,7 @@ Component({
list: Array,
title: {
type: String,
value: '促销说明',
value: '领券中心',
},
show: {
type: Boolean,
@ -27,6 +27,8 @@ Component({
},
closePromotionPopup() {
console.log(this.list);
this.triggerEvent('closePromotionPopup', {
show: false,
});

View File

@ -1,7 +1,8 @@
{
"component": true,
"usingComponents": {
"t-popup": "tdesign-miniprogram/popup/popup",
"t-icon": "tdesign-miniprogram/icon/icon"
}
"component": true,
"usingComponents": {
"t-popup": "tdesign-miniprogram/popup/popup",
"t-icon": "tdesign-miniprogram/icon/icon",
"coupon-card": "/components/coupon-card/index"
}
}

View File

@ -1,13 +1,13 @@
<t-popup visible="{{show}}" placement="bottom" bind:visible-change="closePromotionPopup">
<view class="promotion-popup-container">
<view class="promotion-popup-close" bindtap="closePromotionPopup">
<t-icon name="close" size="36rpx" />
</view>
<view class="promotion-popup-title">
<view class="title">{{title}}</view>
</view>
<view class="promotion-popup-content">
<view class="promotion-detail-list">
<view class="promotion-popup-container">
<view class="promotion-popup-close" bindtap="closePromotionPopup">
<t-icon name="close" size="36rpx" />
</view>
<view class="promotion-popup-title">
<view class="title">{{title}}</view>
</view>
<view class="promotion-popup-content">
<!-- <view class="promotion-detail-list">
<view
class="list-item"
wx:for="{{list}}"
@ -26,9 +26,14 @@
color="#bbb"
/>
</view>
</view>
</view>
<slot name="promotion-bottom" />
</view>
</t-popup>
</view> -->
<view class="coupon-list-item" wx:for="{{list}}" wx:key="key">
{{item}}
<coupon-card couponDTO="{{item}}" />
</view>
</view>
<slot name="promotion-bottom" />
</view>
</t-popup>

View File

@ -453,12 +453,12 @@ Page({
});
});
const promotionArray = [];
activityList.forEach((item) => {
promotionArray.push({
tag: item.promotionSubCode === 'MYJ' ? '满减' : '满折',
label: '满100元减99.9元',
});
});
// activityList.forEach((item) => {
// promotionArray.push({
// tag: item.promotionSubCode === 'MYJ' ? '满减' : '满折',
// label: '满100元减99.9元',
// });
// });
this.setData({
details,
activityList,

View File

@ -40,7 +40,7 @@
<view class="sold-num">已售{{soldNum}}</view>
</view>
<view wx:if="{{details.goodsSellingPoint}}">{{ details.goodsSellingPoint }}</view>
<!-- <view wx:if="{{activityList.length > 0}}" class="goods-activity" bindtap="showPromotionPopup">
<!-- <view class="goods-activity" bindtap="showPromotionPopup">
<view class="tags-container">
<view wx:for="{{activityList}}" data-promotionId="{{item.promotionId}}" wx:key="index" wx:if="{{index<4}}">
<view class="goods-activity-tag">{{item.tag}}</view>
@ -51,6 +51,7 @@
<t-icon name="chevron-right" size="42rpx" />
</view>
</view> -->
<view class="goods-title">
<view class="goods-name">{{details.title}}</view>
<view class="goods-tag">

View File

@ -65,7 +65,9 @@ page {
.goods-detail-page .goods-info .goods-activity {
display: flex;
margin-top: 16rpx;
justify-content: space-between;
position: relative;
/* justify-content: space-between; */
justify-content: flex-end;
}
.goods-detail-page .goods-info .goods-activity .tags-container {

View File

@ -61,8 +61,8 @@ Component({
selectedCoupons,
storeId,
}).then((res) => {
console.log(res,'res来咯');
this.initData(res);
// console.log(res,'res来咯');
// this.initData(res);
});
}
},
@ -92,11 +92,12 @@ Component({
selectedNum++;
selectedList.push({
couponId: coupon.key,
promotionId: ruleId,
// promotionId: ruleId,
storeId: this.storeId,
});
}
return {
shopGuid: coupon.shopGuid,
key: coupon.key,
title: coupon.title,
isSelected: false,
@ -104,7 +105,7 @@ Component({
value: coupon.value,
status: coupon.status === 1 ? 'default' : 'useless',
desc: coupon.desc,
type,
type : coupon.type,
tag: '',
};
});
@ -150,16 +151,30 @@ Component({
coupons(coupon = {}) {
return new Promise((resolve, reject) => {
console.log(coupon,'coupon里有什么');
const {
storeId
} =
this.data;
console.log(storeId);
if (coupon?.selectedCoupons) {
let data = {
couponResultList: [],
reduce: 1000,
}
// 优惠券接口
fetchCouponList({
status: 1
}).then((res) => {
resolve({
couponResultList: res,
reduce: 1000,
fetchCouponList({
shopGuid: storeId,
status: 1
}).then((res) => {
data.couponResultList = res
this.initData(data);
});
resolve({
couponResultList: data,
reduce: 1000,
});
}
return reject({
couponResultList: [],

View File

@ -48,6 +48,7 @@ Page({
promotionGoodsList: [], //当前门店商品列表(优惠券)
couponList: [], //当前门店所选优惠券
submitCouponList: [], //所有门店所选优惠券
resSubmitCouponList:[],
currentStoreId: null, //当前优惠券storeId
userAddress: null,
},
@ -434,6 +435,7 @@ Page({
invoiceData,
storeInfoList,
submitCouponList,
resSubmitCouponList
} = this.data;
const {
goodsRequestList
@ -458,7 +460,8 @@ Page({
return;
}
// this.payLock = true;
const resSubmitCouponList = this.handleCouponList(submitCouponList);
console.log(submitCouponList);
// const resSubmitCouponList = this.handleCouponList(submitCouponList);
const openId = wx.getStorageSync('openId')
console.log(openId, '我的openId');
const params = {
@ -625,12 +628,16 @@ Page({
storeCoupon.couponList,
};
});
console.log(tempSubmitCouponList,'查看确定优惠券 temp');
const resSubmitCouponList = this.handleCouponList(tempSubmitCouponList);
console.log(resSubmitCouponList,'查看确定优惠券 res');
//确定选择优惠券
this.handleOptionsParams({
goodsRequestList
}, resSubmitCouponList);
this.setData({
resSubmitCouponList:resSubmitCouponList,
couponsShow: false
});
},

View File

@ -41,20 +41,23 @@
<text wx:else>免运费</text>
</view>
</view>
<view class="pay-item">
<!-- <view class="pay-item">
<text>活动优惠</text>
<view class="pay-item__right primary font-bold">
-
<price priceUnit="yuan" fill price="{{settleDetailData.totalPromotionAmount || 0}}" />
</view>
</view>
</view> -->
<view class="pay-item">
<text>优惠券</text>
<view class="pay-item__right" data-storeid="{{settleDetailData.storeGoodsList[0].storeId}}" catchtap="onOpenCoupons">
<view class="pay-item__right" data-storeid="{{stores.storeId}}" catchtap="onOpenCoupons">
<block wx:if="{{submitCouponList.length}}">
<block wx:if="{{settleDetailData.totalCouponAmount && settleDetailData.totalCouponAmount !== '0'}}">
<!-- <block wx:if="{{settleDetailData.totalCouponAmount && settleDetailData.totalCouponAmount !== '0'}}"> -->
<block wx:if="{{stores.storeTotalCouponAmount && stores.storeTotalCouponAmount !== '0'}}">
-
<price class="pay-item__right primary font-bold" priceUnit="yuan" fill decimalSmaller price="{{settleDetailData.totalCouponAmount}}" />
<!-- <price class="pay-item__right primary font-bold" priceUnit="yuan" fill decimalSmaller price="{{settleDetailData.totalCouponAmount}}" /> -->
<price class="pay-item__right primary font-bold" priceUnit="yuan" fill decimalSmaller price="{{stores.storeTotalCouponAmount}}" />
</block>
<block wx:else>选择优惠券</block>
</block>

View File

@ -43,7 +43,8 @@
"showES6CompileOption": false,
"useCompilerPlugins": false,
"ignoreUploadUnusedFiles": true,
"useStaticServer": true
"useStaticServer": true,
"condition": false
},
"compileType": "miniprogram",
"libVersion": "2.23.1",

View File

@ -3,7 +3,7 @@ import {
} from '../_utils/request';
/** 优惠券列表 */
export function fetchCouponList(parm) {
export async function fetchCouponList(parm) {
return new Promise((resolve, reject) => {
request({
url: `CustomerCouponApi/getCustomerCouponList`,