index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // pages/interaction/interaction.js
  2. const app = getApp(),
  3. {
  4. globalData: {
  5. util: {
  6. regeneratorRuntime,
  7. api: {
  8. departments,
  9. matters,
  10. interactionSave,
  11. guide
  12. },
  13. showTip,
  14. request: {
  15. post_auth,
  16. get
  17. },
  18. getUserInfo,
  19. goSuccess,
  20. get_global_param,
  21. verify: {
  22. isPhone,
  23. form_verify
  24. },
  25. pickerChange
  26. }
  27. }
  28. } = app,
  29. t = {
  30. name: '请选择'
  31. },
  32. init = {
  33. dep_index: 0,
  34. matter_index: 0,
  35. title: '',
  36. content: '',
  37. name: '',
  38. consultantPhone: ''
  39. }, verify = {
  40. consultantName: "请输入姓名",
  41. consultantPhone: x => x ? !isPhone(x) && '您输入的联系方式格式不正确' : '请输入联系方式',
  42. content: (x, { type }) => !x && `请输入${type == 1 ? '投诉' : '咨询'}内容`,
  43. deptUnid: (x, { type }) => !x && `请选择${type == 1 ? '投诉' : '咨询'}部门`,
  44. serviceUnid: (x, { type }) => !x && `请选择${type == 1 ? '投诉' : '咨询'}事项`,
  45. title: (x, { type }) => !x && `请输入${type == 1 ? '投诉' : '咨询'}主题`
  46. };
  47. Page({
  48. data: Object.assign({
  49. dep_list: [t],
  50. matter_list: [t],
  51. tab: ['咨询', '投诉']
  52. }, init),
  53. async _pickerChange(_index, value) {
  54. this.setData({
  55. [_index]: value | 0
  56. })
  57. if (_index != 'dep_index') return
  58. let deptUnid = this.data.dep_list[value].id, matter_list = [t]
  59. if (deptUnid) {
  60. let list = await get(matters, { deptUnid })
  61. if (!list._err)
  62. matter_list = [t, ...list.map(({ UNID: id, SERVICE_NAME: name }) => ({ id, name }))]
  63. }
  64. this.setData({
  65. matter_index: 0,
  66. matter_list
  67. })
  68. },
  69. async formSubmit({ detail: { value } }) {
  70. const msg = form_verify(value, verify)
  71. if (msg) return showTip(msg)
  72. const { _err } = await post_auth(interactionSave, value, { loading: true, loadingMsg: '信息提交中。。。' });
  73. if (_err) return _err.status && showTip('提交失败')
  74. await goSuccess('interaction')
  75. this.setData(init)
  76. },
  77. async onLoad() {
  78. const list = await get(departments)
  79. this.setData({
  80. dep_list: list._err ? [t] : [t, ...list.map(({ deptUnid: id, deptName: name }) => ({ id, name }))]
  81. })
  82. },
  83. async onShow() {
  84. const { unid, tab_index = 0 } = get_global_param(), { name = '', phone = '' } = await getUserInfo()
  85. if (unid) {
  86. const { preService: { deptUnid, deptName, serviceName } = {}, } = await get(guide, { unid })
  87. this.setData({
  88. serviceUnid: unid,
  89. deptUnid,
  90. deptName,
  91. serviceName
  92. })
  93. }
  94. this.setData(Object.assign({}, init, {
  95. flag: !!unid,
  96. name,
  97. phone,
  98. tab_index
  99. }))
  100. },
  101. pickerChange,
  102. // tab切换
  103. tab({ currentTarget: { dataset: { index: tab_index } } }) {
  104. this.setData({
  105. tab_index
  106. })
  107. }
  108. })