/*
 * @Author: your name
 * @Date: 2021-12-24 11:36:07
 * @LastEditTime: 2022-02-09 10:59:01
 * @LastEditors: Please set LastEditors
 * @Description: 权限公用
 * @FilePath: \Foshan4A2.0\src\views\authorityManagement\minixs\roleData.js
 */
import { QueryRole, DeleteRole } from '@/api/apiAuthority'

export default {
  data () {
    return {
      dataList: []
    }
  },
  created () {
    // this.gueryRole()
  },
  methods: {
    //获取列表数据
    async gueryRole (obj) {
      try {
        this.loading = true
        const res = await QueryRole(obj)
        if (res.code === 0) {
          const datas = res.returnData.records
          const num = res.returnData.pages
          datas.forEach(item => {
            item.isauto = item.Status == 1 ? true : false
          })
          this.dataList.push(datas)
          const arrs = this.dataList.flat()
          const msgs = _.unionBy(arrs, "RoleId")
          this.arrs = msgs
          this.total = num
          this.loading = false
        } else {
          this.$message.error(res.message)
          this.loading = false
        }
      } catch (error) {
        console.log('出错了', error)
        this.loading = false
      }
    },
    //删除角色
    async deleteRole (id, num) {
      try {
        const res = await DeleteRole({
          RoleId: id
        })
        if (res.code === 0) {
          this.flag = false
          this.$message.success(res.message)
          this.arrs.splice(num, 1)
          this.num = null
        } else {
          this.flag = false
          this.$message.error(res.message)
        }
      } catch (error) {
        this.flag = false
        console.log('出错了', error)
      }
    }
  }
}
