<template>
  <div>
    <div>
      <add v-if="tool.checkAuth($route.name,'contactsManage') && data.disabled"  class="inline-16" :data="data" @insertSuccess="onSuccess"></add>
      <el-input
          placeholder="请输入搜索内容"
          suffix-icon="el-icon-search"
          v-model="search"
          style="width:200px"
          size="small"
          class="input-with-select inline-16"
          @keyup.native.enter="queryClick"
          @clear="clearData"
          clearable>
      </el-input>
    </div>
    <div style="margin-top: 15px">
      <tableLayout :layout="tablecols" :data="list" :opwidth="200" :custom="true"  fixedName="operation">
        <template v-slot:customcol="scope">
          <div v-if="scope.column.columnname === 'operation'">
            <span>{{scope.column.data[scope.column.columnname]}}</span>
          </div>
          <p v-else>{{scope.column.data[scope.column.columnname]?scope.column.data[scope.column.columnname]:'--'}}</p>
        </template>
        <template v-slot:opreation="scope">
          <edit  :data="scope.data" class="inline-16" @editSuccess="onSuccess" :disabled="data.disabled"></edit>
          <delContact  :data="scope.data" @delSuccess="onSuccess" class="inline-16" :disabled="data.disabled"></delContact>
        </template>
      </tableLayout>
    </div>
    <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 './components/add'
import edit from './components/edit'
import delContact from './components/delContact'
export default {
  name: "index",
  props:["data"],
  data() {
    return {
      search:"",
      tablecols:[],
      list:[],
      total:0,
      currentPage:0,
      params:{
        "id": 20221111131004,
        "content": {
          "sa_projectid": '',
          "pageNumber": 1,
          "pageSize": 20,
          "where":{
            "conditino":""
          }
        }
      }
    }
  },
  components:{add,edit,delContact},
  methods:{
    async listData(){
      this.params.content.where.condition = this.search
      this.params.content.sa_projectid = this.data.sa_projectid
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    queryClick(){
      this.params.content.pageNumber = 1
      this.listData()
    },
    clearData(){
      this.search = ''
      this.listData()
    },
    onSuccess(){
      this.listData()
    }
  },
  mounted() {
    this.listData()
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).contactsTable.tablecols
  }
}
</script>

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