<!--
  @description:计划准确率统计表
  @Modifier: haoFx
  @routerPath:/statisticalManagement/planAccuracyStatistics-list
  @date: 2021-05-24-20:14
-->
<template>
  <table-crud
    :menu="true"
    :search-form="searchForm"
    search-label-width="auto"
    :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="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="belongBk">
        <el-select v-model="searchForm.belongBk" placeholder="所属板块">
          <el-option
            v-for="item in belong_bkList"
            :key="item.typecode"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="采购单位" prop="purchaseDepartName">
        <el-input
          v-model.trim="searchForm.purchaseDepartName"
          placeholder="采购单位"
          @keyup.enter.native="search.onSearch"
        />
      </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="是否价格偏差正负超过正负50%" 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>
      <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">
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="purchaseNo"
          label="行项目编号"
          align="center"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="purchaseCode"
          label="物资编号"
          align="center"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="purchaseName"
          label="物资名称"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="purchaseDepartName"
          label="采购单位"
          min-width="170"
        />
        <el-table-column
          :formatter="formatterBelongBk"
          header-align="center"
          prop="belongBk"
          label="所属板块"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="purchaseUserRealName"
          label="上报人"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="是否退回计划"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="预算净单价（元）"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="预算净总价（元）"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="订单行项目净单价（元）"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="订单行项目净总价（元）"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="订单行项目净单价-预算净单价"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="是否价格偏差超过正负50%"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="计划上报审批时间"
          align="center"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="订单生成时间"
          align="center"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="订单生效时间"
          align="center"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop=""
          label="是否准确"
          align="center"
          width="170"
        />
      </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>

