东风启辰小程序端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

437 lines
12KB

  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:'',//验证码
  12. vocationList:['网约车司机','公交司机','快的司机'],//职业列表
  13. vocationList2:[],//职业列表2
  14. vocationIndex:'0',
  15. allList:[],//所有列表
  16. cityList: [[''], ['']],//城市列表
  17. cityIndex:['0','0'],
  18. getVcodeTime:0,//获取验证码倒计时
  19. getCodeTimeKey:null,
  20. photoList:[],//图片列表
  21. agree:false,//是否同意本协议
  22. getphone:"",//手机号
  23. maskShow: false,
  24. mydata:[],//我的数据
  25. isbtn:true,//防重复点击
  26. vCodeImg:null
  27. },
  28. /**
  29. * 切换车主非车主
  30. */
  31. changeType(e) {
  32. var type = e.currentTarget.dataset.type;
  33. if (this.data.type != type) {
  34. this.setData({
  35. type: type
  36. })
  37. if (type == 1) {
  38. setTimeout(this.vCodeRefresh, 100);
  39. }
  40. }
  41. },
  42. /**
  43. * 提交信息-认证
  44. */
  45. formSubmit1(e){
  46. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  47. var res = this.mcaptcha.validate(e.detail.value.code);
  48. if (e.detail.value.VIN == "" || e.detail.value.VIN == null) {
  49. wx.showToast({icon:'none',title: '请输入车牌号/VIN号'})
  50. return;
  51. }else if (e.detail.value.code == "" || e.detail.value.code == null) {
  52. wx.showToast({icon:'none',title: '请输入图形验证码'})
  53. }else if (!res) {
  54. wx.showToast({icon:'none',title: '图形验证码错误'})
  55. }else{
  56. if(this.data.isbtn){
  57. this.setData({isbtn: false})
  58. }else{
  59. return;
  60. }
  61. app.wxRequest(app.globalData.urlRoot + "userInfo/certificationCar", {carInfo:e.detail.value.VIN}, res => {
  62. console.log(res)
  63. if (res.code == 200) {
  64. if(res.data!=null){
  65. app.globalData.certificationState=res.data.certificationState;
  66. wx.navigateTo({url: '/pages/scout/scout'})
  67. }else{
  68. this.setData({isbtn: true})
  69. wx.showToast({icon:'none',title: '认证失败'})
  70. }
  71. }else{
  72. this.setData({isbtn: true})
  73. wx.showToast({icon:'none',title: ''+res.msg})
  74. }
  75. }, this,"POST");
  76. }
  77. },
  78. /**
  79. * 提交信息-注册
  80. */
  81. formSubmit2(e) {
  82. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  83. if (e.detail.value.name == "" || e.detail.value.name == null) {
  84. wx.showToast({icon:'none',title: '请输入您的姓名'})
  85. }else if (e.detail.value.phone == "" || e.detail.value.phone == null) {
  86. wx.showToast({icon:'none',title: '请输入您的手机号码'})
  87. }else if (e.detail.value.code == "" || e.detail.value.code == null) {
  88. wx.showToast({icon:'none',title: '请输入您的验证码'})
  89. }else if(this.data.photoList.length<0){
  90. wx.showToast({icon:'none',title: '请上传您的照片'})
  91. }else if(!this.data.agree){
  92. wx.showToast({icon:'none',title: '请阅读并同意协议内容'})
  93. }else{
  94. if(this.data.isbtn){
  95. this.setData({isbtn: false})
  96. }else{
  97. return;
  98. }
  99. app.wxRequest(app.globalData.urlRoot + "userInfo/submitCertificationNoCarInfo", {
  100. mobile:e.detail.value.phone,
  101. captcha:e.detail.value.code,
  102. realname:e.detail.value.name,
  103. jobId:this.data.vocationList2[parseInt(this.data.vocationIndex)]["jobId"],
  104. jobDetail:this.data.vocationList2[parseInt(this.data.vocationIndex)]["jobDetail"],
  105. province: this.data.cityList[0][e.detail.value.city[0]],
  106. city:this.data.cityList[1][e.detail.value.city[1]],
  107. picArr:JSON.stringify(this.data.photoList)
  108. }, res => {
  109. console.log(res)
  110. if (res.code == 200) {
  111. this.setData({maskShow:true})
  112. }else{
  113. this.setData({isbtn: true})
  114. wx.showToast({icon:'none',title: ''+res.msg})
  115. }
  116. }, this,"POST");
  117. }
  118. },
  119. /**
  120. * 关闭弹窗
  121. */
  122. hiddenRule:function(){
  123. this.setData({maskShow: false})
  124. wx.navigateBack({
  125. delta:1
  126. })
  127. // wx.navigateTo({url: '../../star/star'})
  128. },
  129. /**
  130. * 更换职业
  131. */
  132. changeVocation: function (e) {
  133. this.setData({
  134. vocationIndex: e.detail.value
  135. })
  136. },
  137. /**
  138. * 切换城市
  139. */
  140. changeCity(e){
  141. this.setData({
  142. cityIndex: e.detail.value
  143. })
  144. },
  145. changeCity2(e){
  146. if(e.detail.column==0){
  147. var jushu=[];
  148. jushu[0]=e.detail.value;
  149. jushu[1]=0;
  150. this.setData({
  151. cityIndex:jushu
  152. })
  153. var shuju=[];
  154. var shuju2=[];
  155. for(var i=0;i<this.data.allList.length;i++){
  156. if(this.data.cityList[0].indexOf(this.data.allList[i]["province"])==this.data.cityIndex[0]){
  157. shuju2.push(this.data.allList[i]["city"]);
  158. }
  159. }
  160. shuju[0]=this.data.cityList[0];
  161. shuju[1]=shuju2;
  162. this.setData({
  163. cityList:shuju
  164. })
  165. }else{
  166. var jushu=[];
  167. jushu[0]=this.data.cityIndex[0];
  168. jushu[1]=e.detail.value;
  169. this.setData({
  170. cityIndex:jushu
  171. })
  172. }
  173. },
  174. /**
  175. * 获取手机号
  176. */
  177. getphone(e){
  178. this.setData({
  179. getphone: e.detail.value
  180. })
  181. },
  182. /**
  183. * 获取验证码
  184. */
  185. getVcode(){
  186. console.log('获取验证码');
  187. if (this.data.getphone == "" || this.data.getphone == null) {
  188. wx.showToast({
  189. icon:'none',
  190. title: '请输入您的手机号码'
  191. })
  192. return;
  193. }
  194. if (!app.mobileVerify(this.data.getphone)) {
  195. wx.showToast({
  196. icon:'none',
  197. title: '请输入正确手机号码'
  198. })
  199. return;
  200. }
  201. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", {mobile:this.data.getphone}, res => {
  202. console.log(res)
  203. if (res.code == 200) {
  204. this.setData({
  205. getVcodeTime: 60
  206. })
  207. this.getCodeTimeKey=setInterval(this.vCodeDownTime,1000);
  208. }else{
  209. wx.showToast({icon:'none',title: ''+res.msg})
  210. }
  211. }, this);
  212. },
  213. vCodeDownTime(){
  214. var time = this.data.getVcodeTime-1;
  215. this.setData({
  216. getVcodeTime: time
  217. })
  218. if(time<=0){
  219. clearInterval(this.getCodeTimeKey);
  220. }
  221. },
  222. /**
  223. * 上传照片
  224. */
  225. chooseImage(e){
  226. var list=this.data.photoList;
  227. wx.chooseImage({
  228. count: 3-this.data.photoList.length,
  229. sizeType: ['original'], //可选择原图
  230. sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
  231. success: res => {
  232. for (let i = 0; i < res.tempFilePaths.length; i++) {
  233. wx.uploadFile({
  234. url: app.globalData.urlRoot + "upload/uploadImage",
  235. header: { "OPENID": app.globalData.openid },
  236. filePath: res.tempFilePaths[i],
  237. name: "file",
  238. success: res => {
  239. if (res.data) {
  240. var json = JSON.parse(res.data);
  241. if (json.code == 200) {
  242. if (e.currentTarget.dataset.value > -1) {
  243. list[e.currentTarget.dataset.value] = json.data[0].url;
  244. } else {
  245. list.push(json.data[0].url);
  246. }
  247. this.setData({ photoList: list });
  248. } else {
  249. wx.showToast({ icon: 'none', title: '图片上传失败' })
  250. }
  251. }
  252. }
  253. })
  254. }
  255. }
  256. })
  257. },
  258. /**
  259. * 同意协议
  260. */
  261. agreementClick(event){
  262. var agree = this.data.agree;
  263. this.setData({ "agree": !agree });
  264. },
  265. /**
  266. * 生命周期函数--监听页面加载
  267. */
  268. onLoad: function(options) {
  269. },
  270. /**
  271. * 生命周期函数--监听页面初次渲染完成
  272. */
  273. onReady: function() {
  274. wx.getSystemInfo({
  275. success: option => {
  276. var windowScale = option.windowWidth / 750;
  277. this.mcaptcha = new Mcaptcha({
  278. el: 'canvas',
  279. width: windowScale*205,
  280. height: windowScale*51,
  281. createCodeImg: "",
  282. callUrl:{
  283. that:this,
  284. obj:this.changeVode
  285. }
  286. });
  287. }
  288. })
  289. app.wxRequest(app.globalData.urlRoot + "userInfo/getJobList", {}, res => {
  290. console.log(res)
  291. if (res.code == 200) {
  292. var shuju=[];
  293. for(var i=0;i<res.data.length;i++){
  294. shuju.push(res.data[i]["jobDetail"]);
  295. }
  296. this.setData({
  297. vocationList:shuju,
  298. vocationList2:res.data
  299. })
  300. }
  301. }, this);
  302. app.wxRequest(app.globalData.urlRoot + "userInfo/getNoCarCityList", {}, res => {
  303. console.log(res)
  304. if (res.code == 200) {
  305. var shuju=[];
  306. var shuju1=[];
  307. var shuju2=[];
  308. for(var i=0;i<res.data.length;i++){
  309. if(shuju1.indexOf(res.data[i]["province"])==-1){
  310. shuju1.push(res.data[i]["province"]);
  311. }
  312. }
  313. for(var i=0;i<res.data.length;i++){
  314. if(shuju1.indexOf(res.data[i]["province"])==this.data.cityIndex[0]){
  315. shuju2.push(res.data[i]["city"]);
  316. }
  317. }
  318. shuju[0]=shuju1;
  319. shuju[1]=shuju2;
  320. this.setData({
  321. allList:res.data,
  322. cityList:shuju
  323. })
  324. this.getshow();
  325. }
  326. }, this);
  327. },
  328. changeVode:function(e){
  329. this.setData({
  330. vCodeImg: e.tempFilePath
  331. })
  332. },
  333. /**
  334. * 刷新验证码
  335. */
  336. vCodeRefresh() {
  337. this.mcaptcha.refresh();
  338. },
  339. /**
  340. * 生命周期函数--监听页面显示
  341. */
  342. onShow: function() {
  343. this.setData({isbtn: true})
  344. // this.getshow();
  345. },
  346. getshow(){
  347. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationNoCarInfo", {}, res => {
  348. console.log(res)
  349. if(res.code=200 && res.data){
  350. if(res.data.adminState==1){//审核通过
  351. // this.setData({maskShow:true})
  352. wx.navigateTo({url: '/pages/scout/scout'})
  353. }else if(res.data.adminState==0 || res.data.adminState==-1){//审核中&审核失败
  354. if(res.data.adminState==0){
  355. this.setData({maskShow:true})
  356. }
  357. var jushu=[],shuju=[],shuju2=[];
  358. for(var i=0;i<this.data.allList.length;i++){
  359. if(this.data.allList[i]["city"]==res.data.city){
  360. jushu[0]=this.data.cityList[0].indexOf(this.data.allList[i]["province"]);
  361. }
  362. }
  363. for(var i=0;i<this.data.allList.length;i++){
  364. if(this.data.cityList[0].indexOf(this.data.allList[i]["province"])==jushu[0]){
  365. shuju2.push(this.data.allList[i]["city"]);
  366. }
  367. }
  368. for(var i=0;i<shuju2.length;i++){
  369. if(shuju2[i]==res.data.city){
  370. jushu[1]=i;
  371. }
  372. }
  373. shuju[0]=this.data.cityList[0];
  374. shuju[1]=shuju2;
  375. this.setData({
  376. mydata:res.data,
  377. vocationIndex:parseInt(res.data.jobId)-1,
  378. cityIndex:jushu,
  379. cityList:shuju,
  380. agree:true,
  381. photoList:res.data.picArr,
  382. getphone:res.data.mobile,
  383. })
  384. }
  385. }
  386. }, this);
  387. },
  388. /**
  389. * 生命周期函数--监听页面隐藏
  390. */
  391. onHide: function() {
  392. },
  393. /**
  394. * 生命周期函数--监听页面卸载
  395. */
  396. onUnload: function() {
  397. clearInterval(this.getCodeTimeKey);
  398. this.data.getVcodeTime=60;
  399. },
  400. /**
  401. * 页面相关事件处理函数--监听用户下拉动作
  402. */
  403. onPullDownRefresh: function() {
  404. },
  405. /**
  406. * 页面上拉触底事件的处理函数
  407. */
  408. onReachBottom: function() {
  409. },
  410. /**
  411. * 用户点击右上角分享
  412. */
  413. onShareAppMessage: function() {
  414. return app.sharePack();
  415. },
  416. deleteImg:function(e){
  417. var index = e.currentTarget.dataset.index;
  418. this.data.photoList.splice(index,1);
  419. this.setData({
  420. photoList: this.data.photoList
  421. })
  422. }
  423. })