123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- // pages/register/index.js
- const request = require('../../utils/request.js');
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- nvabarData: {
- showCapsule: 0, //是否显示左上角图标,消息中心 1表示显示 0表示不显示
- showBack: 1, //返回
- title: '注册', //导航栏 中间的标题
- // 此页面 页面内容距最顶部的距离
- height: app.globalData.height * 2 + 20,
- },
- instructionBook: '已阅读并同意使用',
- radioCheck: false,
- disabled: false,
- phone:'',
- password:'',
- againpassword:'',
- yanzhengma:'',
- code: '获取验证码',
- defaultType: true,
- passwordType: true,
- defaultType1: true,
- passwordType1: true
-
- },
- radioClick: function (event) {
- var radioCheck = this.data.radioCheck;
- this.setData({
- "radioCheck": !radioCheck
- });
- },
- agreementBtn: function () {
- wx.navigateTo({
- url: '/pages/agreement/index'
- })
- // wx.navigateTo({
- // url: '/pages/agreement/index?phone='this.data.phone +'&password=' +this.data.password+ '&againpassword=' + this.data.againpassword + '&yanzhengma=' + this.data.yanzhengma // 希望跳转过去的页面
- // })
- },
- getCode:function (e) {
- this.setData({
- code:e.detail.value
- })
- },
- talks:function (e) {
- this.setData({
- phone:e.detail.value
- })
- wx.setStorage({
- key:"phone",
- data:e.detail.value
- })
- },
- getYanzhengma:function (e) {
- console.log("e",e);
- this.setData({
- yanzhengma:e.detail.value
- });
- wx.setStorage({
- key:"yanzhengma",
- data:e.detail.value
- });
- },
- getPassword:function (e) {
- console.log("e",e);
- this.setData({
- password:e.detail.value
- });
- wx.setStorage({
- key:"password",
- data:e.detail.value
- });
- },
- getPassword1:function (e) {
- this.setData({
- againpassword:e.detail.value
- })
- wx.setStorage({
- key:"againpassword",
- data:e.detail.value
- })
- },
- //校验手机号
- async isPoneAvailable(str) {
- var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
- if (!myreg.test(str)) {
- wx.showToast({
- title: '请输入正确手机号',
- image:'/pages/images/jinggao.png',
- duration: 2000
- })
- return false;
- } else {
- var that = this;
- var time = 60;
- that.setData({
- code: '60秒后重发',
- disabled: true
- })
- var Interval = setInterval(function() {
- time--;
- if (time>0){
- that.setData({
- code: time + '秒后重发'
- })
- }else{
- clearInterval(Interval);
- that.setData({
- code: '获取验证码',
- disabled: false
- })
- }
- },1000)
- let list = await request.query({
- url: 'api/financial/phoneMessage/sendMessage',
- data: {phone:this.data.phone},
- method: 'post'
- });
- if (list && list.data.data.Message && list.data.data.Message == 'OK' && list.data.data.Code && list.data.data.Code== 'OK') {
- if (list.data.data.number) {
- wx.setStorage({
- key: 'code',
- data: list.data.data.number,
- })
- }
- } else{
- wx.showToast({
- title: '获取验证码失败',
- icon: 'none',
- duration: 2000
- })
- }
- }
- },
- getCode(){
- if (this.data.phone) {
- wx.hideKeyboard()
- this.isPoneAvailable(this.data.phone);
- // var that = this;
- // var time = 60;
- // that.setData({
- // code: '60秒后重发',
- // disabled: true
- // })
- // let list = await request.query({
- // url: 'api/financial/phoneMessage/sendMessage',
- // data: {phone:this.data.phone},
- // method: 'post'
- // });
- // if (list && list.data.data.Message && list.data.data.Message == 'OK' && list.data.data.Code && list.data.data.Code== 'OK') {
- // if (list.data.data.number) {
- // wx.setStorage({
- // key: 'code',
- // data: list.data.data.number,
- // })
- // }
- // var Interval = setInterval(function() {
- // time--;
- // if (time>0){
- // that.setData({
- // code: time + '秒后重发'
- // })
- // }else{
- // clearInterval(Interval);
- // that.setData({
- // code: '获取验证码',
- // disabled: false
- // })
- // }
- // },1000)
- // } else{
- // wx.showToast({
- // title: '获取验证码失败',
- // icon: 'none',
- // duration: 2000
- // })
- // }
- }else{
- wx.showToast({
- title: '请输入手机号',
- icon: 'none',
- duration: 2000
- })
- }
- },
- // 注册账号
- formSubmit: function (e) {
- console.log('form发生了submit事件,携带数据为:', e.detail.value)
- if(e.detail.value.person==""||e.detail.value.phone==""||e.detail.value.yanzhengma==""||e.detail.value.password==""||e.detail.value.againpassword==""){
- wx.showToast({
- title: '缺少部分信息项',
- icon: 'none',
- duration: 1500
- })
- return false
- }
- let code = wx.getStorageSync('code')
- if (code == e.detail.value.yanzhengma) {
- if (this.data.radioCheck ) {
- if(e.detail.value.password==e.detail.value.againpassword){
- let pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])');
- if (!pwdRegex.test(e.detail.value.password) || e.detail.value.password.length < 8|| e.detail.value.password.length >20) {
- wx.showModal({
- title: '提示',
- content: '密码格式错误',
- confirmText: '确定',
- success(res) {
- if (res.confirm) {
- // console.log('用户点击取消')
- } else if (res.cancel) {
- // console.log('用户点击取消')
- }
- }
- })
- // wx.showModal({
- // title: '密码格式错误',
- // // content: '密码至少为8位字母数字组合。',
- // success (res) {
- // if (res.confirm) {
- // // console.log('用户点击取消')
- // } else if (res.cancel) {
- // // console.log('用户点击取消')
- // }
- // }
- // })
- }else{
- wx.setStorage({
- key:"phone",
- data:e.detail.value.phone
- })
- wx.setStorage({
- key:"password",
- data:e.detail.value.password
- })
- wx.request({
- method: "POST",
- url: app.globalData.publicUrl + 'api/financial/companyuser',
- data: {
- phone: e.detail.value.phone,
- passwd: e.detail.value.password,
- // person: e.detail.value.person
- },
- success: (e) => {
- console.log('success', e);
- if (e.data.errcode == 0) {
- wx.showModal({
- title: '注册成功',
- content: '如需获得更多服务请进行企业认证',
- success (res) {
- if (res.confirm) {
- wx.navigateTo({
- url: '/pages/login/index'
- })
- } else if (res.cancel) {
- // console.log('用户点击取消')
- }
- }
- })
- } else {
- if (e.data.details === "phone无效") {
- wx.showToast({
- title: '请重新输入手机号',
- icon: 'none',
- duration: 1500
- })
- } else if (e.data.errmsg === "数据已存在") {
- wx.showToast({
- title: '该手机号已被注册',
- icon: 'none',
- duration: 1500
- })
- } else {
- wx.showToast({
- title: e.data.details ? e.data.details : e.data.errmsg,
- icon: 'none',
- duration: 1500
- })
- }
- }
- }
- })
- }
- }else{
- wx.showToast({
- title: '两次密码输入不一致',
- icon: 'none',
- duration: 1500
- })
- }
- } else {
- wx.showToast({
- title: '请勾选企业授权协议',
- icon: 'none',
- duration: 1500
- })
- }
- } else{
- wx.showToast({
- title: '验证码错误',
- icon: 'none',
- duration: 1500
- })
- }
- },
- // 眼镜变色
- eyeStatus(){
- if (this.data.defaultType) {
- this.setData({
- passwordType: false,
- defaultType: false,
- })
- } else {
- this.setData({
- passwordType: true,
- defaultType: true,
- })
- }
- },
- eyeStatus1(){
- if (this.data.defaultType1) {
- this.setData({
- passwordType1: false,
- defaultType1: false,
- })
- } else {
- this.setData({
- passwordType1: true,
- defaultType1: true,
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- radioCheck: options.radioCheck
- });
- let that = this;
- wx.getStorage({
- key: 'phone',
- success (res) {
- console.log(res.data)
- that.setData({
- phone:res.data
- })
- }
- })
- wx.getStorage({
- key: 'password',
- success (res) {
- console.log(res.data)
- that.setData({
- password:res.data
- })
- }
- })
- wx.getStorage({
- key: 'againpassword',
- success (res) {
- console.log(res.data)
- that.setData({
- againpassword:res.data
- })
- }
- })
- wx.getStorage({
- key: 'yanzhengma',
- success (res) {
- console.log(res.data)
- that.setData({
- yanzhengma:res.data
- })
- }
- })
-
-
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|