<!--
  @description:计划部报表
  @Modifier: zhangyawen
  @routerPath: /statisticalManagement/planningDepartmentReport-list
  @date: 2021-4-20-09:10
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :tabs="tabsList"
      :search-form="searchForm"
      search-label-width="100px"
      :page-flag="false"
      @on-load="loadData"
    >
      <template v-slot:header>
        <span>采购方式报表</span>
      </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 v-if="searchForm.queryStatus!=='04'" 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>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button type="primary" @click="onExportFile">
            导出
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <!-- 采购计划处理记录 -->
        <procurementPlanProcessTableComp
          v-if="searchForm.queryStatus === '00'"
          :loading="loading"
          :table-data="tableData"
        />
        <!-- 计划数据统计 -->
        <planDataStatisticsTableComp
          v-if="searchForm.queryStatus === '01'"
          :loading="loading"
          :table-data="tableData"
        />
        <!-- 计划归集统计情况 -->
        <!--  <procurementMethodHandlingTableComp
          v-if="searchForm.queryStatus === '02'"
          :loading="loading"
          :table-data="tableData"
        />-->
        <declineInProcurementCostsTableComp
          v-if="searchForm.queryStatus === '02'"
          :loading="loading"
          :table-data="tableData"
        />
        <!-- 集中采购订单情况 -->
        <centralizedPurchaseOrderTableComp
          v-if="searchForm.queryStatus === '03'"
          :loading="loading"
          :table-data="tableData"
        />
        <!-- 采购成本下降情况 -->
        <declineInProcurementCostsTableComp
          v-if="searchForm.queryStatus === '04'"
          :loading="loading"
          :table-data="tableData"
        />
      </template>
    </table-crud>
  </div>
</template>

<script>
/* eslint-disable */
/* api*/
import { getPurchasePlanPackApplicationStaticticsList, getPurchasePlanBelongBkDataStatictics, getPurchasePlanPackTenderTypeStaticticsList, getPurchasePlanOrderBelongBkStatictics, getPurchaseCostDownStatictics, downPurchaseCostDownStatictics } from '@api/procurement/statisticalManagement'
import { filterDictText, filterObj, download } from '@/assets/js/utils' // 常用方法
import { statisticalMixins } from '../../mixins/statisticalMixins'// 字典信息
// 表格组件
import procurementPlanProcessTableComp from './procurementPlanProcessTableComp.vue'
import planDataStatisticsTableComp from './planDataStatisticsTableComp.vue'
import procurementMethodHandlingTableComp from './procurementMethodHandlingTableComp.vue'
import centralizedPurchaseOrderTableComp from './centralizedPurchaseOrderTableComp.vue'
import declineInProcurementCostsTableComp from './declineInProcurementCostsTableComp.vue'
export default {
  name: 'PlanningDepartmentReportList',
  components: { procurementPlanProcessTableComp, planDataStatisticsTableComp, procurementMethodHandlingTableComp, centralizedPurchaseOrderTableComp, declineInProcurementCostsTableComp },
  mixins: [statisticalMixins],
  data() {
    return {
      loading: true,
      tableData: [], // 表格数据
      searchForm: {
        timeDate: [], // 统计时间
        statisticsTimeStart: '', // 统计时间-开始
        statisticsTimeEnd: '', // 统计时间-结束
        tenderMethod: '', // 采购方式
        queryStatus: '00'
      },
      tabsList: [
        // 查询tabs数据
        {
          name: '采购计划处理记录',
          index: '00'
        },
        {
          name: '计划数据统计',
          index: '01'
        },
 /*       {
          name: '计划归集统计情况',
          index: '02'
        },*/
        {
          name: '集中采购订单情况',
          index: '03'
        },
        {
          name: '采购成本下降情况',
          index: '04'
        },
        {
          name: '采购成本下降情况（框架协议）',
          index: '02'
        },
      ]
    }
  },
  methods: {
    filterDictText, // 字典检索
    // 数据请求
    loadData(params, callback, tabData) {
      if (tabData) {
        this.searchForm.queryStatus = tabData.index
      }
      delete params.timeDate
      delete params.pageNo
      delete params.pageSize
      delete params.queryStatus
      this.tableData = []
      this.loading = true

      let apiName = ''
      switch (tabData.index) {
        case '00':
          apiName = getPurchasePlanPackApplicationStaticticsList
          break
        case '01':
          apiName = getPurchasePlanBelongBkDataStatictics
          break
        case '02':
          apiName = getPurchaseCostDownStatictics
          break
        case '03':
          apiName = getPurchasePlanOrderBelongBkStatictics
          break
        case '04':
          apiName = getPurchaseCostDownStatictics
          break
      }
      if (apiName === getPurchasePlanPackTenderTypeStaticticsList) {
        getPurchasePlanPackTenderTypeStaticticsList(params).then(response => {
          this.loading = false
          this.tableData = response.data.records
          callback(response.data.total)
        }).catch(() => {
          this.loading = false
        })
      } else {
        apiName(params).then(response => {
          this.loading = false
          this.tableData = response.data
        }).catch(() => {
          this.loading = false
        })
      }

      // if (tabData.typecode === '00') {
      //   getPurchasePlanPackApplicationStaticticsList(params).then(response => {
      //     this.tableData = response.data
      //   }).catch(() => {
      //     this.loading = false
      //   })
      // }
      // if (tabData.typecode === '01') {
      //   getPurchasePlanBelongBkDataStatictics(params).then(response => {
      //     this.tableData = response.data
      //   }).catch(() => {
      //     this.loading = false
      //   }).catch(() => {
      //     this.loading = false
      //   })
      // }
      // if (tabData.typecode === '02') {
      //   getPurchasePlanPackTenderTypeStaticticsList(params).then(response => {
      //     this.tableData = response.data.records
      //   }).catch(() => {
      //     this.loading = false
      //   })
      // }
      // if (tabData.typecode === '03') {
      //   getPurchasePlanOrderBelongBkStatictics(params).then(response => {
      //     this.tableData = response.data
      //   }).catch(() => {
      //     this.loading = false
      //   })
      // }
      // if (tabData.typecode === '04') {
      //   getPurchaseCostDownStatictics(params).then(response => {
      //     this.tableData = response.data
      //   }).catch(() => {
      //     this.loading = false
      //   })
      // }
      // getPurchasePlanDetailQryList(params).then(response => {
      //   this.searchForm.column = ''
      //   this.searchForm.orderSort = ''
      //   this.loading = false
      //   this.tableData = Object.freeze(response.data.records)
      //   callback(response.data.total)
      // }).catch(() => {
      //   this.searchForm.column = ''
      //   this.searchForm.orderSort = ''
      // this.loading = false
      // })
    },
    // 导出
    onExportFile() {
      // const params = {
      //   queryStatus: this.searchForm.queryStatus,
      //   ...this.searchForm
      // }
      // const that = this
      const index = this.tabsList.findIndex((item) => this.searchForm.queryStatus === item.typecode)
      // if (this.tableData.length <= 0) {
      //   this.$message.warning('没有可导出的数据')
      //   return false
      // } else {
      // downPurchaseCostDownStatictics(filterObj(params)).then((res) => {
      //   download(res, `${that.tabsList[index].name}.xls`)
      // })
      // }
    },
    // 处理搜索时间格式
    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>
// 前端做合计时样式问题处理
@import "../../statisticalChartCommon/tableSum.less";
</style>
