// index.js // 获取应用实例 const app = getApp() import api, {getIntelligentMessage,getToken,getStaffbasicinfo,clearMessage,getSituation,overView} from "../../utils/api" import config from "../../utils/config" Page({ data: { topDisplay:false, selectList:['全部消息','居民信息采集','房屋信息采集','社区满意度自查'], selectValue:0, pageSize:5, pageNo:1, tableData:[], lowerThreshold:'20', loadMoreVisible:false, loadMoreType: "none", nodata:false, emptyHouseNum:'', catesNonIntResiNum:'', readFlag:'1', agencyName:'--' }, // 事件处理函数 onLoad: async function () { await this.getToken() // await this.getIntelligentMessage() await this.getStaffbasicinfo() this.setData({ statusHeight: app.globalData.deviceInfo.statusHeight, navigationHeight: app.globalData.deviceInfo.navigationHeight, share:app.globalData.share, }) }, onShow(){ this.getIntelligentMessage() this.getSituation() }, onPullDownRefresh() { this.setData({ pageNo:1, tableData:[] }) this.getIntelligentMessage() this.getStaffbasicinfo() }, onScrollToLower(e){ if (this.data.loadMoreType === 'more') { this.setData({ loadMoreVisible: true, }) this.data.pageNo += 1 this.getIntelligentMessage() } }, getIntelligentMessage(){ this.setData({ loadMoreVisible: true, nodata: false, loadMoreType: "more", }) const parm = { type:this.data.selectValue == 0? null :this.data.selectValue - 1, limit:this.data.pageSize, page:this.data.pageNo, readFlag:this.data.readFlag } if(!parm.type) delete parm.type if(this.data.tableData.length !==0){ return } getIntelligentMessage(parm).then(res=>{ res.data.list.forEach(item => { if (item.msgType === 'resident_base_info') { item.typeName = '居民信息采集' } else if (item.msgType === 'community_house') { item.typeName = '房屋信息采集' } else if (item.msgType === 'resident_categiry') { item.typeName='数据更新提醒' } }) this.setData({ loadMoreType: res.data.list.length === this.data.pageSize ? 'more' : 'none', tableData: this.data.tableData.concat(res.data.list), }) if (this.data.tableData.length == 0) { this.setData({ loadMoreVisible: false, nodata: true, }) } }).catch(err=>{ console.log(err); this.setData({ loadMoreVisible: false, nodata: true, }) }) }, moreNews(){ wx.navigateTo({ url: '../../subpages/morenews/pages/morenews/morenews', }) }, getToken(){ const parm = { wxCode:'', app:'gov', client:'wxmp', appId:'wxaf87b420b87e2d79' } wx.showLoading({ title: '加载中...', }) wx.login({ success: (res) => { parm.wxCode = res.code getToken(parm).then(res=>{ wx.hideLoading() if(res.code === 0){ wx.setStorageSync('token', res.data.token) }else{ wx.reLaunch({ url: '/pages/login/login', }) } }).catch(err=>{ console.log(err); }) }, }) }, getStaffbasicinfo(){ getStaffbasicinfo().then(res=>{ app.globalData.user = res.data; this.setData({ agencyName:res.data.agencyName }) }).catch(err=>{ console.log(err); wx.redirectTo({ url: '/pages/login/login', }) }) }, handleChangeFilter(e){ this.setData({ selectValue:e.detail.value, tableData:[], }) this.getIntelligentMessage() }, handelClickClear(){ clearMessage().then(res=>{ this.setData({ tableData:[], pageNo:1 }) this.getIntelligentMessage() }).catch(err=>{ console.log(err); }) }, toDetail(e){ this.clearOneMessage(e.currentTarget.dataset.item.id) if(e.currentTarget.dataset.item.msgType == 'resident_base_info'){ wx.navigateTo({ url: `/subpages/addResi/pages/addResi/addResi?type=edit&resiId=${e.currentTarget.dataset.item.targetId}`, }) }else if(e.currentTarget.dataset.item.msgType == 'community_house'){ wx.navigateTo({ url: `/subpages/addhouse/pages/addhouse/addhouse?type=edit&houseId=${e.currentTarget.dataset.item.targetId}`, }) }else if(e.currentTarget.dataset.item.msgType == 'resident_category'){ wx.navigateTo({ url: `/subpages/residentCategory/pages/residentCategory/residentCategory?category=${e.currentTarget.dataset.item.category}`, }) } this.setData({ [`tableData[${e.currentTarget.dataset.index}].readFlag`]:'1' }) }, clearOneMessage(id){ let parm= { msgId:id } api.clearOneMessage(parm).then(res=>{ console.log(res); }).catch(err=>{ console.log(err); }) }, // 人房信息采集 getSituation(){ wx.showLoading({ title: '加载中', }) // getSituation().then(res=>{ // this.setData({ // collectedHouseCount:res.data.collectedHouseCount.toLocaleString(), // collectedPopulationCount:res.data.collectedPopulationCount.toLocaleString(), // pendingHouseCount:res.data.pendingHouseCount, // pendingPopulationCount:res.data.pendingPopulationCount, // populationCount:res.data.populationCount, // realEstateCount:res.data.realEstateCount, // }) // wx.hideLoading() // }).catch(err=>{ // wx.hideLoading() // console.log(err); // }) overView().then(res=>{ console.log('123',res) this.setData({ emptyHouseNum: res.data.emptyHouseNum.toLocaleString(), catesNonIntResiNum: res.data.catesNonIntResiNum.toLocaleString(), collectedHouseCount:res.data.totalHouseNum.toLocaleString(), collectedPopulationCount:res.data.totalResiNum.toLocaleString(), }) wx.hideLoading() }).catch(err=>{ wx.hideLoading() console.log(err); }) }, onAddResident(){ wx.navigateTo({ url: '../../subpages/addResi/pages/addResi/addResi', }) }, onAddHouseLL(){ wx.navigateTo({ url: '../../subpages/addhouse/pages/addhouse/addhouse', }) }, noHouse(){ wx.navigateTo({ url: '../../subpages/nohouse/pages/nohouse/nohouse', }) }, onresno(){ wx.navigateTo({ url: '../../subpages/resnoinformation/pages/resnoinformation/resnoinformation', }) }, toDemandCheck(){ wx.navigateTo({ url: '../../subpages/demandCheck/pages/dissatisfied/demandCheck/demandCheck', }) } })