<template>
  <div>
    <div>
      <filteringAdd @addSuccess="onSuccess"></filteringAdd>
    </div>
    <div style="margin-top: 20px">
      <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  :height="tableHieght">
        <template v-slot:customcol="scope">
          <div >{{scope.column.data[scope.column.columnname]}}</div>
        </template>
        <template v-slot:opreation="scope">
          <filteringEdit class="inline-16" :data="scope.data" @editSuccess="onSuccess"></filteringEdit>
          <el-popconfirm
              title="确定删除改内容吗？"
              @confirm="onDel(scope.data)"
          >
            <el-button type="text" size="mini" slot="reference">删除</el-button>
          </el-popconfirm>
        </template>
      </tableLayout>
      <div  class="container normal-panel" style="text-align:right">
        <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[20, 50, 100, 200]"
            layout="total,sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import filteringAdd from './filteringAdd'
import filteringEdit from './filteringEdit'
export default {
  name: "dataFiltering",
  components:{filteringAdd,filteringEdit},
  data(){
    return {
      tablecols:[],
      list:[],
      tableHieght:600,
      total:0,
      currentPage:0,
      param:{
        "id": 20230216181301,
        "content": {
          "pageSize":20,
          "pageNumber":1,
          "roleid": this.$route.query.id
        }
      }
    }
  },
 methods:{
    async listData(){
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      console.log(this.list,'表格数据')
    },
   onSuccess(){
     this.listData()
   },
   handleSizeChange(val) {
     // console.log(`每页 ${val} 条`);
     this.param.content.pageSize = val
     this.listData()
   },
   handleCurrentChange(val) {
     // console.log(`当前页: ${val}`);
     this.param.content.pageNumber = val
     this.listData()
   },
   async onDel(row){
      const res = await this.$api.requested({
       "id": 20230216181401,
       "content": {
          "roleid": this.$route.query.id,
         "sys_role_datalimitids": [row.sys_role_datalimitid]
        }
      })
     this.tool.showMessage(res,()=>{
       this.listData()
     })
   }
 },
  mounted() {
    this.listData()
  },
  created () {
    this.tablecols = this.tool.tabelCol(this.$route.name).dataFilteringTable.tablecols
  },
}
</script>

<style scoped>

</style>