<template>
  <div>
    <add class="normal-margin" :data="data"  @insertSuccess="onSuccess" style="float: left;"></add>
    <div style="width: 20%;float: left;margin-left: 2%">
      <el-input
          placeholder="请输入内容"
          v-model="search"
          clearable
          @clear="clearData()"
          size="mini"
          @keyup.enter.native="queryClick()">
        <i slot="prefix" class="el-icon-search" @click="queryClick()"></i>
      </el-input>
    </div>
    <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  :height="tableHieght" >
      <template v-slot:customcol="scope">
        <p>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <edit v-if="tool.checkAuth($route.name,'update')" :data="scope.data" @updateSuccess="onSuccess"></edit>
        <toVoid v-if="tool.checkAuth($route.name,'toVoid')" :data="scope.data" @toVoidSuccess="onSuccess"></toVoid>
      </template>
    </tableLayout>
    <div style="margin-top:16px;text-align:right">
      <el-pagination
          background
          small
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="params.content.pageSize"
          layout="total, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import add from './modules/add'
import edit from './modules/edit'
import toVoid from './modules/toVoid'
import {mapGetters} from 'vuex'
export default {
  name: "list",
  props:["data"],
  data(){
    return {
      tableHieght:"600px",
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      search:"",
      params:{
        "id": "20221022165503",
        "content": {
          "sys_enterpriseid": "",
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
            "condition": "",
            "workaddress":0
          }
        }
      }
    }
  },
  components:{
    add,edit,toVoid
  },
  computed:{
    ...mapGetters({
      dataToForm:'dataToForm'
    })
  },
  methods:{
    async listData(){
      this.params.content.sys_enterpriseid = this.data.sys_enterpriseid
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageTotal
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData(data)
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData(data)
    },
    onSuccess(){
     this.listData()
    },
    clearData(){
      this.search = ""
    },
    queryClick(){
      this.params.content.where.condition = this.search
      this.listData()
    }
  },
  mounted() {
    this.listData()
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).contactsTable.tablecols
  },
  watch:{
    "dataToForm":function (val){
      console.log(val)
    }
  }
}
</script>

<style scoped>
/deep/.el-input__prefix {
  display: flex;
  align-items: center;
}

</style>