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

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