/*
 * @Author: your name
 * @Date: 2021-12-22 17:00:22
 * @LastEditTime: 2022-02-15 10:16:36
 * @LastEditors: Please set LastEditors
 * @Description: 获取权限树
 * @FilePath: \Foshan4A2.0\src\views\authorityManagement\minixs\treeData.js
 */
import { translateDataToTreeAll } from '@/utils/validate'
import { GetAuthTree } from '@/api/apiAuthority'

export default {
  data () {
    return {
      dataList: {}
    }
  },
  created () {
    // this.getAuthTree()
  },
  methods: {
    async getAuthTree (name = '') {
      try {
        const result = await GetAuthTree({
          "QueryName": name
        })
        if (result.code === 0 && result.returnData.length) {
          result.returnData.forEach(item => {
            item.flag = item.Status === 1 ? true : false
          })
          const obj = {
            AuthId: -1,
            AuthName: "所有权限",
            QueryTarget: 0,
            Status: 0,
            UpAuthId: -1,
            Type: 0,
            disabled: true,
            children: translateDataToTreeAll(result.returnData, 'UpAuthId', 'AuthId')
          }
          this.dataList = obj
          this.dataArr = result.returnData;
          this.dataArr.push({
            AuthId: -1,
            AuthName: "所有权限",
            QueryTarget: 0,
            Status: 0,
            UpAuthId: -2,
            Type: 0,
            disabled: true,
            children: []
          }
          )
        } else {
          const obj = {
            AuthId: -1,
            AuthName: "所有权限",
            QueryTarget: 0,
            Status: 0,
            UpAuthId: -2,
            Type: 0,
            disabled: true,
            children: []
          }
          this.dataList = obj
          this.dataArr.push({
            AuthId: -1,
            AuthName: "所有权限",
            QueryTarget: 0,
            Status: 0,
            UpAuthId: -2,
            Type: 0,
            disabled: true,
            children: []
          }
          )
        }
      } catch (error) {
        const obj = {
          AuthId: -1,
          AuthName: "所有权限",
          QueryTarget: 0,
          Status: 0,
          UpAuthId: -2,
          Type: 0,
          disabled: true,
          children: []
        }
        this.dataList = obj
        this.dataArr.push({
          AuthId: -1,
          AuthName: "所有权限",
          QueryTarget: 0,
          Status: 0,
          UpAuthId: -2,
          Type: 0,
          disabled: true,
          children: []
        }
        )
      }
    }
  }
}
