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

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