/*
 * @Author: your name
 * @Date: 2021-12-22 17:00:22
 * @LastEditTime: 2022-02-10 10:45:54
 * @LastEditors: Please set LastEditors
 * @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: []
    }
  },
  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,
            children: translateDataToTreeAll(result.returnData, 'OrganUpid', 'OrganId')
          }
          this.dataList = obj
        } else {
          const obj = {
            AuthCount: 0,
            JobCount: 0,
            OfficerCount: 0,
            OrganId: -1,
            OrganName: "佛山路桥",
            OrganUpid: -2,
            QueryTarget: "0",
            Type: 0,
            children: []
          }
          this.dataList = obj
        }
      } catch (error) {
        console.log('出错了', error)
      }
    }
  }
}
