|
- // pages/scout/register/register.js
- var Mcaptcha = require('../../../utils/mcaptcha.js');
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- type: 0, //1车主 0非车主
- imgCode:'1234',//验证码
- vocationList:['网约车司机','公交司机','快的司机'],//职业列表
- vocationIndex:0,
- cityList:['宁波','北京','上海','佛山'],//城市列表
- cityIndex:0,
- getVcodeTime:0,//获取验证码倒计时
- getCodeTimeKey:null,
- photoList:[],//图片列表
- agree:false,//是否同意本协议
- },
- /**
- * 切换车主非车主
- */
- changeType(e) {
- var type = e.currentTarget.dataset.type;
- if (this.data.type != type) {
- this.setData({
- type: type
- })
- if (type == 1) {
- setTimeout(this.vCodeRefresh, 100);
- }
- }
- },
- /**
- * 提交信息
- */
- formSubmit1(e){
- console.log('form发生了submit事件,携带数据为:', e.detail.value)
- },
- /**
- * 更换职业
- */
- changeVocation: function (e) {
- this.setData({
- vocationIndex: e.detail.value
- })
- },
- /**
- * 切换城市
- */
- changeCity(e){
- this.setData({
- cityIndex: e.detail.value
- })
- },
- /**
- * 获取验证码
- */
- getVcode(){
- console.log('获取验证码')
- this.setData({
- getVcodeTime: 60
- })
- this.getCodeTimeKey=setInterval(this.vCodeDownTime,1000);
- },
- vCodeDownTime(){
- var time = this.data.getVcodeTime-1;
- console.log(time)
- this.setData({
- getVcodeTime: time
- })
- if(time<=0){
- clearInterval(this.getCodeTimeKey);
- }
- },
- /**
- * 上传照片
- */
- chooseImage(){
- wx.chooseImage({
- count:1,
- sizeType: ['original'], //可选择原图
- sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
- success: res => {
- var list=this.data.photoList;
- list.push(res.tempFilePaths[0]);
- this.setData({
- photoList:list
- })
- }
- })
- },
- /**
- * 同意协议
- */
- agreementClick(event){
- var agree = this.data.agree;
- this.setData({ "agree": !agree });
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
-
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- this.mcaptcha = new Mcaptcha({
- el: 'canvas',
- width: 80,
- height: 35,
- createCodeImg: ""
- });
- setTimeout(this.checkVcode, 1000);
- },
- /**
- * 刷新验证码
- */
- vCodeRefresh() {
- this.mcaptcha.refresh();
- },
- /**
- * 验证验证码
- */
- checkVcode() {
- var res = this.mcaptcha.validate(this.data.imgCode);
- if (this.data.imgCode == "" || this.data.imgCode == null) {
- wx.showToast({
- title: '请输入图形验证码'
- })
- return;
- }
- if (!res) {
- wx.showToast({
- title: '图形验证码错误'
- })
- return;
- }
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- clearInterval(this.getCodeTimeKey);
- this.data.getVcodeTime=60;
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
-
- }
- })
|