You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
210 lines
6.4 KiB
JavaScript
210 lines
6.4 KiB
JavaScript
9 months ago
|
var app = getApp();
|
||
|
var address = require("../../utils/address.js");
|
||
|
const point = require("../../utils/point.js");
|
||
|
var util = require("../../utils/util.js");
|
||
|
var inter
|
||
|
Page({
|
||
|
|
||
|
data: {
|
||
|
showRemark: false,
|
||
|
remark: "请填写备注",
|
||
|
addressFlag: false
|
||
|
},
|
||
|
|
||
|
onLoad: function (options) {
|
||
|
if (app.temData.orderPointProduct && app.temData.orderPointNum) {
|
||
|
var productDetail = app.temData.orderPointProduct;
|
||
|
var num = app.temData.orderPointNum;
|
||
|
if (productDetail.type == 0) {
|
||
|
productDetail.money = (productDetail.pointWorth).toFixed(2) + "积分";
|
||
|
productDetail.totalMoney = (productDetail.pointWorth * num).toFixed(2) + "积分";
|
||
|
} else if (productDetail.type == 1) {
|
||
|
productDetail.money = productDetail.pointWorth + "积分 " + "¥" + productDetail.amountWorth + "元 ";
|
||
|
productDetail.totalMoney = (productDetail.pointWorth * num).toFixed(2) + "积分 " + "¥" + (productDetail.amountWorth * num).toFixed(2) + "元 ";
|
||
|
} else if (productDetail.type == 2) {
|
||
|
productDetail.money = "¥" + productDetail.amountWorth + "元 ";
|
||
|
productDetail.totalMoney = "¥" + (productDetail.amountWorth * num).toFixed(2) + "元 ";
|
||
|
}
|
||
|
this.setData({
|
||
|
productDetail: productDetail,
|
||
|
num: num
|
||
|
})
|
||
|
} else {
|
||
|
wx.showLoading({
|
||
|
title: '数据加载异常 请重试!',
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
// queryConfirmOrderAddress: function () {
|
||
|
// var that = this;
|
||
|
// address.addressInfo.queryConfirmOrderAddress(function (success) {
|
||
|
// var result = success.data;
|
||
|
// if (result.status == 1) {
|
||
|
// that.setData({
|
||
|
// address: result.list[0],
|
||
|
// addressFlag: true
|
||
|
// })
|
||
|
// app.temData.orderAddress = result.list[0];
|
||
|
// } else {
|
||
|
// app.temData.orderAddress = ""
|
||
|
// that.setData({
|
||
|
// address: "",
|
||
|
// addressFlag: false
|
||
|
// })
|
||
|
// }
|
||
|
// }, function fail(error) {
|
||
|
// console.log(error + "------");
|
||
|
// wx.showToast({
|
||
|
// title: "网络连接不稳定, 请重试",
|
||
|
// icon: "none"
|
||
|
// })
|
||
|
// })
|
||
|
// },
|
||
|
cy_loadAddress:function(e){
|
||
|
if(e){
|
||
|
app.temData.orderAddress = e;
|
||
|
}
|
||
|
this.setData({
|
||
|
address: app.temData.orderAddress,
|
||
|
addressFlag: true
|
||
|
})
|
||
|
},
|
||
|
onShow: function () {
|
||
|
if (app.temData.orderAddress) {
|
||
|
// this.queryConfirmOrderAddress();
|
||
|
this.cy_loadAddress('');
|
||
|
}
|
||
|
},
|
||
|
showRemark: function () {
|
||
|
if (this.data.remark == "请填写备注") {
|
||
|
this.setData({
|
||
|
remark: ""
|
||
|
})
|
||
|
}
|
||
|
this.setData({
|
||
|
showRemark: true
|
||
|
})
|
||
|
},
|
||
|
confirmRemark(e) {
|
||
|
// e.detail.formId
|
||
|
if (!this.data.remark) {
|
||
|
this.setData({
|
||
|
remark: "请填写备注"
|
||
|
})
|
||
|
}
|
||
|
this.setData({
|
||
|
showRemark: false
|
||
|
})
|
||
|
},
|
||
|
remarkInput: function (e) {
|
||
|
this.setData({
|
||
|
remark: e.detail.value
|
||
|
})
|
||
|
},
|
||
|
gotoAddressList: function () {
|
||
|
wx.navigateTo({
|
||
|
url: '../mine/managerAddress?flag=couponEnter',
|
||
|
})
|
||
|
},
|
||
|
onSubmit: function (e) {
|
||
|
wx.showLoading({
|
||
|
title: '兑换中....',
|
||
|
})
|
||
|
if (!this.data.address) {
|
||
|
util.showWaring("请选择收货地址");
|
||
|
return;
|
||
|
}
|
||
|
var payAmount = this.data.productDetail.amountWorth * 100 * this.data.num;
|
||
|
var payPoint = this.data.productDetail.pointWorth * this.data.num;
|
||
|
var schemeId = this.data.productDetail.schemeId;
|
||
|
var payType = "微信";
|
||
|
var addressList = this.data.address;
|
||
|
var num = this.data.num;
|
||
|
var imageUrl = this.data.productDetail.imageUrl;
|
||
|
var remark = this.data.remark;
|
||
|
if (remark == '请填写备注') {
|
||
|
remark = '无备注'
|
||
|
}
|
||
|
point.pointInfo.createPointProductOrder(payAmount, payPoint, schemeId, payType, addressList, num, imageUrl, remark).then(res => {
|
||
|
if (res.data.status == 1) {
|
||
|
var outTradeNo = res.data.data.outTradeNo;
|
||
|
var type = this.data.productDetail.type;
|
||
|
point.pointInfo.pullOrderParam(outTradeNo, payAmount, type, schemeId, payPoint, num).then(res => {
|
||
|
var result = res.data;
|
||
|
if (result.status == 1) {
|
||
|
var openData = result.data;
|
||
|
//开始查询订单
|
||
|
this.queryPointOrder(outTradeNo);
|
||
|
if (this.data.productDetail.type >= 1) {
|
||
|
wx.requestPayment({
|
||
|
'timeStamp': openData.timeStamp,
|
||
|
'nonceStr': openData.nonceStr,
|
||
|
'package': openData.package,
|
||
|
'signType': openData.signType,
|
||
|
'paySign': openData.paySign,
|
||
|
'success': function (res) {
|
||
|
console.log('..success..' + JSON.stringify(res));
|
||
|
},
|
||
|
'fail': function (res) {
|
||
|
console.error(JSON.stringify(res));
|
||
|
clearInterval(inter);
|
||
|
util.showWaring("微信支付取消")
|
||
|
},
|
||
|
'complete': function () {
|
||
|
console.log('..complete..');
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
wx.hideLoading();
|
||
|
// app.showMsg(result.errMessage, "none");
|
||
|
util.showFailureMsg(result);
|
||
|
}
|
||
|
}, res => {
|
||
|
wx.showLoading({
|
||
|
title: '数据加载异常 请重试!',
|
||
|
})
|
||
|
})
|
||
|
} else {
|
||
|
wx.hideLoading();
|
||
|
util.showFailureMsg(res.data);
|
||
|
// app.showMsg(res.data.errMessage, "none");
|
||
|
}
|
||
|
})
|
||
|
},
|
||
|
queryPointOrder: function (orderNo) {
|
||
|
var i = 0;
|
||
|
var that = this;
|
||
|
inter = setInterval(function () {
|
||
|
point.pointInfo.queryPointOrder(orderNo).then(res => {
|
||
|
var result = res.data;
|
||
|
if (result.status == 1) {
|
||
|
that.setData({
|
||
|
orderNo: orderNo
|
||
|
})
|
||
|
app.temData.orderNo = orderNo
|
||
|
clearInterval(inter)
|
||
|
var url = '/pages/couponCenter/exchangeSuccess?shopType=1&msg=' + that.data.productDetail.totalMoney + "&productName=" + that.data.productDetail.productName;
|
||
|
wx.redirectTo({
|
||
|
url: url,
|
||
|
})
|
||
|
wx.hideLoading();
|
||
|
} else {
|
||
|
i = i + 1;
|
||
|
if (i >= 100) {
|
||
|
clearInterval(inter);
|
||
|
util.showFailureMsg(result);
|
||
|
// app.showMsg("微信查询订单失败", "none")
|
||
|
wx.hideLoading();
|
||
|
}
|
||
|
}
|
||
|
}, res => {
|
||
|
util.showWaring("微信查询订单失败,网络不稳定")
|
||
|
wx.hideLoading();
|
||
|
})
|
||
|
}, 1000)
|
||
|
},
|
||
|
onUnload:function(){
|
||
|
clearInterval(inter);
|
||
|
}
|
||
|
})
|