Files
bsmall/pages/gas/gas.js
2020-09-24 11:08:03 +08:00

154 lines
3.6 KiB
JavaScript
Executable File

const api = require("../../api/api"),
app = getApp()
var outTime
Page({
data: {
comboArr : [],
comboTypeValue : "",
comboTypeText : "",
tle : "",
codeBtnText : "获取验证码",
codeBtnStat : false,
is_code : 0
},
// 生命周期函数 -- 页面加载
onLoad() {
},
// 生命周期函数 -- 页面显示
onShow(){
this.preferential()
},
// 获取优惠配置信息
preferential(){
api.request({
url : "gas/init",
header: {
"Authorization": app.globalData.token
},
method: "GET"
}).then(res=>{
this.setData({
comboArr : res.data,
is_code : res.data[0].is_code
})
})
},
// 选择套餐类型
comboTypeChange(e){
let comboType = this.data.comboArr,
value = e.detail.value,
comboTypeName = comboType[value].title,
is_code = comboType[value].is_code
this.setData({
comboTypeText : comboTypeName,
comboTypeValue : value,
is_code : is_code
})
},
// 存储手机号码
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.request({
url : "gas/store",
method : "POST",
header: {
"Authorization": app.globalData.token
},
data : {
assist_name : e.detail.value.assist,
gas_id : this.data.comboArr[this.data.comboTypeValue].id,
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.order_id + '&paytype=gasPay'
});
}
my.hideLoading()
}).catch(err=>{
my.showToast({
content: err.data.message
})
my.hideLoading()
})
}else{
my.showToast({
content: "请选择套餐类型"
})
}
},
// 退出页面
onUnload(){
clearInterval(outTime)
}
})