<template>
  <div>
    <el-dialog
        title="选择联系人"
        :visible.sync="dialogProjectVisible"
        append-to-body
        width="900px"
        @close="onColes">
      <div class="panel_Target">
        <el-input style="width:200px;margin-top: 10px;margin-bottom: 15px" placeholder="请输入搜索内容" suffix-icon="el-icon-search" @input="selectChange" v-model="param.content.where.condition" @keyup.native.enter="contactsList(param.content.pageNumber = 1)" @clear="contactsList(param.content.pageNumber = 1)" size="small" class="input-with-select inline-16 layout_search__panel" clearable>
        </el-input>
        <tableLayout  ref="list" :layout="tablecols" :data="list" :custom="true" >
          <template v-slot:customcol="scope">
            <p >{{scope.column.data[scope.column.columnname]}}</p>
          </template>
          <template v-slot:opreation="scope">
            <el-button type="text" size="mini" @click="selectProject(scope.data)">选择该联系人</el-button>
          </template>
        </tableLayout>
        <div class="container normal-panel" style="text-align:right">
          <el-pagination
              background
              small
              @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>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "contactsTable",
  props:["contactsDrawer","id"],
  data(){
    return {
      tablecols:'',
      list:[],
      total:0,
      currentPage:0,
      dialogProjectVisible:false,
      param:{
        "id": "20221022165503",
        "version": 1,
        "content": {
          "sys_enterpriseid":"",
          "where": {
            "condition": "",
            "workaddress": 0//0表示人，1表示地址
          }
        }
      }
    }
  },
  methods:{
    async contactsList(){
      this.param.content.sys_enterpriseid = this.id
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.contactsList()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.contactsList()
    },
    selectProject(val){
      this.$emit('contactsData',val)
      this.dialogProjectVisible = false

    },
    onColes(){
      this.dialogProjectVisible = false
      this.$emit('contactsList')
    },
    selectChange(){
      this.projectList()
    }
  },
  mounted() {
    if (this.contactsDrawer){
      this.dialogProjectVisible = true
      this.contactsList()
    }
  },
  created() {
    this.tablecols = this.tool.tabelCol(this.$route.name).contactsTable.tablecols
  }
}
</script>

<style scoped>

</style>