diff --git a/pages/mine/messageList.vue b/pages/mine/messageList.vue index 18e6aa0..f134282 100644 --- a/pages/mine/messageList.vue +++ b/pages/mine/messageList.vue @@ -1,81 +1,81 @@ @@ -93,11 +93,13 @@ updateAnnList: [], sysItemList: [], list: [{ - name: '系统消息' + name: '接待报告', + id: 1, // 1日报 2周报 3其他(非3为接待报告,3是系统消息) }, { - name: `升级公告`, - count: "", + name: '升级公告', + id: 3, // 1日报 2周报 3其他(非3为接待报告,3是系统消息) }], + count: 0, // 全部条数 current: 0, pageNum: 1, pageSize: 10, @@ -107,30 +109,31 @@ this.updateAnnList = [] this.pageNum = 1 this.updateInit() + this.getMessageNotRed() }, + onLoad() { this._freshing = false; setTimeout(() => { this.triggered = true; }, 1000) }, + onPullDownRefresh() { - this.updateInit() + this.initPage() setTimeout(function() { uni.stopPullDownRefresh(); }, 1000); }, - // onReachBottom(){ - // this.pageNum++ - // this.updateInit() - // }, + methods: { onPulling(e) { console.log("onpulling", e); }, onRefresh() { if (this._freshing) return; - + this.updateAnnList = [] + this.pageNum = 1 this.updateInit() this._freshing = true; setTimeout(() => { @@ -138,161 +141,222 @@ this._freshing = false; }, 3000) }, + onRestore() { this.triggered = 'restore'; // 需要重置 console.log("onRestore"); }, - // uppers(e) { - // this.pageNum = 1 - // this.updateInit() - // }, + lower(e) { this.pageNum++ this.updateInit() }, + + initPage() { + this.updateAnnList = [] + this.pageNum = 1 + this.updateInit() + }, + + // 全部标记已读 + allRead() { + this.$u.get('/zkMessage/updateState', { + accountId: uni.getStorageSync('weapp_session_userInfo_data').accountId, + projectId: uni.getStorageSync('buildingID').id, + }).then(res => { + uni.showToast({ + title: '全部已读成功!', + duration: 2000 + }); + this.initPage() + }).catch(e => { + console.log(e) + }) + }, + updateInit() { uni.request({ url: config.service.updateList, method: "GET", data: { + messageType: this.list[this.current].id, + projectId: uni.getStorageSync('buildingID').id, id: uni.getStorageSync('weapp_session_userInfo_data').accountId, num: this.pageNum, size: this.pageSize }, header: { 'content-type': 'application/json', - 'Authorization': 'Bearer ' + uni.getStorageSync('weapp_session_login_data').token + 'Authorization': 'Bearer ' + uni.getStorageSync('weapp_session_login_data').token }, success: (res) => { - // this.updateAnnList = res.data.data.list.results - if (res.data.data != null) { - this.list[1].count = res.data.data.count - } - if (res.data.data == null) { - uni.showToast({ - title: '已经到底了!', - icon: 'none', - duration: 2000 - }); - } else { + if (res.data.data) { if (this.pageNum != 1) { - this.updateAnnList = [...this.updateAnnList, ...res.data.data.list.records]; + this.updateAnnList = [...this.updateAnnList, ...res.data.data.list.results]; } else { - this.updateAnnList = res.data.data.list.records + + this.updateAnnList = res.data.data.list.results || [] } } + }, + fail: e => { + console.log(e) } }) }, - goDetail(text, id, title) { - let link = encodeURIComponent(JSON.stringify(text)) + goDetail(data) { + this.$store.commit('setMessageObj', data) uni.navigateTo({ - url: "./messageDetail?content=" + link + "&id=" + id + "&tit=" + title + url: "./messageDetail" + }) + }, + + // 获取未读消息数量 + getMessageNotRed() { + uni.request({ + url: config.service.notReadNum, + method: "GET", + data: { + id: uni.getStorageSync('weapp_session_userInfo_data').accountId, + projectId: uni.getStorageSync('buildingID').id, + }, + header: { + 'content-type': 'application/json', + 'Authorization': 'Bearer ' + uni.getStorageSync('weapp_session_login_data').token + }, + success: (res) => { + this.count = res.data.data || 0 + } }) }, + + // 跳转日报 + goReception(data, index) { + this.$store.commit('setMessageObj', data) + data.readFlag = 1 + if (data.messageType == 2) { + uni.navigateTo({ + url: `/pages/reportExcel/weekReport?id=${data.id}` + }) + } else { + uni.navigateTo({ + url: `/pages/reportExcel/dayReport?id=${data.id}` + }) + } + }, + + fomatDate(date) { + if (!date) return '--' + let arr = date.split(' ') + let str = arr[0] + let result = str.split('-') + return `${result[1]}月${result[2]}日` + }, + + // 转换时间 + getTimeLine(date, type = 1) { + let resu = '--' + if (!date) return resu + let time = new Date(date.replace(/-/g, '/')) + time.setDate(time.getDate() - 7) + let arr = date.split(' ') + let str = arr[0] + let result = str.split('-') + + let m = (time.getMonth() + 1) < 10 ? `0${time.getMonth() + 1}` : (time.getMonth() + 1) + let d = time.getDate() < 10 ? `0${time.getDate()}` : time.getDate() + + if (type == 1) { + resu = `${m}.${d}-${result[1]}.${result[2]}` + } else { + resu = `${m}月${d}日~${result[1]}月${result[2]}日` + } + return resu + }, + change(index) { this.current = index; - if (this.current == 1) { - this.updateInit() - } + this.initPage() } } }