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 + '天前' } }