const util = require("../../../utils/jmsUtil"); const api = require("../../../api/jms"); Page({ data: { noData: false, dataId: '', reportList: {}, reportDateList: [], showPopup: false, beginDate: '', endDate: '', columns: [], selectedWeek: '', index: 0 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { console.log("optons", options); this.setData({ dataId: options.id }) }, /** * 生命周期函数--监听页面显示 */ onShow() { this.getReportList() this.getReportDate() }, onHide: function () { console.log('onHide'); }, onUnload: function () { console.log('onunload'); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, getReportList() { let params = { isFra: 1, pushFraFlag: 1, beginDate: this.data.beginDate.replace(/\//g, '-'), endDate: this.data.endDate.replace(/\//g, '-') , dataId: this.data.dataId } console.log("params",params); util.request(api.GetReportList, params, 'post').then(res => { if (res.errno === 0) { if (res.data == null || res.data == undefined ) { this.setData({ noData: true }) }else{ console.log("我的打印", res.data.records[0]); let reportList=res.data.records[0]; this.setData({ noData:false, }) // 遍历 record 对象,并过滤 null 值 for (const key in reportList) { if (reportList[key] != null) { reportList[key] = reportList[key]; }else{ reportList[key]="暂无" } } this.setData({ reportList: reportList }) } } else { wx.showToast({ title: res.errmsg, icon: 'none' }) } }); }, getReportDate() { util.request(api.getReportDate, {}, 'get').then(res => { if (res.errno === 0) { console.log("我的打印", res.data); this.setData({ reportDateList: res.data.reverse() }) // 使用map方法转换每个日期对象 const formattedDates = res.data.map(date => { // 格式化月份和日期,确保它们总是两位数 const beginDate = date.beginDate.split('-').map(part => part.padStart(2, '0')).join('-'); const endDate = date.endDate.split('-').map(part => part.padStart(2, '0')).join('-'); // 返回格式化后的日期字符串 return `${beginDate}-${endDate}`; }); this.setData({ columns: formattedDates }) } else { wx.showToast({ title: res.errmsg, icon: 'none' }) } }); }, showWeekDate() { console.log(111); this.setData({ showPopup: true }) }, onClose() { this.setData({ showPopup: false }); }, onConfirm(event) { const { picker, value, index } = event.detail; this.setData({ showPopup: false, selectedWeek: value, index: index, beginDate: this.data.reportDateList[index].beginDate, endDate: this.data.reportDateList[index].endDate }); console.log("选中",value,index,this.data.reportDateList[index].beginDate); this.getReportList() }, onCancel() { this.setData({ showPopup: false }); }, })