151 lines
3.4 KiB
JavaScript
Executable File
151 lines
3.4 KiB
JavaScript
Executable File
|
|
const api = require("../../api/api"),
|
|
app = getApp()
|
|
|
|
var outTime
|
|
|
|
Page({
|
|
data: {
|
|
comboArr : [],
|
|
comboTypeValue : "",
|
|
comboTypeText : "",
|
|
tle : "",
|
|
codeBtnText : "获取验证码",
|
|
codeBtnStat : false
|
|
},
|
|
// 生命周期函数 -- 页面加载
|
|
onLoad() {
|
|
|
|
},
|
|
// 生命周期函数 -- 页面显示
|
|
onShow(){
|
|
this.preferential()
|
|
},
|
|
// 获取优惠配置信息
|
|
preferential(){
|
|
api.request({
|
|
url : "goods/lists",
|
|
header: {
|
|
"Authorization": app.globalData.token
|
|
},
|
|
method: "POST"
|
|
}).then(res=>{
|
|
console.log(res.data)
|
|
this.setData({
|
|
comboArr : res.data
|
|
})
|
|
})
|
|
},
|
|
// 选择套餐类型
|
|
comboTypeChange(e){
|
|
console.log(e.detail)
|
|
let comboType = this.data.comboArr,
|
|
value = e.detail.value,
|
|
comboTypeName = comboType[value].title
|
|
|
|
this.setData({
|
|
comboTypeText : comboTypeName,
|
|
comboTypeValue : value
|
|
})
|
|
},
|
|
// 存储手机号码
|
|
telInput(e){
|
|
this.setData({
|
|
tle: e.detail.value
|
|
})
|
|
},
|
|
// 获取短信验证码
|
|
getCode(){
|
|
setTimeout(() => {
|
|
if(this.data.tle != ''){
|
|
my.showLoading();
|
|
api.request({
|
|
url : "unicom",
|
|
method: "POST",
|
|
data : {
|
|
mobile : this.data.tle,
|
|
channel : "DEFAULT"
|
|
}
|
|
}).then(res=>{
|
|
// 获取倒计时
|
|
this.setData({
|
|
codeBtnStat: true,
|
|
codeBtnText: "重新获取60s"
|
|
})
|
|
|
|
let outTimeNumber = 60
|
|
outTime = setInterval(()=>{
|
|
if(outTimeNumber >= 1){
|
|
outTimeNumber--
|
|
this.setData({
|
|
codeBtnText: "重新获取" + outTimeNumber + 's'
|
|
})
|
|
}else{
|
|
this.setData({
|
|
codeBtnStat: false,
|
|
codeBtnText: "获取验证码"
|
|
})
|
|
clearInterval(outTime)
|
|
}
|
|
},1000)
|
|
// 提示信息
|
|
my.showToast({
|
|
content: res.data
|
|
})
|
|
my.hideLoading();
|
|
}).catch(err=>{
|
|
console.log(err)
|
|
my.showToast({
|
|
content: err.data.message
|
|
})
|
|
my.hideLoading();
|
|
})
|
|
}else{
|
|
my.showToast({
|
|
content: "手机号码不能为空"
|
|
});
|
|
}
|
|
}, 100)
|
|
},
|
|
// 提交表单
|
|
welfareForm(e){
|
|
if(this.data.comboTypeText != ''){
|
|
my.showLoading()
|
|
// api
|
|
api.request({
|
|
url : "order/createNew/" + this.data.comboArr[this.data.comboTypeValue].param_id,
|
|
method : "POST",
|
|
header: {
|
|
"Authorization": app.globalData.token
|
|
},
|
|
data : {
|
|
mobile : e.detail.value.tel,
|
|
code : e.detail.value.code,
|
|
channel : "DEFAULT"
|
|
}
|
|
}).then(res=>{
|
|
if(res.status == "SUCCESS" && res.data != ''){
|
|
my.redirectTo({
|
|
url: '../payCode/payCode?orderid=' + res.data
|
|
});
|
|
}
|
|
my.hideLoading()
|
|
}).catch(err=>{
|
|
my.showToast({
|
|
content: err.data.message
|
|
})
|
|
my.hideLoading()
|
|
})
|
|
}else{
|
|
my.showToast({
|
|
content: "请选择套餐类型"
|
|
})
|
|
}
|
|
},
|
|
|
|
// 退出页面
|
|
onUnload(){
|
|
clearInterval(outTime)
|
|
}
|
|
})
|