<template>
  <div> 
    <el-dialog :visible.sync="visible" append-to-body width="50%">
      <div class="flex-align-center flex-between mt-10">
        <el-input 
          style="width:200px" 
          size="small"  
          suffix-icon="el-icon-search" 
          placeholder="搜索" 
          @input="valueChange"
          v-model="condition"
          @keyup.enter.native="listData(customParam ? customParam.content.pageNumber = 1 : param.content.pageNumber = 1)" 
          @clear="listData(customParam ? customParam.content.pageNumber = 1 : param.content.pageNumber = 1)" clearable></el-input>
      </div>
      <div>
        <el-table
          ref="multipleTable"
          :data="tableData"
          style="width: 100%"
          size="mini"
          height="50vh"
          border>
          <el-table-column
            prop="enterprisename"
            :label="qiyi ? '企业名称' : '经销商名称'"
            width="180">
          </el-table-column>
          <el-table-column
            prop="agentnum"
            :label="qiyi ? '编号' : '经销商编号'"
            width="180">
          </el-table-column>
          <el-table-column
            prop="contact"
            label="联系人">
          </el-table-column>
          <el-table-column
            label="地址">
            <template slot-scope="scope">
              {{scope.row.province}}{{scope.row.city}}{{scope.row.county}}{{scope.row.address}}
            </template>
          </el-table-column>
          <el-table-column
            label="操作">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="selectRow(scope.row)">选 择</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div style="margin-top:16px;text-align:right">
          <el-pagination
            background
            small
            @current-change="handleCurrentChange"
            :current-page="customParam ? customParam.content.pageNumber : param.content.pageNumber"
            :page-size="customParam ? customParam.content.pageSize : param.content.pageSize"
            layout="total, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
    </el-dialog>
    <slot name="input"></slot>
  </div>
</template>

<script>
import { log } from '@antv/g2plot/lib/utils'
export default {
  props:['customParam','qiyi'],
  data () {
    return {
      visible:false,
      param:{
        "classname": "webmanage.sale.agents.agents",
        "method": "query_agentList",
        "content": {
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": ""
            }
        }
      },
      tableData: [],
      total:0,
      condition:'',
      currentPage:0
    }
  },
  methods:{
    async listData () {
      const res = await this.$api.requested(this.customParam ? this.customParam : this.param)
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      // console.log(this.tableData);
      
    },
    valueChange (data) {
      console.log(data);
      if (this.customParam) {
        this.customParam.content.where.condition = data
      } else {
        this.param.content.where.condition = data
      }
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      if (this.customParam) {
        this.customParam.content.pageNumber = val
      } else {
        this.param.content.pageNumber = val
      }
      this.listData()
    },
    selectRow (row) {
      this.$emit('selectRow',row)
    }
  },
  created () {
    this.listData()
  },
}

</script>
<style>
</style>