/*
 * @Author: your name
 * @Date: 2021-12-24 11:36:07
 * @LastEditTime: 2022-01-17 10:05:35
 * @LastEditors: Please set LastEditors
 * @Description: 权限公用
 * @FilePath: \Foshan4A2.0\src\views\authorityManagement\minixs\roleData.js
 */
import { organpop } from '@/api/postInterface'
import { GetGroupByOrgan, GroupAuths } from '@/api/authGroupApi'
import { GetGroupTree } from '@/api/AccountGroup'
import { QueryRole } from '@/api/apiAuthority'
export default {
  data () {
    return {
      arrs: []
    }
  },
  methods: {
    // 根据组织获取角色
    async getRoleByOrgan (id) {
      try {
        const res = await organpop({
          OrganId: id
        })
        if (res.code === 0) {
          const arr = res.returnData
          if (id == -1) {
            arr.forEach(item => {
              item.name = item.RoleName
            });
            this.arrs = arr
          } else {
            const datas = []
            arr.forEach(item => {
              item.name = item.RoleName
              if (item.IsSelected == 1) {
                datas.push(item)
              }
            });
            this.arrs = datas
          }
        } else {
          this.$message.error(res.message)
        }
      } catch (error) {
        console.log('出错了', error)
      }
    },
    //根据组织获取岗位
    async getGroupByOrgan (id) {
      try {
        let params = {
          OrganId: id
        }
        const res = await GetGroupByOrgan(params)
        if (res.code === 0) {
          const arr = res.returnData
          arr.forEach(item => {
            item.name = item.GroupName
          });
          this.arrs = arr
        } else {
          this.$message.error(res.message)
        }
      } catch (error) {
        console.log('出错了', error)
      }
    },
    //根组织获取岗位
    async getGroupTree (name = '') {
      try {
        let params = {
          QueryName: name
        }
        const res = await GetGroupTree(params)
        if (res.code === 0) {
          const arr = res.returnData
          arr.forEach(item => {
            item.name = item.GroupName
          });
          this.arrs = arr
        } else {
          this.$message.error(res.message)
        }
      } catch (error) {
        console.log('出错了', error)
      }
    },
    //根据岗位查询权限列表
    async groupAuths (id) {
      try {
        let params = {
          GroupId: id
        }
        const res = await GroupAuths(params)
        if (res.code === 0) {
          this.RoleList = res.returnData
        } else {
          this.$message.error(res.message)
        }
      } catch (error) {
        console.log('出错了', error)
      }
    },
    //获取角色列表数据
    async gueryRole (name = '') {
      try {
        const res = await QueryRole({
          QueryName: name
        })
        if (res.code === 0) {
          const datas = res.returnData
          datas.forEach(item => {
            item.name = item.RoleName
          });
          this.arrs = datas
        } else {
          this.$message.error(res.message)
        }
      } catch (error) {
        console.log('出错了', error)
      }
    },
  }
}