const app=getApp(); const utils = require("../../utils/util.js") Page({ /** * 页面的初始数据 */ data: { noticeList: [], imageList: [], // 存储图片路径的数组 showCustomPreview: false, // 是否显示自定义预览 currentPreviewImages: [], // 当前预览的图片数组 }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getNoticeList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, // 获取列表数据 getNoticeList() { const _this = this; wx.showLoading({ title: '获取中...', mask: true, }); // debugger; wx.request({ url: app.globalData.interfaceUrls.mineRepair, method: 'POST', header: { 'content-type': 'application/json', // 默认值 'token': app.globalData.userWxInfo.token, 'source': "wc", '!SAAS_LOGIN_TOKEN_!': app.globalData.currentAccountInfo.dsKey }, success(res) { debugger wx.hideLoading(); let apiReturnData = res.data; let listData = apiReturnData.data; listData.forEach(data => { // 处理创建日期 data.createdate = data.createdate ? data.createdate.slice(0, 10) : ''; // 处理图片数据 let imgs = []; if (data.images && typeof data.images === 'string' && data.images.trim() !== '') { imgs = data.images.split(',').filter(img => img).map(img => { return app.globalData.weChatImgPreviewUrl + 'REPAIR/' + img; }); } // 设置附件相关属性 data.hasAttachment = imgs.length > 0; data.attachments = imgs; // 处理回复状态 data.isReplied = data.iscompleted === '1'; // 处理恢复日期 if (data.recoverydate) { data.recoverydate = data.recoverydate.slice(0, 10); } else { data.recoverydate = ''; } }); app.globalData.mineRepairList = listData; _this.setData({ noticeList: listData, }) debugger }, fail(error) { wx.hideLoading() utils.simleInfo('获取报修记录,请稍后再试') } }); }, previewImage: function (e) { // 获取当前点击项的id const id = e.currentTarget.dataset.id; // 根据id找到对应的投诉建议项 const item = this.data.noticeList.find(item => item.id === id); debugger; // 确保有附件 if (item && item.hasAttachment && item.attachments.length > 0) { this.setData({ showCustomPreview: true, currentPreviewImages: item.attachments, currentPreviewIndex: 0 }); } else { console.log('没有找到附件或附件为空'); } }, // 关闭预览 closePreview: function () { this.setData({ showCustomPreview: false }); }, // 切换预览图片 changePreviewImage: function (e) { const direction = e.currentTarget.dataset.direction; let newIndex = this.data.currentPreviewIndex; if (direction === 'prev') { newIndex = newIndex > 0 ? newIndex - 1 : this.data.currentPreviewImages.length - 1; } else { newIndex = newIndex < this.data.currentPreviewImages.length - 1 ? newIndex + 1 : 0; } this.setData({ currentPreviewIndex: newIndex }); }, // 防止点击图片内容时关闭预览 preventBubble: function () { return; }, // 跳转到详情页 goToDetail(e) { const id = e.currentTarget.dataset.id; const item = this.data.noticeList.find(item => item.id === id); // 统一使用预览模式,传递isReplied参数 wx.navigateTo({ url: `/pages/baoxiudj/baoxiudj?id=${id}&mode=preview&isReplied=${item.isReplied ? 'true' : 'false'}` }); }, // 跳转到表单页 goToForm() { wx.navigateTo({ url: '/pages/baoxiudj/baoxiudj' }) }, // 返回上一页 goBack() { wx.navigateBack() }, })