createOrEditSchedule.js 6.52 KB
import create from 'dd-store'
import exampleStore from '/stores/exampleStore'
import { saveMettingRoom, getUserScheduleInTime } from '../../api/request'
create.Page({
  store: exampleStore,
  useAll: true,
  data: {
    timeStaus: '',
    isShowModal: false,
    title: null,
    time1: '',
    week1: '',
    time2: '',
    week2: '',
    propsTime: '',
    conflictPeople: []
  },
  onLoad() {
    this.store.data.participatorList = []
    this.store.data.locationName = ''
    this.store.data.participatorUserId = []
    this.update()
    dd.setNavigationBar({
      title: '创建会议'
    })
    var date = new Date();
    var y = date.getFullYear();
    var m = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);//获取当前月份的日期,不足10补0
    var d = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();//获取当前几号,不足10补0
    var weekList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
    var w = weekList[date.getDay()];
    var h = date.getHours()
    var min = date.getMinutes();
    console.log(h, min)
    this.setData({
      time1: `${y}/${m}/${d} ${h < 10 ? "0" + date.getHours() : date.getHours()}:${min < 30 ? '00' : '30'}`,
      time2: `${y}/${m}/${d} ${min < 30 ? h < 10 ? "0" + date.getHours() : date.getHours() : (h + 1) < 10 ? "0" + (date.getHours() + 1) : date.getHours() + 1}:${min < 30 ? '30' : '00'}`,
      week1: w,
      week2: w,
    })
  },
  // 选择时间
  selectTime(event) {
    this.setData({
      timeStaus: event.target.dataset.timeStaus,
      isShowModal: true,
      propsTime: event.target.dataset.timeStaus == 0 ? this.data.time1 : this.data.time2
    })
  },
  // 选择时间组件回调
  changeSelectTime(e) {
    console.log(e)
    if (e.status === 1) {
      var date1 = new Date(e.time);
      var weekList = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
      var w1 = weekList[date1.getDay()];
      if (this.data.timeStaus == 0) {
        if (new Date(e.time).getTime() > new Date(this.data.time2).getTime()) {
          var date = new Date(e.time);
          date.setMinutes(date.getMinutes() + 30)
          var y = date.getFullYear();
          var m = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1);//获取当前月份的日期,不足10补0
          var d = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();//获取当前几号,不足10补0
          var w2 = weekList[date.getDay()];
          var h = date.getHours()
          var min = date.getMinutes();
          this.setData({
            time1: e.time,
            time2: `${y}/${m}/${d} ${h < 10 ? "0" + date.getHours() : date.getHours()}:${min < 10 ? "0" + min : min}`,
            isShowModal: false,
            week1: w1,
            week2: w2
          })
        } else {
          this.setData({
            time1: e.time,
            isShowModal: false,
            week1: w1
          })
        }
      } else {
        if (new Date(e.time).getTime() < new Date(this.data.time1).getTime()) {
          dd.alert({
            title: '提示',
            content: '会议结束时间不能小于开始时间',
            buttonText: '我知道了',
            success: () => {
            },
          });
        } else {
          this.setData({
            time2: e.time,
            isShowModal: false,
            week2: w1
          })
        }
      }
    } else {
      this.setData({
        isShowModal: false
      })
    }
  },
  // input 输入事件
  getTitle(event) {
    this.setData({
      title: event.detail.value
    })
  },
  // 添加参会人
  addParticipants() {
    const _that = this
    dd.complexChoose({
      title: "选择参会人",            //标题
      multiple: true,            //是否多选
      limitTips: "超出了",          //超过限定人数返回提示
      maxUsers: 1000,            //最大可选人数
      pickedUsers: _that.store.data.participatorUserId,            //已选用户
      requiredUsers: [],            //必选用户(不可取消选中状态)
      requiredDepartments: [],        //必选部门(不可取消选中状态)
      permissionType: "xxx",          //可添加权限校验,选人权限,目前只有GLOBAL这个参数
      responseUserOnly: true,        //返回人,或者返回人和部门
      success: function (res) {
        res.users.forEach((item, index) => {
          _that.store.data.participatorList.push({ userId: item.userId, username: item.name, headUrl: item.headUrl })
          _that.store.data.participatorUserId.push(item.userId)

        })
        _that.store.data.participatorList = _that.setArrary(_that.store.data.participatorList)
        _that.store.data.participatorUserId = [...new Set(_that.store.data.participatorUserId)]
        _that.update()
        _that.conflict()
      },
      fail: function (err) {
      }
    })
  },
  // 跳转下一页
  nextPage(event) {
    switch (event.target.dataset.nextPage) {
      case 'participantsDetail':
        dd.navigateTo({ url: './../participantsDetail/participantsDetail' })
        break;
      case 'place':
        dd.navigateTo({ url: './../place/place' })
        break;
    }
  },
  // 数组去重
  setArrary(arr, userId) {
    let containt = {}
    for (let x of arr) {
      containt['id' + x.userId] = x
    }
    return Object.values(containt)
  },
  // 保存
  saveCreate() {
    let data = {
      title: this.data.title || '无主题',
      location: {
        longitude: '10',
        latitude: '10',
        locationName: this.store.data.locationName || ''
      },
      startTime: `${this.data.time1.replace(/\//g,"-")}:00`,
      endTime: `${this.data.time2.replace(/\//g,'-')} :00`,
      scheduleType: 'common',
      noticeType: 'dd_notice',
      participatorList: this.store.participatorList,
      repeatable: 0,
      aheadTimes: [],
      recurrenceModel: {
        model: 'no_repeat'
      },
      meetingRoomId: 222 || null
    }
    saveMettingRoom(data).then(res => {
      dd.navigateBack({
        delta: 1
      })
    })

  },
  // 清除地点
  closePlace() {
    this.store.data.place = ""
    this.update()

  },
  // 会议冲突
  conflict() {
    let data = {
      startTime: `${this.data.time1.replace(/\//g,"-")}:00`,
      endTime: `${this.data.time2.replace(/\//g,"-")}:00`,
      userIds: this.store.data.participatorUserId
    }
    getUserScheduleInTime(data).then(res => {
      for(let value in res.data.data) {
        if(res.data.data[value] === []) {
          conflictPeople.push(value)
        }
      }
 
    })
  }

});