index.ts 2.5 KB

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