<template>
  <div class="container normal-panel">
    <p class="normal-title normal-margin">经销商目录</p>
    <div class="flex-align-center flex-between">
      <el-form size="small" inline label-position="left" label-width="50px" :model="search">
        <el-form-item label="搜索">
          <el-input v-model="search.condition" prefix-icon="el-icon-search" placeholder="标号,经销商名称" @clear="listData(params.content.pageNumber = 1)" @keyup.native.enter="listData(params.content.pageNumber = 1)" clearable></el-input>
        </el-form-item>
      </el-form>
      <slot name="add"></slot>
    </div>
    <tableLayout :layout="tablecols" :data="list" :custom="true" height="calc(100vh - 452px)">
      <template v-slot:customcol="scope">
        <div v-if="scope.column.columnname === 'province'">
          <span>{{scope.column.data.province}} - {{scope.column.data.city}} - {{scope.column.data.county}}</span>
        </div>
        <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <slot name="del" :data="scope"></slot>
      </template>
    </tableLayout>
    <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>
</template>

<script>
export default {
  data () {
    return {
      params:{
        "classname":"webmanage.saletool.orderclue.ordercluerule",
        "method": "queryOrderclueruledetail",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where":{
            "condition":""
          }
        }
      },
      search:{},
      tablecols:[],
      list:[],
      total:0,
      currentPage:0
    }
  },
  methods:{
    async listData () {
      this.params.content.where = this.search
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
  },
  mounted () {
    this.listData()
  },
  created () {
    //获取表结构
    this.tablecols = this.tool.tabelCol(this.$route.name)['agentTable'].tablecols
  }
}

</script>
<style>
</style>