tanghaolin
2022-07-27 fd4d1d9296ba620de15b47bd1d58383d46ecb626
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const app = getApp()
var Constant = require('../../utils/constant.js');
var CorpID = Constant.CorpID;
 
Page({
 
  data: {
    tongzhi_list: []
  },
 
  onLoad: function (options) {
 
    this.initialNoticeList();
 
 
  },
  onShareAppMessage: function () {
    return Constant.Share;
  },
  //初始化列表 
  initialNoticeList: function () {
    var that = this;
    wx.request({
      url: Constant.BASE_SERVER_URL + "Notice/GetListByEmployeeID",
      method: 'GET',
      data: {
        DataType: "json",
        SoftType: Constant.SoftType,
        PortType: Constant.PortType,
        CorpID: CorpID,
        EmployeeID: 1
      },
      header: {
        'content-type': 'application/json'
      },
      fail: function (err) {
        wx.showModal({
          title: '',
          content: '通讯失败',
        })
      }, //请求失败
      success: function (res) {
        // console.log(res.data)
        var result = res.data;
        if (result.Code != 0) {
          wx.showModal({
            title: '',
            content: result.Message,
          })
          return;
        }
        var allNotices = result.Data;
 
        for (var i = 0; i < allNotices.length; i++) {
          allNotices[i].riqi = day_Date_last_now(allNotices[i].Day);
          allNotices[i].icon = "icon-qingkong";
        }
        console.log(allNotices)
 
        that.setData({
          tongzhi_list: allNotices
        })
 
      }
    });
  },
  onReady: function () {
 
  },
  onShow: function () {
 
  },
  //键盘输入时实时调用搜索方法
  inputKeyWrd(e) {
    this.searchByKeyWrd(e.detail.value)
  },
  //点击完成按钮时触发
  confirmKeyWrd(e) {
    this.searchByKeyWrd(e.detail.value)
  },
  searchByKeyWrd(key) {
    var that = this;
    //从本地缓存中异步获取指定 key 的内容
    var tongzhi_list = wx.getStorage({
      key: 'tongzhi_list',
      //从Storage中取出存储的数据
      success: function (res) {
        console.log(res, 21)
        if (key == '') { //用户没有输入时全部显示
          that.setData({
            tongzhi_list: res.data
          })
          return;
        }
        var arr = []; //临时数组,用于存放匹配到的数组
        for (let i in res.data) {
          res.data[i].show = false; //所有数据隐藏
          if (res.data[i].title.indexOf(key) >= 0) {
            res.data[i].show = true; //让匹配到的数据显示
            arr.push(res.data[i])
          }
        }
        if (arr.length == 0) {
          that.setData({
            tongzhi_list: [{
              show: true,
              name: '没有相关数据!'
            }]
          })
        } else {
          that.setData({
            tongzhi_list: arr
          })
        }
      },
    })
  }
 
})
//检测几天前
function day_Date_last_now(e) {
  var date = e.toString();
  var year = e.substring(0, 4);
  var month = e.substring(5, 7);
  var day = e.substring(8, 10);
  var d1 = new Date(year + '/' + month + '/' + day);
  // console.log(e, date, year, month, day, d1)
 
  var dd = new Date();
  var y = dd.getFullYear();
  var m = dd.getMonth() + 1;
  var d = dd.getDate();
 
  var d2 = new Date(y + '/' + m + '/' + d);
  var iday = parseInt(d2 - d1) / 1000 / 60 / 60 / 24;
 
  switch (iday) {
    case 0:
      return '今天'
      break
    case 1:
      return '昨天'
      break
    default:
      return iday + '天前'
  }
}