<!--
  @description: 采购计划明细报表
  @Modifier: haoFx
  @routerPath:/statisticalManagement/procurementPlanDetails-list
  @date: 2021-05-25-17:52
-->
<template>
  <table-crud
    :menu="true"
    :search-form="searchForm"
    search-label-width="auto"
    @on-load="loadData"
  >
    <template v-slot:header>
      采购计划明细表
    </template>
    <template v-slot:search="search">
      <el-form-item label="行项目编号" prop="purchaseNo">
        <el-input
          v-model.trim="searchForm.purchaseNo"
          placeholder="行项目编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="物资编号" prop="purchaseCode">
        <el-input
          v-model.trim="searchForm.purchaseCode"
          placeholder="物资编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="订单编号" prop="orderCode">
        <el-input
          v-model.trim="searchForm.orderCode"
          placeholder="订单编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item label="sap订单编号" prop="ebeln">
        <el-input
          v-model.trim="searchForm.ebeln"
          placeholder="sap订单编号"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item
        label="供应商名称"
        prop="suppliersName"
      >
        <el-input
          v-model.trim="searchForm.suppliersName"
          placeholder="供应商名称"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <el-form-item
        label="采购员"
        prop="sourcingUserRealName"
      >
        <el-input
          v-model.trim="searchForm.sourcingUserRealName"
          placeholder="采购员"
          @keyup.enter.native="search.onSearch"
        />
      </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="供应商sap编码" prop="partnerNo">
        <el-input
          v-model.trim="searchForm.partnerNo"
          placeholder="供应商sap编码"
          @keyup.enter.native="search.onSearch"
        />
      </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>
    </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="行项目编号"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="purchaseCode"
          label="物资编号"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="purchaseSpecification"
          label="物资描述"
          width="170"
        />
        <el-table-column
          :formatter="formatterPurchaseUnit"
          header-align="center"
          prop="purchaseUnit"
          label="计量单位"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="purchaseNum"
          label="数量"
          width="90"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="purchaseBudget"
          label="预算净单价(元)"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="purchaseTotalBudget"
          label="预算净总价(元)"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="offerAvgMoney"
          label="报价平均单价(元)"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="offerAvgHalfTotalMoney"
          label="报价平均总价(元)"
          min-width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="transactionBudget"
          label="订单行项目净单价（元）"
          width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="distributionTotalMoney"
          label="订单行项目净总价（元）"
          width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="purchaseCostMoney"
          label="采购资金节约额"
          width="170"
          align="right"
        />
        <el-table-column
          header-align="center"
          prop="purchaseCostRate"
          label="采购成本节约率"
          width="170"
          align="right"
        />
        <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="deliveryAddress"
          label="到货地点"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="activeTime"
          label="订单生效日期"
          align="center"
          width="170"
        />
        <el-table-column
          label="订单编号"
          prop="orderCode"
          width="170"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="ebeln"
          label="sap订单编号"
          width="170"
          align="center"
        />
        <el-table-column
          header-align="center"
          prop="suppliersName"
          label="中选供应商"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="partnerNo"
          label="供应商sap编码"
          width="170"
          align="center"
        />
        <el-table-column
          :formatter="formatterTenderMethod"
          header-align="center"
          prop="tenderMethod"
          label="采购方式"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="sourcingUserRealName"
          label="采购员"
          width="170"
        />
        <el-table-column
          :formatter="formatterPlanType"
          header-align="center"
          prop="planType"
          label="是否框架协议"
          min-width="120"
        />
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* api */
import { getProcurementCostCalanalysisStatistics, downProcurementCostCalanalysisStatistics } from '@/api/procurement/statisticalManagement'
import { statisticalMixins } from '../../mixins/statisticalMixins'// 字典信息
// /* 公用方法*/
import { download } from '@/assets/js/utils'// 常用方法
export default {
  name: 'CostAnalysisList',
  mixins: [statisticalMixins],
  data() {
    return {
      loading: true,
      // 搜索
      searchForm: {
        purchaseNo: '', // 行项目编号
        purchaseCode: '', // 物资编号
        orderCode: '', // 订单编号
        ebeln: '', // sap订单编号
        suppliersName: '', // 供应商名称
        sourcingUserRealName: '', // 采购员
        belongBk: '', // 所属板块
        partnerNo: '', // 供应商sap编码
        timeDate: [], // 订单生效日期
        statisticsTimeStart: '', // 订单生效日期-起期
        statisticsTimeEnd: ''// 订单生效日期-止期
      },
      tableData: [],
      searchParams: {} // 参数
    }
  },
  methods: {
    // 导出
    exportAll() {
      downProcurementCostCalanalysisStatistics(this.searchParams).then(res => {
        download(res, '成本分析表.xls')
      })
    },
    // 获取数据
    loadData(params, callback) {
      this.searchParams = params
      delete this.searchParams.timeDate
      getProcurementCostCalanalysisStatistics(this.searchParams).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>

