fixed 修改订单提交参数

This commit is contained in:
AERWEN\26795 2023-10-14 15:21:03 +08:00
parent cab6ac91e2
commit f8b6610566
3 changed files with 169 additions and 69 deletions

View File

@ -1,8 +1,17 @@
import Toast from 'tdesign-miniprogram/toast/index'; import Toast from 'tdesign-miniprogram/toast/index';
import { fetchSettleDetail } from '~/services/order/orderConfirm'; import {
import { getGoodsFreight } from '~/services/order/getGoodsFreight'; fetchSettleDetail
import { commitPay, wechatPayOrder } from './pay'; } from '~/services/order/orderConfirm';
import { getAddressPromise } from '../../usercenter/address/list/util'; import {
getGoodsFreight
} from '~/services/order/getGoodsFreight';
import {
commitPay,
wechatPayOrder
} from './pay';
import {
getAddressPromise
} from '../../usercenter/address/list/util';
const stripeImg = `https://cdn-we-retail.ym.tencent.com/miniapp/order/stripe.png`; const stripeImg = `https://cdn-we-retail.ym.tencent.com/miniapp/order/stripe.png`;
@ -68,13 +77,21 @@ Page({
this.setData({ this.setData({
loading: true, loading: true,
}); });
const { goodsRequestList } = this; const {
this.handleOptionsParams({ goodsRequestList }); goodsRequestList
} = this;
this.handleOptionsParams({
goodsRequestList
});
}, },
// 处理不同情况下跳转到结算页时需要的参数 // 处理不同情况下跳转到结算页时需要的参数
async handleOptionsParams(options, couponList) { async handleOptionsParams(options, couponList) {
let { goodsRequestList } = this; // 商品列表 let {
let { userAddressReq } = this; // 收货地址 goodsRequestList
} = this; // 商品列表
let {
userAddressReq
} = this; // 收货地址
const storeInfoList = []; // 门店列表 const storeInfoList = []; // 门店列表
// 如果是从地址选择页面返回,则使用地址显选择页面新选择的地址去获取结算数据 // 如果是从地址选择页面返回,则使用地址显选择页面新选择的地址去获取结算数据
@ -85,7 +102,7 @@ Page({
// 从购物车跳转过来时,获取传入的商品列表数据 // 从购物车跳转过来时,获取传入的商品列表数据
const goodsRequestListJson = wx.getStorageSync('order.goodsRequestList'); const goodsRequestListJson = wx.getStorageSync('order.goodsRequestList');
goodsRequestList = JSON.parse(goodsRequestListJson); goodsRequestList = JSON.parse(goodsRequestListJson);
console.log(goodsRequestList,'数据看看'); console.log(goodsRequestList, '数据看看');
} else if (typeof options.goodsRequestList === 'string') { } else if (typeof options.goodsRequestList === 'string') {
goodsRequestList = JSON.parse(options.goodsRequestList); goodsRequestList = JSON.parse(options.goodsRequestList);
} }
@ -109,20 +126,20 @@ Page({
couponList, couponList,
}; };
if(userAddressReq){ if (userAddressReq) {
// 计算运费接口 // 计算运费接口
console.log(goodsRequestList,'看看看看') console.log(goodsRequestList, '看看看看')
console.log(userAddressReq.customerAddressGuid,'看看看看地址') console.log(userAddressReq.customerAddressGuid, '看看看看地址')
let data = { let data = {
GoodsRequestList: goodsRequestList, GoodsRequestList: goodsRequestList,
CustomerAddressGuid: userAddressReq.customerAddressGuid CustomerAddressGuid: userAddressReq.customerAddressGuid
} }
await getGoodsFreight(data).then((res) => { await getGoodsFreight(data).then((res) => {
params.totalDeliveryFee = res.data params.totalDeliveryFee = res.data
console.log(this.data.settleDetailData,'运费'); console.log(this.data.settleDetailData, '运费');
}) })
} }
console.log(params,'计算参数'); console.log(params, '计算参数');
fetchSettleDetail(params).then( fetchSettleDetail(params).then(
(res) => { (res) => {
this.setData({ this.setData({
@ -142,9 +159,13 @@ Page({
this.userAddressReq = resData.userAddress; this.userAddressReq = resData.userAddress;
if (resData.userAddress) { if (resData.userAddress) {
this.setData({ userAddress: resData.userAddress }); this.setData({
userAddress: resData.userAddress
});
} }
this.setData({ settleDetailData: data }); this.setData({
settleDetailData: data
});
this.isInvalidOrder(data); this.isInvalidOrder(data);
}, },
@ -156,10 +177,14 @@ Page({
data.abnormalDeliveryGoodsList.length > 0) || data.abnormalDeliveryGoodsList.length > 0) ||
(data.inValidGoodsList && data.inValidGoodsList.length > 0) (data.inValidGoodsList && data.inValidGoodsList.length > 0)
) { ) {
this.setData({ popupShow: true }); this.setData({
popupShow: true
});
return true; return true;
} }
this.setData({ popupShow: false }); this.setData({
popupShow: false
});
if (data.settleType === 0) { if (data.settleType === 0) {
return true; return true;
} }
@ -186,7 +211,9 @@ Page({
const filterStoreGoodsList = []; const filterStoreGoodsList = [];
storeGoodsList && storeGoodsList &&
storeGoodsList.forEach((store) => { storeGoodsList.forEach((store) => {
const { storeName } = store; const {
storeName
} = store;
store.skuDetailVos && store.skuDetailVos &&
store.skuDetailVos.forEach((goods) => { store.skuDetailVos.forEach((goods) => {
const data = goods; const data = goods;
@ -246,7 +273,9 @@ Page({
specs: item.skuSpecLst?.map((s) => s.specValue), // 规格列表 string[] specs: item.skuSpecLst?.map((s) => s.specValue), // 规格列表 string[]
price: item.tagPrice || item.settlePrice || '0', // 优先取限时活动价 price: item.tagPrice || item.settlePrice || '0', // 优先取限时活动价
settlePrice: item.settlePrice, settlePrice: item.settlePrice,
titlePrefixTags: item.tagText ? [{ text: item.tagText }] : [], titlePrefixTags: item.tagText ? [{
text: item.tagText
}] : [],
num: item.quantity, num: item.quantity,
skuId: item.skuId, skuId: item.skuId,
spuId: item.spuId, spuId: item.spuId,
@ -269,10 +298,14 @@ Page({
orderCardList.push(orderCard); orderCardList.push(orderCard);
}); });
this.setData({ orderCardList, storeInfoList, submitCouponList });
this.setData({
orderCardList,
storeInfoList,
submitCouponList
});
return data; return data;
}, },
onGotoAddress() { onGotoAddress() {
@ -280,12 +313,17 @@ Page({
getAddressPromise() getAddressPromise()
.then((address) => { .then((address) => {
this.handleOptionsParams({ this.handleOptionsParams({
userAddressReq: { ...address, checked: true }, userAddressReq: {
...address,
checked: true
},
}); });
}) })
.catch(() => {}); .catch(() => {});
const { userAddressReq } = this; // 收货地址 const {
userAddressReq
} = this; // 收货地址
let id = ''; let id = '';
@ -298,7 +336,9 @@ Page({
}); });
}, },
onNotes(e) { onNotes(e) {
const { storenoteindex: storeNoteIndex } = e.currentTarget.dataset; const {
storenoteindex: storeNoteIndex
} = e.currentTarget.dataset;
// 添加备注信息 // 添加备注信息
this.setData({ this.setData({
dialogShow: true, dialogShow: true,
@ -306,7 +346,9 @@ Page({
}); });
}, },
onInput(e) { onInput(e) {
const { storeNoteIndex } = this.data; const {
storeNoteIndex
} = this.data;
this.noteInfo[storeNoteIndex] = e.detail.value; this.noteInfo[storeNoteIndex] = e.detail.value;
}, },
onBlur() { onBlur() {
@ -326,7 +368,10 @@ Page({
}, },
onNoteConfirm() { onNoteConfirm() {
// 备注信息 确认按钮 // 备注信息 确认按钮
const { storeInfoList, storeNoteIndex } = this.data; const {
storeInfoList,
storeNoteIndex
} = this.data;
this.tempNoteInfo[storeNoteIndex] = this.noteInfo[storeNoteIndex]; this.tempNoteInfo[storeNoteIndex] = this.noteInfo[storeNoteIndex];
storeInfoList[storeNoteIndex].remark = this.noteInfo[storeNoteIndex]; storeInfoList[storeNoteIndex].remark = this.noteInfo[storeNoteIndex];
@ -337,7 +382,9 @@ Page({
}, },
onNoteCancel() { onNoteCancel() {
// 备注信息 取消按钮 // 备注信息 取消按钮
const { storeNoteIndex } = this.data; const {
storeNoteIndex
} = this.data;
this.noteInfo[storeNoteIndex] = this.tempNoteInfo[storeNoteIndex]; this.noteInfo[storeNoteIndex] = this.tempNoteInfo[storeNoteIndex];
this.setData({ this.setData({
dialogShow: false, dialogShow: false,
@ -346,9 +393,15 @@ Page({
onSureCommit() { onSureCommit() {
// 商品库存不足继续结算 // 商品库存不足继续结算
const { settleDetailData } = this.data; const {
const { outOfStockGoodsList, storeGoodsList, inValidGoodsList } = settleDetailData
settleDetailData; } = this.data;
const {
outOfStockGoodsList,
storeGoodsList,
inValidGoodsList
} =
settleDetailData;
if ( if (
(outOfStockGoodsList && outOfStockGoodsList.length > 0) || (outOfStockGoodsList && outOfStockGoodsList.length > 0) ||
(inValidGoodsList && storeGoodsList) (inValidGoodsList && storeGoodsList)
@ -358,7 +411,9 @@ Page({
const filterOutGoodsList = []; const filterOutGoodsList = [];
outOfStockGoodsList && outOfStockGoodsList &&
outOfStockGoodsList.forEach((outOfStockGoods) => { outOfStockGoodsList.forEach((outOfStockGoods) => {
const { storeName } = outOfStockGoods; const {
storeName
} = outOfStockGoods;
outOfStockGoods.unSettlementGoods.forEach((ele) => { outOfStockGoods.unSettlementGoods.forEach((ele) => {
const data = ele; const data = ele;
data.quantity = ele.reminderStock; data.quantity = ele.reminderStock;
@ -368,7 +423,9 @@ Page({
}); });
const filterStoreGoodsList = this.getRequestGoodsList(storeGoodsList); const filterStoreGoodsList = this.getRequestGoodsList(storeGoodsList);
const goodsRequestList = filterOutGoodsList.concat(filterStoreGoodsList); const goodsRequestList = filterOutGoodsList.concat(filterStoreGoodsList);
this.handleOptionsParams({ goodsRequestList }); this.handleOptionsParams({
goodsRequestList
});
} }
}, },
// 提交订单 // 提交订单
@ -380,7 +437,9 @@ Page({
storeInfoList, storeInfoList,
submitCouponList, submitCouponList,
} = this.data; } = this.data;
const { goodsRequestList } = this; const {
goodsRequestList
} = this;
if (!userAddressReq && !settleDetailData.userAddress) { if (!userAddressReq && !settleDetailData.userAddress) {
Toast({ Toast({
@ -403,7 +462,7 @@ Page({
// this.payLock = true; // this.payLock = true;
const resSubmitCouponList = this.handleCouponList(submitCouponList); const resSubmitCouponList = this.handleCouponList(submitCouponList);
const openId = wx.getStorageSync('openId') const openId = wx.getStorageSync('openId')
console.log(openId,'我的openId'); console.log(openId, '我的openId');
const params = { const params = {
userAddressReq: settleDetailData.userAddress || userAddressReq, userAddressReq: settleDetailData.userAddress || userAddressReq,
goodsRequestList: goodsRequestList, goodsRequestList: goodsRequestList,
@ -412,18 +471,21 @@ Page({
invoiceRequest: null, invoiceRequest: null,
storeInfoList, storeInfoList,
couponList: resSubmitCouponList, couponList: resSubmitCouponList,
openId: openId openId: openId,
customerAddressGuid: settleDetailData.userAddress.customerAddressGuid
}; };
if (invoiceData && invoiceData.email) { if (invoiceData && invoiceData.email) {
params.invoiceRequest = invoiceData; params.invoiceRequest = invoiceData;
} }
console.log(params,'下单参数!'); console.log(params, '下单参数!');
/** 提交订单方法(接口) */ /** 提交订单方法(接口) */
commitPay(params).then( commitPay(params).then(
(res) => { (res) => {
this.payLock = false; this.payLock = false;
const { data } = res; const {
console.log(res,'后端接口返回调起微信支付的参数'); data
} = res;
console.log(res, '后端接口返回调起微信支付的参数');
// 提交出现 失效 不在配送范围 限购的商品 提示弹窗 // 提交出现 失效 不在配送范围 限购的商品 提示弹窗
if (this.isInvalidOrder(data)) { if (this.isInvalidOrder(data)) {
return; return;
@ -468,19 +530,22 @@ Page({
icon: 'close-circle', icon: 'close-circle',
}); });
setTimeout(() => { setTimeout(() => {
wx.redirectTo({ url: '/order/list' }); wx.redirectTo({
url: '/order/list'
});
}); });
} else if (err.code === 'ILLEGAL_CONFIG_PARAM') { } else if (err.code === 'ILLEGAL_CONFIG_PARAM') {
Toast({ Toast({
context: this, context: this,
selector: '#t-toast', selector: '#t-toast',
message: message: '支付失败,微信支付商户号设置有误,请商家重新检查支付设置。',
'支付失败,微信支付商户号设置有误,请商家重新检查支付设置。',
duration: 2000, duration: 2000,
icon: 'close-circle', icon: 'close-circle',
}); });
setTimeout(() => { setTimeout(() => {
wx.redirectTo({ url: '/order/list' }); wx.redirectTo({
url: '/order/list'
});
}); });
} else { } else {
Toast({ Toast({
@ -501,8 +566,17 @@ Page({
// 处理支付 // 处理支付
handlePay(data, settleDetailData) { handlePay(data, settleDetailData) {
const { channel, jsApiUiPackage, outTradeNo, interactId, transactionId } = data; const {
const { totalAmount, totalPayAmount } = settleDetailData; channel,
jsApiUiPackage,
outTradeNo,
interactId,
transactionId
} = data;
const {
totalAmount,
totalPayAmount
} = settleDetailData;
const payOrderInfo = { const payOrderInfo = {
payInfo: jsApiUiPackage, payInfo: jsApiUiPackage,
orderId: outTradeNo, orderId: outTradeNo,
@ -512,10 +586,10 @@ Page({
tradeNo: outTradeNo, tradeNo: outTradeNo,
transactionId: transactionId, transactionId: transactionId,
}; };
console.log(payOrderInfo,'支付信息'); console.log(payOrderInfo, '支付信息');
// if (channel === 'wechat') { // if (channel === 'wechat') {
wechatPayOrder(payOrderInfo); wechatPayOrder(payOrderInfo);
// } // }
}, },
@ -536,24 +610,36 @@ Page({
}, },
onCoupons(e) { onCoupons(e) {
const { submitCouponList, currentStoreId } = this.data; const {
const { goodsRequestList } = this; submitCouponList,
const { selectedList } = e.detail; currentStoreId
} = this.data;
const {
goodsRequestList
} = this;
const {
selectedList
} = e.detail;
const tempSubmitCouponList = submitCouponList.map((storeCoupon) => { const tempSubmitCouponList = submitCouponList.map((storeCoupon) => {
return { return {
couponList: couponList: storeCoupon.storeId === currentStoreId ?
storeCoupon.storeId === currentStoreId selectedList :
? selectedList storeCoupon.couponList,
: storeCoupon.couponList,
}; };
}); });
const resSubmitCouponList = this.handleCouponList(tempSubmitCouponList); const resSubmitCouponList = this.handleCouponList(tempSubmitCouponList);
//确定选择优惠券 //确定选择优惠券
this.handleOptionsParams({ goodsRequestList }, resSubmitCouponList); this.handleOptionsParams({
this.setData({ couponsShow: false }); goodsRequestList
}, resSubmitCouponList);
this.setData({
couponsShow: false
});
}, },
onOpenCoupons(e) { onOpenCoupons(e) {
const { storeid } = e.currentTarget.dataset; const {
storeid
} = e.currentTarget.dataset;
this.setData({ this.setData({
couponsShow: true, couponsShow: true,
currentStoreId: storeid, currentStoreId: storeid,
@ -572,23 +658,36 @@ Page({
onGoodsNumChange(e) { onGoodsNumChange(e) {
const { const {
detail: { value }, detail: {
value
},
currentTarget: { currentTarget: {
dataset: { goods }, dataset: {
goods
},
}, },
} = e; } = e;
const index = this.goodsRequestList.findIndex( const index = this.goodsRequestList.findIndex(
({ storeId, spuId, skuId }) => ({
goods.storeId === storeId && storeId,
goods.spuId === spuId && spuId,
goods.skuId === skuId, skuId
}) =>
goods.storeId === storeId &&
goods.spuId === spuId &&
goods.skuId === skuId,
); );
if (index >= 0) { if (index >= 0) {
// eslint-disable-next-line no-confusing-arrow // eslint-disable-next-line no-confusing-arrow
const goodsRequestList = this.goodsRequestList.map((item, i) => const goodsRequestList = this.goodsRequestList.map((item, i) =>
i === index ? { ...item, quantity: value } : item, i === index ? {
...item,
quantity: value
} : item,
); );
this.handleOptionsParams({ goodsRequestList }); this.handleOptionsParams({
goodsRequestList
});
} }
}, },
@ -597,4 +696,4 @@ Page({
popupShow: !this.data.popupShow, popupShow: !this.data.popupShow,
}); });
}, },
}); });

View File

@ -25,6 +25,7 @@ export const commitPay = (params) => {
couponList: params.couponList, couponList: params.couponList,
groupInfo: params.groupInfo, groupInfo: params.groupInfo,
openId: params.openId, // openId openId: params.openId, // openId
customerAddressGuid: params.customerAddressGuid, // openId
}); });
}; };

View File

@ -10,7 +10,7 @@
<view class="content-wrapper"> <view class="content-wrapper">
<button type="primary" bind:tap="getOpenIdFun">获取OpenID</button> <!-- <button type="primary" bind:tap="getOpenIdFun">获取OpenID</button> -->
<view class="order-group-wrapper"> <view class="order-group-wrapper">
<t-order-group orderTagInfos="{{orderTagInfos}}" bind:onClickTop="jumpAllOrder" bind:onClickItem="jumpNav" /> <t-order-group orderTagInfos="{{orderTagInfos}}" bind:onClickTop="jumpAllOrder" bind:onClickItem="jumpNav" />
</view> </view>