<template>
  <div class="app-container">
    <table-list
      :operationsDefaultLength="3"
      :listLoading="listLoading"
      :data="tableData"
      :columns="listConfig"
      :currentPage="currentPage"
      :pageSize="pageSize"
      :totalRecords="totalRecords"
      @currentChange="pageHandle"
      :isAdd="true"
      @add="openPopup"
    />
    <popup-edit
      :isShow="isPopupShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import PopupEdit from './components/popup/RoleEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'xx',
  components: {
    PopupEdit
  },
  provide () {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  created () {},
  data () {
    return {
      apiStr: 'base.admroleslist',
      searchForm: null,
      isPopupShow: false,
      curObj: {},
    }
  },
  mounted () {
    this.listConfig = {
      rows: [
        { label: '角色名称', prop: 'name' },
        { label: '角色描述', prop: 'description' },
        { label: '操作', width: 230, type: 'handle2',
          operations: [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '删除', func: this.delHandle, btnType: 'danger'},
          ]
        }
      ]
    }
  },
  methods: {
    delHandle (row) {
      const msgHtml = `确定要删除该角色吗？`
      this.$msg(msgHtml, 'confirm', ()=> {
        this.$api.base.admrolesdel({
          id: row.id,
        }).then(data => {
          this.$msgs(`删除成功！`)
          this.fetchData()
        })
      }, null, true)
    },
    openPopup (row) {
      this.curObj = row
      this.isPopupShow = true
    },
    closePopup (obj) {
      this.isPopupShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
