<template>
  <div style="display:inline">
    <el-button type="primary" size="mini" @click="onShow" icon="el-icon-thumb">授 权</el-button>
    <el-drawer class="auth-container" title="授权报表列表" append-to-body :visible.sync="dialogTableVisible" size="50%">
      <div class="container">
          <div class="flex-align-center normal-margin">
        <p style="width:50px">搜索:&nbsp;</p>
        <el-input style="width:250px" v-model="value" size="small" @keyup.native.enter="listData(param.content.where.condition = value)" @clear="listData(param.content.where.condition = '')" placeholder="应用名称" clearable></el-input>
      </div>
      <el-row>
        <el-col :span="24">
          <Table ref="table" :layout="tablecols" :data="list" :custom="false" height="500px">
          </Table>
          <div style="margin:20px 0;text-align:right">
            <el-pagination
              background
              small
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="param.content.pageNumber"
              :page-size="param.content.pageSize"
              layout="total, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          </div>
        </el-col>
      </el-row>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="dialogTableVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>

  </div>
</template>

<script>
import Table from './table'
export default {
  props:['data'],
  components:{Table},
  data () {
    return {
      dialogTableVisible:false,
      param:{
        "id":20221213141501,
        "content": {
            "roleid":'',
            "pageNumber": 1,
            "pageSize": 10,
            "where":{
              "condition":"",
            
            }
        }
      },
      list:[],
      total:0,
      value:'',
      tablecols:[]
    }
  },
  created () {
    this.tablecols = this.tool.tabelCol(this.$route.name).userCenter.tablecols

  },
  methods:{
    async listData () {
      this.param.content.roleid = this.$route.query.id
      let res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      console.log(this.list);
      
    },
    onShow () {
      this.dialogTableVisible = true
      this.listData()
    },
    async onSubmit () {
      let result = this.$refs.table.allArr.map(item => item.sys_reportid)
      let res = await this.$api.requested({
        "id":20221213141801,
        "content": {
          roleid:this.$route.query.id,
          sys_reportids: result
        }
      })
      console.log(res);
      this.tool.showMessage(res,() => {
        this.$emit('onSuccess')
        this.dialogTableVisible = false
      })
      
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.query_all_auth()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.query_all_auth()
    },
  }
}

</script>
<style>
.auth-container .el-tabs--border-card{
  box-shadow: none !important;
}
.auth-container .el-tabs--border-card>.el-tabs__content{
  padding: 0;
}
</style>