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.

363 lines
6.7 KiB

3 years ago
// pages/mine/pages/register/register.js
const app = getApp()
3 years ago
import timer from '../../../utils/timer'
3 years ago
Page({
/**
* 页面的初始数据
*/
data: {
sUserName: '',
sPwd: '',
sPhone: '',
sEmail: '',
companyName: '',
brandName: '',
sVerifycode: '',
captchaLabel: '获取验证码',
captchaDisabled: false,
show: false,
imageUrl: getApp().globalData.imageUrl,
mockData: []
},
//用户输入
usernameInput(e) {
this.setData({
sUserName: e.detail.value
})
},
//密码输入
passwordInput(e) {
this.setData({
sPwd: e.detail.value
})
},
//手机号输入
sPhoneInput(e) {
this.setData({
sPhone: e.detail.value
})
},
//邮箱输入
sEmailInput(e) {
this.setData({
sEmail: e.detail.value
})
},
//名称输入
companyInput(e) {
this.setData({
companyName: e.detail.value
})
},
//品牌输入
brandInput(e) {
this.setData({
brandName: e.detail.value
})
},
//验证码输入
codeInput(e) {
this.setData({
sVerifycode: e.detail.value
})
},
//获取验证码
captcha() {
let b = this.validPhone();
if (!b) return;
let obj = {
action: 'getVERCode',
sPhone: this.data.sPhone,
}
return new Promise((resolve, reject) => {
app.globalData.request(obj, (res) => {
// 定时60s
timer(this)
resolve(true)
}).catch(err => {
wx.showModal({
title: '提示',
content: err.Msg,
})
reject(false)
})
})
},
/**
* 生命周期函数--监听页面加载
*/
//提交审核
Submit() {
let a = this.validfrom();
if (!a) return;
let obj = {
action: 'regUser',
sUserName: this.data.sUserName,
sPwd: this.data.sPwd,
sPhone: this.data.sPhone,
sEmail: this.data.sEmail,
companyName: this.data.companyName,
brandName: this.data.brandName,
sVerifycode: this.data.sVerifycode,
}
return new Promise((resolve, reject) => {
app.globalData.request(obj, (res) => {
if (res.Code == 1) {
wx.showModal({
title: '提示',
content: res.Msg,
success(res) {
if (res.confirm) {
wx.navigateBack({
delta: 1
});
} else {
}
}
})
}
resolve(true)
}).catch(err => {
wx.showModal({
title: '提示',
content: err.Msg,
})
reject(false)
})
})
},
getlist() {
let that = this
let obj = {
action: 'ifUserAdminOnly',
sUserName: this.data.sUserName,
sPhone: this.data.sPhone,
sEmail: this.data.sEmail,
}
return new Promise((resolve, reject) => {
app.globalData.request(obj, (res) => {
if (res.Code == 1) {
wx.showModal({
title: '提示',
content: res.Msg,
success(res) {
if (res.confirm) {
that.captcha()
} else {
}
}
})
}
resolve(true)
}).catch(err => {
wx.showModal({
title: '提示',
content: err.Msg,
})
reject(false)
})
})
},
validPhone() {
let b = true;
let sPhone = this.data.sPhone;
//验证手机号
if (!this.data.sPhone) {
wx.showModal({
title: '提示',
content: "手机号不能为空",
})
b = false;
return b;
}
//验证手机格式
if (!(/^1[345678]\d{9}$/.test(sPhone))) {
wx.showModal({
title: '提示',
content: "手机格式错误",
})
b = false
return b;
}
return b;
},
validfrom() {
let a = true;
//验证用户名
if (!this.data.sUserName) {
wx.showModal({
title: '提示',
content: "用户名不能为空",
})
a = false;
return a;
}
//验证密码
if (!this.data.sPwd) {
wx.showModal({
title: '提示',
content: "密码不能为空",
})
a = false;
return a;
}
//验证手机号
if (!this.data.sPhone) {
wx.showModal({
title: '提示',
content: "手机号不能为空",
})
a = false;
return a;
}
//验证邮箱
if (!this.data.sEmail) {
wx.showModal({
title: '提示',
content: "邮箱不能为空",
})
a = false;
return a;
}
//验证公司名称
if (!this.data.companyName) {
wx.showModal({
title: '提示',
content: "公司名称不能为空",
})
a = false;
return a;
}
//验证品牌
if (!this.data.brandName) {
wx.showModal({
title: '提示',
content: "公司品牌不能为空",
})
a = false;
return a;
}
//验证验证码
if (!this.data.sVerifycode) {
wx.showModal({
title: '提示',
content: "验证码不能为空",
})
a = false;
return a;
}
return a;
},
handlerBack() {
wx.navigateBack({
delta: 1
});
},
onLoad(options) {
this.getdata()
},
Brands(e) {
let brand = e.currentTarget.dataset.brand
this.setData({
brandName: brand,
show: false
})
},
showPopup() {
this.setData({
show: true
});
},
onClose() {
this.setData({
show: false
});
},
getdata() {
//页面数据
wx.showToast({
title: '加载中',
icon: 'loading',
duration: 300000
})
app.globalData.request({
action: 'getUserBrandHome',
}).then(res => {
let arr = []
for (let i = 65; i <= 90; i++) {
arr.push({
name: String.fromCharCode(i),
data: []
});
}
for (let i of res) {
for (let j of arr) {
if (i.firstword == j.name) {
j.data.push(i)
}
}
}
this.setData({
mockData: arr
})
setTimeout(() => {
wx.hideToast();
}, 2000)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})