|
@@ -122,8 +122,7 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
postOrder(){
|
|
|
- let self = this
|
|
|
- let list = self.shoppingCartList
|
|
|
+ let list = this.shoppingCartList
|
|
|
for(let i=0;i<list.length;i++){
|
|
|
let item = list[i];
|
|
|
if(item.goodsType==1){
|
|
@@ -147,15 +146,28 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
let data = {goodsList:list}
|
|
|
-
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
this.$api.placeSmallOrder(data).then(res => {
|
|
|
console.log(res,'res')
|
|
|
- if(res.data.code==200){
|
|
|
+ this.orderResult(res)
|
|
|
+ });
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ // #ifdef H5
|
|
|
+ data['url'] = location.href
|
|
|
+ this.$api.placeGzhOrder(data).then(res => {
|
|
|
+ console.log(res,'res')
|
|
|
+ this.orderResult(res)
|
|
|
+ });
|
|
|
+ // #endif
|
|
|
+ },
|
|
|
+ orderResult(res) {
|
|
|
+ if(res.data.code==200){
|
|
|
|
|
|
uni.setStorageSync('updateCart',1) //提醒刷新购物车
|
|
|
if(this.totalPrice == 0) { //免费商品
|
|
|
uni.redirectTo({
|
|
|
- url: `/pages2/order/confirm_success?sn=${res.data.data.orderSn}&isBk=${self.isBK}`
|
|
|
+ url: `/pages2/order/confirm_success?sn=${res.data.data.orderSn}&isBk=${this.isBK}`
|
|
|
});
|
|
|
} else {
|
|
|
let data = res.data.data
|
|
@@ -163,6 +175,7 @@ export default {
|
|
|
title:'支付中',
|
|
|
mask:true,
|
|
|
})
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
uni.requestPayment({
|
|
|
provider: data.provider,
|
|
|
nonceStr: data.nonceStr,
|
|
@@ -170,33 +183,38 @@ export default {
|
|
|
signType: data.signType,
|
|
|
paySign: data.sign,
|
|
|
timeStamp: String(data.timeStamp),
|
|
|
- success: function (res) {
|
|
|
+ success: (res) => {
|
|
|
|
|
|
- uni.hideLoading()
|
|
|
- self.btnNo = false
|
|
|
+ uni.hideLoading()
|
|
|
+ this.btnNo = false
|
|
|
uni.redirectTo({
|
|
|
- url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${self.isBK}`
|
|
|
+ url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${this.isBK}`
|
|
|
});
|
|
|
console.log('success:' + JSON.stringify(res));
|
|
|
},
|
|
|
- fail: function (err) {
|
|
|
+ fail: (err) => {
|
|
|
uni.hideLoading()
|
|
|
- self.btnNo = false
|
|
|
+ this.btnNo = false
|
|
|
console.log('fail:' + JSON.stringify(err));
|
|
|
}
|
|
|
});
|
|
|
+ // #endif
|
|
|
+
|
|
|
+ // #ifdef H5
|
|
|
+ this.h5_wxpay(data)
|
|
|
+ // #endif
|
|
|
}
|
|
|
|
|
|
}else if(res.data.code == 510){ //有未支付订单
|
|
|
- self.hasPaying = true;
|
|
|
- self.btnNo = false
|
|
|
+ this.hasPaying = true;
|
|
|
+ this.btnNo = false
|
|
|
this.modalMsg = res.data.msg;
|
|
|
this.showConfirmButton = true;
|
|
|
this.confirmText = "跳转到【我的订单】\n查看未支付订单";
|
|
|
this.showModal = true;
|
|
|
} else if(res.data.code == 511) { //511 重复购买
|
|
|
- self.hasPaying = false;
|
|
|
- self.btnNo = false
|
|
|
+ this.hasPaying = false;
|
|
|
+ this.btnNo = false
|
|
|
this.modalMsg = res.data.msg;
|
|
|
this.showConfirmButton = true;
|
|
|
this.showModal = true;
|
|
@@ -219,13 +237,55 @@ export default {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- self.hasPaying = false;
|
|
|
- self.btnNo = false
|
|
|
+ this.hasPaying = false;
|
|
|
+ this.btnNo = false
|
|
|
this.showConfirmButton = false;
|
|
|
this.modalMsg = res.data.msg;
|
|
|
this.showModal = true;
|
|
|
}
|
|
|
- });
|
|
|
+ },
|
|
|
+ h5_wxpay(data) {
|
|
|
+ function onBridgeReady() {
|
|
|
+ // 加载框
|
|
|
+ WeixinJSBridge.invoke(
|
|
|
+ 'getBrandWCPayRequest', {
|
|
|
+ 'appId': data.appId, // 公众号名称,由商户传入
|
|
|
+ 'timeStamp': data.timeStamp, // 时间戳,自1970年以来的秒数
|
|
|
+ 'nonceStr': data.nonceStr, // 随机串
|
|
|
+ 'package': data.package,
|
|
|
+ 'signType': data.signType, // 微信签名方式:
|
|
|
+ 'paySign': data.paySign // 微信签名
|
|
|
+ },
|
|
|
+ function(res) {
|
|
|
+ // 判断支付状态
|
|
|
+ console.log('支付状态',res)
|
|
|
+ if (res.err_msg === 'get_brand_wcpay_request:ok') {
|
|
|
+ this.$u.toast('支付成功')
|
|
|
+ uni.hideLoading()
|
|
|
+ this.btnNo = false
|
|
|
+ uni.redirectTo({
|
|
|
+ url: `/pages2/order/confirm_success?sn=${data.orderSn}&isBk=${this.isBK}`
|
|
|
+ });
|
|
|
+ } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
|
|
|
+ this.$u.toast('取消支付')
|
|
|
+ } else {
|
|
|
+ uni.hideLoading()
|
|
|
+ this.btnNo = false
|
|
|
+ this.$u.toast('支付失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (typeof WeixinJSBridge === 'undefined') {
|
|
|
+ if (document.addEventListener) {
|
|
|
+ document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
|
|
|
+ } else if (document.attachEvent) {
|
|
|
+ document.attachEvent('WeixinJSBridgeReady', onBridgeReady)
|
|
|
+ document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ onBridgeReady()
|
|
|
+ }
|
|
|
},
|
|
|
modalCancel() {
|
|
|
this.showModal = false;
|
|
@@ -273,13 +333,8 @@ export default {
|
|
|
// #endif
|
|
|
|
|
|
// #ifdef H5
|
|
|
- // https://www.xyyxt.net/?ask_type=h.xyyxt.net
|
|
|
- // location.replace(
|
|
|
- // "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6f48f721d18244eb" +
|
|
|
- // "&redirect_uri=" +
|
|
|
- // encodeURIComponent('https://www.xyyxt.net/?ask_type=h.xyyxt.net') +
|
|
|
- // "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"
|
|
|
- // )
|
|
|
+ // 在首页已经请求过接口/gzh_login 提交code了
|
|
|
+ this.postOrder()
|
|
|
// #endif
|
|
|
},
|
|
|
radioChange(e) {
|