...
|
...
|
@@ -5,45 +5,193 @@ |
|
|
*@description 订单支付确认界面
|
|
|
*/
|
|
|
|
|
|
import orderService from '../orderService'
|
|
|
import {getImgUrl} from '../../../utils';
|
|
|
|
|
|
Page({
|
|
|
|
|
|
data: {
|
|
|
productInfo: {
|
|
|
"colorId": 1,
|
|
|
"colorName": "红色",
|
|
|
"goodImg": "http://img11.static.yhbimg.com/goodsimg/2018/10/18/17/01699014e8981a532f27abc74730e40bbd.jpg?imageMogr2/thumbnail/90x90/background/d2hpdGU=/position/center/quality/80",
|
|
|
"goodPrice": "9.00",
|
|
|
"productName": "Air Jordan XX9 Low “Chicago Bulls”",
|
|
|
"sizeId": 2,
|
|
|
"sizeName": "M111",
|
|
|
"skup": 1468
|
|
|
},
|
|
|
"damagesDesc": "如卖家原因导致交易失败,您将获得赔偿金¥0.80元",
|
|
|
"promotionFormulaList": [{
|
|
|
"promotion": "商品金额",
|
|
|
"promotionAmount": "¥9.00"
|
|
|
}, {
|
|
|
"promotion": "运费",
|
|
|
"promotionAmount": "+ ¥0.0"
|
|
|
}, {
|
|
|
"promotion": "实付金额",
|
|
|
"promotionAmount": "¥9.00"
|
|
|
}],
|
|
|
"deliveryWay": {
|
|
|
"deliveryWayCost": "¥0.0",
|
|
|
"deliveryWayId": 2,
|
|
|
"deliveryWayName": "顺丰速运"
|
|
|
},
|
|
|
"paymentWay": {
|
|
|
"paymentType": 1,
|
|
|
"paymentTypeName": "在线支付"
|
|
|
},
|
|
|
payLabel: '待支付:',
|
|
|
payButton: '去支付',
|
|
|
amount: '9.00',
|
|
|
|
|
|
},
|
|
|
onLoad: function (option) {
|
|
|
console.log(option)
|
|
|
|
|
|
this.setData({
|
|
|
skup: option && option.skup ? option.skup : '',
|
|
|
product_id: option && option.product_id ? option.product_id : '',
|
|
|
hasAddress: false
|
|
|
})
|
|
|
|
|
|
this.fetchData()
|
|
|
this.fetchAddress()
|
|
|
},
|
|
|
|
|
|
fetchData() {
|
|
|
let api = new orderService();
|
|
|
wx.showLoading({
|
|
|
title: '',
|
|
|
});
|
|
|
let params = {
|
|
|
uid: '500031182',
|
|
|
skup: this.data.skup,
|
|
|
debug: 'XYZ'
|
|
|
}
|
|
|
api.createPaymentInfo(params, () => wx.hideLoading())
|
|
|
.then(data => {
|
|
|
if (data) {
|
|
|
if (data.good && data.good.goodImg) {
|
|
|
data.good.goodImg = getImgUrl(data.good.goodImg,90,90)
|
|
|
}
|
|
|
this.setData(data)
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.log(error)
|
|
|
})
|
|
|
},
|
|
|
|
|
|
fetchAddress() {
|
|
|
let api = new orderService().yohoApi()
|
|
|
wx.showLoading({
|
|
|
title: '',
|
|
|
})
|
|
|
|
|
|
let params = {
|
|
|
uid: '500031182',
|
|
|
debug: 'XYZ'
|
|
|
}
|
|
|
|
|
|
api.buyerGetAddress(params, () => wx.hideLoading())
|
|
|
.then(data => {
|
|
|
if (Array.isArray(data)){
|
|
|
for (let item of data) {
|
|
|
let index = data.indexOf(item)
|
|
|
if (item.is_default === 'Y') {
|
|
|
this.setData({
|
|
|
address: item,
|
|
|
hasAddress: true,
|
|
|
})
|
|
|
break
|
|
|
}
|
|
|
if (index == data.length - 1){
|
|
|
this.setData({
|
|
|
address: item,
|
|
|
hasAddress: true,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.log(error)
|
|
|
})
|
|
|
},
|
|
|
|
|
|
submit() {
|
|
|
if (!this.data.hasAddress) {
|
|
|
wx.showToast({
|
|
|
title:'请选择地址'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
let addressId = this.data.hasAddress && this.data.address && this.data.address.address_id
|
|
|
let skup = this.data.skup
|
|
|
let channelNo = ''
|
|
|
let uid = '500031182'
|
|
|
|
|
|
let api = new orderService()
|
|
|
wx.showLoading({
|
|
|
title: '',
|
|
|
})
|
|
|
|
|
|
api.buyerSubmit(uid,skup,channelNo,addressId, () => wx.hideLoading())
|
|
|
.then(data => {
|
|
|
if (data && data.orderCode) {
|
|
|
this.prePay(data.orderCode)
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.log(error)
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
prePay(orderCode) {
|
|
|
this.setData({
|
|
|
orderCode: orderCode
|
|
|
})
|
|
|
// return wx.navigateTo({
|
|
|
// url: `./orderSuccess?product_id=${this.data.product_id}&orderCode=${this.data.orderCode}`
|
|
|
// })
|
|
|
|
|
|
let uid = '500031182'
|
|
|
let api = new orderService()
|
|
|
wx.showLoading({
|
|
|
title: '',
|
|
|
})
|
|
|
|
|
|
api.prePay(uid,orderCode, () => wx.hideLoading())
|
|
|
.then(data => {
|
|
|
if (data && data.prePayData) {
|
|
|
this.callWxPay(data.prePayData)
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.log(error)
|
|
|
})
|
|
|
},
|
|
|
|
|
|
callWxPay(data) {
|
|
|
data.paySign = data.sign;
|
|
|
data.timeStamp = data.timestamp
|
|
|
data.nonceStr = data.noncestr
|
|
|
data.signType = 'MD5'
|
|
|
data.package = 'prepay_id=' + data.prepayid
|
|
|
|
|
|
|
|
|
wx.requestPayment({
|
|
|
...data,
|
|
|
success: function (res) {
|
|
|
wx.navigateTo({
|
|
|
url: `./orderSuccess?product_id=${this.data.product_id}&orderCode=${this.data.orderCode}`
|
|
|
})
|
|
|
},
|
|
|
fail: function (res) {
|
|
|
console.log(res)
|
|
|
if(res.errMsg=='requestPayment:fail cancel'){
|
|
|
// wx.redirectTo({
|
|
|
// url: '../orders/orders'
|
|
|
// })
|
|
|
}else{
|
|
|
wx.showModal({
|
|
|
content: res.errMsg,
|
|
|
showCancel: false,
|
|
|
confirmText: "确定",
|
|
|
complete: function(res) {
|
|
|
// wx.redirectTo({
|
|
|
// url: '../orders/orders'
|
|
|
// })
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
|
|
|
chooseAddress: function(){
|
|
|
// var pages = getCurrentPages();
|
|
|
// var prevPage = pages[pages.length - 2]; //上一个页面
|
|
|
// prevPage.setData({
|
|
|
// })
|
|
|
//
|
|
|
// wx.navigateBack();
|
|
|
wx.navigateTo({
|
|
|
url: '../../userCenter/addressManager/addressManager'
|
|
|
})
|
|
|
}
|
|
|
|
|
|
|
|
|
}) |
...
|
...
|
|