东风启辰小程序端
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.

189 lines
3.5KB

  1. // pages/scout/register/register.js
  2. var Mcaptcha = require('../../../utils/mcaptcha.js');
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgUrl: app.globalData.urlStatic,//图片路径
  10. type: 0, //1车主 0非车主
  11. imgCode:'1234',//验证码
  12. vocationList:['网约车司机','公交司机','快的司机'],//职业列表
  13. vocationIndex:0,
  14. cityList:['宁波','北京','上海','佛山'],//城市列表
  15. cityIndex:0,
  16. getVcodeTime:0,//获取验证码倒计时
  17. getCodeTimeKey:null,
  18. photoList:[],//图片列表
  19. agree:false,//是否同意本协议
  20. },
  21. /**
  22. * 切换车主非车主
  23. */
  24. changeType(e) {
  25. var type = e.currentTarget.dataset.type;
  26. if (this.data.type != type) {
  27. this.setData({
  28. type: type
  29. })
  30. if (type == 1) {
  31. setTimeout(this.vCodeRefresh, 100);
  32. }
  33. }
  34. },
  35. /**
  36. * 提交信息
  37. */
  38. formSubmit1(e){
  39. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  40. },
  41. /**
  42. * 更换职业
  43. */
  44. changeVocation: function (e) {
  45. this.setData({
  46. vocationIndex: e.detail.value
  47. })
  48. },
  49. /**
  50. * 切换城市
  51. */
  52. changeCity(e){
  53. this.setData({
  54. cityIndex: e.detail.value
  55. })
  56. },
  57. /**
  58. * 获取验证码
  59. */
  60. getVcode(){
  61. console.log('获取验证码')
  62. this.setData({
  63. getVcodeTime: 60
  64. })
  65. this.getCodeTimeKey=setInterval(this.vCodeDownTime,1000);
  66. },
  67. vCodeDownTime(){
  68. var time = this.data.getVcodeTime-1;
  69. console.log(time)
  70. this.setData({
  71. getVcodeTime: time
  72. })
  73. if(time<=0){
  74. clearInterval(this.getCodeTimeKey);
  75. }
  76. },
  77. /**
  78. * 上传照片
  79. */
  80. chooseImage(){
  81. wx.chooseImage({
  82. count:1,
  83. sizeType: ['original'], //可选择原图
  84. sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
  85. success: res => {
  86. var list=this.data.photoList;
  87. list.push(res.tempFilePaths[0]);
  88. this.setData({
  89. photoList:list
  90. })
  91. }
  92. })
  93. },
  94. /**
  95. * 同意协议
  96. */
  97. agreementClick(event){
  98. var agree = this.data.agree;
  99. this.setData({ "agree": !agree });
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function(options) {
  105. },
  106. /**
  107. * 生命周期函数--监听页面初次渲染完成
  108. */
  109. onReady: function() {
  110. this.mcaptcha = new Mcaptcha({
  111. el: 'canvas',
  112. width: 80,
  113. height: 35,
  114. createCodeImg: ""
  115. });
  116. setTimeout(this.checkVcode, 1000);
  117. },
  118. /**
  119. * 刷新验证码
  120. */
  121. vCodeRefresh() {
  122. this.mcaptcha.refresh();
  123. },
  124. /**
  125. * 验证验证码
  126. */
  127. checkVcode() {
  128. var res = this.mcaptcha.validate(this.data.imgCode);
  129. if (this.data.imgCode == "" || this.data.imgCode == null) {
  130. wx.showToast({
  131. title: '请输入图形验证码'
  132. })
  133. return;
  134. }
  135. if (!res) {
  136. wx.showToast({
  137. title: '图形验证码错误'
  138. })
  139. return;
  140. }
  141. },
  142. /**
  143. * 生命周期函数--监听页面显示
  144. */
  145. onShow: function() {
  146. },
  147. /**
  148. * 生命周期函数--监听页面隐藏
  149. */
  150. onHide: function() {
  151. },
  152. /**
  153. * 生命周期函数--监听页面卸载
  154. */
  155. onUnload: function() {
  156. clearInterval(this.getCodeTimeKey);
  157. this.data.getVcodeTime=60;
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function() {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function() {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function() {
  173. }
  174. })