outLookContact.js 5.7 KB
import { getUserScheduleInTime } from '../../api/request.js'
import { throttle } from './../../utils/utils.js'
import pageStore from '../participantsDetail/store';
import create from 'dd-store'
// 传递给组件toast的所有数据
const conToastData = {
  showToast: false,
  title: '邮箱格式错误'
}
create.Page({
  store: pageStore,
  useAll: true,
  data: {
    $data: null,
    outlookContact: [],
    conflictPeople: [],
    scheduleItem: '',
    // 传递给组件toast的所有数据
    conToastData: conToastData,
    currentPeople: '',
    value: '',
    toPage: ''
  },
  onLoad(event) {
    const _that = this
    if (event.scheduleItem) {
      event.scheduleItem = decodeURIComponent(event.scheduleItem)
      let scheduleItem = JSON.parse(event.scheduleItem)
      this.setData({
        scheduleItem: scheduleItem
      })
    }
    if (event.toPage) {
      this.setData({
        toPage: event.toPage
      })
    }

    let outlookContact = []
    let userList = []
    if (!this.data.scheduleItem || !this.data.toPage) {
      userList = this.$store.data.participatorList
    } else {
      userList = this.store.data.contactPeople
    }

    for (let value of userList) {
      if (value.platform === 'outlook') {
        outlookContact.push(value)
      }
    }
    this.setData({
      outlookContact: outlookContact,
      currentPeople: getApp().globalData.userid
    })

    this.conflictPeople()
  },
  onShow() {
  },
  // input 的输入 事件
  onInput(event) {
    this.setData({
      value: event.detail.value
    })
  },
  // 添加email
  addEmail() {
    let reg = /^(?!.* )\w+((.\w+)|(-\w+))@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+).[A-Za-z0-9]+$/
    if (!!this.data.value) {
      if (reg.test(this.data.value)) {
        let outlookContact = this.data.outlookContact
        outlookContact.push({
          userId: this.data.value,
          username: this.data.value,
          headUrl: '',
          platform: 'outlook'
        })
        outlookContact = this.setArrary(outlookContact)
        this.setData({
          value: '',
          outlookContact: outlookContact
        })
        this.conflictPeople()
      }
      else {
        this.setData({
          'conToastData.showToast': true
        })
      }
    }
  },
  // 关闭
  close(event) {
    let outlookContact = this.data.outlookContact
    let index = 0
    for (let value of this.data.outlookContact) {
      if (value.userId === event.currentTarget.dataset.item.userId) {
        outlookContact.splice(index, 1)
        this.setData({
          outlookContact: outlookContact
        })
        return
      }
      index++
    }
  },
  // 数组 去重
  setArrary(arr) {
    let containt = {}
    for (let x of arr) {
      containt['id' + x.userId] = x
    }
    return Object.values(containt)
  },
  // 保存
  save() {
    let userList = []
    let userId = []
    userList.push({ userId: getApp().globalData.userid, username: getApp().globalData.name, headUrl: getApp().globalData.avatar, platform: 'dingtalk' })
    userId.push(getApp().globalData.userid)
    for (let value of this.data.outlookContact) {
      userList.push(value)
      userId.push(value.userId)
    }
    userList = this.setArrary(userList)
    userId = [...new Set(userId)]

    if (!this.data.scheduleItem || !this.data.toPage) {
      this.$store.data.participatorList.push(...userList)
      this.$store.data.participatorUserId.push(...userId)
      this.$store.data.participatorList = this.setArrary(this.$store.data.participatorList)
      this.$store.data.participatorUserId = [...new Set(this.$store.data.participatorUserId)]
    } else {
      this.store.data.contactPeople.push(...userList)
      this.store.data.contactPeopleId.push(...userId)
      this.store.data.contactPeople = this.setArrary(this.store.data.contactPeople)
      this.store.data.contactPeopleId = [...new Set(this.store.data.userId)]
      if (this.store.data.contactPeople != this.$store.data.originalData.userList) {
        this.$store.data.updateInfo.isUpate = true
        this.$store.data.updateInfo.updateType = 'operate_user'
      }
    }
    this.update()
    dd.navigateBack({
      delta: 1
    })
  },
  // 选择弹窗
  onSelectPopup(event) {
    this.setData({
      'conSelectPopupData.showSelectPopup': false,
      'conSelectPopupData.selectPopupId': event.currentTarget.dataset.item.id,
      'centerPopup.showCenterPopup': true
    })
  },
  // toast 消失之后的回调
  onToastHidden() {
    this.setData({
      'conToastData.showToast': false
    })
  },
  // 会议冲突
  conflictPeople() {
    let userIds = []
    for (let value of this.data.outlookContact) {
      userIds.push(value.userId)
    }
    let data = {
      startTime: this.$store.data.startTime.replace(/\//g, "-"),
      endTime: this.$store.data.endTime.replace(/\//g, "-"),
      userIds: userIds
    }
    getUserScheduleInTime(data).then(res => {
      let conflictPeople = []
      for (let value in res.data.data) {
        if (!!this.data.scheduleItem) {
          const arr = res.data.data[value].filter(function (item) {
            return item.confirmAttendance === 1
          })
          if (arr.length > 1) {
            conflictPeople.push(value)
          }

        } else {
          const arr = res.data.data[value].filter(function (item) {
            return item.confirmAttendance === 1
          })
          if (arr.length > 1) {
            conflictPeople.push(value)
          }
        }

      }
      this.setData({
        conflictPeople: conflictPeople
      })
    })
  },
  // onSelectPopupCancel 点击取消 
  onSelectPopupCancel() {
    this.setData({
      'conSelectPopupData.showSelectPopup': false,
      'centerPopup.showCenterPopup': false
    })
    this.operateUserE(false)
  },
  // 页面卸载
  onUnload() {


  }

});