uploadFile.js 2.7 KB
import create from 'dd-store'
import { saveFileInfo, addSchedule, uploadPermissions, previewPermissions, updateMeetingTask } from '../../api/request.js'
import { throttle, debounce, getCreateShowTime } from './../../utils/utils.js'
import pageStore from '../meetingDetail/store';
import { getFileInfo } from '../meetingDetail/uploadFile';

create.Page({
  store: pageStore,
  data: {
    fileInfos: null, //store
    description: '',//store
    id: '',
  },
  onLoad(query) {
    dd.setNavigationBar({
      title: '会议文件'
    });
    // 编辑的时候传了文件ID
    if (query && query.id) {
      this.setData({
        id: query.id
      });
    }
  },
  onShow() {
    this.update()
  },
  inputChange: debounce(function (e) {
    const value = e.detail.value;
    if (value) {
      this.store.data.description = value;
      this.update();
    }
  }, 100),

  //添加会议文件
  async add() {
    const res = await getFileInfo();
    console.log(res.data)
    if (res.code === -1) {
      dd.alert({
        content: res.msg
      })
      return
    }
    let data = []
    res.data.map(it => {
      this.store.data.fileInfos.push({
        fileId: it.fileId,
        name: it.fileName,
        size: it.fileSize,
        spaceId: it.spaceId,
        platform: "dingTalk",
        mimeType: it.fileType,
      })


    })
    // console.log(this.store.data.fileInfos)
    this.update();

  },

  // 保存
  saveUpload: throttle(function () {
    const { fileInfos, oldFileInfos, description, oldDescription } = this.store.data;

    if (!fileInfos || (fileInfos && fileInfos.length == 0)) {
      dd.showToast({
        content: '请上传文件'
      })
      return;
    }

    //如果实际没有修改,不生成记录
    if (this.data.id) {
      if (oldFileInfos == JSON.stringify(fileInfos) && description == oldDescription) {
        return dd.navigateBack()
      }
    }

    const data = {
      meetingId: this.data.id,
      platform: 'dingTalk',
      remark: description,
      fileModel: {
        fileList: fileInfos
      }
    }

    updateMeetingTask(data).then(res => {

      this.store.data.fileInfos = []
      this.store.data.description = ''
      this.update();

      if (res.data.data) {
        const addData = res.data.data[0].commentListDataModelList[0];
        addData.updateTime = getCreateShowTime(addData.updateTime);
        this.store.data.affairList.unshift(addData);
        addData.fileDetailList.forEach(it => this.store.data.files.unshift(it));
        this.store.data.isNeedReloadIndexList = true;
        if (this.store.data.separateIndex !== -1) {
          this.store.data.separateIndex += 1;
        }
        this.update();
        dd.navigateBack();
      }


    })
  }, 1000)
});