detail.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. import { notice_type } from '../../utils/dict';
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. frameStyle: { useTop: true, name: '维护公告信息', leftArrow: true, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. form: {},
  14. // 文件
  15. file: [],
  16. typeList: notice_type,
  17. //用户列表
  18. userList: [],
  19. // 接收人
  20. receive_user: [],
  21. // 弹框
  22. dialog: { title: '选择接收人', show: false, type: '1' }
  23. },
  24. initValidate() {
  25. const rules = { content: { required: true } }
  26. // 验证字段的提示信息,若不传则调用默认的信息
  27. const messages = { nickname: { content: '请输入发送内容', } };
  28. this.WxValidate = new WxValidate(rules, messages)
  29. },
  30. back: function () {
  31. wx.navigateBack({ url: '/pages/user/index' })
  32. },
  33. // 上传图片
  34. imgUpload: function (e) {
  35. const that = this;
  36. let data = that.data.file;
  37. data.push(e.detail)
  38. that.setData({ file: data })
  39. },
  40. // 删除图片
  41. imgDel: function (e) {
  42. const that = this;
  43. let list = that.data.file;
  44. let arr = list.filter((i, index) => index != e.detail.index)
  45. that.setData({ file: arr })
  46. },
  47. // 选择发送时间
  48. dateChange: function (e) {
  49. const that = this;
  50. const { value } = e.detail;
  51. that.setData({ 'form.send_time': value })
  52. },
  53. // 选择用户类别
  54. typeChange: function (e) {
  55. const that = this;
  56. let index = e.detail.value;
  57. let data = that.data.typeList[index];
  58. if (data) that.setData({ 'form.type': data.label });
  59. },
  60. // 选择接收人
  61. userAdd() {
  62. const that = this;
  63. that.setData({ dialog: { title: '选择接收人', show: true, type: '1' } })
  64. },
  65. // 选择接收人
  66. userChange: function (e) {
  67. const that = this;
  68. let data = e.detail.value;
  69. let user = that.data.userList;
  70. let receive_user = [];
  71. for (const val of data) {
  72. let arr = user.find((i) => i._id == val);
  73. if (arr) receive_user.push({ user_id: arr._id, name: arr.nickname, status: '0' })
  74. }
  75. that.setData({ receive_user: receive_user })
  76. },
  77. // 关闭弹框
  78. toClose() {
  79. const that = this;
  80. that.setData({ dialog: { title: '选择接收人', show: false, type: '1' } })
  81. },
  82. // 提交登录
  83. onSubmit: async function (e) {
  84. const that = this;
  85. const params = e.detail.value;
  86. const receive_user = that.data.receive_user;
  87. params.receive_user = receive_user;
  88. if (!this.WxValidate.checkForm(params)) {
  89. const error = this.WxValidate.errorList[0];
  90. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  91. return false
  92. } else {
  93. let arr;
  94. params.file = that.data.file;
  95. arr = await app.$post(`/courtAdmin/api/notice`, params);
  96. if (arr.errcode == '0') { wx.showToast({ title: `添加信息完成`, icon: 'success', duration: 2000 }); that.back(); }
  97. else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  98. }
  99. },
  100. /**
  101. * 生命周期函数--监听页面加载
  102. */
  103. onLoad: function (options) {
  104. //验证规则函数
  105. this.initValidate();
  106. // 计算高度
  107. this.searchHeight();
  108. // 监听用户是否登录
  109. this.watchLogin();
  110. },
  111. // 监听用户是否登录
  112. watchLogin: async function () {
  113. const that = this;
  114. wx.getStorage({
  115. key: 'token',
  116. success: async res => {
  117. that.setData({ 'form': { send_id: res.data.id, send_name: res.data.nickname, file: [] } });
  118. const arr = await app.$get(`/courtAdmin/api/user`, { status: '1' });
  119. if (arr.errcode == '0') {
  120. let p1 = arr.data.filter((i) => i.type != '0')
  121. that.setData({ userList: p1 })
  122. }
  123. },
  124. fail: res => {
  125. wx.redirectTo({ url: '/pages/index/index', })
  126. }
  127. })
  128. },
  129. // 计算高度
  130. searchHeight: function () {
  131. let frameStyle = this.data.frameStyle;
  132. let client = app.globalData.client;
  133. let infoHeight = client.windowHeight;
  134. // 是否去掉状态栏
  135. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  136. // 是否减去底部菜单
  137. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  138. if (infoHeight) this.setData({ infoHeight: infoHeight })
  139. },
  140. /**
  141. * 生命周期函数--监听页面初次渲染完成
  142. */
  143. onReady: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面显示
  147. */
  148. onShow: function () { },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function () {
  173. }
  174. })