import create from 'dd-store' import exampleStore from '/stores/exampleStore' import { saveFileInfo, addSchedule, uploadPermissions, previewPermissions } from '../../api/request.js' create.Page({ store: exampleStore, useAll: true, data: { scheduleItem: '', upLoadInfo: '', descript: '', uploadSpaceId: '' }, onLoad(event) { let scheduleItem = JSON.parse(event.scheduleItem) let upLoadInfo = JSON.parse(event.upLoadInfo) this.setData({ scheduleItem: scheduleItem, upLoadInfo: upLoadInfo }) dd.setNavigationBar({ title: '上传文件' }) }, onShow() { }, inputDes(event) { let value = event.detail.value this.setData({ descript: value }) }, close(event) { let fileId = event.target.dataset.item.fileId this.data.upLoadInfo.data.forEach((item, index) => { if (item.fileId == fileId) { this.data.upLoadInfo.data.splice(index, 1) return } }) this.setData({ upLoadInfo: this.data.upLoadInfo }) }, add() { uploadPermissions().then(res => { this.setData({ uploadSpaceId: res.data.data }) const _that = this dd.uploadAttachmentToDingTalk({ image: { multiple: true, compress: false, max: 9, spaceId: this.data.uploadSpaceId }, space: { spaceId: this.data.uploadSpaceId, max: 9 }, file: { spaceId: this.data.uploadSpaceId, max: 9 }, types: ["photo", "camera", "space"],//PC端仅支持["photo","file","space"] success: (res) => { _that.data.upLoadInfo.data.push(...res.data) _that.setData({ upLoadInfo: _that.data.upLoadInfo }) }, fail: (err) => { } }) }) }, // 点击保存 save() { if (!!this.data.scheduleItem.id) { this.saveUpload(this.data.scheduleItem.id) } else { let getId = { scheduleTemplateId: this.data.scheduleItem.scheduleTemplateId, planDate: this.data.scheduleItem.planDate, createModel: 'auto' } addSchedule(getId).then(success => { this.data.saveUpload(success.data.id) }) } }, // 保存的接口 saveUpload(id) { let data = { scheduleId: id, uploader: getApp().globalData.userid, uploaderInfo: JSON.stringify({ userId: getApp().globalData.userid, username: getApp().globalData.name, headUrl: getApp().globalData.avatar }), thirdStoreTenant: 'dingTalk', fileInfos: JSON.stringify(this.data.upLoadInfo.data), descript: this.data.descript } saveFileInfo(data).then(res => { dd.navigateBack({ delta: 1 }) }) } });