register.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <template>
  2. <view>
  3. <view class="container"></view>
  4. <view class="bg-mask" @tap="cancelSelectRegion" v-if="openSelectRegion"></view>
  5. </view>
  6. </template>
  7. <script>
  8. var util = require('../../../utils/util');
  9. var api = require('../../../config/api.js');
  10. var check = require('../../../utils/check.js');
  11. var user = require('../../../utils/user.js');
  12. var area = require('../../../utils/area.js');
  13. var app = getApp();
  14. export default {
  15. data() {
  16. return {
  17. username: '',
  18. mobile: '',
  19. birthday: '',
  20. code: '',
  21. nid: '',
  22. type: 0,
  23. userInfo: {},
  24. show: false,
  25. items: [
  26. {
  27. name: '钟点工',
  28. value: 1,
  29. checked: false
  30. },
  31. {
  32. name: '白班保姆',
  33. value: 2,
  34. checked: false
  35. },
  36. {
  37. name: '住家保姆',
  38. value: 3,
  39. checked: false
  40. }
  41. ],
  42. address: {
  43. id: 0,
  44. areaCode: 0,
  45. address: '',
  46. isDefault: 0,
  47. province: '',
  48. city: '',
  49. county: ''
  50. },
  51. isread: 0,
  52. openSelectRegion: false,
  53. checked: false,
  54. selectRegionList: [
  55. {
  56. code: 0,
  57. name: '省份'
  58. },
  59. {
  60. code: 0,
  61. name: '城市'
  62. },
  63. {
  64. code: 0,
  65. name: '区县'
  66. }
  67. ],
  68. regionType: 1,
  69. regionList: [],
  70. selectRegionDone: false,
  71. confirmPassword: '',
  72. password: ''
  73. };
  74. },
  75. onLoad: function (options) {
  76. // 页面初始化 options为页面跳转所带来的参数
  77. /* 页面渲染完成 */
  78. if (app.globalData.hasLogin) {
  79. let userInfo = uni.getStorageSync('userInfo');
  80. this.setData({
  81. userInfo: userInfo
  82. });
  83. }
  84. },
  85. onReady: function () {},
  86. onShow: function () {
  87. // 页面显示
  88. let that = this;
  89. //初始化安心包历史数据信息
  90. let cus = uni.getStorageSync('nurseInfo');
  91. if (cus) {
  92. that.setData({
  93. username: cus.username,
  94. mobile: cus.mobile,
  95. nid: cus.nid,
  96. type: cus.type
  97. });
  98. //缓存中 保姆类型
  99. console.info(cus);
  100. let _items = that.items;
  101. let _index = parseInt(cus.type) - 1;
  102. _items[_index].checked = true;
  103. that.setData({
  104. items: _items
  105. });
  106. let address = this.address;
  107. address.address = cus.address;
  108. address.province = cus.province;
  109. address.city = cus.city;
  110. address.county = cus.county;
  111. address.areaCode = cus.regionId;
  112. that.setData({
  113. address: address
  114. });
  115. }
  116. },
  117. onHide: function () {
  118. // 页面隐藏
  119. },
  120. onUnload: function () {
  121. // 页面关闭
  122. },
  123. methods: {
  124. radioChange(e) {
  125. console.info(e);
  126. this.setData({
  127. type: e.detail.value
  128. });
  129. },
  130. bindinputAddress(event) {
  131. let address = this.address;
  132. address.address = event.detail.value;
  133. this.setData({
  134. address: address
  135. });
  136. },
  137. bindIsRead(e) {
  138. let that = this;
  139. this.setData({
  140. isread: that.isread == 0 ? 1 : 0
  141. });
  142. },
  143. setRegionDoneStatus() {
  144. let that = this;
  145. let doneStatus = that.selectRegionList.every((item) => {
  146. return item.code != 0;
  147. });
  148. that.setData({
  149. selectRegionDone: doneStatus
  150. });
  151. },
  152. chooseRegion() {
  153. let that = this;
  154. this.setData({
  155. openSelectRegion: !this.openSelectRegion
  156. });
  157. //设置区域选择数据
  158. let address = this.address;
  159. if (address.areaCode > 0) {
  160. let selectRegionList = this.selectRegionList;
  161. //console.info(selectRegionList);
  162. selectRegionList[0].code = address.areaCode.slice(0, 2) + '0000';
  163. selectRegionList[0].name = address.province;
  164. selectRegionList[1].code = address.areaCode.slice(0, 4) + '00';
  165. selectRegionList[1].name = address.city;
  166. selectRegionList[2].code = address.areaCode;
  167. selectRegionList[2].name = address.county;
  168. let regionList = area.getList('county', address.areaCode.slice(0, 4));
  169. regionList = regionList.map((item) => {
  170. //标记已选择的
  171. if (address.areaCode === item.code) {
  172. item.selected = true;
  173. } else {
  174. item.selected = false;
  175. }
  176. return item;
  177. });
  178. this.setData({
  179. selectRegionList: selectRegionList,
  180. regionType: 3,
  181. regionList: regionList
  182. });
  183. } else {
  184. let selectRegionList = [
  185. {
  186. code: 0,
  187. name: '省份'
  188. },
  189. {
  190. code: 0,
  191. name: '城市'
  192. },
  193. {
  194. code: 0,
  195. name: '区县'
  196. }
  197. ];
  198. this.setData({
  199. selectRegionList: selectRegionList,
  200. regionType: 1,
  201. regionList: area.getList('province')
  202. });
  203. }
  204. this.setRegionDoneStatus();
  205. },
  206. selectRegionType(event) {
  207. console.info('selectRegionType');
  208. let that = this;
  209. let regionTypeIndex = event.target.dataset.regionTypeIndex;
  210. let selectRegionList = that.selectRegionList;
  211. //判断是否可点击
  212. if (regionTypeIndex + 1 == this.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex - 1].code <= 0)) {
  213. return false;
  214. }
  215. let selectRegionItem = selectRegionList[regionTypeIndex];
  216. let code = selectRegionItem.code;
  217. let regionList;
  218. if (regionTypeIndex === 0) {
  219. // 点击省级,取省级
  220. regionList = area.getList('province');
  221. } else if (regionTypeIndex === 1) {
  222. // 点击市级,取市级
  223. regionList = area.getList('city', code.slice(0, 2));
  224. } else {
  225. // 点击县级,取县级
  226. console.info(code);
  227. regionList = area.getList('county', code.slice(0, 4));
  228. console.info(regionList);
  229. }
  230. regionList = regionList.map((item) => {
  231. //标记已选择的
  232. if (that.selectRegionList[regionTypeIndex].code == item.code) {
  233. item.selected = true;
  234. } else {
  235. item.selected = false;
  236. }
  237. return item;
  238. });
  239. this.setData({
  240. regionList: regionList,
  241. regionType: regionTypeIndex + 1
  242. });
  243. this.setRegionDoneStatus();
  244. },
  245. selectRegion(event) {
  246. let that = this;
  247. let regionIndex = event.target.dataset.regionIndex;
  248. let regionItem = this.regionList[regionIndex];
  249. let regionType = this.regionType;
  250. let selectRegionList = this.selectRegionList;
  251. selectRegionList[regionType - 1] = regionItem;
  252. if (regionType == 3) {
  253. this.setData({
  254. selectRegionList: selectRegionList
  255. });
  256. let regionList = that.regionList.map((item) => {
  257. //标记已选择的
  258. if (that.selectRegionList[that.regionType - 1].code == item.code) {
  259. item.selected = true;
  260. } else {
  261. item.selected = false;
  262. }
  263. return item;
  264. });
  265. this.setData({
  266. regionList: regionList
  267. });
  268. this.setRegionDoneStatus();
  269. return;
  270. }
  271. //重置下级区域为空
  272. selectRegionList.map((item, index) => {
  273. if (index > regionType - 1) {
  274. item.code = 0;
  275. item.name = index == 1 ? '城市' : '区县';
  276. }
  277. return item;
  278. });
  279. //console.info(selectRegionList);
  280. this.setData({
  281. selectRegionList: selectRegionList,
  282. regionType: regionType + 1
  283. });
  284. let code = regionItem.code;
  285. let regionList = [];
  286. if (regionType === 1) {
  287. // 点击省级,取市级
  288. regionList = area.getList('city', code.slice(0, 2));
  289. } else {
  290. // 点击市级,取县级
  291. regionList = area.getList('county', code.slice(0, 4));
  292. }
  293. this.setData({
  294. regionList: regionList
  295. });
  296. this.setRegionDoneStatus();
  297. },
  298. doneSelectRegion() {
  299. if (this.selectRegionDone === false) {
  300. return false;
  301. }
  302. let address = this.address;
  303. let selectRegionList = this.selectRegionList;
  304. address.province = selectRegionList[0].name;
  305. address.city = selectRegionList[1].name;
  306. address.county = selectRegionList[2].name;
  307. address.areaCode = selectRegionList[2].code;
  308. this.setData({
  309. address: address,
  310. openSelectRegion: false
  311. });
  312. },
  313. cancelSelectRegion() {
  314. this.setData({
  315. openSelectRegion: false,
  316. regionType: this.regionDoneStatus ? 3 : 1
  317. });
  318. },
  319. showPopup() {
  320. this.setData({
  321. show: true
  322. });
  323. },
  324. //获取手机号 一键注册
  325. getPhoneNumber: function (e) {
  326. console.log(e.detail.encryptedData);
  327. user.denPhone(e.detail)
  328. .then((res) => {
  329. this.setData({
  330. mobile: res.data
  331. });
  332. })
  333. .catch((err) => {
  334. console.log(err);
  335. /*wx.navigateTo({ //授权过期 需要重新授权
  336. url: '/pages/auth/login/login?reg=1',
  337. })*/
  338. });
  339. },
  340. requestRegister: function () {
  341. let that = this;
  342. let auth = {
  343. username: that.username,
  344. mobile: that.mobile,
  345. region: that.address.province + that.address.city + that.address.county,
  346. province: that.address.province,
  347. city: that.address.city,
  348. county: that.address.county,
  349. regionId: that.address.areaCode,
  350. address: that.address.address,
  351. nid: that.nid,
  352. type: that.type
  353. };
  354. uni.setStorageSync('nurseInfo', auth);
  355. util.request(api.AuthCert, auth).then(function (res) {
  356. if (res.errno == 0) {
  357. uni.showToast({
  358. title: '实名认证成功',
  359. icon: 'success',
  360. duration: 2000,
  361. complete: function () {
  362. setTimeout(function () {
  363. uni.navigateTo({
  364. url: '/pages/checkout/checkout?nurseId=' + res.data
  365. });
  366. }, 2000);
  367. }
  368. });
  369. } else {
  370. uni.showModal({
  371. title: '错误信息',
  372. content: res.errmsg,
  373. showCancel: false
  374. });
  375. }
  376. });
  377. },
  378. startRegister: function () {
  379. var that = this;
  380. if (that.username.length < 2) {
  381. uni.showModal({
  382. title: '错误信息',
  383. content: '请输入真实姓名',
  384. showCancel: false
  385. });
  386. return false;
  387. }
  388. if (that.nid.length != 18 || !check.isCardCheck(that.nid)) {
  389. uni.showModal({
  390. title: '错误信息',
  391. content: '身份证号码不正确',
  392. showCancel: false
  393. });
  394. return false;
  395. }
  396. if (that.mobile.length == 0 || !check.isValidPhone(that.mobile)) {
  397. uni.showModal({
  398. title: '错误信息',
  399. content: '手机号输入不正确',
  400. showCancel: false
  401. });
  402. return false;
  403. }
  404. if (that.address.areaCode == 0) {
  405. uni.showModal({
  406. title: '错误信息',
  407. content: '请选择省市区信息',
  408. showCancel: false
  409. });
  410. return false;
  411. }
  412. if (that.address.address.length < 5) {
  413. uni.showModal({
  414. title: '错误信息',
  415. content: '请输入详细地址',
  416. showCancel: false
  417. });
  418. return false;
  419. }
  420. that.requestRegister();
  421. },
  422. bindUsernameInput: function (e) {
  423. this.setData({
  424. username: e.detail.value
  425. });
  426. },
  427. bindNidInput: function (e) {
  428. this.setData({
  429. nid: e.detail.value
  430. });
  431. },
  432. confirmFn(e) {
  433. var newTime = new Date(e.detail);
  434. newTime = util.formetdate(newTime);
  435. this.setData({
  436. birthday: newTime,
  437. show: false
  438. });
  439. },
  440. // 时间-取消按钮
  441. cancelFn() {
  442. this.setData({
  443. show: false
  444. });
  445. },
  446. bindConfirmPasswordInput: function (e) {
  447. this.setData({
  448. confirmPassword: e.detail.value
  449. });
  450. },
  451. bindMobileInput: function (e) {
  452. this.setData({
  453. mobile: e.detail.value
  454. });
  455. },
  456. clearInput: function (e) {
  457. switch (e.currentTarget.id) {
  458. case 'clear-username':
  459. this.setData({
  460. username: ''
  461. });
  462. break;
  463. case 'clear-password':
  464. this.setData({
  465. password: ''
  466. });
  467. break;
  468. case 'clear-confirm-password':
  469. this.setData({
  470. confirmPassword: ''
  471. });
  472. break;
  473. case 'clear-mobile':
  474. this.setData({
  475. mobile: ''
  476. });
  477. break;
  478. case 'clear-nid':
  479. this.setData({
  480. nid: ''
  481. });
  482. break;
  483. case 'clear-address':
  484. let address = this.address;
  485. address.address = '';
  486. this.setData({
  487. address: address
  488. });
  489. break;
  490. }
  491. }
  492. }
  493. };
  494. </script>
  495. <style>
  496. .form-box {
  497. width: 100%;
  498. height: auto;
  499. overflow: hidden;
  500. padding: 0 40rpx;
  501. margin-top: 96rpx;
  502. background: #fff;
  503. }
  504. .form-center {
  505. text-align: center;
  506. }
  507. .form-center text {
  508. font-size: 32rpx;
  509. font-weight: 600;
  510. }
  511. .userinfo-avatar {
  512. width: 128rpx;
  513. height: 128rpx;
  514. margin: 20rpx;
  515. border-radius: 50%;
  516. }
  517. .form-item {
  518. position: relative;
  519. background: #fff;
  520. height: 96rpx;
  521. border-bottom: 1px solid #d9d9d9;
  522. }
  523. .form-default {
  524. height: 96rpx;
  525. background: #fff;
  526. padding-top: 38rpx;
  527. font-size: 28rpx;
  528. }
  529. .form-item .username,
  530. .form-item .password,
  531. .form-item .mobile,
  532. .area,
  533. .form-item .address {
  534. position: absolute;
  535. top: 26rpx;
  536. left: 0;
  537. display: block;
  538. width: 100%;
  539. height: 44rpx;
  540. background: #fff;
  541. color: #333;
  542. font-size: 30rpx;
  543. }
  544. .form-item-code {
  545. margin-top: 32rpx;
  546. height: auto;
  547. overflow: hidden;
  548. width: 100%;
  549. float: left;
  550. width: 350rpx;
  551. }
  552. .form-item-code .form-item {
  553. float: left;
  554. width: 350rpx;
  555. }
  556. .form-item-getPhone {
  557. margin-top: 18rpx;
  558. height: auto;
  559. float: right;
  560. /*border: 1px solid #242a48;*/
  561. border-radius: 6rpx;
  562. color: #242a48;
  563. /*background: green;*/
  564. font-size: 30rpx;
  565. }
  566. .form-item .clear {
  567. position: absolute;
  568. top: 32rpx;
  569. right: 18rpx;
  570. z-index: 2;
  571. display: block;
  572. background: #fff;
  573. }
  574. .register-btn {
  575. margin: 40rpx 0 20rpx 0;
  576. height: 96rpx;
  577. line-height: 96rpx;
  578. color: #fff;
  579. font-size: 30rpx;
  580. background-color: #242a48;
  581. position: absolute;
  582. width: 90%;
  583. height: 90rpx;
  584. line-height: 98rpx;
  585. position: absolute;
  586. bottom: 25rpx;
  587. left: 0;
  588. border-radius: 0;
  589. padding: 0;
  590. margin: 0;
  591. margin-left: 5%;
  592. border-top-left-radius: 50rpx;
  593. border-bottom-left-radius: 50rpx;
  594. border-top-right-radius: 50rpx;
  595. border-bottom-right-radius: 50rpx;
  596. letter-spacing: 3rpx;
  597. }
  598. .region-select {
  599. width: 100%;
  600. height: 600rpx;
  601. background: #fff;
  602. position: fixed;
  603. z-index: 10;
  604. left: 0;
  605. bottom: 0;
  606. }
  607. .region-select .hd {
  608. height: 108rpx;
  609. width: 100%;
  610. border-bottom: 1px solid #f4f4f4;
  611. padding: 46rpx 30rpx 0 30rpx;
  612. }
  613. .region-select .region-selected {
  614. float: left;
  615. height: 60rpx;
  616. display: flex;
  617. }
  618. .region-select .region-selected .item {
  619. max-width: 140rpx;
  620. margin-right: 30rpx;
  621. text-align: left;
  622. line-height: 60rpx;
  623. height: 100%;
  624. color: #333;
  625. font-size: 28rpx;
  626. overflow: hidden;
  627. text-overflow: ellipsis;
  628. white-space: nowrap;
  629. }
  630. .region-select .region-selected .item.disabled {
  631. color: #999;
  632. }
  633. .region-select .region-selected .item.selected {
  634. color: #b4282d;
  635. }
  636. .region-select .done {
  637. float: right;
  638. height: 60rpx;
  639. width: 60rpx;
  640. border: none;
  641. background: #fff;
  642. line-height: 60rpx;
  643. text-align: center;
  644. color: #333;
  645. font-size: 28rpx;
  646. }
  647. .region-select .done.disabled {
  648. color: #999;
  649. }
  650. .region-select .bd {
  651. height: 492rpx;
  652. width: 100%;
  653. padding: 0 30rpx;
  654. }
  655. .region-select .region-list {
  656. height: 492rpx;
  657. }
  658. .region-select .region-list .item {
  659. width: 100%;
  660. height: 104rpx;
  661. line-height: 104rpx;
  662. text-align: left;
  663. color: #333;
  664. font-size: 28rpx;
  665. }
  666. .region-select .region-list .item.selected {
  667. color: #b4282d;
  668. }
  669. .bg-mask {
  670. height: 100%;
  671. width: 100%;
  672. background: rgba(0, 0, 0, 0.4);
  673. position: fixed;
  674. top: 0;
  675. left: 0;
  676. z-index: 8;
  677. }
  678. </style>