index.ts 2.3 KB

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