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

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