mirror of
https://gitee.com/java110/WechatOwnerService.git
synced 2026-02-23 21:36:38 +08:00
优化代码
This commit is contained in:
parent
e3a1abd921
commit
e01272c71f
@ -5,7 +5,17 @@ import {
|
||||
import url from '../../constant/url.js';
|
||||
|
||||
|
||||
// #ifdef APP-PLUS
|
||||
import {
|
||||
getPayInfo
|
||||
} from '../../factory/WexinAppPayFactory.js'
|
||||
// #endif
|
||||
|
||||
// #ifdef H5
|
||||
|
||||
const WexinPayFactory = require('../../factory/WexinPayFactory.js');
|
||||
|
||||
// #endif
|
||||
|
||||
/**
|
||||
* 查询活动列表
|
||||
@ -98,7 +108,7 @@ export function saveStoreCart(dataObj) {
|
||||
//动态数据
|
||||
success: function(res) {
|
||||
if (res.statusCode == 200) {
|
||||
|
||||
|
||||
resolve(res.data);
|
||||
return;
|
||||
}
|
||||
@ -124,7 +134,7 @@ export function getStoreCart(dataObj) {
|
||||
//动态数据
|
||||
success: function(res) {
|
||||
if (res.statusCode == 200) {
|
||||
|
||||
|
||||
resolve(res.data);
|
||||
return;
|
||||
}
|
||||
@ -137,3 +147,81 @@ export function getStoreCart(dataObj) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品统一下单
|
||||
* @param {Object} dataObj 下单报文
|
||||
*/
|
||||
export function goodsUnifieldOrder(dataObj) {
|
||||
return new Promise(
|
||||
(resolve, reject) => {
|
||||
request({
|
||||
url: url.goodsUnifieldOrder,
|
||||
method: "POST",
|
||||
data: dataObj,
|
||||
//动态数据
|
||||
success: function(res) {
|
||||
if (res.statusCode == 200) {
|
||||
resolve(res.data);
|
||||
return;
|
||||
}
|
||||
reject();
|
||||
},
|
||||
fail: function(e) {
|
||||
reject();
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起微信支付
|
||||
* add by 吴学文 2020-11-12
|
||||
* @param {Object} data 微信支付参数
|
||||
*/
|
||||
export function toPay(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let obj = {};
|
||||
let orderInfo = {};
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.requestPayment({
|
||||
'timeStamp': data.timeStamp,
|
||||
'nonceStr': data.nonceStr,
|
||||
'package': data.package,
|
||||
'signType': data.signType,
|
||||
'paySign': data.sign,
|
||||
'success': function(res) {
|
||||
resolve(res);
|
||||
},
|
||||
'fail': function(err) {
|
||||
reject(err)
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
WexinPayFactory.wexinPay(data,function(){
|
||||
uni.showToast({
|
||||
title: "支付成功",
|
||||
duration: 2000
|
||||
});
|
||||
resolve(res);
|
||||
});
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
obj = getPayInfo(data);
|
||||
// 第二种写法,传对象字符串
|
||||
orderInfo = JSON.stringify(obj)
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
orderInfo: orderInfo, //微信、支付宝订单数据
|
||||
success: function(res) {
|
||||
console.log("购买",res)
|
||||
resolve(res);
|
||||
},
|
||||
fail: function(err) {
|
||||
console.log("购买失败",err)
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
})
|
||||
}
|
||||
|
||||
@ -99,6 +99,7 @@ export default {
|
||||
queryUserAddress: baseUrl + 'app/userAddress/queryUserAddress',
|
||||
saveUserAddress: baseUrl + 'app/userAddress/saveUserAddress',
|
||||
deleteUserAddress: baseUrl+'app/userAddress/deleteUserAddress',
|
||||
goodsUnifieldOrder: baseUrl +'goods/unifieldOrder',
|
||||
|
||||
NEED_NOT_LOGIN_PAGE: [
|
||||
'/pages/login/login',
|
||||
|
||||
@ -99,7 +99,7 @@
|
||||
|
||||
|
||||
import {
|
||||
getStoreCart
|
||||
getStoreCart,goodsUnifieldOrder,toPay
|
||||
} from '../../api/goods/goodsApi.js'
|
||||
|
||||
import {
|
||||
@ -119,23 +119,16 @@
|
||||
isDefault: 0
|
||||
},
|
||||
addressId: 0,
|
||||
from: '',
|
||||
orderType: '',
|
||||
grouponBuyType: 'alone',
|
||||
grouponId: 0,
|
||||
perGoodsList: [], //确认单订单商品
|
||||
remark: '',
|
||||
couponId: 0,
|
||||
expressTypeCur: '',
|
||||
showCheckTime: false, //配送时间弹窗。
|
||||
inExpressType: [], //当前商品支持的配送方式。
|
||||
getFocus: false, //获取焦点。
|
||||
checkType: '自提',
|
||||
checkTime: {},
|
||||
checkTimeCur: 0, //默认选中时间。
|
||||
checkTimeId: 'c1', //锚点用
|
||||
checkDayCur: 0, //默认日期
|
||||
personId: '',
|
||||
personName:'',
|
||||
totalFee:0.0,
|
||||
goodsCount:0
|
||||
|
||||
@ -153,7 +146,8 @@
|
||||
price: options.price,
|
||||
prodName: options.prodName,
|
||||
coverPhoto: decodeURIComponent(options.coverPhoto),
|
||||
storeId: options.storeId
|
||||
storeId: options.storeId,
|
||||
cartId:'-1'
|
||||
});
|
||||
|
||||
_that.totalFee = parseFloat(options.goodsNum) * parseFloat(options.price);
|
||||
@ -199,7 +193,7 @@
|
||||
row:50
|
||||
|
||||
}).then(res => {
|
||||
if (res.code === 0) {
|
||||
if (res.code === 0 && res.data.length> 0) {
|
||||
let _data = res.data;
|
||||
_data.forEach(item => {
|
||||
that.perGoodsList.push({
|
||||
@ -210,7 +204,8 @@
|
||||
price: item.price,
|
||||
prodName: item.prodName,
|
||||
coverPhoto: item.coverPhoto,
|
||||
storeId: item.storeId
|
||||
storeId: item.storeId,
|
||||
cartId:item.cartId
|
||||
});
|
||||
|
||||
that.totalFee = parseFloat(that.totalFee)+(parseFloat(item.cartNum) * parseFloat(item.price));
|
||||
@ -224,64 +219,61 @@
|
||||
// 提交订单
|
||||
subOrder() {
|
||||
let that = this;
|
||||
that.isSubOrder = true;
|
||||
that.$api('order.createOrder', {
|
||||
goods_list: that.goodsList,
|
||||
from: that.from,
|
||||
address_id: that.addressId,
|
||||
coupons_id: that.couponId,
|
||||
wx.showLoading({
|
||||
title: '支付中'
|
||||
});
|
||||
let _tradeType = 'APP';
|
||||
// #ifdef H5 || MP-WEIXIN
|
||||
_tradeType = 'JSAPI';
|
||||
// #endif
|
||||
goodsUnifieldOrder({
|
||||
goodsList: that.perGoodsList,
|
||||
remark: that.remark,
|
||||
order_type: that.orderType,
|
||||
buy_type: that.grouponBuyType,
|
||||
groupon_id: that.grouponId
|
||||
addressId: that.address.addressId,
|
||||
personId: that.personId,
|
||||
personName: that.personName,
|
||||
userId:that.personId,
|
||||
tradeType: _tradeType,
|
||||
}).then(res => {
|
||||
if (res.code === 1) {
|
||||
let orderId = res.data.id;
|
||||
let orderSn = res.data.order_sn;
|
||||
that.getCartList();
|
||||
that.isSubOrder = false;
|
||||
// #ifdef MP-WEIXIN
|
||||
res.data.activity_type == 'groupon' ? this.$store.dispatch('getMessageIds', 'grouponResult') : this.$store.dispatch(
|
||||
'getMessageIds', 'result');
|
||||
// #endif
|
||||
if (res.data.status > 0) {
|
||||
that.$Router.replace({
|
||||
path: '/pages/order/payment/result',
|
||||
query: {
|
||||
orderSn: orderSn,
|
||||
type: '',
|
||||
pay: 1
|
||||
}
|
||||
});
|
||||
} else {
|
||||
uni.redirectTo({
|
||||
url: `/pages/order/payment/method?orderId=${orderId}`
|
||||
});
|
||||
}
|
||||
} else {
|
||||
that.isSubOrder = false;
|
||||
let _data = null;
|
||||
if (res.code == '0') {
|
||||
return toPay(res);
|
||||
}
|
||||
uni.showToast({
|
||||
icon:'none',
|
||||
title:res.msg
|
||||
})
|
||||
return _data;
|
||||
})
|
||||
.then((res)=>{
|
||||
console.log('res',res);
|
||||
if(res == null){
|
||||
return ;
|
||||
}
|
||||
wx.hideLoading();
|
||||
uni.showToast({
|
||||
icon:'none',
|
||||
title:'支付成功',
|
||||
})
|
||||
},(err)=>{
|
||||
wx.hideLoading();
|
||||
uni.showToast({
|
||||
icon:'none',
|
||||
title:err,
|
||||
})
|
||||
});
|
||||
},
|
||||
// 初始地址
|
||||
getDefaultAddress() {
|
||||
// this.$api('address.defaults').then(res => {
|
||||
// if (res.code === 1) {
|
||||
// if (res.data) {
|
||||
// this.address = res.data;
|
||||
// this.selfPhone = res.data.phone
|
||||
// }
|
||||
|
||||
// }
|
||||
// });
|
||||
|
||||
},
|
||||
getOwner: function() {
|
||||
let _that = this;
|
||||
return getCurOwner()
|
||||
.then((owner) => {
|
||||
console.log(owner)
|
||||
_that.personId = owner.memberId
|
||||
|
||||
_that.personId = owner.userId;
|
||||
_that.personName = owner.userName;
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user