<!--
  @description:供应商审批报表
  @Modifier: zhangyawen
  @routerPath: /statisticalManagement/supplierApproval-list
  @date: 2021-4-19-16:20
-->
<template>
  <table-crud
    :menu="true"
    :search-form="searchForm"
    search-label-width="100px"
    @on-load="loadData"
  >
    <template v-slot:header>
      供应商审批报表
    </template>
    <template v-slot:search="search">
      <el-form-item label="供应商名称" prop="supplierName">
        <el-input
          v-model.trim="searchForm.supplierName"
          placeholder="供应商名称"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="供应商类型" prop="supplierType">
        <el-select
          v-model="searchForm.supplierType"
          placeholder="供应商类型"
        >
          <el-option
            v-for="item in supplierAuditTypeList"
            :key="item.typecode"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="业务类型" prop="businessType">
        <el-select
          v-model="searchForm.businessType"
          placeholder="业务类型"
        >
          <el-option
            v-for="item in supplierAuditBusinessTypeList"
            :key="item.typecode"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="供应商管理员" prop="supplierManager">
        <el-input
          v-model.trim="searchForm.supplierManager"
          placeholder="供应商管理员"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="供应商提交时间" prop="submitDate">
        <el-date-picker
          v-model="searchForm.submitDate"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="(val) => {handleCreateTime(val, 'supplierSubmitTimeStart', 'supplierSubmitTimeEnd');}"
        />
      </el-form-item>
      <el-form-item label="审批完成时间" prop="passDate">
        <el-date-picker
          v-model="searchForm.passDate"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="(val) => {handleCreateTime(val, 'supplierPassTimeStart', 'supplierPassTimeEnd');}"
        />
      </el-form-item>
      <el-form-item label="供应商管理员通过时间" prop="managerPassDate">
        <el-date-picker
          v-model="searchForm.managerPassDate"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="(val) => {handleCreateTime(val, 'supplierManagerPassTimeStart','supplierManagerPassTimeEnd');}"
        />
      </el-form-item>
    </template>
    <template slot="menuLeft">
      <div class="mb10">
        <el-button type="primary" @click="exportAll">
          导出
        </el-button>
      </div>
    </template>
    <template v-slot:GXTable>
      <el-table ref="smallTable" v-loading="loading" :data="tableData">
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="supplierName"
          label="供应商名称"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="supplierType"
          label="供应商类型"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="businessType"
          label="业务类型"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="supplierSubmitTime"
          label="供应商提交时间"
          min-width="170"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="supplierManager"
          label="供应商管理员"
          min-width="170"
        />
        <el-table-column
          header-align="center"
          prop="supplierManagerPassTime"
          label="供应商管理员审核通过时间"
          min-width="170"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="supplierPassTime"
          label="审批完成时间"
          min-width="150"
          align="center"
        />
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* 接口*/
import { getProcurementSupplierAuditStatistics, downProcurementSupplierAuditStatistics } from '@api/procurement/statisticalManagement'
import { statisticalMixins } from '../../mixins/statisticalMixins'// 字典信息
import { download } from '@/assets/js/utils'// 常用方法
export default {
  name: 'PurchaseOrderList',
  mixins: [statisticalMixins],
  data() {
    return {
      loading: true,
      // 搜索
      searchForm: {
        supplierName: '', // 供应商名称
        supplierType: '', // 供应商类型
        businessType: '', // 业务类型
        supplierManager: '', // 供应商管理员
        submitDate: [], // 供应商提交时间
        supplierSubmitTimeStart: '', // 供应商提交时间-开始
        supplierSubmitTimeEnd: '', // 供应商提交时间-结束
        passDate: [], // 审批完成时间
        supplierPassTimeStart: '', // 审批完成时间-开始
        supplierPassTimeEnd: '', // 审批完成时间-结束
        managerPassDate: [], // 供应商管理员通过时间
        supplierManagerPassTimeStart: '', // 供应商管理员通过时间-开始
        supplierManagerPassTimeEnd: '' // 供应商管理员通过时间-结束
      },
      tableData: [],
      queryObj: {}
    }
  },
  created() {
  },
  methods: {
    // 导出
    exportAll() {
      if (this.tableData.length <= 0) {
        this.$message.warning('没有可导出的数据')
        return false
      } else {
        downProcurementSupplierAuditStatistics(this.queryObj).then((res) => {
          download(res, '供应商审批报表.xls')
        })
      }
    },
    // 获取数据
    loadData(params, callback) {
      delete params.submitDate
      delete params.passDate
      delete params.managerPassDate
      this.queryObj = params
      getProcurementSupplierAuditStatistics(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 处理搜索时间格式
    handleCreateTime(val, start, end) {
      if (val) {
        this.searchForm[start] = this.$Moment(val[0]).format(this.momentDate) // 开始时间
        this.searchForm[end] = this.$Moment(val[1]).format(this.momentDate) // 结束时间
      }
    }
  }
}
</script>

<style  lang="less" scoped>
</style>

