real_name.js 13 KB

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