riku
2022-10-10 437144f41c74505d362a5214a18cec3d01b3ce4b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// pages/notice/notice.js
const notificationservice = require("../../../service/notificationservice")
const moment = require('../../../utils/moment.min')
const util = require("../../../utils/util.js")
const app = getApp()
 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    tabList: [{
        "name": "工作通知"
      },
      {
        "name": "预警警示"
      },
      {
        "name": "系统通知"
      }
    ],
    pageList: [
      [],
      [],
      []
    ]
  },
 
  //计算swiper高度方法(在切换的时候调用)
  tabsHeight(element) {
    let that = this;
    let query = wx.createSelectorQuery(); //必须要先创建一个查询
    query.select(element).boundingClientRect(function (rect) {
      that.setData({
        pageheight: rect.height + 'px'
      });
    }).exec();
  },
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current,
        navScrollLeft: e.target.dataset.current >= 4 ? ((e.target.dataset.current) * 60) : 0 //判断当前选中的个数是否是第5个
      })
      that.tabsHeight('.page'+e.target.dataset.current);    //查询哪一个元素
    }
  },
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current,
      navScrollLeft: e.detail.current >= 4 ? ((e.detail.current) * 60) : 0 //判断当前选中的个数是否是第5个
    });
    // that.tabsHeight('.page'+e.target.dataset.current);    //查询哪一个元素
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.tabsHeight('.page0');
    this.getNotice()
  },
 
  onReachBottom () {
    if (this.cPage && this.tPage) {
      if (this.cPage < this.tPage) {
        this.getNotice(this.cPage + 1)
      }
    }
  },
 
  getNotice(cPage = 1) {
    var that = this
    notificationservice.getNotification(app.globalData.accessToken.userId, cPage, {
      onHead(header) {
        that.cPage = parseInt(header.currentPage)
        that.tPage = parseInt(header.totalPage)
        console.log(`cPage:${that.cPage}, tPage:${that.tPage}`);
      },
      success(res) {
        res.forEach(r => {
          r.updateTime = util.formatTime(r.updateTime)
        });
        let notices = that.data.pageList[0].concat(res)
        that.setData({
          ['pageList[0]']: notices
        })
 
        that.tabsHeight('.page0');    //刷新高度
      }
    }, 5)
  },
})