// pages/materialUpload/index.js const $$ = require('../../utils/util'); const app = getApp(); // 获取附件 function getCaseFilesApi(id) { return $$.request({ url: 'paCaseInfo/listCaseFile?caseId=' + id, type: 'get', service: 'mediate' }); } // 删除附件 function delfileApi(id) { return $$.request({ url: 'fileInfo/deleteById?id=' + id, type: 'get', service: 'sys', v1: true }); } Page({ /** * 页面的初始数据 */ settimeout: null, previewImageVisible: false, // 判断是否进入查看图片 touchstarttime: '', //触摸开始时间 caseId: '', data: { imgUrl: $$.url.img, material_data: [ { icon: `${$$.url.img}material-evidence.png`, iconActive: `${$$.url.img}material-evidence-active.png`, num: 0, title: '证据材料', type: '22_00018-102', explain: '证据材料:包括但不限于物证、书证、证词、鉴定结论等内容,可作为纠纷的重要判断依据,形式主要为图片、word、pdf等。', files: [], }, { icon: `${$$.url.img}material-apply.png`, iconActive: `${$$.url.img}material-apply-active.png`, num: 0, title: '申请材料', type: '22_00018-101', explain: '申请材料:申请材料包括但不限于纠纷登记表、送达地址确认书、司法确认申请表等,形式主要为图片、word、pdf等。', files: [], }, { icon: `${$$.url.img}material-identity.png`, iconActive: `${$$.url.img}material-identity-active.png`, num: 0, title: '身份材料', type: '22_00018-202', explain: '身份材料:包括但不限于居民身份证、企业工商登记证明(法人时需要)、组织机构代码证(非法人组织时需要)、代理人授权委托书(代理人时需要)等,形式主要为图片、word、pdf等。', files: [], }, { icon: `${$$.url.img}material-other.png`, iconActive: `${$$.url.img}material-other-active.png`, num: 0, title: '其他材料', type: '22_00018-199', explain: '其他材料:与案件关系密切的其他材料,形式主要为图片、word、pdf等。', files: [], }, ], activeMaterial: 0, // 当前选中的材料下标 editVisible: true, // 是否编辑状态 }, // 切换显示文件 handleChangeTab(e) { this.setData({ activeMaterial: e.detail, }); }, // 长按删除文件 handleTouchstart(e) { this.touchstarttime = e.timeStamp; let item = e.detail; let that = this; this.settimeout = setTimeout(() => { if (this.touchstarttime && that.data.editVisible) { $$.showModal({ content: '确定删除' + item.name + '吗?', success: (res) => { if (res.confirm) { that.delfile(item.id); } }, }); } }, 1500); }, // 长按结束 handleTouchend(e) { let item = e.detail; if (e.timeStamp - this.touchstarttime < 1000) { // 判断用户为点击 let imgUrl = $$.baseUrl + $$.url.fileShowUrl + item.id; const visible = $$.openFiles(item.cat, imgUrl, [imgUrl]); if (visible) { this.previewImageVisible = true; } } if (this.settimeout) { clearTimeout(this.settimeout); } this.touchstarttime = false; }, // 跳转至上传文件页面 handleGoUpload() { wx.navigateTo({ url: '../../pages/materialUpload/index?activeMaterial=' + this.data.activeMaterial + '&caseId=' + this.caseId, }); }, // 删除附件 async delfile(id) { $$.showLoading(); const res = await delfileApi(id); $$.hideLoading(); if (res.type) { this.getCaseFiles(this.caseId, 'delete'); } }, // 查询案件附件 async getCaseFiles(id, type) { $$.showLoading(); const res = await getCaseFilesApi(id); $$.hideLoading(); if (res.type) { if (type) { $$.showToast({ icon: 'success', title: '删除成功', duration: 500 }); } let arr = ['evidenceFile', 'applyFile', 'identityFile', 'otherFile']; arr.forEach((x, t) => { this.data.material_data[t].num = res.data[x]?.size || 0; this.data.material_data[t].files = res.data[x]?.dataList || []; }); app.globalData.material.data = this.data.material_data; this.setData({ activeMaterial: this.data.activeMaterial || 0, material_data: this.data.material_data }); } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { if (options.caseId) { this.caseId = options.caseId; this.getCaseFiles(this.caseId); }L this.setData({ editVisible: !!options?.editVisible }); }, /** * 生命周期函数--监听页面显示 */ onShow() { if (this.caseId && !this.previewImageVisible && app.globalData.material.uploadVisible) { app.globalData.material.uploadVisible = false; this.getCaseFiles(this.caseId); } if (this.previewImageVisible) { this.previewImageVisible = false; } }, });