<template>
  <div class="container normal-panel">
    <el-form size="small" inline label-position="left" label-width="50px" :model="params.content.where">
      <el-form-item label="搜索">
        <el-input v-model="params.content.where.condition" prefix-icon="el-icon-search" placeholder="客户名称,手机号" @keyup.native.enter="listData(params.content.pageNumber = 1)" @clear="listData(params.content.pageNumber = 1)" clearable></el-input>
      </el-form-item>&emsp;
      <el-form-item label="状态">
        <el-select v-model="params.content.where.status" placeholder="请选择" clearable @change="listData(params.content.pageNumber = 1)">
          <el-option
            v-for="item in sys_options"
            :key="item.index"
            :label="item.value"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <tableLayout :layout="tablecols" :data="list" :custom="true" :height="tableHieght">
      <template v-slot:customcol="scope">
        <div v-if="scope.column.columnname === 'status'">
          <span v-if="scope.column.data.status === '待分配'" style="color:#3874F6">{{scope.column.data.status}}</span>
          <span v-if="scope.column.data.status === '待跟进'" style="color:#FA8C16">{{scope.column.data.status}}</span>
          <span v-if="scope.column.data.status === '跟进中'" style="color:#52C41A">{{scope.column.data.status}}</span>
          <span v-if="scope.column.data.status === '已过期'" style="color:#999999">{{scope.column.data.status}}</span>
          <span v-if="scope.column.data.status === '丢单'" style="color:#FF3B30">{{scope.column.data.status}}</span>
          <span v-if="scope.column.data.status === '已成交'" style="color:#333333">{{scope.column.data.status}}</span>
          <span v-if="scope.column.data.status === '无效'" style="color:#333333">{{scope.column.data.status}}</span>
        </div>
        <div v-else-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="detail" :data="scope"></slot>
        <slot name="edit" :data="scope"></slot>
        <slot name="recall" :data="scope"></slot>
        <slot name="data_statistics" :data="scope"></slot>
        <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>
import {mapGetters} from 'vuex'

export default {
  data () {
    return {
      params:{
        "classname": "webmanage.saletool.orderclue.publicclue.PublicClue",
        "method": "selectList",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
              "condition": "",
              "status": ""
          }
        }
      },
      options:[],
      tablecols:[],
      list:[],
      total:0,
      currentPage:0
    }
  },
  computed:{
    ...mapGetters({
      sys_options:'sys_options'
    })
  },
  methods:{
    async listData () {
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber

      this.$store.dispatch('optiontypeselect','cluepublic')
    },
    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)['cluePublicTable'].tablecols
  }
}

</script>

<style>
.el-form-item {
  margin-bottom: 16px !important;
}
</style>