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

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