import axios from '@/common/services/axios-instance'
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import eventBus from '@/common/services/event-bus'
import TodoListService from '@/todo/todo-list-service'
class LeaderscheduleService {
  // 获取领导秘书列表
  getLeaders(params) {
    return axios
      .post(`api/framework/v1/leader-secretary-manager/leader-permission-list`, params, {
        headers: {
          'Content-Type': 'application/json',
        },
      })
      .then(function(res) {
        return res.data
      })
  }

  // 设置待办置顶
  setTop(params) {
    return axios.post('api/framework/v1/extra-task-process/set-todo-top', params).then((res) => {
      return res.data
    })
  }

  // 秘书以领导身份打开领导待办
  openTaskItem(task, listType, activeKey, id) {
    let url =
      `/sd-webflow/${TodoListService.makePath(task, listType)}` +
      (activeKey
        ? `?openAuthType=leaderDone&openAuthParameter=${encodeURIComponent(activeKey)}`
        : '')
    const setUrl = (value) => (url = value)
    return eventBus.emit('sdTaskItemClick', task, { setUrl }).then((evt) => {
      if (evt.defaultPrevented) return
      return crossWindowWatcher.waitForChanged(url, `MS${id}`)
    })
  }

  // 获取秘书id
  getMsId(params) {
    return axios.get('api/framework/v1/leader-secretary-manager/sub-id', params).then((res) => {
      return res.data
    })
  }
}

export default new LeaderscheduleService()
