<template>
  <div> 
    <el-dialog :visible.sync="visible" append-to-body width="50%">
      <el-tabs v-model="param.content.where.type" @tab-click="listData">
        <el-tab-pane label="客户" name="7"></el-tab-pane>
        <el-tab-pane label="经销商" name="5"></el-tab-pane>
      </el-tabs>
      <div class="flex-align-center mt-10">
        <el-input 
          style="width:200px" 
          size="small"  
          suffix-icon="el-icon-search" 
          placeholder="搜索" 
          v-model="param.content.where.condition"
          @keyup.enter.native="listData(param.content.pageNumber = 1)" 
          @clear="listData(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="经销商名称"
            width="180">
          </el-table-column>
          <el-table-column
            prop="agentnum"
            label="经销商编号"
            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="param.content.pageNumber"
            :page-size="param.content.pageSize"
            layout="total, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </div>
    </el-dialog>
    <slot name="input"></slot>
  </div>
</template>

<script>
export default {
  props:[],
  data () {
    return {
      visible:false,
      param:{
        "id":20220920083901,
        "content": {
            "pageNumber": 1,
            "pageSize": 20,
            "where": {
                "condition": "",
                "type":"7"
            }
        }
      },
      tableData: [],
      total:0,
      condition:'',
      currentPage:0
    }
  },
  watch: {
  
  },
  methods:{
    radioChange (data) {
      this.param.content.where.type = data
      this.listData()
    },
    async listData () {
      const res = await this.$api.requested(this.param)
      this.tableData = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      console.log(this.tableData);
      
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val
      this.listData()
    },
    selectRow (row) {
      this.$emit('selectRow',row)
      this.visible = false
    }
  },
  created () {
    this.listData()
  },
}

</script>
<style>
</style>