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

415 line
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. this.mcaptcha = new Mcaptcha({
  274. el: 'canvas',
  275. width: 80,
  276. height: 35,
  277. createCodeImg: ""
  278. });
  279. app.wxRequest(app.globalData.urlRoot + "userInfo/getJobList", {}, res => {
  280. console.log(res)
  281. if (res.code == 200) {
  282. var shuju=[];
  283. for(var i=0;i<res.data.length;i++){
  284. shuju.push(res.data[i]["jobDetail"]);
  285. }
  286. this.setData({
  287. vocationList:shuju,
  288. vocationList2:res.data
  289. })
  290. }
  291. }, this);
  292. app.wxRequest(app.globalData.urlRoot + "userInfo/getNoCarCityList", {}, res => {
  293. console.log(res)
  294. if (res.code == 200) {
  295. var shuju=[];
  296. var shuju1=[];
  297. var shuju2=[];
  298. for(var i=0;i<res.data.length;i++){
  299. if(shuju1.indexOf(res.data[i]["province"])==-1){
  300. shuju1.push(res.data[i]["province"]);
  301. }
  302. }
  303. for(var i=0;i<res.data.length;i++){
  304. if(shuju1.indexOf(res.data[i]["province"])==this.data.cityIndex[0]){
  305. shuju2.push(res.data[i]["city"]);
  306. }
  307. }
  308. shuju[0]=shuju1;
  309. shuju[1]=shuju2;
  310. this.setData({
  311. allList:res.data,
  312. cityList:shuju
  313. })
  314. this.getshow();
  315. }
  316. }, this);
  317. },
  318. /**
  319. * 刷新验证码
  320. */
  321. vCodeRefresh() {
  322. this.mcaptcha.refresh();
  323. },
  324. /**
  325. * 生命周期函数--监听页面显示
  326. */
  327. onShow: function() {
  328. this.setData({isbtn: true})
  329. this.getshow();
  330. },
  331. getshow(){
  332. app.wxRequest(app.globalData.urlRoot + "userInfo/getCertificationNoCarInfo", {}, res => {
  333. console.log(res)
  334. if(res.code=200 && res.data){
  335. if(res.data.adminState==1){//审核通过
  336. // this.setData({maskShow:true})
  337. wx.navigateTo({url: '/pages/scout/scout'})
  338. }else if(res.data.adminState==0 || res.data.adminState==-1){//审核中&审核失败
  339. if(res.data.adminState==0){
  340. this.setData({maskShow:true})
  341. }
  342. var jushu=[],shuju=[],shuju2=[];
  343. for(var i=0;i<this.data.allList.length;i++){
  344. if(this.data.allList[i]["city"]==res.data.city){
  345. jushu[0]=this.data.cityList[0].indexOf(this.data.allList[i]["province"]);
  346. }
  347. }
  348. for(var i=0;i<this.data.allList.length;i++){
  349. if(this.data.cityList[0].indexOf(this.data.allList[i]["province"])==jushu[0]){
  350. shuju2.push(this.data.allList[i]["city"]);
  351. }
  352. }
  353. for(var i=0;i<shuju2.length;i++){
  354. if(shuju2[i]==res.data.city){
  355. jushu[1]=i;
  356. }
  357. }
  358. shuju[0]=this.data.cityList[0];
  359. shuju[1]=shuju2;
  360. this.setData({
  361. mydata:res.data,
  362. vocationIndex:parseInt(res.data.jobId)-1,
  363. cityIndex:jushu,
  364. cityList:shuju,
  365. agree:true,
  366. photoList:res.data.picArr,
  367. getphone:res.data.mobile,
  368. })
  369. }
  370. }
  371. }, this);
  372. },
  373. /**
  374. * 生命周期函数--监听页面隐藏
  375. */
  376. onHide: function() {
  377. },
  378. /**
  379. * 生命周期函数--监听页面卸载
  380. */
  381. onUnload: function() {
  382. clearInterval(this.getCodeTimeKey);
  383. this.data.getVcodeTime=60;
  384. },
  385. /**
  386. * 页面相关事件处理函数--监听用户下拉动作
  387. */
  388. onPullDownRefresh: function() {
  389. },
  390. /**
  391. * 页面上拉触底事件的处理函数
  392. */
  393. onReachBottom: function() {
  394. },
  395. /**
  396. * 用户点击右上角分享
  397. */
  398. onShareAppMessage: function() {
  399. return app.sharePack();
  400. }
  401. })