register.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. var util = require('../../../utils/util');
  2. var api = require('../../../config/api.js');
  3. var check = require('../../../utils/check.js');
  4. var user = require('../../../utils/user.js');
  5. var area = require('../../../utils/area.js');
  6. var app = getApp();
  7. Page({
  8. data: {
  9. username: '',
  10. mobile: '',
  11. birthday: '',
  12. code: '',
  13. nid: '',
  14. type: 0,
  15. userInfo: {},
  16. show: false,
  17. items: [{
  18. name: "钟点工",
  19. value: 1,
  20. checked:false
  21. }, {
  22. name: "白班保姆",
  23. value: 2,
  24. checked:false
  25. }, {
  26. name: "住家保姆",
  27. value: 3,
  28. checked:false
  29. }],
  30. address: {
  31. id: 0,
  32. areaCode: 0,
  33. address: '',
  34. isDefault: 0,
  35. province: '',
  36. city: '',
  37. county: ''
  38. },
  39. isread: 0,
  40. openSelectRegion: false,
  41. checked: false,
  42. selectRegionList: [{
  43. code: 0,
  44. name: '省份'
  45. },
  46. {
  47. code: 0,
  48. name: '城市'
  49. },
  50. {
  51. code: 0,
  52. name: '区县'
  53. }
  54. ],
  55. regionType: 1,
  56. regionList: [],
  57. selectRegionDone: false
  58. },
  59. onLoad: function (options) {
  60. // 页面初始化 options为页面跳转所带来的参数
  61. /* 页面渲染完成 */
  62. if (app.globalData.hasLogin) {
  63. let userInfo = wx.getStorageSync('userInfo');
  64. this.setData({
  65. userInfo: userInfo
  66. })
  67. }
  68. },
  69. onReady: function () {
  70. },
  71. onShow: function () {
  72. // 页面显示
  73. let that = this;
  74. //初始化安心包历史数据信息
  75. let cus = wx.getStorageSync('nurseInfo');
  76. if (cus) {
  77. that.setData({
  78. username: cus.username,
  79. mobile: cus.mobile,
  80. nid: cus.nid,
  81. type:cus.type
  82. })
  83. //缓存中 保姆类型
  84. console.info(cus)
  85. let _items= that.data.items;
  86. let _index=parseInt(cus.type)-1;
  87. _items[_index].checked=true;
  88. that.setData({
  89. items:_items
  90. });
  91. let address = this.data.address;
  92. address.address = cus.address;
  93. address.province = cus.province;
  94. address.city = cus.city;
  95. address.county = cus.county;
  96. address.areaCode = cus.regionId;
  97. that.setData({
  98. address: address
  99. });
  100. }
  101. },
  102. onHide: function () {
  103. // 页面隐藏
  104. },
  105. onUnload: function () {
  106. // 页面关闭
  107. },
  108. radioChange(e) {
  109. console.info(e)
  110. this.setData({
  111. type:e.detail.value
  112. })
  113. },
  114. bindinputAddress(event) {
  115. let address = this.data.address;
  116. address.address = event.detail.value;
  117. this.setData({
  118. address: address
  119. });
  120. },
  121. bindIsRead(e) {
  122. let that = this;
  123. this.setData({
  124. isread: that.data.isread == 0 ? 1 : 0
  125. });
  126. },
  127. setRegionDoneStatus() {
  128. let that = this;
  129. let doneStatus = that.data.selectRegionList.every(item => {
  130. return item.code != 0;
  131. });
  132. that.setData({
  133. selectRegionDone: doneStatus
  134. })
  135. },
  136. chooseRegion() {
  137. let that = this;
  138. this.setData({
  139. openSelectRegion: !this.data.openSelectRegion
  140. });
  141. //设置区域选择数据
  142. let address = this.data.address;
  143. if (address.areaCode > 0) {
  144. let selectRegionList = this.data.selectRegionList;
  145. //console.info(selectRegionList);
  146. selectRegionList[0].code = address.areaCode.slice(0, 2) + '0000';
  147. selectRegionList[0].name = address.province;
  148. selectRegionList[1].code = address.areaCode.slice(0, 4) + '00';
  149. selectRegionList[1].name = address.city;
  150. selectRegionList[2].code = address.areaCode;
  151. selectRegionList[2].name = address.county;
  152. let regionList = area.getList('county', address.areaCode.slice(0, 4));
  153. regionList = regionList.map(item => {
  154. //标记已选择的
  155. if (address.areaCode === item.code) {
  156. item.selected = true;
  157. } else {
  158. item.selected = false;
  159. }
  160. return item;
  161. })
  162. this.setData({
  163. selectRegionList: selectRegionList,
  164. regionType: 3,
  165. regionList: regionList
  166. });
  167. } else {
  168. let selectRegionList = [{
  169. code: 0,
  170. name: '省份',
  171. },
  172. {
  173. code: 0,
  174. name: '城市',
  175. },
  176. {
  177. code: 0,
  178. name: '区县',
  179. }
  180. ];
  181. this.setData({
  182. selectRegionList: selectRegionList,
  183. regionType: 1,
  184. regionList: area.getList('province')
  185. });
  186. }
  187. this.setRegionDoneStatus();
  188. },
  189. selectRegionType(event) {
  190. console.info('selectRegionType');
  191. let that = this;
  192. let regionTypeIndex = event.target.dataset.regionTypeIndex;
  193. let selectRegionList = that.data.selectRegionList;
  194. //判断是否可点击
  195. if (regionTypeIndex + 1 == this.data.regionType || (regionTypeIndex - 1 >= 0 && selectRegionList[regionTypeIndex - 1].code <= 0)) {
  196. return false;
  197. }
  198. let selectRegionItem = selectRegionList[regionTypeIndex];
  199. let code = selectRegionItem.code;
  200. let regionList;
  201. if (regionTypeIndex === 0) {
  202. // 点击省级,取省级
  203. regionList = area.getList('province');
  204. } else if (regionTypeIndex === 1) {
  205. // 点击市级,取市级
  206. regionList = area.getList('city', code.slice(0, 2));
  207. } else {
  208. // 点击县级,取县级
  209. console.info(code);
  210. regionList = area.getList('county', code.slice(0, 4));
  211. console.info(regionList);
  212. }
  213. regionList = regionList.map(item => {
  214. //标记已选择的
  215. if (that.data.selectRegionList[regionTypeIndex].code == item.code) {
  216. item.selected = true;
  217. } else {
  218. item.selected = false;
  219. }
  220. return item;
  221. })
  222. this.setData({
  223. regionList: regionList,
  224. regionType: regionTypeIndex + 1
  225. })
  226. this.setRegionDoneStatus();
  227. },
  228. selectRegion(event) {
  229. let that = this;
  230. let regionIndex = event.target.dataset.regionIndex;
  231. let regionItem = this.data.regionList[regionIndex];
  232. let regionType = this.data.regionType;
  233. let selectRegionList = this.data.selectRegionList;
  234. selectRegionList[regionType - 1] = regionItem;
  235. if (regionType == 3) {
  236. this.setData({
  237. selectRegionList: selectRegionList
  238. })
  239. let regionList = that.data.regionList.map(item => {
  240. //标记已选择的
  241. if (that.data.selectRegionList[that.data.regionType - 1].code == item.code) {
  242. item.selected = true;
  243. } else {
  244. item.selected = false;
  245. }
  246. return item;
  247. })
  248. this.setData({
  249. regionList: regionList
  250. })
  251. this.setRegionDoneStatus();
  252. return
  253. }
  254. //重置下级区域为空
  255. selectRegionList.map((item, index) => {
  256. if (index > regionType - 1) {
  257. item.code = 0;
  258. item.name = index == 1 ? '城市' : '区县';
  259. }
  260. return item;
  261. });
  262. //console.info(selectRegionList);
  263. this.setData({
  264. selectRegionList: selectRegionList,
  265. regionType: regionType + 1
  266. })
  267. let code = regionItem.code;
  268. let regionList = [];
  269. if (regionType === 1) {
  270. // 点击省级,取市级
  271. regionList = area.getList('city', code.slice(0, 2))
  272. } else {
  273. // 点击市级,取县级
  274. regionList = area.getList('county', code.slice(0, 4))
  275. }
  276. this.setData({
  277. regionList: regionList
  278. })
  279. this.setRegionDoneStatus();
  280. },
  281. doneSelectRegion() {
  282. if (this.data.selectRegionDone === false) {
  283. return false;
  284. }
  285. let address = this.data.address;
  286. let selectRegionList = this.data.selectRegionList;
  287. address.province = selectRegionList[0].name;
  288. address.city = selectRegionList[1].name;
  289. address.county = selectRegionList[2].name;
  290. address.areaCode = selectRegionList[2].code;
  291. this.setData({
  292. address: address,
  293. openSelectRegion: false
  294. });
  295. },
  296. cancelSelectRegion() {
  297. this.setData({
  298. openSelectRegion: false,
  299. regionType: this.data.regionDoneStatus ? 3 : 1
  300. });
  301. },
  302. showPopup() {
  303. this.setData({
  304. show: true
  305. });
  306. },
  307. //获取手机号 一键注册
  308. getPhoneNumber: function (e) {
  309. console.log(e.detail.encryptedData);
  310. user.denPhone(e.detail).then(res => {
  311. this.setData({
  312. mobile: res.data
  313. })
  314. }).catch((err) => {
  315. console.log(err);
  316. /*wx.navigateTo({ //授权过期 需要重新授权
  317. url: '/pages/auth/login/login?reg=1',
  318. })*/
  319. });
  320. },
  321. requestRegister: function () {
  322. let that = this;
  323. let auth = {
  324. username: that.data.username,
  325. mobile: that.data.mobile,
  326. region: that.data.address.province + that.data.address.city + that.data.address.county,
  327. province: that.data.address.province,
  328. city: that.data.address.city,
  329. county: that.data.address.county,
  330. regionId: that.data.address.areaCode,
  331. address: that.data.address.address,
  332. nid: that.data.nid,
  333. type:that.data.type
  334. };
  335. wx.setStorageSync('nurseInfo', auth);
  336. util.request(api.AuthCert, auth).then(function (res) {
  337. if (res.errno == 0) {
  338. wx.showToast({
  339. title: '实名认证成功',
  340. icon: 'success',
  341. duration: 2000,
  342. complete: function () {
  343. setTimeout(function () {
  344. wx.navigateTo({
  345. url: '/pages/checkout/checkout?nurseId=' + res.data,
  346. })
  347. }, 2000);
  348. }
  349. });
  350. } else {
  351. wx.showModal({
  352. title: '错误信息',
  353. content: res.errmsg,
  354. showCancel: false
  355. });
  356. }
  357. });
  358. },
  359. startRegister: function () {
  360. var that = this;
  361. if (that.data.username.length < 2) {
  362. wx.showModal({
  363. title: '错误信息',
  364. content: '请输入真实姓名',
  365. showCancel: false
  366. });
  367. return false;
  368. }
  369. if (that.data.nid.length != 18 || !check.isCardCheck(that.data.nid)) {
  370. wx.showModal({
  371. title: '错误信息',
  372. content: '身份证号码不正确',
  373. showCancel: false
  374. });
  375. return false;
  376. }
  377. if (that.data.mobile.length == 0 || !check.isValidPhone(that.data.mobile)) {
  378. wx.showModal({
  379. title: '错误信息',
  380. content: '手机号输入不正确',
  381. showCancel: false
  382. });
  383. return false;
  384. }
  385. if (that.data.address.areaCode == 0) {
  386. wx.showModal({
  387. title: '错误信息',
  388. content: '请选择省市区信息',
  389. showCancel: false
  390. });
  391. return false;
  392. }
  393. if (that.data.address.address.length < 5) {
  394. wx.showModal({
  395. title: '错误信息',
  396. content: '请输入详细地址',
  397. showCancel: false
  398. });
  399. return false;
  400. }
  401. that.requestRegister();
  402. },
  403. bindUsernameInput: function (e) {
  404. this.setData({
  405. username: e.detail.value
  406. });
  407. },
  408. bindNidInput: function (e) {
  409. this.setData({
  410. nid: e.detail.value
  411. });
  412. },
  413. confirmFn(e) {
  414. var newTime = new Date(e.detail);
  415. newTime = util.formetdate(newTime);
  416. this.setData({
  417. birthday: newTime,
  418. show: false
  419. });
  420. },
  421. // 时间-取消按钮
  422. cancelFn() {
  423. this.setData({
  424. show: false
  425. });
  426. },
  427. bindConfirmPasswordInput: function (e) {
  428. this.setData({
  429. confirmPassword: e.detail.value
  430. });
  431. },
  432. bindMobileInput: function (e) {
  433. this.setData({
  434. mobile: e.detail.value
  435. });
  436. },
  437. clearInput: function (e) {
  438. switch (e.currentTarget.id) {
  439. case 'clear-username':
  440. this.setData({
  441. username: ''
  442. });
  443. break;
  444. case 'clear-password':
  445. this.setData({
  446. password: ''
  447. });
  448. break;
  449. case 'clear-confirm-password':
  450. this.setData({
  451. confirmPassword: ''
  452. });
  453. break;
  454. case 'clear-mobile':
  455. this.setData({
  456. mobile: ''
  457. });
  458. break;
  459. case 'clear-nid':
  460. this.setData({
  461. nid: ''
  462. });
  463. break;
  464. case 'clear-address':
  465. let address = this.data.address;
  466. address.address = '';
  467. this.setData({
  468. address: address
  469. });
  470. break;
  471. }
  472. }
  473. })