增加新功能

This commit is contained in:
hejiangming
2025-03-23 20:36:06 +08:00
parent 2ae62b59ed
commit 78270eeda0
184 changed files with 2690 additions and 1496 deletions
+123 -13
View File
@@ -155,7 +155,8 @@
<script>
import Address from '@/components/address.vue';
import { PAYMENT_WAY,PAYMENT_WAY_,PRODUCT_DELIVERY_TIME,getValue } from '@/utils/enumUtils.js';
import { getSettleList } from '@/api/cart.js'
import { getSettleList,settle } from '@/api/cart.js'
import { feedback } from '@/api/payment.js';
import { assembleAddress } from '@/utils/index.js'
export default {
@@ -242,7 +243,6 @@
}
data.shops = shops;
data.paymentMethod = null;// 支付方式
console.log("data",data);
this.orderInfo = data;
}
},
@@ -274,29 +274,138 @@
// 获取备注
getRemark(){
const orderInfo = this.orderInfo;
console.log("orderInfo",orderInfo);
const remarkArr = [];
if(orderInfo && Object.keys(orderInfo).length!==0){
const remarObj={};
if(orderInfo.shops && orderInfo.shops.length!==0){
orderInfo.shops.map(sItem=>{
if(sItem.addrTimes && sItem.addrTimes.length !==0){
sItem.addrTimes.map(addItem=>{
if(addItem.remark){
remarObj.gkey = addItem.groupKey;
remarObj.rmk = addItem.remark;
}
})
}
})
}
remarkArr.push(remarObj);
}
console.log("remarkArr",remarkArr);
return remarkArr;
},
/**
* 去支付
*/
goPay(){
async goPay(){
const orderInfo = this.orderInfo;
const way = orderInfo.paymentMethod;
if(!way || way === 0){
this.$refs.uToastRef.show({
type: 'error',
message: "请先选择支付方式",
});
return;
}
const params={
addrId:this.orderInfo.address.id,// 收货地址ID
addrId:orderInfo.address.id,// 收货地址ID
cartIds:this.ids,//结算的购物车ID,多个以逗号分割,ALL表示全选
payway:0,// 支付方式:1-微信,2-支付宝
remark:null,//备注信息'[{"sid":"店铺ID","rmk":"备注内容"},{"sid":"店铺ID","rmk":"备注内容"}]'
payway:way,// 支付方式:1-微信,2-支付宝
remark:JSON.stringify(this.getRemark()),//备注信息'[{"sid":"店铺ID","rmk":"备注内容"},{"sid":"店铺ID","rmk":"备注内容"}]'
}
console.log("params",params);
// 支付成功的页面
// uni.navigateTo({
// url:"/pages/order_submit_ok/order_submit_ok",
// })
const resp = await settle(params);
// 提交订单成功,就唤起支付
if(resp && resp.bizcode === 100){
const item = resp.data;
if(params.payway === PAYMENT_WAY.WECHAT){// APP微信支付
if(item.wechat && Object.keys(item.wechat).length !==0){
this.appWxpay(item.wechat);
}else{
this.$refs.uToastRef.show({
type: 'error',
message: "订单支付失败",
});
}
}else if(params.payway === PAYMENT_WAY.ALIPAY){// 支付宝支付
if(item.alipay && Object.keys(item.alipay).length !==0){
this.zfbPay(item.alipay);
}else{
this.$refs.uToastRef.show({
type: 'error',
message: "订单支付失败",
});
}
}
}
},
// app 微信支付
appWxpay(item){
const newThis = this;
const orderInfo = {
"appid": item.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
"noncestr": item.nonceStr, // 随机字符串
"package": "Sign=WXPay", // 固定值
"partnerid": item.partnerId, // 微信支付商户号
"prepayid": item.prepayId, // 统一下单订单号
"timestamp": item.timeStamp, // 时间戳(单位:秒)
"sign": item.sign // 签名,这里用的 MD5/RSA 签名
};
uni.requestPayment({
provider:"wxpay",
orderInfo: orderInfo,
success: function(res) {
console.log('success:' + res);
newThis.payFeedbackFun(item.orderId,res.orderNum,1);
newThis.jumpWayOk();
},
fail: function(err) {
console.log('fail:',err);
this.$refs.uToastRef.show({
type: 'error',
message: "支付失败",
});
}
});
},
// 支付宝支付
zfbPay(item){
const that = this;
uni.requestPayment({
provider: 'alipay',
orderInfo: item.orderStr,
success(res) {
console.log("res",res);
that.payFeedbackFun(item.orderId,item.orderNum,1);
that.jumpWayOk();
},
//调用失败的回调
fail(err) {
console.log('fail:',err);
this.$refs.uToastRef.show({
type: 'error',
message: "支付失败",
});
}
})
},
// 跳转到支付成功页面
jumpWayOk(){
uni.navigateTo({
url:"/pages/order_submit_ok/order_submit_ok",
})
},
// 支付结果回调
async payFeedbackFun(orderId,orderNum,status){
const params = {
orderId,
orderNum,
status,
}
console.log("params",params);
const response = await feedback(params);
console.log("反馈结果",response);
},
// 地址选中
getAddressValueFunc(item){
@@ -304,6 +413,7 @@
addressObj.addressStr = assembleAddress(addressObj).names;
this.selectAddress = addressObj;
},
// 地址选中OK
addressOk(){
const type = this.addressType;
const addressIndex = this.addressIndex;