<template>
  <div class="app-container" v-if="isShow">
    <div class="screen-container">
      <Collapse :screen-form="screenForm">
        <template #right_btn>
          <el-button size="mini" @click="resetScreenForm">清空</el-button>
          <el-button type="primary" size="mini" @click="submitScreenForm">搜索</el-button>
        </template>
        <template #search>
          <el-form
            size="mini"
            :model="screenForm"
            ref="screenForm"
            :inline="false"
            label-position="left"
            label-width="120px"
          >
            <el-row :gutter="20">
              <el-col :xs="24" :sm="8" :lg="8">
                <el-form-item prop="code" label="销售政策编号">
                  <el-input size="mini" v-model="screenForm.code" placeholder="销售政策编号"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :lg="8">
                <el-form-item prop="remark" label="销售政策说明">
                  <el-input size="mini" v-model="screenForm.remark" placeholder="销售政策说明"></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="8" :lg="8">
                <el-form-item prop="title" label="表头备注">
                  <el-input size="mini" v-model="screenForm.title" placeholder="表头备注"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </Collapse>
    </div>
    <!--    <div class="btn-group">-->
    <!--      <el-row type="flex">-->
    <!--        <el-button type="primary" size="mini" @click="">导出</el-button>-->
    <!--      </el-row>-->
    <!--    </div>-->
    <div class="mymain-container">
      <div class="table">
        <el-table :data="dataList" border>
          <el-table-column prop="name" label="操作" width="120" align="center" class="table">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click=";(id = scope.row.id), (isShow = false)">详情</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态" width="120" align="left">
            <template slot-scope="scope">
              <el-tag type="success" size="mini" v-if="scope.row.status == 1">已生效</el-tag>
              <el-tag type="danger" size="mini" v-else>未生效</el-tag>
            </template>
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="200" prop="code" label="销售政策编号" align="left">
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" prop="title" label="销售政策说明" align="left">
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="150" prop="title" label="表头备注" align="left">
          </el-table-column>
          <el-table-column
            show-overflow-tooltip
            min-width="150"
            prop="customerCount"
            label="关联经销商"
            width="150"
            align="left"
          >
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="200" prop="startTime" label="生效日期" align="left">
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="200" prop="endTime" label="结束日期" align="left">
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="200" prop="createBy" label="制表人" align="left">
          </el-table-column>
          <el-table-column show-overflow-tooltip min-width="200" prop="createTime" label="制表日期" align="left">
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="fr">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 50, 500]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listTotal"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
  <Distributor v-else :cid="id" />
</template>

<script>
import { getCustomerlist } from '@/api/policy_list'
import Minxin from '@/mixin'
import Distributor from './components/Distributor'

export default {
  mixins: [Minxin],
  data() {
    return {
      isCollapse: true,
      isShow: true,
      id: '',
      input: '',
      dataList: [],
      screenForm: {
        code: '',
        remark: '',
        title: ''
      }
    }
  },
  methods: {
    getList() {
      this.listLoading = true
      const params = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        code: this.screenForm.code,
        remark: this.screenForm.remark,
        title: this.screenForm.title
      }
      getCustomerlist(params).then(res => {
        console.log(res)
        this.dataList = res.data.records
        this.listTotal = res.data.total
        this.listLoading = false
      })
    }
  },
  components: {
    Distributor
  }
}
</script>

<style lang="scss" scoped>
.mg {
  margin: 20px 0;
}
.app-main {
  margin-top: 100%;
}
.btn {
  text-align: right;
}
</style>
