import axios from '@/common/services/axios-instance'
class AuditOperateTreeService {
  // 获取年度树
  getYearTree(account) {
    return axios({
      url: 'api/xcoa-mobile/v1/iam-work-paper/projectTree',
      method: 'get',
    }).then((res) => {
      res.data.forEach((item) => {
        item.id = item.planId + item.year
        item.text = item.year
        item.isLeaf = false
        item.props = { ORG_ID: item.id, BELONGED_ORG_ID: -1 }
        var child = []
        item.projectList.forEach((o) => {
          var obj = {
            id: o.projectId,
            text: o.projectName,
            leaf: false,
            props: { ORG_ID: item.id, BELONGED_ORG_ID: -1, projectId: o.projectId },
            children: [],
            key: Number(o.projectId),
          }
          child.push(obj)
        })
        item.children = child
        item.key = Number(item.planId)
      })
      res.data.sort(function(a, b) {
        return a.year - b.year
      })
      return res
    })
  }

  // 拖拽功能
  dragNode(params) {
    return axios({
      url: `api/xcoa-mobile/v1/iam-tree/moveTreeNode/${params.configId}/${params.id}/${params.targetId}/${params.position}`,
      method: 'post',
      data: null,
    }).then((res) => {
      res.data.forEach((item) => (item.isLeaf = item.leaf))
      return res
    })
  }
}
export default new AuditOperateTreeService()
