东风启辰小程序端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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. app.globalData.nowPage = 2;
  281. },
  282. /**
  283. * 生命周期函数--监听页面初次渲染完成
  284. */
  285. onReady: function() {
  286. wx.getSystemInfo({
  287. success: option => {
  288. var windowScale = option.windowWidth / 750;
  289. this.mcaptcha = new Mcaptcha({
  290. el: 'canvas',
  291. width: windowScale*205,
  292. height: windowScale*51,
  293. createCodeImg: "",
  294. callUrl:{
  295. that:this,
  296. obj:this.changeVode
  297. }
  298. });
  299. }
  300. })
  301. app.wxRequest(app.globalData.urlRoot + "userInfo/getJobList", {}, res => {
  302. console.log(res)
  303. if (res.code == 200) {
  304. var shuju=[];
  305. for(var i=0;i<res.data.length;i++){
  306. shuju.push(res.data[i]["jobDetail"]);
  307. }
  308. this.setData({
  309. vocationList:shuju,
  310. vocationList2:res.data
  311. })
  312. }
  313. }, this);
  314. app.wxRequest(app.globalData.urlRoot + "userInfo/getNoCarCityList", {}, res => {
  315. console.log(res)
  316. if (res.code == 200) {
  317. var shuju=[];
  318. var shuju1=[];
  319. var shuju2=[];
  320. for(var i=0;i<res.data.length;i++){
  321. if(shuju1.indexOf(res.data[i]["province"])==-1){
  322. shuju1.push(res.data[i]["province"]);
  323. }
  324. }
  325. for(var i=0;i<res.data.length;i++){
  326. if(shuju1.indexOf(res.data[i]["province"])==this.data.cityIndex[0]){
  327. shuju2.push(res.data[i]["city"]);
  328. }
  329. }
  330. shuju[0]=shuju1;
  331. shuju[1]=shuju2;
  332. this.setData({
  333. allList:res.data,
  334. cityList:shuju
  335. })
  336. this.getshow();
  337. }
  338. }, this);
  339. },
  340. changeVode:function(e){
  341. this.setData({
  342. vCodeImg: e.tempFilePath
  343. })
  344. },
  345. /**
  346. * 刷新验证码
  347. */
  348. vCodeRefresh() {
  349. this.mcaptcha.refresh();
  350. },
  351. /**
  352. * 生命周期函数--监听页面显示
  353. */
  354. onShow: function() {
  355. this.setData({isbtn: true})
  356. // this.getshow();
  357. },
  358. getshow(){
  359. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationNoCarInfo", {}, res => {
  360. console.log(res)
  361. if(res.code=200 && res.data){
  362. if(res.data.adminState==1){//审核通过
  363. // this.setData({maskShow:true})
  364. wx.navigateTo({url: '/pages/scout/scout'})
  365. }else if(res.data.adminState==0 || res.data.adminState==-1){//审核中&审核失败
  366. if(res.data.adminState==0){
  367. this.setData({maskShow:true})
  368. }
  369. var jushu=[],shuju=[],shuju2=[];
  370. for(var i=0;i<this.data.allList.length;i++){
  371. if(this.data.allList[i]["city"]==res.data.city){
  372. jushu[0]=this.data.cityList[0].indexOf(this.data.allList[i]["province"]);
  373. }
  374. }
  375. for(var i=0;i<this.data.allList.length;i++){
  376. if(this.data.cityList[0].indexOf(this.data.allList[i]["province"])==jushu[0]){
  377. shuju2.push(this.data.allList[i]["city"]);
  378. }
  379. }
  380. for(var i=0;i<shuju2.length;i++){
  381. if(shuju2[i]==res.data.city){
  382. jushu[1]=i;
  383. }
  384. }
  385. shuju[0]=this.data.cityList[0];
  386. shuju[1]=shuju2;
  387. this.setData({
  388. mydata:res.data,
  389. vocationIndex:parseInt(res.data.jobId)-1,
  390. cityIndex:jushu,
  391. cityList:shuju,
  392. agree:true,
  393. photoList:res.data.picArr,
  394. getphone:res.data.mobile,
  395. })
  396. }
  397. }
  398. }, this);
  399. },
  400. /**
  401. * 生命周期函数--监听页面隐藏
  402. */
  403. onHide: function() {
  404. },
  405. /**
  406. * 生命周期函数--监听页面卸载
  407. */
  408. onUnload: function() {
  409. clearInterval(this.getCodeTimeKey);
  410. this.data.getVcodeTime=60;
  411. },
  412. /**
  413. * 页面相关事件处理函数--监听用户下拉动作
  414. */
  415. onPullDownRefresh: function() {
  416. },
  417. /**
  418. * 页面上拉触底事件的处理函数
  419. */
  420. onReachBottom: function() {
  421. },
  422. /**
  423. * 用户点击右上角分享
  424. */
  425. onShareAppMessage: function() {
  426. return app.sharePack();
  427. },
  428. deleteImg:function(e){
  429. var index = e.currentTarget.dataset.index;
  430. this.data.photoList.splice(index, 1);
  431. this.data.photoListShow.splice(index, 1);
  432. this.setData({
  433. photoList: this.data.photoList,
  434. photoListShow: this.data.photoListShow
  435. })
  436. }
  437. })