// pages/mobileVerification/mobileVerification.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { imgUrl: app.globalData.urlStatic,//图片路径 isAgreement: true,//是否同意协议 verificationCode: '获取验证码',//验证码文案 sendCode: true, realName:"",//姓名 mobileText: "",//手机号 verificationText: null, getMobileBtnShow: true, agreement: false,//是否显示协议 httpState: false, provinceDataAll: null,//地区所有数据 provinceDataArr: [[""], [""]],//省市数据 provinceDataValue: [0, 0],//选中的省市下标 nowProvince: "",//选中的省市文字 storeArr: [],//专营店数据 storeValue: 0,//选中的专营店下标 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { app.globalData.nowPage = 2; if (app.globalData.openid) { this.loadFun(); } else { app.globalData.openidSuccessFuc = this.loadFun; } }, loadFun: function () { if (app.globalData.userMobile) { this.setData({ getMobileBtnShow: false, mobileText: app.globalData.userMobile }) } this.getUserLocation();//获取用户当前位置 }, getUserLocation: function (e) { wx.getLocation({ type: 'wgs84', //wgs84 gcj02 success: (res) => { this.getDistributorList(res.longitude, res.latitude); }, fail: (res) => { this.getDistributorList("", ""); } }) }, getDistributorList: function (longitude, latitude) {//获取经销商列表 app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => { if (res.code == 200) { //整理数据 var datas = res.data; var province = []; var city = []; for (let i = 0; i < res.data.list.length; i++) { province.push(res.data.list[i].province); } for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) { city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city) } //将数据赋值给变量 this.setData({ provinceDataAll: res.data.list, provinceDataArr: [province, city], provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex], nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex], storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children, storeValue: res.data.nearData.agentIndex }) } else { wx.showToast({ title: res.msg, icon: "none" }) } }, this); }, provinceDataChange: function (e) { if (e.detail.column == 0) { var city = []; for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) { city.push(this.data.provinceDataAll[e.detail.value].children[i].city); } this.data.provinceDataArr[1] = city; this.setData({ provinceDataArr: this.data.provinceDataArr }) } }, provinceDataChane: function (e) { this.setData({ provinceDataValue: e.detail.value, nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]], storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children, storeValue: 0 }) }, storeChane: function (e) { this.setData({ storeValue: e.detail.value }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { return app.sharePack(); }, agreementState: function () {//协议 this.setData({ isAgreement: !this.data.isAgreement }) }, getCode: function (e) {//获取验证码 if (!app.mobileVerify(this.data.mobileText)) { if (this.data.mobileText) { wx.showToast({ title: '请输入正确的电话', icon: 'none' }) } else { wx.showToast({ title: '请输入电话', icon: 'none' }) } return; } if (!this.data.sendCode) { return; } this.data.sendCode = false; app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobileText }, res => { if (res.code == 200) { this.countDown(); wx.showToast({ title: '验证码获取成功', icon: "none" }) this.setData({ verificationCode: 60 }) } else { this.data.sendCode = true; wx.showToast({ title: res.msg, icon: "none" }) } }, this) }, countDown: function () {//倒计时 setTimeout(() => { this.setData({ verificationCode: this.data.verificationCode - 1 }) if (this.data.verificationCode > 0) { this.countDown(); } else { this.setData({ verificationCode: "获取验证码" }) this.data.sendCode = true; } }, 1000); }, getRealName: function (e) {//获取用户输入的姓名 this.data.realName = e.detail.value }, getMoblie: function (e) {//获取用户输入的手机号 this.data.mobileText = e.detail.value }, getCodeText: function (e) {//获取用户输入的手机号 this.data.verificationText = e.detail.value }, submitMobile: function () { if (!this.data.realName) { wx.showToast({ title: '请输入姓名', icon: 'none' }) return; } if (!app.mobileVerify(this.data.mobileText)) { if (this.data.mobileText) { wx.showToast({ title: '请输入正确的电话', icon: 'none' }) } else { wx.showToast({ title: '请输入电话', icon: 'none' }) } return; } if (!this.data.verificationText) { wx.showToast({ title: '请输入验证码', icon: 'none' }) return; } if (!this.data.isAgreement) { wx.showToast({ title: '请同意协议', icon: 'none' }) return; } var parames = { realName:this.data.realName, mobile:this.data.mobileText, captcha:this.data.verificationText, province:this.data.provinceDataArr[0][this.data.provinceDataValue[0]], city:this.data.provinceDataArr[1][this.data.provinceDataValue[1]], agentDetail:this.data.storeArr[this.data.storeValue].agent_detail, agentCode:this.data.storeArr[this.data.storeValue].agent_code } // console.log(parames); // return; if (this.data.httpState) { return; } this.data.httpState = true; app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationInfoV2", parames, res => { this.data.httpState = false; if (res.code == 200) { wx.setStorageSync('userMobile', this.data.mobileText); app.globalData.userMobile = this.data.mobileText; if (res.data != null) { app.globalData.certificationState = res.data.certificationState; wx.redirectTo({ url: '../scout/scout' }) } else { wx.redirectTo({ url: '../scout/register/register' }) } } else { wx.showToast({ title: res.msg, icon: 'none' }) } }, this); }, getPhone(e) { this.setData({ getMobileBtnShow: false }) if (e.detail.errMsg == 'getPhoneNumber:ok') { app.getMobile(e.detail.encryptedData, e.detail.iv, res => { if (res.code == 200) { if (res.data && res.data.decodeData) { this.setData({ mobileText: res.data.decodeData.phoneNumber }) } } }, this) } }, agreementControl: function () { this.setData({ agreement: !this.data.agreement }) }, showRule: function () { if (app.globalData.entered) { wx.navigateTo({ url: '/pages/everyday/everyday' }) } else { wx.navigateTo({ url: '/pages/fragmentRule/fragmentRule' }) } } })