123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- import Toast from '../../vant/toast/toast';
- Page({
-
- data: {
- userName: null,
- phone: null,
- email: null,
- carNum:null,
- password: null,
- rePassword: null,
- checkPass: false,
- errorMsg: '',
- userInfo: {},
- hasUserInfo: false,
- canIUseGetUserProfile: false,
- vcodeFlag: false,
- vcodeTimeOut: 0,
- vcodeTimeOutDefault: 0,
- scene: "REGIST",
- vcodeLen:6,
- vcodeInterval:null,
- vcode_button_text:'获取验证码',
- servicetel: '4009608068',
- showMsg: false,
- timeing: true,
- checked:false
- },
-
- onLoad: function(options) {
- if (wx.getUserProfile) {
- this.setData({
- canIUseGetUserProfile: true
- })
- }
- let scene = this.data.scene;
- let that = this
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/vcodeInfo',
-
- data: {
- scene,
- },
- method: 'POST',
- success(res) {
- that.setData({
- vcodeInfo:false,
-
- vcodeTimeOutDefault:res.data.result.expire,
- vcodeLen:res.data.result.len
- })
- }
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- getUserProfile(e) {
-
-
- if(!this.data.checked){
- Toast('请先阅读并同意用户使用协议');
- return;
- }
- this.checkAll();
- this.setData({
- showMsg:true
- })
- if(!this.data.checkPass){
- return;
- }
- let that=this
- wx.getUserProfile({
- desc: '用于完善会员资料',
- success: (res) => {
- that.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- that.bindGetUserInfo(res.userInfo);
- }
- })
- },
- bindGetUserInfo(userInfo) {
-
- console.info(this.userInfo)
- let that = this;
- if (userInfo) {
- let {
- nickName: userName,
- gender: sex,
- avatarUrl: avatar
- } = userInfo;
- let {
- userName: loginName,
- password,
- phone,
- carNum,
- email,
- vcode
- } = this.data;
- wx.login({
- success(res) {
- console.log(res);
- if (res.code) {
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/register',
- data: {
- userName,
- sex:"0",
- avatar:'http://cdglyy.pjnes.com/web/profile/avatar/c134f314cbbe985a8aae1787b45e6d6a.jpg',
- loginName,
- password,
- phonenumber: phone,
- email,
- vcode,
- license_number: carNum,
- code: res.code,
-
- },
- method: 'POST',
- success(res1) {
-
-
- if (res1.data.code == 1 || res1.data.code == 2) {
- if(res1.data.msg!=null && res1.data.msg.startsWith("503")){
- getApp().showNetworkError();
- return;
- }
-
-
-
- wx.showModal({
- title: '提示',
- content: res1.data.msg,
- showCancel:false,
- confirmColor:'#00AADD',
- });
- } else {
-
-
- wx.setStorageSync("userInfo", res1.data);
- wx.setStorageSync("isLogin", true);
- wx.navigateBack();
-
-
-
-
- }
- }
- });
- } else {
- console.log('登录失败!' + res.errMsg)
- }
- }
- });
- }
- },
- inputAccount(e) {
- this.setData({
- userName: e.detail.value
- });
- this.checkAll();
- },
- inputPassword(e) {
- this.setData({
- password: e.detail.value,
- showMsg: false
- });
- this.checkAll();
- },
- inputRepassword(e) {
- this.setData({
- rePassword: e.detail.value,
- showMsg: false
- });
- this.checkAll();
- },
- inputPhone(e) {
- this.setData({
- phone: e.detail.value,
- showMsg: false
- });
- this.checkAll();
- },
- inputVcode(e) {
- this.setData({
- vcode: e.detail.value,
- showMsg: false
- });
- if(!this.msgVcode()){
- return;
- }
- this.checkAll();
- },
- inputEmail(e) {
- this.setData({
- email: e.detail.value
- });
- this.checkAll();
- },
- inputCarNum(e){
- this.setData({
- carNum: e.detail.value
- });
- this.checkAll();
- },
- checkPassword() {
- if (!this.data.password || !this.data.rePassword || this.data.password != this.data.rePassword) {
- return false;
- }
- return true;
- },
- checkPhone() {
- if (!(/^1[3456789]\d{9}$/.test(this.data.phone))) {
- this.setData({
- vcodeFlag:false
- })
- return false;
- }
- if(this.data.vcodeTimeOut<=0){
- this.setData({
- vcodeFlag:true,
- })
- }
- return true;
- },
- checkMail() {
- if (!(/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/.test(this.data.email))) {
- return false;
- }
- return true;
- },
- checkVcode() {
- if (this.data.vcode==undefined || this.data.vcode=="") {
- return false;
- }
- if(this.data.vcode.length==this.data.vcodeLen){
- return true;
- }
- return false;
- },
- checkCarNum(){
- if (this.data.carNum){
-
- if (!/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领].*$/.test(this.data.carNum)) {
- return false;
- }
- }
- return true;
- },
- sendVcode(e){
- let that = this
- if (!that.checkPhone()) {
- that.setData({
- errorMsg: '手机号输入有误,请重新输入'
- });
- that.setData({
- checkPass: false
- });
- return;
- } else {
- that.setData({
- errorMsg: ''
- });
- }
- let phone = that.data.phone;
- that.setData({
- vcodeTimeOut:that.data.vcodeTimeOutDefault
- })
- let vcodeInterval = setInterval(that.vcodeFun,1000);
- that.setData({
- vcodeInterval
- })
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/sendPhoneVcodeUnique',
-
- data: {
- scene: that.data.scene,
- terminal: phone,
- },
- method: 'POST',
- success(res) {
-
-
- if (res.data.code == 1) {
- if(res.data.msg!=null && res.data.msg.startsWith("503")){
- getApp().showNetworkError();
- return;
- }
- that.setData({
- vcodeTimeOut:0,
- vcodeFlag:true,
- vcode_button_text:'获取验证码'
- })
- wx.showModal({
- title: '提示',
- content:res.data.msg,
- showCancel:false,
- confirmColor:'#00AADD',
- });
- }else if (res.data.code == 2) {
- that.setData({
- vcodeTimeOut:0,
- vcodeFlag:true,
- vcode_button_text:'获取验证码'
- })
-
- wx.showModal({
- title: '提示',
- content: '手机号已绑定账户,请检查手机号是否填写正确或联系客服',
- showCancel:true,
- confirmText: '去登录',
- cancelText:"确定",
- confirmColor:'#00AADD',
- success: function (res1) {
- if (res1.confirm) {
- let url = '/pages/login/phone_login/phone_login';
- wx.redirectTo({
- url
- })
- }
- }
-
- });
- }else{
- wx.showToast({
- title: '验证码已发送',
- icon: 'success',
- duration: 1000
- })
- }
- }
- });
- },
- vcodeFun(){
-
- if(this.data.vcodeTimeOut<=0){
- this.setData({
- vcodeFlag:true,
- vcode_button_text:'获取验证码',
- timeing:true
- })
- clearInterval(this.data.vcodeInterval)
- }else{
- this.setData({
- vcodeTimeOut:this.data.vcodeTimeOut-1,
- vcodeFlag:false,
- vcode_button_text:'获取验证码(' + this.data.vcodeTimeOut+'s)',
- timeing:false
- })
- }
- },
- msgVcode(){
- if (!this.checkVcode()) {
- this.setData({
-
- errorMsg: '验证码格式不正确'
- });
- this.setData({
- checkCode: false
- });
- return false;
- } else {
- this.setData({
- errorMsg: ''
- });
- }
- return true;
- },
- checkAll() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (!this.checkPhone()) {
- this.setData({
- errorMsg: '手机号输入有误,请重新输入'
- });
- this.setData({
- checkPass: false,
- vcodeFlag: false
- });
- return;
- } else {
- this.setData({
- errorMsg: '',
- vcodeFlag: true
- });
- }
- if(!this.msgVcode()){
- return;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (this.data.password && (this.data.password.length < 5 || this.data.password.length > 20)) {
- this.setData({
- errorMsg: '密码长度应为5-20'
- });
- this.setData({
- checkPass: false
- });
- return;
- }
- if (!this.checkPassword()) {
- this.setData({
- errorMsg: '两次密码输入不一致,请重新输入'
- });
- this.setData({
- checkPass: false
- });
- return;
- } else {
- this.setData({
- errorMsg: ''
- });
- }
- this.setData({
- checkPass: true
- });
- },
- phoneCall(){
- wx.makePhoneCall({
- phoneNumber: this.data.servicetel,
- })
- },
- userAgreement(){
- let url = '/pages/agreement/userAgreement'
- wx.navigateTo({
- url
- });
- },
-
- onReady: function() {
- },
-
- onShow: function() {
- },
-
- onHide: function() {
- },
-
- onUnload: function() {
- },
-
- onPullDownRefresh: function() {
- },
-
- onReachBottom: function() {
- },
-
- onShareAppMessage: function() {
- },
- onCheckBoxChange(event) {
- this.setData({
- checked: event.detail,
- });
- },
- })
|