createMeeting.js 8.27 KB
import { addSchedule, updateMeetingTask, getDeviceBySn } from '../../api/request.js'
import { selectPeople, modifyTimeImpactRepeat, throttle, dealRepeatModal, getInterTime, getShowTime, getTwoYearToday } from './../../utils/utils.js'
import { checkFullScren } from "../../utils/checkFullScren";
import { repeatList, repeatWeek, aheadTimeList } from "./constant"
import create from 'dd-store'
import pageStore from '../meetingDetail/store';
create.Page({
  store: pageStore,
  data: {
    $data: null,
    relatedAppPlatform: null,
    title: ``,
    meetingRemark: '',
    isShowRemark: false,
    showTime: '',
    repeat: {
      repeatList: repeatList,
      recurrenceModel: { model: 'no_repeat' },
      repeatable: 0,
      selectRepeatId: ''
    },
    popup: {
      show: false,
      title: '',
      mask: '',
      type: ''
    },
    placeholder: '',
    isIPX: false,
    limitClick: false,
    aheadTime: {
      aheadTimeList: aheadTimeList,
      aheadTimes: [15],
      iconType: 'icon',
      aheadTimesListId: [15],
    },

  },
  onLoad(query) {
    if (query && query.sn) {
      getDeviceBySn(query.sn).then(res => {
        if (res.data.code === 0) {
          this.$store.data.locationName = res.data.data.meetingRooomFullName
          this.$store.data.roomId = res.data.data.meetingRoomId
        }
      })
    }
    dd.setNavigationBar({
      title: `创建会议`
    })
    this.setData({
      isIPX: checkFullScren(),
      placeholder: `${getApp().globalData.name}创建的会议`
    })
    this.reset(query)
  },
  onShow() {
    if (this.$store.data.shouldUpdateShowTime) {
      this.setData({
        showTime: getShowTime(this.$store.data.startTime, this.$store.data.endTime)
      })
      this.$store.data.shouldUpdateShowTime = false;
      this.update();
    }
    setTimeout(() => {
      this.update()
    }, 100)

  },

  // 添加标题
  handleChangeTitle(event) {
    this.setData({
      title: event.detail.value
    })
  },


  // 打开添加描述
  handleOpenRemark() {
    this.setData({
      isShowRemark: true
    })
  },
  // 添加描述
  handleChangeRemark(event) {
    this.setData({
      meetingRemark: event.detail.value
    })
  },


  // 跳转选择地点
  goSelectPlace() {
    dd.navigateTo({ url: './../place/place' })
  },
  // 删除地点
  handleDeletePlace() {
    this.$store.data.locationName = ''
    this.$store.data.roomId = ''
    this.update()
  },

  // 选择时间 打开popup
  handleTime() {
    this.setData({
      popup: {
        show: true,
        title: "选择会议时间",
        mask: true,
        type: 'time'
      }
    })
  },
  // 选择时间点击完成
  onComplete(event) {
    this.$store.data.startTime = `${event.startTime}:00`
    this.$store.data.endTime = `${event.endTime}:00`
    this.update()
    this.setData({
      showTime: getShowTime(this.$store.data.startTime, this.$store.data.endTime)
    })
    this.closePopup()

    /* 
    改时间 改掉重复规则
    先选重复规则 再改时间 重复规则也要改变
    暂时修改每周 每月重复问题
     */
    if (this.data.repeatable !== 0) {
      let recurrenceModel = modifyTimeImpactRepeat(this.data.repeat.recurrenceModel)
      this.setData({
        'repeat.recurrenceModel': recurrenceModel
      })
    }
  },

  // 选择重复规则 打开popup
  handleRepeatModal() {
    this.setData({
      popup: {
        show: true,
        title: "重复规则",
        mask: true,
        type: 'repeat'
      }
    })
  },
  // 选择重复
  selectRepeatListItem(event) {
    const item = event.currentTarget.dataset.item
    const repeat = dealRepeatModal(item)
    this.setData({
      'repeat.repeatable': repeat.repeatable,
      'repeat.recurrenceModel': repeat.recurrenceModel,
      'repeat.selectRepeatId': repeat.selectRepeatId,
    })
    this.closePopup()
  },
  // 保存重复
  handleSaveRepeat() {

  },

  // 选择会前提醒
  handleSelectAheadTime() {
    this.setData({
      popup: {
        show: true,
        title: "会前提醒",
        mask: true,
        type: 'aheadTime'
      }
    })
  },
  // 会前提醒点击完成
  handleAheadTimeSave(event) {
    this.closePopup()
    this.setData({
      'aheadTime.aheadTimes': event,
      'aheadTime.aheadTimesListId': event,
    })
  },


  // 关闭popup
  closePopup() {
    this.setData({
      popup: {
        show: false,
        title: "",
        mask: true,
        type: ''
      }
    })
  },

  // 添加参会人
  handleAddParticipator: throttle(async function () {
    const select = Object.keys(this.$store.data.participatorList)
    const require = [getApp().globalData.userid]
    selectPeople(select, require).then(res => {
      let participatorList = {
        [getApp().globalData.userid]: {
          userId: getApp().globalData.userid, username: getApp().globalData.name, headUrl: getApp().globalData.avatar, platform: 'dingtalk'
        }
      }
      for (let i = 0; i < res.users.length; i++) {
        participatorList[res.users[i].userId] = { userId: res.users[i].userId, username: res.users[i].name, headUrl: res.users[i].avatar, platform: 'dingtalk' }
      }
      this.$store.data.participatorList = participatorList
      this.$store.data.showParticipatorList = Object.values(participatorList)
      this.update()
    })
  }),
  // 参会人详情
  goParticipantsDetail() {
    dd.navigateTo({ url: './../participantsDetail/participantsDetail' })
  },

  addSchedule1: throttle(async function () {
    if (this.data.limitClick) {
      return
    }
    this.setData({ limitClick: true });
    dd.showLoading({
      content: '正在创建...',
    });
    let data = {
      title: this.data.title || `${getApp().globalData.name}创建的会议`,
      location: {
        longitude: '10',
        latitude: '10',
        meetingRoomName: this.$store.data.locationName
      },
      startTime: this.$store.data.startTime.replace(/\//g, "-"),
      endTime: this.$store.data.endTime.replace(/\//g, "-"),
      meetingRoomId: this.$store.data.roomId,
      scheduleType: this.$store.data.roomId ? 'meeting' : 'common',
      participatorList: !!this.$store.data.showParticipatorList.length ? this.$store.data.showParticipatorList : [{ userId: getApp().globalData.userid, username: getApp().globalData.name, headUrl: getApp().globalData.avatar, platform: 'dingtalk' }],
      repeatable: this.data.repeat.repeatable,
      remark: this.data.meetingRemark,
      recurrenceModel: this.data.repeat.recurrenceModel,
      meetingWayModel: { model: null },
      aheadTimes: this.data.aheadTime.aheadTimesListId
    }
    const res = await addSchedule(data).catch(err => {
      this.setData({ limitClick: false });
      dd.hideLoading();
    });
    if (res.data.code === 0) {
      this.$store.data.tabBarIndex = '1';
      this.update();
      if (this.data.repeat.repeatable === 0) {
        if (this.$store.addOnceMeeting) {
          await this.$store.addOnceMeeting({
            startTime: new Date(this.$store.data.startTime),
            endTime: new Date(this.$store.data.endTime),
            confirmAttendance: res.data.data.confirmAttendance,
            title: res.data.data.title,
            id: res.data.data.id
          })
        }
      } else {
        if (this.$store.modifyErpeatMeeting) {
          await this.$store.modifyErpeatMeeting()
        }
      }
      this.setData({ limitClick: false });
      dd.hideLoading();
      dd.navigateBack()
    }

  }),

  // 初始化
  reset(query) {
    if (query && query.type == 'copy') {
      this.$store.resetCopyData()
    } else {
      this.$store.resetData()
    }
    this.$store.data.startTime = this.getTimes()
    this.$store.data.endTime = this.getTimes(new Date().setMinutes(new Date().getMinutes() + 30))
    this.update()
    this.setData({
      showTime: getShowTime(this.$store.data.startTime, this.$store.data.endTime)
    })
  },

  // 获取时间参数
  getTimes(time = new Date()) {
    let date = getInterTime(new Date(time))
    let year = date.getFullYear()
    let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
    let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    let hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
    let miunutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
    return `${year}/${month}/${day} ${hour}:${miunutes}:00`
  },
});