<!--
  @description:采购单报表
  @Modifier: zhangyawen
  @routerPath: /statisticalManagement/purchaseOrder-list
  @date: 2021-4-19-15:40
-->
<template>
  <table-crud
    :menu="true"
    :search-form="searchForm"
    search-label-width="90px"
    :page-flag="false"
    @on-load="loadData"
  >
    <template v-slot:header>
      采购单报表
    </template>
    <template v-slot:search>
      <el-form-item label="统计时间" prop="timeDate">
        <el-date-picker
          v-model="searchForm.timeDate"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="(val) => {handleCreateTime(val, 'statisticsTimeStart', 'statisticsTimeEnd');}"
        />
      </el-form-item>
      <el-form-item label="采购方式" prop="tenderMethod">
        <el-select
          v-model="searchForm.tenderMethod"
          placeholder="采购方式"
        >
          <el-option
            v-for="item in tender_methodList"
            :key="item.typecode"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否框架" prop="planType">
        <el-select
          v-model="searchForm.planType"
          placeholder="是否框架"
        >
          <el-option
            v-for="item in isFramePlanList"
            :key="item.typecode"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </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" show-summary :summary-method="getSum">
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="sourcingUserRealName"
          label="采购员"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="projectSubmitNum"
          label="发起公告审批个数"
          width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="projectPassNum"
          label="采购单发出个数"
          width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="orderNum"
          label="生成订单个数"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="orderDetailsNum"
          label="生成订单行项目数"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="winningMoney"
          label="中选净总价（元）"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="winningSubmitNum"
          label="发起结果审批个数"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="winningPassNum"
          label="完成结果审批个数"
          min-width="170"
          align="right"
        />
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* 接口*/
import { getProcurementProjectStatisticsReport, downProcurementProjectStatisticsReport } 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: {
        timeDate: [], // 统计时间
        statisticsTimeStart: '', // 统计时间-开始
        statisticsTimeEnd: '', // 统计时间-结束
        tenderMethod: '', // 采购方式
        planType: '' // 是否框架
      },
      tableData: [],
      searchParams: {} // 入参
    }
  },
  created() {
  },
  methods: {
    // 导出
    exportAll() {
      downProcurementProjectStatisticsReport(this.searchParams).then(res => {
        download(res, '采购单报表.xls')
      })
    },
    // 获取数据
    loadData(params, callback) {
      delete params.timeDate
      delete params.pageNo
      delete params.pageSize
      this.searchParams = params
      getProcurementProjectStatisticsReport(params).then(response => {
        this.loading = false
        this.tableData = response.data
      }).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) // 结束时间
      }
    },
    getSum(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        /*     switch(column.property) {
          case "money":
            sums[index] = (this.footer.moneySum / 100).toFixed(2) + '元’; //值取自后台
            break;
          case "profit":
            sums[index] = this.footer.profitSum / 100 + '元’; //值取自后台
            break;
          default:
            break;
        }*/
      })
      return sums
    }
  }
}
</script>

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

