scheduleDetail.js 3.71 KB
import create from 'dd-store'
import exampleStore from '/stores/exampleStore'
import { deleteSchedule, getScheduleDetail, uploadPermissions, previewPermissions } from '../../api/request.js'
create.Page({
  store: exampleStore,
  useAll: true,
  data: {
    title: '',
    location: '',
    startTime: '',
    endTime: '',
    weeks: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
    week: '',
    isAcrossDay: true,
    uploadSpaceId: '',
    previewSpaceId: '',
    scheduleItem: '',
    planDate: '',
    scheduleTemplateId: ''

  },
  onLoad(event) {
    let scheduleItem = JSON.parse(event.scheduleItem)
    this.setData({
      scheduleItem: scheduleItem
    })
    dd.setNavigationBar({
      title: '会议详情'
    })
  },
  onShow() {
    let data = {
      id: this.data.scheduleItem.id,
      planDate: this.data.scheduleItem.planDate,
      templateId: this.data.scheduleItem.scheduleTemplateId
    }
    getScheduleDetail(data).then(res => {
      this.setData({
        title: res.data.data.title,
        location: res.data.data.location,
        startTime: res.data.data.startTime,
        endTime: res.data.data.endTime,
        week: this.data.weeks[new Date(res.data.data.startTime).getDay() - 1]
      })
      this.store.data.userList = res.data.data.userList
      this.store.data.aheadTimes = res.data.data.aheadTimes
      this.store.data.remark = res.data.data.remark
      this.acrossDay(res.data.data.startTime, res.data.data.endTime)
      this.update()
      return uploadPermissions()
    }).then(res => {
      this.setData({
        uploadSpaceId: res.data.data
      })
    })

  },
  // 是否跨天
  acrossDay(time1, time2) {
    let isAcrossDay = ''
    if (JSON.stringify(this.dealTime(time1)) === JSON.stringify(this.dealTime(time2))) {
      isAcrossDay = false
    } else {
      isAcrossDay = true
    }
    this.setData({
      isAcrossDay: isAcrossDay
    })
  },
  // 处理时间
  dealTime(time) {
    let time1 = time.replace(/-/g, "/")
    let date = new Date(time1)
    let day = date.getDate()
    let year = date.getFullYear()
    let month = date.getMonth() + 1
    return {
      year: year,
      month: month,
      day: day
    }
  },
  // 上传文件
  upload() {
    const _that = this
    dd.uploadAttachmentToDingTalk({
      image: { multiple: true, compress: false, max: 9, spaceId: this.data.uploadSpaceId },
      space: { spaceId: this.data.uploadSpaceId, isCopy: 1, max: 9 },
      file: { spaceId: this.data.uploadSpaceId, max: 1 },
      types: ["photo", "camera", "space"],//PC端仅支持["photo","file","space"]
      success: (res) => {
        previewPermissions(res.data[0].fileId).then(success => {
          _that.setData({
            previewSpaceId: success.data.data
          })
          _that.preview(res.data[0].fileId, res.data[0].fileSize, res.data[0].fileType, res.data[0].fileName)
        })
      },
      fail: (err) => {
        dd.alert({
          content: JSON.stringify(err)
        })
      }
    })
  },
  // 跳转下一页
  nextPage(event) {
    switch (event.target.dataset.nextPage) {
      case 'participants':
        dd.navigateTo({ url: `./../attendingSituation/attendingSituation?userList=${JSON.stringify(this.store.data.userList)}` })
        break;
      case 'edit':
        console.log(this.data.scheduleItem.id)
        dd.navigateTo({ url: `./../createOrEditSchedule/createOrEditSchedule?scheduleItem=${JSON.stringify(this.data.scheduleItem)}` })
        break;
    }
  },
  // 预览文件
  preview(fileId, fileSize, fileType, fileName) {
    dd.previewFileInDingTalk({
      corpId: dd.corpId,
      spaceId: this.data.previewSpaceId,
      fileId: fileId,
      fileName: fileName,
      fileSize: fileSize,
      fileType: fileType
    })
  }



});