<template>
  <div>
    <el-popover
      placement="bottom"
      width="100%"
      v-model="visible">
      <div>
        <div class="flex-align-center flex-between" style="margin-bottom:10px">
          <el-input style="width:200px" suffix-icon="el-icon-search" size="small" v-model="params.content.where.condition" placeholder="输入经销商信息" @keyup.enter.native="queryEnterpriseArchives(params.content.pageNumber = 1)" @clear="queryEnterpriseArchives(params.content.pageNumber = 1)" clearable></el-input>
          <addTemp @onSuccess="onSuccess"></addTemp>
        </div>
        <el-table
          :data="ENlist"
          size="small"
          stripe
          style="width: 100%"
          height="300"
          border>
          <el-table-column
            prop="enterprisename"
            :label="qiyi ? '企业名称' : '经销商名称'"
            width="180">
          </el-table-column>
          <el-table-column
            prop="contact"
            label="联系人"
            width="180">
          </el-table-column>
          <el-table-column
            prop="phonenumber"
            label="联系电话"
            width="180">
          </el-table-column>
          <el-table-column>
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="rowClick(scope.row)">选 择</el-button>
            </template>
          </el-table-column>
        </el-table>
        <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>
      <el-button v-if="showType === 'button'"  slot="reference" type="primary" size="mini" @click="queryEnterpriseArchives">选择企业</el-button>
      <el-input v-else readonly :validate-event="false" slot="reference" v-model="form.enterprisename" @focus="queryEnterpriseArchives"  placeholder="输入经销商信息" clearable></el-input>
    </el-popover>
  </div>
</template>

<script>
import addTemp from '@/Form/EnterpriseArchives/add.vue'
export default {
  components:{
    addTemp
  },
  props:['type','qiyi','showType'],
  data () {
    return {
      ENlist:[],
      total:0,
      currentPage:0,
      form:{
        enterprisename:''
      },
      params:{
        "id": 20220920083901,
        "content": {
          "pageNumber": 1,
          "pageSize": 10,
          "where": {
            "condition": '',
            "type":''
          },
          "sort":[{
            "sortname":"默认",
            "sorted":1,
            "sortid":56,
            "reversed":1
          }],
        }
      },
      visible:false
    }
  },
  methods:{
    async queryEnterpriseArchives () {
      if (this.type) this.params.content.where.type = this.type
      const res = await this.$api.requested(this.params)
      this.ENlist = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      this.params.content.pageSize = val
      this.queryEnterpriseArchives()
    },
    handleCurrentChange(val) {
      this.params.content.pageNumber = val
      this.queryEnterpriseArchives()
    },
    rowClick (row) {
      this.visible = false
      this.form.enterprisename = row.enterprisename
      this.$emit('rowClick',row)
    },
    onSuccess () {
      this.queryEnterpriseArchives()
      this.form.enterprisename = this.ENlist[0].enterprisename
      this.$emit('rowClick',this.ENlist[0])
    }
  },
  mounted () {
    // this.queryEnterpriseArchives()
  }
}

</script>
<style>
</style>