<template>
  <div>
    <el-dialog title="添加经销商" :visible.sync="dialogTableVisible" width="800px">
      <tablelayout :layout="tablecols" :data="list" :custom="true" :checkbox="true" height="calc(100vh - 452px)" @checkboxCallBack="checkboxCallBack">
        <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>
      </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 class="dialog-footer">
        <el-button size="small" @click="dialogTableVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" :disabled="selection.length === 0" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import tablelayout from '@/components/table/index.vue'
export default {
  components:{
    tablelayout
  },
  data () {
    return {
      dialogTableVisible:false,
      params:{
        "classname":"webmanage.saletool.orderclue.ordercluerule",
        "method": "queryAgent",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where":{
            "condition":""
          }
        }
      },
      selection:[],
      tablecols:[],
      list:[],
      total:0,
      currentPage:0
    }
  },
  methods:{
    onShow () {
      this.dialogTableVisible = true
      this.listData()
    },
     async listData () {
      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()
    },
    checkboxCallBack (val) {
      console.log(val)
      this.selection = val
    },
    async onSubmit () {
      const res = await this.$api.requested({
        "classname":"webmanage.saletool.orderclue.ordercluerule",
        "method": "insertOrderclueruleArea",
        "content": {
          "cluetype":"经销商",
          "sat_orderclue_areas":this.selection
        }
      })
      this.tool.showMessage(res,()=>{
        this.dialogTableVisible = false
        this.$emit('onSuccess')
      })
    },
  },
  created () {
    //获取表结构
    this.tablecols = this.tool.tabelCol(this.$route.name)['agentTable'].tablecols
  }
}

</script>
<style>
</style>