|
|
|
@@ -8,10 +8,13 @@ Page({ |
|
|
|
* 页面的初始数据 |
|
|
|
*/ |
|
|
|
data: { |
|
|
|
teljpgUrl: imgurl.teljpg.url, |
|
|
|
couponChannelId:'', |
|
|
|
couponId:'', |
|
|
|
detailData:[], |
|
|
|
spellData:null |
|
|
|
data:[], |
|
|
|
spellData:null, |
|
|
|
canSpell:true, |
|
|
|
canBuyIf:true |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -25,6 +28,34 @@ Page({ |
|
|
|
this.getDetail(options.couponChannelId); |
|
|
|
this.getOneSpell(options.couponId) |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 拨打电话 |
|
|
|
*/ |
|
|
|
phone: function (e) { |
|
|
|
let that = this; |
|
|
|
wx.makePhoneCall({ |
|
|
|
phoneNumber: e.target.dataset.merchantlinkphone |
|
|
|
}); |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 直接购买 |
|
|
|
*/ |
|
|
|
gotoBuy(){ |
|
|
|
console.log(22222) |
|
|
|
this.setData({ |
|
|
|
canBuyIf: false |
|
|
|
}) |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 发起拼团 |
|
|
|
*/ |
|
|
|
gotoSpell(){ |
|
|
|
console.log(111111111) |
|
|
|
this.setData({ |
|
|
|
canSpell:false |
|
|
|
}) |
|
|
|
this.orderFunc() |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 获取一个拼团信息 |
|
|
|
*/ |
|
|
|
@@ -58,10 +89,219 @@ Page({ |
|
|
|
data.price = (data.price / 100).toFixed(2) |
|
|
|
data.salePrice = (data.salePrice / 100).toFixed(2) |
|
|
|
that.setData({ |
|
|
|
detailData: data |
|
|
|
data |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 发起支付 |
|
|
|
*/ |
|
|
|
orderFunc(discount) { |
|
|
|
var that = this; |
|
|
|
Http.post({ |
|
|
|
url: config.api.checkPhoneStatus, |
|
|
|
data: {} |
|
|
|
}) |
|
|
|
.then(res => { |
|
|
|
/** |
|
|
|
* orderSave 下单 |
|
|
|
*/ |
|
|
|
debugger |
|
|
|
// return Http.post({ |
|
|
|
// url: config.api.orderSave, |
|
|
|
// data: data |
|
|
|
// }); |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
console.log(err); |
|
|
|
that.setData({ |
|
|
|
showbutton: false, |
|
|
|
showbutton1: false |
|
|
|
}) |
|
|
|
if (err.code == 2011) { |
|
|
|
wx.showToast({ |
|
|
|
title: "商户信息没找到", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 2013) { |
|
|
|
wx.showToast({ |
|
|
|
title: "商户信息禁用", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 3000) { |
|
|
|
wx.showToast({ |
|
|
|
title: "库存不足", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 3001) { |
|
|
|
wx.showToast({ |
|
|
|
title: "超过限购条件", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 3002) { |
|
|
|
wx.showToast({ |
|
|
|
title: "订单失败", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 3003) { |
|
|
|
wx.showToast({ |
|
|
|
title: "订单不存在", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 3004) { |
|
|
|
wx.showToast({ |
|
|
|
title: "订单不存在", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 4003) { |
|
|
|
wx.showToast({ |
|
|
|
title: "卡券已作废", |
|
|
|
image: './../../../assets/images/fail.png', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} else if (err.code == 11005) { |
|
|
|
/** |
|
|
|
* 将值传到用户手机号授权的页面 |
|
|
|
* |
|
|
|
*/ |
|
|
|
wx.redirectTo({ |
|
|
|
url: "/pages/getphoneInfo/index?path=spell&couponChannelId=" + |
|
|
|
that.data.couponChannelId + '&couponId=' + that.data.couponId |
|
|
|
}); |
|
|
|
} else if (err.code == 11006) { |
|
|
|
// 用户手机已加密 |
|
|
|
wx.redirectTo({ |
|
|
|
url: "/pages/phoneinput/phoneinput?path=spell&couponChannelId=" + |
|
|
|
that.data.couponChannelId + '&couponId=' + that.data.couponId |
|
|
|
}); |
|
|
|
} else { |
|
|
|
wx.showToast({ |
|
|
|
title: err.message, |
|
|
|
icon: 'none', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
} |
|
|
|
}) |
|
|
|
.then(res => { |
|
|
|
console.log(res) |
|
|
|
if (discount != 'discount') { |
|
|
|
if (typeof (res) != "undefined") { |
|
|
|
let orderId = "" + res.data.id; |
|
|
|
that.setData({ |
|
|
|
orderId: orderId |
|
|
|
}); |
|
|
|
if (res.data.payment > 0) { |
|
|
|
// 支付金额不为0 |
|
|
|
/** |
|
|
|
* 支付订单创建 |
|
|
|
*/ |
|
|
|
Http.post({ |
|
|
|
url: config.api.payOrderCreate, |
|
|
|
data: { |
|
|
|
orderId: orderId |
|
|
|
} |
|
|
|
}) |
|
|
|
.then(res => { |
|
|
|
var payOrderId = "" + res.data.payOrderId; |
|
|
|
wx.hideLoading(); |
|
|
|
wx.requestPayment({ |
|
|
|
timeStamp: res.data.timeStamp, |
|
|
|
nonceStr: res.data.nonceStr, |
|
|
|
package: res.data.package, |
|
|
|
signType: (res.data.signType) ? res.data.signType : "MD5", |
|
|
|
paySign: res.data.paySign, |
|
|
|
success: res => { |
|
|
|
wx.showLoading({ |
|
|
|
title: '订单正在处理中...', |
|
|
|
}) |
|
|
|
setTimeout(function () { |
|
|
|
wx.hideLoading() |
|
|
|
}, 5000) |
|
|
|
that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); |
|
|
|
if (res.errMsg == "requestPayment:ok") { |
|
|
|
setTimeout(function () { |
|
|
|
wx.hideLoading(); |
|
|
|
}, 2000); |
|
|
|
/** |
|
|
|
* 用户支付成功以后跳转到券包列表 |
|
|
|
*/ |
|
|
|
if (that.data.cardType == 100) { |
|
|
|
wx.setStorage({ |
|
|
|
key: 'couponNum2', |
|
|
|
data: "couponNum2" |
|
|
|
}) |
|
|
|
} else if (that.data.data.type != 5) { |
|
|
|
wx.setStorage({ |
|
|
|
key: 'couponNum', |
|
|
|
data: "couponNum" |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: res => { |
|
|
|
/** |
|
|
|
* 支付失败,需要更新订单的状态 |
|
|
|
*/ |
|
|
|
that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that); |
|
|
|
that.setData({ |
|
|
|
showbutton: false |
|
|
|
}) |
|
|
|
return; |
|
|
|
}, |
|
|
|
complete: res => { } |
|
|
|
}); |
|
|
|
/// End payment -------- |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
wx.showToast({ |
|
|
|
title: err.message, |
|
|
|
icon: 'none', |
|
|
|
duration: 2000, |
|
|
|
mask: false |
|
|
|
}); |
|
|
|
}) |
|
|
|
} else { |
|
|
|
console.log(that.data.type) |
|
|
|
// 免费券 |
|
|
|
that.payOrderUpdate(orderId, "0", 1, '', 'free'); |
|
|
|
if (that.data.cardType == 100) { |
|
|
|
wx.setStorage({ |
|
|
|
key: 'couponNum2', |
|
|
|
data: "couponNum2" |
|
|
|
}) |
|
|
|
} else if (that.data.data.type != "5") { |
|
|
|
wx.setStorage({ |
|
|
|
key: 'couponNum', |
|
|
|
data: "couponNum" |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (res) { |
|
|
|
wx.navigateTo({ |
|
|
|
url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`, |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
/** |
|
|
|
* 生命周期函数--监听页面初次渲染完成 |
|
|
|
*/ |
|
|
|
@@ -73,7 +313,10 @@ Page({ |
|
|
|
* 生命周期函数--监听页面显示 |
|
|
|
*/ |
|
|
|
onShow: function () { |
|
|
|
|
|
|
|
this.setData({ |
|
|
|
canSpell:true, |
|
|
|
canBuyIf:true |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -102,12 +345,5 @@ Page({ |
|
|
|
*/ |
|
|
|
onReachBottom: function () { |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 用户点击右上角分享 |
|
|
|
*/ |
|
|
|
onShareAppMessage: function () { |
|
|
|
|
|
|
|
} |
|
|
|
}) |