<template>
  <div>
    <Card style="height: 95%">
      <Table ref="tables" searchable search-place="top" :data="tableData" :columns="dataColumns" size="small"
             :loading="loading" @on-selection-change="selectedChange"
             highlight-row style="margin-top: 10px;" border>
             <template #actions slot-scope="{row}">
                <a @click="onCurrentChange(row)">选择</a>
             </template>
      </Table>
      <bcPage ref="role-list-page" @reload-data="reloadData" :dataCount="dataCount" size="small"
              :pageSize.sync="pageSize"></bcPage>
    </Card>
  </div>
</template>

<script>
  import { getRolePage, getRoleList, deleteRole } from '../../../../api/rbac/role-api'

  let $this
  export default {
    name: 'authorityObjPart',
    components: {},
    data () {
      return {
        importUrl: '',
        searchForm: {},
        showModal: false,
        modalParams: {},
        nowRole: {},
        dataCount: 0,
        pageSize: 10,
        columnsShow: [],
        dataColumns: [
          { title: '所属应用', key: 'forSystemName', sortable: true, show: true },
          { title: '角色编码', key: 'roleCode', sortable: true, show: true },
          { title: '角色名称', key: 'roleName', sortable: true, show: true },
          {
            title: '角色类型',
            key: '',
            render: (h, params) => h('span', params.row.type == 1 ? '普通角色' : '超级管理员'),
            sortable: true,
            show: true
          },
           { title: '操作', key: 'action', width: 70, align: 'center',slot:'actions', show: true }
          /*{ title: '是否默认角色', key: '',render: (h, params) => h('span', params.row.isDefault==1?'是':'否'), sortable: true, show: true },
          { title: '状态', key: '',render: (h, params) => h('span', params.row.state==1?'正常':'禁用'), sortable: true, show: true },
          { title: '备注', key: 'remark', sortable: true, show: true },
          { title: '操作', key: 'action', width: 200, align: 'center',slot:'actions', show: true }*/
        ],
        tableData: [],
        selectedData: [],
        loading: false,
        sortParams: [], //[{title: 姓名, orderStr: 降序, sortKey: name, order: -}]
        getList: getRoleList,
        commonList: [],//固化常用列表
        fieldList: []
      }
    },
    methods: {
      selectedChange (selection) {
        this.selectedData = selection
      },
      reloadData (pageSize, pageNo) {
        //表格加载中效果
        this.loading = true
        //处理表单查询参数及分页
        if (!pageNo) {
          this.dataCount = 0
        }
        if (!pageSize) {
          pageSize = this.pageSize
        }
        let page_params = { 'pageSize': pageSize, 'pageNo': pageNo }
        let params = Object.assign({}, page_params, this.searchForm) // 这样不会改变原对象

        getRolePage(params).then(res => {
          if (res.data.result.totalSize) {
            this.dataCount = parseInt(res.data.result.totalSize)
          }
          if (res.data.result.datas && res.data.result.datas.length > 0) {
            this.tableData = res.data.result.datas
            this.tableData[0]._highlight = true
            this.nowRole = this.tableData[0]
          } else {
            this.tableData = []
          }
          this.loading = false
        }).catch(err => {
          this.tableData = []
          this.$Message.error('查询失败！')
          console.log(err)
        })
      },
      onCurrentChange (currentRow) {
        this.nowRole = currentRow
        this.nowRole.name = this.nowRole.roleName
        this.$emit('update:nowObj', this.nowRole)
      },
    },
    mounted () {
      this.reloadData()
      $this = this
    }
  }
</script>

<style>

</style>
