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

430 lines
11KB

  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. city:this.data.cityList[1][e.detail.value.city[1]],
  106. picArr:JSON.stringify(this.data.photoList)
  107. }, res => {
  108. console.log(res)
  109. if (res.code == 200) {
  110. this.setData({maskShow:true})
  111. }else{
  112. this.setData({isbtn: true})
  113. wx.showToast({icon:'none',title: ''+res.msg})
  114. }
  115. }, this,"POST");
  116. }
  117. },
  118. /**
  119. * 关闭弹窗
  120. */
  121. hiddenRule:function(){
  122. this.setData({maskShow: false})
  123. wx.navigateBack({
  124. delta:1
  125. })
  126. // wx.navigateTo({url: '../../star/star'})
  127. },
  128. /**
  129. * 更换职业
  130. */
  131. changeVocation: function (e) {
  132. this.setData({
  133. vocationIndex: e.detail.value
  134. })
  135. },
  136. /**
  137. * 切换城市
  138. */
  139. changeCity(e){
  140. this.setData({
  141. cityIndex: e.detail.value
  142. })
  143. },
  144. changeCity2(e){
  145. if(e.detail.column==0){
  146. var jushu=[];
  147. jushu[0]=e.detail.value;
  148. jushu[1]=0;
  149. this.setData({
  150. cityIndex:jushu
  151. })
  152. var shuju=[];
  153. var shuju2=[];
  154. for(var i=0;i<this.data.allList.length;i++){
  155. if(this.data.cityList[0].indexOf(this.data.allList[i]["province"])==this.data.cityIndex[0]){
  156. shuju2.push(this.data.allList[i]["city"]);
  157. }
  158. }
  159. shuju[0]=this.data.cityList[0];
  160. shuju[1]=shuju2;
  161. this.setData({
  162. cityList:shuju
  163. })
  164. }else{
  165. var jushu=[];
  166. jushu[0]=this.data.cityIndex[0];
  167. jushu[1]=e.detail.value;
  168. this.setData({
  169. cityIndex:jushu
  170. })
  171. }
  172. },
  173. /**
  174. * 获取手机号
  175. */
  176. getphone(e){
  177. this.setData({
  178. getphone: e.detail.value
  179. })
  180. },
  181. /**
  182. * 获取验证码
  183. */
  184. getVcode(){
  185. console.log('获取验证码');
  186. if (this.data.getphone == "" || this.data.getphone == null) {
  187. wx.showToast({
  188. icon:'none',
  189. title: '请输入您的手机号码'
  190. })
  191. return;
  192. }
  193. if (!app.mobileVerify(this.data.getphone)) {
  194. wx.showToast({
  195. icon:'none',
  196. title: '请输入正确手机号码'
  197. })
  198. return;
  199. }
  200. app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", {mobile:this.data.getphone}, res => {
  201. console.log(res)
  202. if (res.code == 200) {
  203. this.setData({
  204. getVcodeTime: 60
  205. })
  206. this.getCodeTimeKey=setInterval(this.vCodeDownTime,1000);
  207. }else{
  208. wx.showToast({icon:'none',title: ''+res.msg})
  209. }
  210. }, this);
  211. },
  212. vCodeDownTime(){
  213. var time = this.data.getVcodeTime-1;
  214. this.setData({
  215. getVcodeTime: time
  216. })
  217. if(time<=0){
  218. clearInterval(this.getCodeTimeKey);
  219. }
  220. },
  221. /**
  222. * 上传照片
  223. */
  224. chooseImage(e){
  225. var list=this.data.photoList;
  226. wx.chooseImage({
  227. count:1,
  228. sizeType: ['original'], //可选择原图
  229. sourceType: ['album', 'camera'], //可选择性开放访问相册、相机
  230. success: res => {
  231. wx.uploadFile({
  232. url: app.globalData.urlRoot + "upload/uploadImage",
  233. header:{"OPENID": app.globalData.openid},
  234. filePath: res.tempFilePaths[0],
  235. name: "file",
  236. success: res => {
  237. console.log(res)
  238. if(res.data){
  239. console.log(JSON.parse(res.data));
  240. var json=JSON.parse(res.data);
  241. if(json.code==200){
  242. console.log(json.data[0].url);
  243. if(e.currentTarget.dataset.value>-1){
  244. list[e.currentTarget.dataset.value]=json.data[0].url;
  245. }else{
  246. list.push(json.data[0].url);
  247. }
  248. this.setData({photoList:list});
  249. }else{
  250. wx.showToast({icon:'none',title: '图片上传失败'})
  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. })