index.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import { queryNotice } from "../../../../services/api/common/index"
  2. import { loginid } from '../../../../services/utils'
  3. import { hideLoading, showLoading } from "../../../../utils/message/index"
  4. import { formatDateString } from "../../../../utils/util"
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. /// 公告消息
  11. msgs: <GuangZuan.Notice[]>[],
  12. /// tabs
  13. tabs: [{id: 1, title: '公告'}, {id: 2, title: '消息'}],
  14. /// 是否空数据
  15. isEmpty: false,
  16. /// 激活xiang
  17. active: 0
  18. },
  19. /// 进入公告消息详情页
  20. goToMsgDetail(r: any) {
  21. let jsonStr = JSON.stringify(this.data.msgs[r.currentTarget.id])
  22. wx.navigateTo({
  23. url: '/mHome/pages/msg/msgdetail/index?id='+jsonStr
  24. })
  25. },
  26. /**
  27. * 返回上层视图
  28. */
  29. backToParent() {
  30. /// 返回上层视图
  31. wx.navigateBack()
  32. },
  33. /// onChange
  34. onChange(e: any) {
  35. this.setData({ active: e.detail.index })
  36. this.queryNotice(this.data.active+1)
  37. },
  38. /// 查询公告消息信息
  39. queryNotice(msgtype: number){
  40. /// loding.....
  41. showLoading(()=>{
  42. /// 发送查询请求
  43. queryNotice({
  44. data: {
  45. msgType: msgtype,
  46. loginID: loginid()
  47. },
  48. success:(res) => {
  49. /// 加载失败
  50. if (res.code != 200) {
  51. hideLoading(()=>{}, '请求失败,原因:'+res.msg)
  52. return
  53. }
  54. hideLoading(()=>{
  55. /// 加载成功
  56. this.setData({
  57. msgs: res.data.map(itm => {
  58. var obj = itm
  59. obj.scheduletime = formatDateString(itm.scheduletime, 'YYYY/MM/DD HH:mm:ss')
  60. return obj
  61. }),
  62. isEmpty: res.data.length === 0
  63. })
  64. })
  65. },
  66. fail: (emsg) => {
  67. /// 加载失败
  68. hideLoading(()=>{}, emsg)
  69. },
  70. complete: () => {
  71. wx.stopPullDownRefresh()
  72. }
  73. })
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad() {
  80. /// 查询公告消息
  81. this.queryNotice(1)
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady() {
  87. },
  88. /**
  89. * 生命周期函数--监听页面显示
  90. */
  91. onShow() {
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide() {
  97. },
  98. /**
  99. * 生命周期函数--监听页面卸载
  100. */
  101. onUnload() {
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh() {
  107. /// 查询公告消息
  108. this.queryNotice(this.data.active+1)
  109. },
  110. /**
  111. * 页面上拉触底事件的处理函数
  112. */
  113. onReachBottom() {
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage() {
  119. }
  120. })