<template>
  <div>
    <el-popover
        :placement="placement || 'bottom-start'"
        width="900"
        v-model="show"
        trigger="click">
      <el-input  style="width:200px;margin-bottom: 10px" :placeholder="$t('搜索')" :suffix-icon="param.content.where.condition?param.content.where.condition.length > 0?'':'':'el-icon-search'" v-model="param.content.where.condition" @keyup.native.enter="listData(param.content.pageNumber = 1)" @clear="clearSearchValue" size="small" class="input-with-select inline-16 layout_search__panel" clearable>
      </el-input>
      <el-table
          border
          height="500px"
          :data="list"
          @row-click="contactSelect"
          :header-cell-style="{background:'#EEEEEE',color:'#333'}"
          size="mini">
        <el-table-column width="80" :label="$t(`姓名`)">
          <template slot-scope="scope">
            <span >{{ scope.row.name?scope.row.name:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="120" :label="$t(`联系方式`)">
          <template slot-scope="scope">
            <span >{{ scope.row.phonenumber?scope.row.phonenumber:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="200"  :label="$t(`邮箱`)">
          <template slot-scope="scope">
            <span >{{ scope.row.email?scope.row.email:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="200"  :label="$t(`单位`)">
          <template slot-scope="scope">
            <span >{{ scope.row.enterprisename?scope.row.enterprisename:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="120"  :label="$t(`部门`)">
          <template slot-scope="scope">
            <span >{{ scope.row.position?scope.row.position:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="120"  :label="$t(`职位`)">
          <template slot-scope="scope">
            <span >{{ scope.row.depname?scope.row.depname:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="80"  :label="$t(`性别`)">
          <template slot-scope="scope">
            <span >{{ scope.row.sex?scope.row.sex:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="120"  :label="$t(`生日`)">
          <template slot-scope="scope">
            <span >{{ scope.row.birthday?scope.row.birthday:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="300"  :label="$t(`家庭住址`)">
          <template slot-scope="scope">
            <span >{{ scope.row.address?scope.row.address:'--' }}</span>
          </template>
        </el-table-column>
        <el-table-column width="200"  :label="$t(`备注`)">
          <template slot-scope="scope">
            <span >{{ scope.row.remarks?scope.row.remarks:'--' }}</span>
          </template>
        </el-table-column>
      </el-table>
      <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]"
            :page-size="20"
            layout="total,sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
      <el-input  slot="reference" :readonly="isReadonly" autosize v-model="name?name:nameValue" :placeholder="$t('请填写联系人')" @focus="listData"  :disabled="disabled" @change="inputChange"></el-input>
    </el-popover>
  </div>
</template>

<script>
export default {
  name: "index",
  props:['disabled','ownertable','ownerid','name','placement','isParam','newParam','isReadonly','phonenumber'],
  data(){
    return {
      list:[],
      show:false,
      currentPage:0,
      total:0,
      param:{
        "id": 20240531152004,
        "content": {
          "phonenumber":'',
          "ownertable":"sa_project",// 客户 sys_enterprise  项目 sa_project
          "ownerid":"7074",// 客户 sys_enterpriseid  项目 sa_projectid
          "pageNumber": 1,
          "pageSize": 20,
          "where":{
            "condition":""
          }
        }
      },
      nameValue:''
    }
  },
  methods:{
    async listData(){
      console.log('激活')
      console.log(this.phonenumber,'手机号')
      if (this.isParam){
        this.param = this.newParam
      }else {
        this.param.content.ownertable = this.ownertable
        this.param.content.ownerid = this.ownerid
      }
      if (this.phonenumber) {
        this.param.content.phonenumber = this.phonenumber
      }
      const res = await this.$api.requested(this.param)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    contactSelect(val){
      this.nameValue = val.name
      this.show = false
      this.param.content.where.condition = ''
      this.$emit('contactData',val)
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
    inputChange(){
      this.$emit('inputChange',this.nameValue)
    },
    clearSearchValue () {
      this.$store.dispatch('clearSearchValue')
      this.listData(this.param.content.pageNumber = 1)
    }
  },
  mounted() {
  },
  watch:{
    'show':function (val){
      if (!val){
        this.param.content.where.condition = ''
      }
    },
    'name':function (val){
      val?this.nameValue = val:this.nameValue = ''
    }
  }
}
</script>

<style scoped>
/deep/ .el-input__validateIcon {
  display: none;
}
</style>
