/*
 * @Author: your name
 * @Date: 2021-12-22 17:00:22
 * @LastEditTime: 2022-03-21 03:29:33
 * @LastEditors: your name
 * @Description: 获取权限树
 * @FilePath: \Foshan4A2.0\src\views\authorityManagement\minixs\treeData.js
 */
import { translateDataToTreeAll } from '@/utils/validate'
import { tissueTreeList } from '@/api/postInterface'

export default {
  data () {
    return {
      dataList: {
        AuthCount: 0,
        JobCount: 0,
        OfficerCount: 0,
        OrganId: -1,
        OrganName: "系统组织",
        OrganUpid: -2,
        QueryTarget: "0",
        Type: 0,
        children: []
      },
      dataArr: []
    }
  },
  created () {
    // this.getOrganTree()
  },
  methods: {
    async getOrganTree (name = '') {
      try {
        const result = await tissueTreeList({
          "QueryName": name
        })
        if (result.code === 0 && result.returnData.length) {
          result.returnData.forEach(item => {
            item.flag = item.Status == 1 ? true : false
          })
          const obj = {
            AuthCount: 0,
            JobCount: 0,
            OfficerCount: 0,
            OrganId: -1,
            OrganName: "系统组织",
            OrganUpid: -2,
            QueryTarget: "0",
            Type: 0,
            disabled: true,
            children: translateDataToTreeAll(result.returnData, 'OrganUpid', 'OrganId')
          }
          this.orgList = result.returnData
          this.dataList = obj
          this.dataArr = result.returnData;
          this.dataArr.push({
            AuthCount: 0,
            JobCount: 0,
            OfficerCount: 0,
            OrganId: -1,
            OrganName: "系统组织",
            OrganUpid: -2,
            QueryTarget: "0",
            Type: 0,
            disabled: true,
          }
          )
        } else {
          const obj = {
            AuthCount: 0,
            JobCount: 0,
            OfficerCount: 0,
            OrganId: -1,
            OrganName: "系统组织",
            OrganUpid: -2,
            QueryTarget: "0",
            Type: 0,
            disabled: true,
            children: []
          }
          this.dataList = obj
          this.dataArr.push({
            AuthCount: 0,
            JobCount: 0,
            OfficerCount: 0,
            OrganId: -1,
            OrganName: "系统组织",
            OrganUpid: -2,
            QueryTarget: "0",
            Type: 0,
            disabled: true,
          }
          )
        }
        this.currDataArr = this.decompose(this.dataArr, 'OrganId', this.currentKey)
        this.childrenData = this.decompose(this.dataArr, 'OrganUpid', this.currentKey)
      } catch (error) {
        console.log('出错了', error)
        this.currDataArr = this.decompose(this.dataArr, 'OrganId', this.currentKey)
        this.childrenData = this.decompose(this.dataArr, 'OrganUpid', this.currentKey)
      }
      this.$nextTick(() => {
        this.$refs.tree?.setCurrentKey(this.currentKey)
      })
    }
  }
}
