index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // pages/login/login.js
  2. import { notice_type } from '../../utils/dict';
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '通知公告', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. //用户信息
  13. user: {},
  14. list: [],
  15. // 弹框
  16. dialog: { title: '详细信息', show: false, type: '1' },
  17. form: {},
  18. typeList: notice_type,
  19. },
  20. back: function () {
  21. wx.navigateBack({ url: '/pages/me/index' })
  22. },
  23. // 添加通知公告
  24. toAdd: function () {
  25. wx.navigateTo({ url: `/pages/notice/detail` })
  26. },
  27. // 查看
  28. toView: async function (e) {
  29. const that = this;
  30. let { id } = e.currentTarget.dataset;
  31. const arr = await app.$get(`/courtAdmin/api/notice/${id}`);
  32. if (arr.errcode == '0') {
  33. that.setData({ form: arr.data })
  34. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  35. }
  36. },
  37. // 关闭弹框
  38. toClose: function () {
  39. this.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. // 计算高度
  46. this.searchHeight();
  47. // 监听用户是否登录
  48. this.watchLogin();
  49. },
  50. // 监听用户是否登录
  51. watchLogin: function () {
  52. const that = this;
  53. wx.getStorage({
  54. key: 'token',
  55. success: async res => {
  56. that.setData({ user: res.data });
  57. let params = {};
  58. if (res.data.type != '0') params.user_id = res.data.id;
  59. const arr = await app.$get(`/courtAdmin/api/notice`, params);
  60. if (arr.errcode == '0') this.setData({ list: arr.data })
  61. },
  62. fail: res => {
  63. wx.redirectTo({ url: '/pages/login/index', })
  64. }
  65. })
  66. },
  67. // 计算高度
  68. searchHeight: function () {
  69. let frameStyle = this.data.frameStyle;
  70. let client = app.globalData.client;
  71. let infoHeight = client.windowHeight;
  72. // 是否去掉状态栏
  73. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  74. // 是否减去底部菜单
  75. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  76. if (infoHeight) this.setData({ infoHeight: infoHeight })
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. onReachBottom: function () {
  107. },
  108. /**
  109. * 用户点击右上角分享
  110. */
  111. onShareAppMessage: function () {
  112. }
  113. })