// pages/handleFile/handleFile.js import { documentList, deleteDocument } from "../../api/document"; Page({ /** * 页面的初始数据 */ data: { currentPage: 1, hasNext: false, fileList: [], delFileList: [] }, /** * 生命周期函数--监听页面显示 */ onShow() { this.getDocumentList() }, // 获取档案列表 getDocumentList () { var data = { currentPage: this.data.currentPage } wx.showLoading({ title: '加载中...', mask: true }) documentList(data).then(res => { wx.hideLoading() var response = res.data.vos response.map(item => { item.birthDay = item.birthday.split(' ')[0] }) this.setData({ hasNext: res.data.hasNext, fileList: response }) }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, /** * 删除文档 */ handleDelFile() { var that = this var delArr = [] var flag = this.data.delFileList.find(item => { return item == true }) this.data.delFileList.forEach(item => { if (item) { delArr.push(item) } }) console.log(this.data.delFileList, delArr); if (!flag) { wx.showToast({ title: '请选择删除的档案!', icon: 'error', mask: true, duration: 2000 }) return } if (delArr.length > 1) { wx.showToast({ title: '请选择一条数据!', icon: 'error', mask: true, duration: 2000 }) return } wx.showModal({ title: '确定要删除档案信息吗?', content: '相对应的体检报告也会删除哦!', cancelColor: '#666', confirmColor: '#333', success (res) { if (res.confirm) { that.handleConfirm() } } }) }, /* 确定 */ handleConfirm () { var delPara = {} for (let index = 0; index < this.data.delFileList.length; index++) { const element = this.data.delFileList[index]; if (element) { delPara.documentId = this.data.fileList[index].documentId } } wx.showLoading({ title: '删除中...', mask: true }) deleteDocument(delPara).then(res => { wx.hideLoading() wx.showToast({ title: '删除成功', icon: 'success' }) wx.navigateBack() }).catch(e => { wx.hideLoading() wx.showModal({ content: e, confirmColor: '#333', showCancel: false }) }) }, /** * 用户点击 单选radio */ handleRadio (e) { var choseIndex = e.currentTarget.dataset.index var currentList = this.data.fileList currentList[choseIndex].choseFlag = !currentList[choseIndex].choseFlag this.setData({ fileList: currentList }) this.initDelList() }, /* 处理删除的数据 */ initDelList () { var currentList = this.data.fileList var _a = [] currentList.map(item => { _a.push(item.choseFlag) }) this.setData({ delFileList: _a }) } })