You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
224 lines
6.1 KiB
224 lines
6.1 KiB
//index.js
|
|
//获取应用实例
|
|
const app = getApp()
|
|
|
|
|
|
Page({
|
|
data: {
|
|
items: [
|
|
{ name: '陈晓旭', phone: '18775242654', address1: '广州市 天河区 东圃大马路时代TIT广场A栋423' }
|
|
],
|
|
read: true,
|
|
remark:'',
|
|
clock:300,
|
|
},
|
|
imageOnload(ev) {
|
|
console.log('图片加载成功,width: ${ev.detail.width}; height: ${ev.detail.height}');
|
|
},
|
|
imageOnloadError() {
|
|
console.log('图片加载失败');
|
|
},
|
|
formSubmit: function (e) {
|
|
console.log('form发生了submit事件,携带数据为:', e.detail.value)
|
|
},
|
|
formReset: function () {
|
|
console.log('form发生了reset事件')
|
|
},
|
|
//事件处理函数
|
|
loading: function (e) {
|
|
let str = JSON.stringify(e.currentTarget.dataset.item);
|
|
wx.navigateTo({
|
|
url: '../detail/detail?jsonStr=' + str
|
|
})
|
|
},
|
|
changeAddr: function (e) {
|
|
let str = JSON.stringify(e.currentTarget.dataset.item);
|
|
wx.navigateTo({
|
|
url: '../addr/addr?jsonStr=' + str
|
|
})
|
|
},
|
|
goRemark: function (e) {
|
|
let str = JSON.stringify(e.currentTarget.dataset.item);
|
|
wx.navigateTo({
|
|
url: '../remark/remark?jsonStr=' + str+'&&remark='+this.data.remark
|
|
})
|
|
},
|
|
checkboxChange: function (e) {
|
|
this.setData({
|
|
read: !this.data.read
|
|
})
|
|
},
|
|
goLook: function (e) {
|
|
wx.navigateTo({
|
|
url: '../agreement/agreement'
|
|
})
|
|
},
|
|
pay: function (e) {
|
|
// let str = JSON.stringify(e.currentTarget.dataset.item);
|
|
let str = e.currentTarget.dataset.item;
|
|
console.log(str.goodsNo);
|
|
let that=this;
|
|
wx.showToast({
|
|
title: '正在调起支付',
|
|
icon: 'loading'
|
|
})
|
|
wx.request({//获取orderNo
|
|
url: app.gw.hostUrl + '/mall/wxa/order/new',
|
|
method: 'post',
|
|
data: {
|
|
addressId:'',
|
|
goodsNo:str.goodsNo,
|
|
sourceType: 0,
|
|
goodsNum: 1,
|
|
couponNo: '',
|
|
remark:that.data.remark
|
|
},
|
|
header: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'sessionId': wx.getStorageSync('sessionId')
|
|
},
|
|
success: function (res) {
|
|
//--init data
|
|
let data = res.data;
|
|
let status = data.code;
|
|
if (status != 0) {
|
|
wx.showToast({
|
|
title: data.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
return;
|
|
}
|
|
that.setData({
|
|
orderNo:data.response.orderNo
|
|
})
|
|
|
|
wx.request({//获取微信支付想要的数据
|
|
url: app.gw.hostUrl + '/mall/wxa/order/pay',
|
|
method: 'put',
|
|
data: {
|
|
openid: app.globalData.openid,
|
|
orderNo: data.response.orderNo,
|
|
paymentType: 8
|
|
},
|
|
header: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'sessionId': wx.getStorageSync('sessionId')
|
|
},
|
|
success: function (res) {
|
|
//--init data
|
|
let data = res.data;
|
|
let status = data.code;
|
|
if (status != 0) {
|
|
wx.showToast({
|
|
title: data.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
return;
|
|
}
|
|
console.log(data.response);
|
|
let dr = data.response.weixinTransParameters;
|
|
console.log(dr);
|
|
wx.requestPayment({//微信支付
|
|
"timeStamp": dr.timeStamp,
|
|
"nonceStr": dr.nonceStr,
|
|
"package": dr.package,
|
|
"signType": dr.signType,
|
|
"paySign": dr.paySign,
|
|
"success": function (res) {
|
|
console.log(res);
|
|
wx.showToast({
|
|
title: '支付成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
})
|
|
wx.switchTab({//跳转到订单页面
|
|
url: '../order/order' ,
|
|
success: function (e) {
|
|
var page = getCurrentPages().pop();
|
|
if (page == undefined || page == null) return;
|
|
console.log(page);
|
|
page.onShow();
|
|
}
|
|
})
|
|
},
|
|
"fail": function (res) {
|
|
console.log(res);
|
|
if(res.errMsg=='requestPayment:fail cancel'){
|
|
wx.showToast({
|
|
title: '取消支付',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
}else{
|
|
wx.showToast({
|
|
title: '支付出错',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
fail: function (e) {
|
|
wx.showToast({
|
|
title: '网络异常!err:authlogin',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
},
|
|
});
|
|
},
|
|
fail: function (e) {
|
|
wx.showToast({
|
|
title: '网络异常!err:authlogin',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
},
|
|
});
|
|
},
|
|
onLoad: function (options) {
|
|
let item = JSON.parse(options.jsonStr);
|
|
console.log(item);
|
|
this.setData({
|
|
product: item,
|
|
})
|
|
if (app.globalData.userInfo) {
|
|
this.setData({
|
|
userInfo: app.globalData.userInfo,
|
|
hasUserInfo: true,
|
|
product: item,
|
|
})
|
|
} else if (this.data.canIUse) {
|
|
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
// 所以此处加入 callback 以防止这种情况
|
|
app.userInfoReadyCallback = res => {
|
|
this.setData({
|
|
userInfo: res.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
} else {
|
|
// 在没有 open-type=getUserInfo 版本的兼容处理
|
|
wx.getUserInfo({
|
|
success: res => {
|
|
app.globalData.userInfo = res.userInfo
|
|
this.setData({
|
|
userInfo: res.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
})
|
|
}
|
|
},
|
|
getUserInfo: function (e) {
|
|
console.log(e)
|
|
app.globalData.userInfo = e.detail.userInfo
|
|
this.setData({
|
|
userInfo: e.detail.userInfo,
|
|
hasUserInfo: true
|
|
})
|
|
}
|
|
})
|