participantsDetail.js 3.01 KB
import create from 'dd-store'
import exampleStore from '/stores/exampleStore'
import { addSchedule, getUserScheduleInTime, getHomeUserSchedule } from '../../api/request.js'
create.Page({
  store: exampleStore,
  useAll: true,
  time1: '',
  time2: '',
  data: {
  },
  onLoad(event) {
    this.setData({
      time1: event.time1,
      time2: event.time1
    })
    dd.setNavigationBar({
      title: `参会人(${this.store.data.participatorList.length}人)`
    })

  },
  // 保存信息
  saveInfo() {
    this.conflict()
  },
  // 添加参会人
  addParticipants() {
    const _that = this
    dd.complexChoose({
      title: "选择参会人",            //标题
      multiple: true,            //是否多选
      limitTips: "超出了",          //超过限定人数返回提示
      maxUsers: 1000,            //最大可选人数
      pickedUsers: _that.store.data.participatorUserId,            //已选用户
      requiredUsers: [],            //必选用户(不可取消选中状态
      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()
        dd.setNavigationBar({
          title: `参会人(${_that.store.data.participatorList.length}人)`
        })
      },
      fail: function (err) {
      }
    })
  },
  // 删除参会人
  delParticipants(event) {
    let userId = event.target.dataset.userId
    this.store.data.participatorList.forEach((item, index) => {
      if (userId === item.userId) {
        this.store.data.participatorList.splice(index, 1)
        this.update()
        return
      }
    })
    this.store.data.participatorUserId.forEach((item, index) => {
      if (userId === item) {
        this.store.data.participatorUserId.splice(index, 1)
        this.update()
        return
      }
    })
    dd.setNavigationBar({
      title: `参会人(${this.store.data.participatorList.length}人)`
    })
  },
  // 数组去重
  setArrary(arr, userId) {
    console.log(arr)
    let containt = {}
    for (let x of arr) {
      containt['id' + x.userId] = x
    }
    return Object.values(containt)
  },
  // 会议冲突
  conflict() {
    this.store.data.conflictPeople = []
    let data = {
      startTime: `${this.data.time1}:00`,
      endTime: `${this.data.time2}:00`,
      userIds: this.store.data.participatorUserId
    }
    getUserScheduleInTime(data).then(res => {
      for (let value in res.data.data) {
        if (!!res.data.data[value].length) {
          this.store.data.conflictPeople.push(value)
        }
      }
      this.update()
      dd.navigateBack({
        delta: 1
      })
    })
  }
});