const app= getApp(); Page({ /** * 页面的初始数据 */ data: { noticeList: [ ], imageList: [], // 存储图片路径的数组 description: '', content: '', contact: '', phone: '', replyTime: '', replyContent: '', showCustomPreview: false, currentPreviewIndex: 0, currentPreviewImages: [] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { this.getNoticeList() }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, // 获取列表数据 getNoticeList() { const _this = this; wx.showLoading({ title: '获取中...', mask: true, }); // debugger; wx.request({ url: app.globalData.interfaceUrls.mineFeedback, method: 'POST', header: { 'content-type': 'application/json', // 默认值 'token': app.globalData.userWxInfo.token, 'source': "wc", '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey }, success(res) { wx.hideLoading(); let apiReturnData = res.data; let listData = apiReturnData.data; listData.forEach(data => { data.createdate = data.createdate.slice(0, 10); // 添加对file字段的空值检查 let imgs = []; if (data.file) { imgs = data.file.split(',').filter(img => img).map(img => { return app.globalData.weChatImgPreviewUrl + 'FEEDBACK/' + img; }); } data.hasAttachment = imgs.length > 0; data.attachments = imgs; data.isReplied = data.iscompleted == '1'; if ((data.recoverydate || "") != '') { data.recoverydate = data.recoverydate.slice(0, 10); } }); app.globalData.mineRepairList=listData; _this.setData({ noticeList: listData, }) }, fail(error) { wx.hideLoading() utils.simleInfo('获取报修记录,请稍后再试') } }); }, previewImage: function(e) { // 获取当前点击项的id或索引 const { id, index } = e.currentTarget.dataset; // 如果是点击列表项的预览按钮 if (id) { // 根据id找到对应的投诉建议项 const item = this.data.noticeList.find(item => item.id === id); // 确保有附件 if (item && item.hasAttachment && item.attachments.length > 0) { wx.previewImage({ current: item.attachments[0], // 当前显示图片的链接 urls: item.attachments // 需要预览的图片链接列表 }); } else { console.log('没有找到附件或附件为空'); } } // 如果是点击图片列表中的图片 else if (typeof index !== 'undefined') { const { imageList } = this.data; wx.previewImage({ current: imageList[index], // 当前显示图片的链接 urls: imageList // 需要预览的图片链接列表 }); } }, // 关闭预览 closePreview: function() { this.setData({ showCustomPreview: false, currentPreviewIndex: 0, currentPreviewImages: [] }); }, // 上一张图片 prevImage: function() { const { currentPreviewIndex } = this.data; if (currentPreviewIndex > 0) { this.setData({ currentPreviewIndex: currentPreviewIndex - 1 }); } }, // 下一张图片 nextImage: function() { const { currentPreviewIndex, currentPreviewImages } = this.data; if (currentPreviewIndex < currentPreviewImages.length - 1) { this.setData({ currentPreviewIndex: currentPreviewIndex + 1 }); } }, // 处理滑动事件 swiperChange: function(e) { const current = e.detail.current; this.setData({ currentPreviewIndex: current }); }, // 防止点击图片内容时关闭预览 preventBubble: function() { return; }, // 跳转到详情页 goToDetail(e) { debugger; const id = e.currentTarget.dataset.id const item = this.data.noticeList.find(item => item.id === id); // 无论是否回复,都跳转到预览页面,但传递不同的回复状态参数 wx.navigateTo({ url: `/pages/tousujianyi/tousujianyi?id=${id}&mode=preview&isReplied=${item.isReplied}` }) }, // 跳转到表单页 goToForm() { wx.navigateTo({ url: '/pages/tousujianyi/tousujianyi' }) }, // 返回上一页 goBack() { wx.navigateBack() }, getDataById: function(id) { if (!id) { console.log('未获取到有效的ID'); return; } const item = this.data.noticeList.find(item => item.id === id); if (item) { debugger this.setData({ description: item.description, content: item.content, contact: item.contact, phone: item.phone, replyTime: item.recoverydate, replyContent: item.replycontent }); } }, })