index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. const app = getApp(),
  2. {
  3. globalData: {
  4. util: {
  5. regeneratorRuntime,
  6. api: {
  7. server,
  8. getUser,
  9. updateUser
  10. },
  11. showTip,
  12. request: {
  13. post_auth,
  14. get
  15. },
  16. getUserInfo,
  17. goSuccess,
  18. pickerChange,
  19. verify: {
  20. isPhone,
  21. isEmail,
  22. form_verify
  23. }
  24. }
  25. }
  26. } = app,
  27. list = [
  28. [{
  29. title: '用户姓名',
  30. field: 'userName',
  31. maxLength: 20
  32. },
  33. {
  34. title: '证件类型',
  35. field: 'pDocumentType',
  36. picker: true
  37. },
  38. {
  39. title: '证件号码',
  40. field: 'pDocumentNum',
  41. // maxLength: 18 //因为证件类型不确定
  42. },
  43. {
  44. title: '手机号码',
  45. field: 'pPhone',
  46. maxLength: 11,
  47. fn: x => x ? !isPhone(x) && '您输入的电话格式不正确' : '请输入手机号码'
  48. },
  49. {
  50. title: '电子邮箱',
  51. field: 'pEmail',
  52. ignore: true,
  53. fn: x => x && !isEmail(x) && '您输入的电子邮箱格式不正确'
  54. },
  55. {
  56. title: '用户地址',
  57. field: 'pAddress',
  58. ignore: true,
  59. textarea: true,
  60. fn: () => false
  61. },
  62. ],
  63. [{
  64. title: '公司名称',
  65. field: 'lInstitutionName',
  66. maxLength: 30
  67. }, {
  68. title: '公司证件类型',
  69. field: 'lInstitutionType',
  70. picker: true
  71. }, {
  72. title: '公司证件号码',
  73. field: 'lInstitutionNum',
  74. maxLength: 20
  75. }, {
  76. title: '法人姓名',
  77. field: 'lUsername',
  78. maxLength: 20
  79. }, {
  80. title: '法人证件类型',
  81. field: 'lDocumentType',
  82. picker: true
  83. }, {
  84. title: '法人证件号码',
  85. field: 'lDocumentNum',
  86. // maxLength: 18
  87. }, {
  88. title: '联系方式',
  89. field: 'lPhone',
  90. maxLength: 11,
  91. fn: x => x ? !isPhone(x) && '您输入的电话格式不正确' : '请输入手机号码'
  92. }, {
  93. title: '电子邮箱',
  94. field: 'lEmail',
  95. ignore: true,
  96. fn: x => x && !isEmail(x) && '您输入的电子邮箱格式不正确'
  97. }, {
  98. title: '联系地址',
  99. field: 'lAddress',
  100. ignore: true,
  101. textarea: true,
  102. fn: () => false
  103. }]
  104. ]
  105. Page({
  106. async onLoad() {
  107. wx.showLoading({ mask: true, title: '信息获取中...' })
  108. let userInfo = await getUserInfo(),
  109. codeList = await get(server, {
  110. code: 'CARDTYPE'
  111. }),
  112. items = list[userInfo.identity | 0]
  113. if (codeList._err) codeList = []
  114. codeList = codeList.map(({
  115. dictValueCode: id,
  116. dictValueName: name
  117. }) => ({
  118. id,
  119. name
  120. }))
  121. items.filter(x => {
  122. x.value = userInfo[x.field]
  123. return x.picker
  124. }).forEach(x => {
  125. x.picker_index = Math.max(codeList.map(({ id }) => id).indexOf(userInfo[x.field]), 0)
  126. x.picker_name = codeList[x.picker_index].name
  127. x.value = codeList[x.picker_index].id
  128. })
  129. this.setData({
  130. codeList,
  131. items,
  132. userId: app.globalData.userId,
  133. verify: Object.fromEntries(items.map(({ title, field, fn }) => [field, fn || `请输入${title}`]))
  134. })
  135. wx.hideLoading()
  136. },
  137. _pickerChange(index, value) {
  138. let { data: { items, codeList } } = this,
  139. item = items[index],
  140. { id, name } = codeList[value]
  141. item.value = id
  142. item.picker_index = value
  143. item.picker_name = name
  144. this.setData({
  145. [`items[${index}]`]: item
  146. })
  147. },
  148. async formSubmit({
  149. detail: {
  150. value: userInfo
  151. }
  152. }) {
  153. const msg = form_verify(userInfo, this.data.verify)
  154. if (msg) return showTip(msg)
  155. const { _err } = await post_auth(updateUser, { userInfo }, { loading: true, loadingMsg: '信息提交中。。。' });
  156. if (_err) return _err.status && showTip('更新信息失败');
  157. app.globalData.userInfo = null
  158. goSuccess('userinfo')
  159. },
  160. pickerChange
  161. })