real_name.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. // pages/real_name/read_name.js
  2. const app = getApp();
  3. const util = require('../../utils/utils.js');
  4. let timer1 = null;
  5. Page({
  6. data: {
  7. state1: '1', //步骤一
  8. state2: '', //步骤二
  9. state3: '', //步骤三
  10. state4: '', //步骤四
  11. index: 0, //0 手机验证 1 实名认证 2 缴纳押金 3完成
  12. index1: 0, //0 选择获取手机号码方式 1 手动输入页面
  13. nameVal: '', //输入的名字
  14. cardVal: '', //输入的身份证号码
  15. smsVal: '', //输入的短信验证码
  16. phoneVal: '', //输入的手机号码
  17. code: '获取验证码', //获取短信验证码
  18. phoneDisabele: false, //输入的手机号是否能更改
  19. currentTime: 60, //倒计时秒数
  20. codeDisabled: false, //是否禁用按钮
  21. timer: null, //定时器
  22. money: wx.getStorageSync('setting').deposit,
  23. payment: true,
  24. count: 10,
  25. statusIndex: 0, //0 缴纳押金 1退回押金 2退押金状态
  26. pay: 0, // 1 支付押金 0 支付/缴纳/退回
  27. popShow: true, //是否显示弹窗
  28. money: '',
  29. depoSuce: true,
  30. imgUrl: 'http://resource.bike.hanyiyun.com/xiaobanma/moneyBg.png',
  31. depShow: true, //是否选中缴纳押金 true选中 false 未选中
  32. curShow: '', //是否选中购买免押金卡 undefined 未选中 有值选中
  33. cardList: [], //免押金卡列表
  34. state: [],
  35. userState: wx.getStorageSync('userState'),
  36. title: app.globalData.title,
  37. setting: wx.getStorageSync('setting'),
  38. hidden: true
  39. },
  40. onLoad: function (options) {
  41. if (options.index) {
  42. this.setData({
  43. index: options.index,
  44. state2: options.state2
  45. })
  46. }
  47. if (options.hidden) {
  48. this.setData({
  49. hidden: false
  50. })
  51. }
  52. this.getState();
  53. // this.setData({
  54. // money: wx.getStorageSync('setting').deposit
  55. // })
  56. // if (wx.getStorageSync('setting') == '') {
  57. // wx.showModal({
  58. // title: '提示',
  59. // content: '您附近暂无运营区域~',
  60. // showCancel: false,
  61. // success: function (res) {
  62. // if (res.confirm) {
  63. // wx.navigateBack()
  64. // }
  65. // }
  66. // })
  67. // } else {
  68. // this.setData({
  69. // money: wx.getStorageSync('setting').deposit
  70. // })
  71. // }
  72. if (options.home) {
  73. this.setData({
  74. pay: 1
  75. })
  76. }
  77. this.getCard();
  78. },
  79. student: function () {
  80. wx.navigateTo({
  81. url: '../student_certification/student_certification',
  82. })
  83. },
  84. //返回首页
  85. backPage() {
  86. clearInterval(timer1);
  87. if (app.globalData.compatible) {
  88. wx.reLaunch({
  89. url: '/pages/compatible/index/index',
  90. })
  91. } else {
  92. wx.reLaunch({
  93. url: '/pages/index/index',
  94. })
  95. }
  96. },
  97. //验证名字
  98. ckName(e) {
  99. this.setData({
  100. nameVal: e.detail.value
  101. })
  102. },
  103. name(e) {
  104. this.setData({
  105. nameVal: e.detail.value
  106. })
  107. },
  108. namefirm(e) {
  109. this.setData({
  110. nameVal: e.detail.value
  111. })
  112. },
  113. //验证身份证号
  114. ckCard(e) {
  115. this.setData({
  116. cardVal: e.detail.value
  117. })
  118. },
  119. input(e) {
  120. this.setData({
  121. cardVal: e.detail.value
  122. })
  123. },
  124. valuefirm(e) {
  125. this.setData({
  126. cardVal: e.detail.value
  127. })
  128. },
  129. //验证手机号
  130. ckPhone(e) {
  131. this.setData({
  132. phoneVal: e.detail.value
  133. })
  134. },
  135. //验证短信验证码
  136. ckSms(e) {
  137. this.setData({
  138. smsVal: e.detail.value
  139. })
  140. },
  141. //获取短信验证码
  142. getCode: util.throttle(function () {
  143. let self = this
  144. let currentTime = self.data.currentTime
  145. let timer = self.data.timer
  146. if (self.data.phoneVal.length != 11) {
  147. wx.showToast({
  148. title: '请输入正确的手机号',
  149. icon: 'none',
  150. duration: 2000
  151. })
  152. } else {
  153. self.setData({
  154. phoneDisabele: true
  155. })
  156. // 调用短信验证码接口
  157. let data = {
  158. mobile: this.data.phoneVal,
  159. type: 1
  160. }
  161. app.request('/verification-code', data, 'POST').then(res => {
  162. if (res.statusCode == 200) {
  163. //60秒倒计时
  164. if (!timer) {
  165. timer = setInterval(() => {
  166. if (currentTime > 0 && currentTime <= 60) {
  167. currentTime--;
  168. }
  169. if (currentTime !== 0) {
  170. self.setData({
  171. code: "重新发送" + "(" + currentTime + ")",
  172. codeDisabled: true,
  173. })
  174. } else {
  175. clearInterval(timer);
  176. self.setData({
  177. code: '获取验证码',
  178. phoneDisabele: false,
  179. codeDisabled: false,
  180. currentTime: 60,
  181. timer: null,
  182. })
  183. }
  184. }, 1000)
  185. }
  186. }
  187. })
  188. }
  189. }, 1000),
  190. //提交申请按钮
  191. submit: util.throttle(function () {
  192. let reg = /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/;
  193. let reg1 = /^[\u4E00-\u9FA5]{2,4}$/;
  194. var that = this;
  195. if (!reg1.test(this.data.nameVal)) {
  196. wx.showToast({
  197. title: '请输入正确的姓名',
  198. icon: 'none',
  199. duration: 2000
  200. })
  201. } else if (!reg.test(this.data.cardVal)) {
  202. wx.showToast({
  203. title: '请输入正确的身份证号',
  204. icon: 'none',
  205. duration: 2000
  206. })
  207. } else {
  208. that.checkIDCard(that.data.cardVal)
  209. }
  210. }, 1000),
  211. // 一键获取手机号
  212. checkIDCard(idcode) {
  213. // 加权因子
  214. var that = this;
  215. var weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
  216. // 校验码
  217. var check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']
  218. var code = idcode + ''
  219. var last = idcode[17] //最后一位
  220. var seventeen = code.substring(0, 17)
  221. // ISO 7064:1983.MOD 11-2
  222. // 判断最后一位校验码是否正确
  223. var arr = seventeen.split('')
  224. var len = arr.length
  225. var num = 0
  226. for (var i = 0; i < len; i++) {
  227. num = num + arr[i] * weight_factor[i]
  228. }
  229. // 获取余数
  230. var resisue = num % 11
  231. var last_no = check_code[resisue]
  232. var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/
  233. // 判断格式是否正确
  234. var format = idcard_patter.test(idcode)
  235. console.log(format)
  236. console.log(last)
  237. console.log(last_no)
  238. // 返回验证结果,校验码和格式同时正确才算是合法的身份证号码
  239. if(last==last_no && format==true){
  240. wx.showLoading({
  241. title: '认证中...',
  242. mask: true
  243. })
  244. if (app.globalData.req) {
  245. let data = {
  246. card_id: that.data.cardVal,
  247. name: that.data.nameVal
  248. }
  249. app.request('/user/real-name-authentication', data, 'POST', app.globalData.req).then(res => {
  250. console.log(res)
  251. if (res.statusCode == 200) {
  252. if (that.data.hidden == false) {
  253. wx.navigateBack()
  254. } else {
  255. that.setData({
  256. state3: 3,
  257. index: 2
  258. })
  259. }
  260. wx.hideLoading()
  261. }
  262. }).catch(err => {
  263. console.log(err)
  264. })
  265. } else {
  266. wx.showToast({
  267. title: '您的操作过于频繁,请稍后再试~',
  268. icon: 'none'
  269. })
  270. }
  271. }else{
  272. wx.showToast({
  273. title: '身份证号输入有误~',
  274. icon:'none'
  275. })
  276. }
  277. },
  278. getPhoneNumber(e) {
  279. var that = this;
  280. if (e.detail.errMsg == "getPhoneNumber:ok") {
  281. let data = {
  282. session_key: wx.getStorageSync('session_key'),
  283. iv: e.detail.iv,
  284. encryptedData: e.detail.encryptedData
  285. }
  286. app.request('/user/bind-wechat-mobile', data, 'POST').then(res => {
  287. if (res.statusCode == 200) {
  288. //获取成功判断当前有没有实名认证,如果有跳到交押金 没有则正常执行
  289. if (wx.getStorageSync('setting').is_card == 0 && wx.getStorageSync('setting').is_deposit == 1) {
  290. this.setData({
  291. state3: 3,
  292. index: 2,
  293. state2: 2
  294. })
  295. } else if (wx.getStorageSync('setting').is_card == 0 && wx.getStorageSync('setting').is_deposit == 0) {
  296. this.setData({
  297. state3: 3,
  298. index: 3,
  299. state2: 2,
  300. state4: 4
  301. })
  302. if (!timer1) {
  303. let count = that.data.count;
  304. timer1 = setInterval(() => {
  305. if (count > 0) {
  306. that.setData({
  307. count: --count
  308. })
  309. }
  310. if (count <= 0) {
  311. clearInterval(timer1)
  312. that.backPage();
  313. }
  314. }, 1000)
  315. }
  316. } else {
  317. if (wx.getStorageSync('userState').is_card_certified == 1) {
  318. this.setData({
  319. state3: 3,
  320. index: 2,
  321. state2: 2
  322. })
  323. } else {
  324. this.setData({
  325. state2: 2,
  326. index: 1
  327. })
  328. }
  329. }
  330. }
  331. })
  332. } else {
  333. wx.showToast({
  334. title: '获取手机号失败',
  335. icon: 'none',
  336. duration: 2000
  337. })
  338. }
  339. },
  340. // 手动输入手机号码
  341. manual() {
  342. this.setData({
  343. index1: 1
  344. })
  345. },
  346. //立即验证按钮
  347. verify: util.throttle(function () {
  348. let reg = 11 && /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/;
  349. let reg1 = /^\d{4}$/
  350. if (!reg1.test(this.data.smsVal)) {
  351. wx.showToast({
  352. title: '请输入短信验证码',
  353. icon: 'none',
  354. duration: 2000
  355. })
  356. }
  357. if (!reg.test(this.data.phoneVal)) {
  358. wx.showToast({
  359. title: '请输入正确的手机号',
  360. icon: 'none',
  361. duration: 2000
  362. })
  363. return;
  364. } else if (!this.data.smsVal) {
  365. wx.showToast({
  366. title: '短信验证码不能为空',
  367. icon: 'none',
  368. duration: 2000
  369. })
  370. return;
  371. } else {
  372. if (app.globalData.req) {
  373. let data = {
  374. mobile: this.data.phoneVal,
  375. code: this.data.smsVal
  376. }
  377. app.request('/user/bind-mobile', data, 'POST', app.globalData.req).then(res => {
  378. if (res.statusCode == 200) {
  379. if (wx.getStorageSync('userState').is_card_certified == 1) {
  380. this.setData({
  381. state3: 3,
  382. index: 2,
  383. state2: 2
  384. })
  385. } else {
  386. this.setData({
  387. state2: 2,
  388. index: 1
  389. })
  390. }
  391. }
  392. if (res.statusCode == 422) {
  393. console.log(res)
  394. wx.showToast({
  395. title: res.data.errors,
  396. icon: 'none',
  397. duration: 2000
  398. })
  399. }
  400. })
  401. } else {
  402. wx.showToast({
  403. title: '您的操作过于频繁,请稍后再试~',
  404. icon: 'none'
  405. })
  406. }
  407. }
  408. }, 1000),
  409. phone: function () {
  410. wx.makePhoneCall({
  411. phoneNumber: wx.getStorageSync('home').customer_service_phone,
  412. })
  413. },
  414. privacy: util.throttle(function () {
  415. //点击个人隐私条约
  416. wx.navigateTo({
  417. url: '/pages/personal/privacy/privacy',
  418. })
  419. }, 1000),
  420. agreement: util.throttle(function () {
  421. //充值条约
  422. wx.navigateTo({
  423. url: '/pages/agreement/agreement',
  424. })
  425. }, 1000),
  426. onReady: function () {
  427. },
  428. onShow: function () {
  429. this.setData({
  430. money: wx.getStorageSync('setting').deposit,
  431. setting: wx.getStorageSync('setting')
  432. })
  433. },
  434. onHide: function () {
  435. },
  436. onUnload: function () {
  437. },
  438. onPullDownRefresh: function () {
  439. },
  440. onReachBottom: function () {
  441. },
  442. onShareAppMessage: function () {
  443. },
  444. explain() {
  445. wx.navigateTo({
  446. url: '/pages/explain_card_free/explain_card_free',
  447. })
  448. },
  449. getCard() {
  450. let data = {
  451. area_id: wx.getStorageSync('home').id
  452. }
  453. app.request('/deposit_card/index', data, 'GET').then(res => {
  454. console.log(res.data);
  455. this.setData({
  456. cardList: res.data.data
  457. })
  458. console.log(this.data.cardList)
  459. })
  460. },
  461. // 切换免押金卡
  462. cut(e) {
  463. let that = this;
  464. let id = e.currentTarget.dataset.id;
  465. if (id == undefined) {
  466. that.setData({
  467. depShow: true,
  468. curShow: "text_undefined",
  469. depshow: true
  470. })
  471. } else {
  472. that.setData({
  473. curShow: id,
  474. depShow: false,
  475. depshow: false
  476. })
  477. }
  478. },
  479. //进入页面判断是否缴纳押金
  480. getState: util.throttle(function (e) {
  481. app.request('/user/status', '', 'GET').then(res => {
  482. console.log(res, '判断');
  483. this.setData({
  484. statusIndex: res.data.is_deposit,
  485. state: res.data
  486. })
  487. })
  488. }, 1000),
  489. //缴纳押金
  490. pay: util.throttle(function (e) {
  491. this.setData({
  492. pay: 1
  493. })
  494. }, 100),
  495. //显示弹窗
  496. showPop: util.throttle(function (e) {
  497. this.setData({
  498. popShow: false,
  499. })
  500. }, 1000),
  501. //取消退回押金
  502. cancle: util.throttle(function (e) {
  503. this.setData({
  504. popShow: true,
  505. })
  506. }, 1000),
  507. //确定退回押金
  508. confirm: util.throttle(function (e) {
  509. this.setData({
  510. popShow: true,
  511. statusIndex: 1,
  512. })
  513. if (app.globalData.req) {
  514. app.request('/deposit/refund', '', 'POST', app.globalData.req).then(res => {
  515. console.log(res);
  516. if (res.statusCode == 200) {
  517. wx.showToast({
  518. title: '押金退还成功稍后到账~',
  519. icon: 'none',
  520. duration: 3000
  521. })
  522. this.setData({
  523. statusIndex: 0
  524. })
  525. }
  526. })
  527. } else {
  528. wx.showToast({
  529. title: '您的操作过于频繁,请稍后再试~',
  530. icon: 'none'
  531. })
  532. }
  533. }, 1000),
  534. //立即支付
  535. depoSuce: util.throttle(function (e) {
  536. console.log('支付')
  537. var that = this;
  538. let url = '';
  539. var data = '';
  540. if(that.data.money!='0.00'){
  541. if (app.globalData.req) {
  542. console.log(that.data.depShow)
  543. if (that.data.depShow) { //缴纳押金
  544. console.log(11111)
  545. url = "/deposit/pay";
  546. data = {
  547. area_id: wx.getStorageSync('home').id
  548. }
  549. } else { //购买免押金卡
  550. console.log(2222)
  551. url = "/deposit_card/pay";
  552. data = {
  553. area_id: wx.getStorageSync('home').id,
  554. id: that.data.curShow
  555. }
  556. }
  557. app.request(url, data, 'POST', app.globalData.req).then(res => {
  558. if (res.statusCode == 200) {
  559. console.log(res)
  560. wx.requestPayment({
  561. timeStamp: res.data.timeStamp.toString(),
  562. nonceStr: res.data.nonceStr,
  563. package: res.data.package,
  564. signType: res.data.signType,
  565. paySign: res.data.paySign,
  566. success(res) {
  567. that.setData({
  568. payment: false,
  569. state4: 4,
  570. index: 3,
  571. depoSuce: true
  572. })
  573. if (!timer1) {
  574. let count = that.data.count;
  575. timer1 = setInterval(() => {
  576. if (count > 0) {
  577. that.setData({
  578. count: --count
  579. })
  580. }
  581. if (count <= 0) {
  582. clearInterval(timer1)
  583. that.backPage();
  584. }
  585. }, 1000)
  586. }
  587. },
  588. fail(err) {
  589. console.log(err)
  590. wx.showToast({
  591. title: '支付失败',
  592. icon: 'none'
  593. })
  594. that.setData({
  595. depoSuce: true
  596. })
  597. }
  598. })
  599. } else {
  600. console.log(res)
  601. that.setData({
  602. depoSuce: true
  603. })
  604. }
  605. })
  606. } else {
  607. wx.showToast({
  608. title: '您的操作过于频繁,请稍后再试~',
  609. icon: 'none'
  610. })
  611. }
  612. }else{
  613. that.setData({
  614. payment: false,
  615. state4: 4,
  616. index: 3,
  617. depoSuce: true
  618. })
  619. }
  620. }, 1000),
  621. agreement: util.throttle(function (e) {
  622. //充值条约
  623. wx.navigateTo({
  624. url: '/pages/agreement/agreement',
  625. })
  626. }, 1000),
  627. })