<template>
  <div class="container normal-panel">
    <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-item label="状态">
        <el-select v-model="search.status" placeholder="请选择" @change="listData(params.content.pageNumber = 1)" clearable>
          <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-item label="类型">
        <el-select v-model="search.cluetype" placeholder="请选择" @change="listData(params.content.pageNumber = 1)" clearable>
          <el-option label="经销商" value="经销商">
          </el-option>
          <el-option label="业务员" 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 :style="scope.column.data.status === '待审核'?'color:#3874F6':''">{{scope.column.data.status}}</span>
        </div>
        <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <slot name="detail" :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 {
  computed:{
    ...mapGetters({
      sys_options:'sys_options'
    })
  },
  data () {
    return {
      params:{
        "classname":"webmanage.saletool.orderclue.orderclue",
        "method": "queryOrderclueuploadbillList",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "where":{
            "condition":"",
            "status":"",
            "cluetype":""
          }
        }
      },
      search:{},
      options:[],
      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
      sessionStorage.setItem('clue_pageTotal',this.total)

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

</script>

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