index.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. const {
  2. globalData: {
  3. util: {
  4. regeneratorRuntime,
  5. api: {
  6. guide,
  7. addCollect,
  8. delCollect,
  9. server,
  10. reservationServiceList,
  11. reservationSave,
  12. reservationDateStatus,
  13. sendVerifCode,
  14. verifSmsCode
  15. },
  16. navigate,
  17. navigate_native,
  18. navigate_auth_native,
  19. navigateBack,
  20. showTip,
  21. request: {
  22. get,
  23. get_auth,
  24. post_auth
  25. },
  26. extend: {
  27. dateLaters
  28. },
  29. getUserInfo,
  30. inputChange,
  31. pickerChange,
  32. appKey,
  33. md5,
  34. goSuccess,
  35. init,
  36. verify: {
  37. isPhone,
  38. form_verify
  39. }
  40. }
  41. }
  42. } = getApp(),
  43. t = {
  44. name: '请选择',
  45. list: [
  46. {
  47. name: '请选择',
  48. }
  49. ]
  50. },
  51. t_arr = ['请选择'],
  52. realNameTip = true,
  53. date_list = [t_arr, ...dateLaters(7).filter(([, x]) => !/[六|日]/.test(x))];
  54. let lock;
  55. Page({
  56. data: {
  57. date_list_range: date_list.map(x => x.join(' ')),
  58. dep_list: [t],
  59. verify: {
  60. applicantIdCard: "请输入证件号码",
  61. applicantIdType: "请输入证件类型",
  62. applicantName: "请输入预约姓名",
  63. applicantPhone: x => x ? !isPhone(x) && '您输入的电话格式不正确' : '请输入预约电话',
  64. checked: (x, { mask }) => mask && !x && '请先阅读预约须知',
  65. code: x => x.length != 4 && '请输入六位短信验证码',
  66. deptUnid: "请选择预约窗口",
  67. reservationDate: "请选择预约日期",
  68. reservationInterval: "请选择预约时段",
  69. serviceUnid: "请选择预约事项"
  70. }
  71. },
  72. onLoad({ unid }) {
  73. unid && this.setData({ flag: !!this.setHandleInfo(unid) })
  74. init(this).p_code = get(server, { code: 'CARDTYPE' }, { loading: true, loadingMsg: '加载证件列表...' }).then(code_list => {
  75. if (code_list._err) return []
  76. code_list = code_list.map(({ dictValueCode: id, dictValueName: name }) => ({ id, name }))
  77. this.setData({ code_list })
  78. return code_list
  79. })
  80. },
  81. async onShow() {
  82. lock = false
  83. const { num: applicantIdCard, code_type: applicantIdType, name: applicantName, phone: applicantPhone, _err } = await getUserInfo({ realNameTip, loading: true })
  84. if (_err) return _err.status && showTip('用户信息加载失败')
  85. this.setData({
  86. mask: false,
  87. checked: false,
  88. applicantIdCard,
  89. applicantName,
  90. applicantPhone,
  91. applicantIdType,
  92. code_index: applicantIdType ? Math.max((await this.p_code).map(({ id }) => id).indexOf(applicantIdType), 0) : 0
  93. })
  94. if (this.data.flag) return
  95. const dep_list = await get_auth(reservationServiceList, null, { loginTip: false });
  96. if (dep_list._err) return dep_list._err.status && showTip('部门列表加载失败')
  97. this.setData({ dep_list: [t, ...dep_list.map(({ deptName: name, deptUnid: id, serviceList: list }) => ({ id, name, list: [t, ...list.map(({ UNID: id, serviceName: name }) => ({ id, name }))] }))] })
  98. this._pickerChange('dep_index')
  99. },
  100. async send_verify_code() {
  101. let context = this, { data: { applicantPhone: phone, send_time } } = context;
  102. if (send_time) return
  103. if (!isPhone(phone))
  104. return showTip('您输入的电话格式不正确')
  105. let timeStamp = new Date().getTime() + '', sign = md5(md5(appKey).toUpperCase() + md5(timeStamp).toUpperCase()).toUpperCase()
  106. let { _err } = await get_auth(sendVerifCode, { phone, timeStamp, sign }, { loading: true, loadingMsg: '正在发送验证码...', })
  107. if (_err) return _err.status && showTip('验证码发送失败')
  108. showTip('发送成功')
  109. context._setData({ send_time: 60 });
  110. (function timer() {
  111. let { data: { send_time } } = context
  112. if (!send_time--) return
  113. context._setData({ send_time })
  114. setTimeout(timer, 1000)
  115. })()
  116. },
  117. async setHandleInfo(unid = '') {
  118. const { isCollect, preService: { serviceName = '', amStartTime = '', amEndTime = '', pmStartTime = '', pmEndTime = '', deptName = '', deptUnid = '' } = {}, _err } = unid ? await get_auth(guide, { unid, type: 2, }, { loading: true, loadingMsg: '事项信息获取中...' }) : { _err: { status: false } }
  119. this.setData({
  120. deptUnid,
  121. deptName,
  122. isCollect: isCollect == '1',
  123. serviceName,
  124. serviceUnid: unid,
  125. amTime: amStartTime && amEndTime ? `${amStartTime}-${amEndTime}` : '',
  126. pmTime: pmStartTime && pmEndTime ? `${pmStartTime}-${pmEndTime}` : ''
  127. })
  128. if (_err) return _err.status && showTip('获取信息失败')
  129. this._pickerChange('reservation_date_index', 1)
  130. },
  131. reserva_change({ currentTarget: { dataset: { val: reservationInterval } } }) {
  132. let { serviceUnid, [`${reservationInterval.toLowerCase()}Status`]: status } = this.data
  133. serviceUnid && status && this.setData({ reservationInterval })
  134. },
  135. async _pickerChange(_index, value = 0) {
  136. this.setData({ [_index]: value })
  137. let { dep_list, dep_index, serviceUnid, deptUnid, reservation_date_index, code_list } = this.data;
  138. switch (_index) {
  139. case 'dep_index':
  140. return this._pickerChange('matter_index')
  141. case 'matter_index':
  142. await this.setHandleInfo(dep_list[dep_index].list[value].id)
  143. return this._pickerChange('reservation_date_index', value && (reservation_date_index || 1))
  144. case 'reservation_date_index':
  145. let reservationDate = value ? date_list[value][0] : '', { amStatus = false, pmStatus = false } = value && await get_auth(reservationDateStatus, { reservationDate, deptUnid, serviceUnid }, { loading: true, loadingMsg: '预约信息获取中...' })
  146. return this.setData({ reservationDate, amStatus, pmStatus, reservationInterval: '' })
  147. case 'code_index':
  148. return this.setData({
  149. applicantIdType: code_list[value].id
  150. })
  151. }
  152. },
  153. async verify_code() {
  154. const msg = this.form_verify()
  155. if (msg) return showTip(msg)
  156. const { data } = this, { applicantPhone: phone, code } = data,
  157. { _err } = await get_auth(verifSmsCode, { phone, code }, { loading: true, loadingMsg: '信息验证中。。。', realNameTip })
  158. if (_err) return _err.status && showTip('短信验证码错误')
  159. this.setData({ mask: true, checked: false })
  160. },
  161. async formSubmit({ detail: { value } }) {
  162. const msg = this.form_verify(value)
  163. if (msg) return showTip(msg)
  164. let { id, _err } = await post_auth(reservationSave, value, { loading: true, loadingMsg: '信息提交中。。。', realNameTip })
  165. if (_err) return _err.status && showTip(`提交失败 ${_err.errmsg}`)
  166. goSuccess('reservation', id)
  167. },
  168. cancel() {
  169. this.setData({
  170. mask: false,
  171. checked: false
  172. })
  173. },
  174. async keep() {
  175. let
  176. {
  177. isCollect,
  178. serviceUnid,
  179. serviceName
  180. } = this.data
  181. if (!serviceUnid || lock) return
  182. lock = !this.setData({
  183. isCollect: !isCollect
  184. })
  185. let [req, url] = isCollect ? [get_auth, delCollect] : [post_auth, addCollect],
  186. { _err } = await req(url, {
  187. type: 2,
  188. serviceUnid,
  189. serviceName,
  190. })
  191. if (_err) {
  192. _err.status && showTip(`${isCollect ? "取消" : ""}收藏失败`)
  193. this.setData({
  194. isCollect: isCollect
  195. })
  196. }
  197. lock = false
  198. },
  199. checkboxChange({ detail: { value: [checked] } }) {
  200. this.setData({
  201. checked
  202. })
  203. },
  204. inputChange,
  205. pickerChange,
  206. navigateBack
  207. })