<!--
  @description: 项目各月完成情况统计
  @Modifier: haofengxian
  @routerPath: /statisticalAnalysis/projectCompletionEachMonthList
  @date: 2020-7-14-16:30
-->
<template>
  <table-crud
    :menu="true"
    :search-form="searchForm"
    search-label-width="110px"
    @on-load="loadData"
  >
    <template v-slot:header>
      查询项目各月完成情况统计信息
    </template>
    <template v-slot:search="search">
      <!--招标方式-->
      <el-form-item ref="tenderMethod" label="招标方式" prop="tenderMethod">
        <el-select v-model="searchForm.tenderMethod" placeholder="请选择" style="width: 220px">
          <el-option
            v-for="(item,index) in bidTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <!--项目类型-->
      <!--      <el-form-item ref="tenderNo" label="项目类型" prop="tenderNo">
        <el-select v-model="searchForm.tenderMethod" placeholder="请选择" style="width: 220px">
          <el-option
            v-for="(item,index) in bidTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>-->
      <!--招标人单位-->
      <el-form-item ref="buyersDepartMent" label="招标人单位" prop="buyersDepartMent">
        <el-input
          v-model.trim="searchForm.buyersDepartMent"
          placeholder="招标人单位"
          style="width:220px"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!--标段（包）编号-->
      <el-form-item ref="packNo" label="标段（包）编号" prop="packNo">
        <el-input
          v-model.trim="searchForm.packNo"
          placeholder="标段（包）编号"
          style="width:220px"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!--招标项目名称-->
      <el-form-item ref="tenderName" label="招标项目名称" prop="tenderName">
        <el-input
          v-model.trim="searchForm.tenderName"
          placeholder="招标项目名称"
          style="width:220px"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!--负责部门-->
      <el-form-item ref="tenderDepart" label="负责部门" prop="tenderDepart">
        <el-select v-model="searchForm.tenderDepart" placeholder="请选择" style="width: 220px">
          <el-option
            v-for="(item,index) in bidTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <!--招标编号-->
      <el-form-item ref="tenderNo" label="招标编号" prop="tenderNo">
        <el-input
          v-model.trim="searchForm.tenderNo"
          placeholder="招标编号"
          style="width:220px"
          @keyup.enter.native="search.onSearch"
        />
      </el-form-item>
      <!--项目行业-->
      <el-form-item ref="projectIndustry" label="项目行业" prop="projectIndustry">
        <el-select v-model="searchForm.projectIndustry" placeholder="请选择" style="width: 220px">
          <el-option
            v-for="(item,index) in bidTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <!--采购级别-->
      <el-form-item ref="purchaseLevel" label="采购级别" prop="purchaseLevel">
        <el-select v-model="searchForm.purchaseLevel" placeholder="请选择" style="width: 220px">
          <el-option
            v-for="(item,index) in bidTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <!--采购类别-->
      <el-form-item ref="purchaseType" label="采购类别" prop="purchaseType">
        <el-select v-model="searchForm.purchaseType" placeholder="请选择" style="width: 220px">
          <el-option
            v-for="(item,index) in bidTypeList"
            :key="index"
            :label="item.typename"
            :value="item.typecode"
          />
        </el-select>
      </el-form-item>
      <!--中标通知书发放-->
      <el-form-item label="中标通知书发放">
        <el-date-picker
          v-model="searchForm.winNoticePushTime"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 220px"
          @change="handleWinNoticePushTime"
        />
      </el-form-item>
      <!--完成月份-->
      <el-form-item ref="complateMonth" label="完成月份" prop="complateMonth">
        <el-date-picker
          v-model="searchForm.complateMonth"
          style="width: 220px"
          type="month"
          placeholder="选择月"
        />
      </el-form-item>
      <!--预审非开票日期-->
      <el-form-item label="预审非开票日期">
        <el-date-picker
          v-model="searchForm.zsInvoiceTime"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 220px"
          @change="handlezsInvoiceTime"
        />
      </el-form-item>
      <!--标书费开票日期-->
      <el-form-item label="标书费开票日期">
        <el-date-picker
          v-model="searchForm.feeDocInvoiceTime"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 220px"
          @change="handleFeeDocInvoiceTime"
        />
      </el-form-item>
      <!--服务费开票日期-->
      <el-form-item label="服务费开票日期">
        <el-date-picker
          v-model="searchForm.serviceInvoiceTime"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 220px"
          @change="handleServiceInvoiceTime"
        />
      </el-form-item>
    </template>
    <template slot="menuLeft">
      <el-row class="mb10 table-alert-info">
        <el-col>
          <el-button type="primary" @click="exportCurrentPage">
            导出当前页
          </el-button>
          <el-button type="primary" @click="exportAll">
            导出全部
          </el-button>
        </el-col>
        <el-col>
          <el-link :underline="false">
            单页委托金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
          <el-link :underline="false">
            单页中标金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
          <el-link :underline="false">
            总委托金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
          <el-link :underline="false">
            总中标金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
        </el-col>
        <el-col>
          <el-link :underline="false">
            预审费总金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
          <el-link :underline="false">
            标书费总金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
          <el-link :underline="false">
            服务费总金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
          <el-link :underline="false">
            支出总金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
          <el-link :underline="false">
            项目毛利总金额<span class="sum_color">{{ moneyFormat(selectDocumentPrice) }}</span>元
          </el-link>
        </el-col>
      </el-row>
    </template>
    <template v-slot:GXTable>
      <el-table
        ref="smallTable"
        v-loading="loading"
        :data="tableData"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60px"
          align="center"
          fixed
        />
        <el-table-column
          prop="complateMonth"
          label="完成月份"
          width="170"
        />
        <el-table-column
          prop="projectIndustry"
          label="项目行业"
          width="170"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in projectIndustryList"
              v-if="scope.row.projectType===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <!--<el-table-column
          prop="projectType"
          align="center"
          label="项目类型"
          width="170"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in projectNatureList"
              v-if="scope.row.projectType===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>-->
        <el-table-column
          prop="purchaseType"
          label="采购类型"
          width="170"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseTypeList"
              v-if="scope.row.projectType===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="purchaseLevel"
          label="采购级别"
          width="170"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in purchaseLevelList"
              v-if="scope.row.projectType===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="tenderDepart"
          label="负责部门"
          width="170"
        />
        <el-table-column
          header-align="center"
          prop="tenderManager"
          label="项目经理"
          width="90"
        />
        <el-table-column
          header-align="center"
          prop="tenderName"
          label="招标项目名称"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="packName"
          label="标段（包）名称"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="tenderNo"
          align="center"
          label="招标编号"
          width="160"
        />
        <el-table-column
          header-align="center"
          prop="packNo"
          label="标段（包）编号"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="belongCompany"
          label="所属公司"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="buyersDepartMent"
          label="招标人单位"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="contractPrice"
          label="委托金额"
          align="right"
          width="100"
        />
        <el-table-column
          header-align="center"
          prop="tenderMethod"
          label="招标方式"
          width="80"
          align="center"
        >
          <template slot-scope="scope">
            <span
              v-for="(item,index) in bidTypeList"
              v-if="scope.row.tenderMethod===item.typecode"
              :key="index"
            >{{ item.typename }}</span>
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="winSupplierName"
          label="中标单位"
          min-width="230"
        />
        <el-table-column
          header-align="center"
          prop="winningResultPrice"
          label="中标金额（元）"
          align="right"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="spareRate"
          label="节资率"
          width="100"
        />
        <el-table-column
          header-align="center"
          prop="openingTime"
          label="开标时间"
          width="130"
        >
          <template slot-scope="scope">
            {{ scope.row.openingTime && $Moment(scope.row.openingTime).format(momentDateTime) }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="winNoticePushTime"
          label="中标通知书发放时间"
          width="130"
        >
          <template slot-scope="scope">
            {{ scope.row.winNoticePushTime && $Moment(scope.row.winNoticePushTime).format(momentDateTime) }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="biddingBudgetNo"
          label="预算编号"
          width="160"
        />
        <el-table-column
          header-align="center"
          prop="zsPrice"
          align="right"
          label="资审费"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="zsInvoice"
          label="资审费开票"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="zsInvoiceTime"
          label="资审费开票时间"
          width="130"
        >
          <template slot-scope="scope">
            {{ scope.row.zsInvoiceTime && $Moment(scope.row.zsInvoiceTime).format(momentDateTime) }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop=""
          align="right"
          label="标书费"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="feeDocInvoice"
          label="标书费开票"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="feeDocInvoiceTime"
          label="标书费开票时间"
          width="130"
        >
          <template slot-scope="scope">
            {{ scope.row.feeDocInvoiceTime && $Moment(scope.row.feeDocInvoiceTime).format(momentDateTime) }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="servicePrice"
          align="right"
          label="服务费"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="allServicePrice"
          align="right"
          label="服务费全额到账"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="arrearageServicePrice"
          align="right"
          label="服务费欠账金额"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="invoicePrice"
          align="right"
          label="已开票金额"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="invoiceTime"
          label="开票日期"
          width="130"
        >
          <template slot-scope="scope">
            {{ scope.row.invoiceTime && $Moment(scope.row.invoiceTime).format(momentDateTime) }}
          </template>
        </el-table-column>
        <el-table-column
          header-align="center"
          prop="noInvoicePrice"
          align="right"
          label="未开票金额"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="feePrice"
          align="right"
          label="费用金额"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="grossProfit"
          align="right"
          label="项目毛利"
          width="120"
        />
        <el-table-column
          header-align="center"
          prop="grossProfitRate"
          align="right"
          label="项目毛利率"
          width="120"
        />
      </el-table>
    </template>
  </table-crud>
</template>
<script>
/* 接口*/
import { queryPerformanceToMonthPage } from '@api/statisticalAnalysis'
import { exportInvoiceList } from '@api/fee/docfee'
/* 公用方法*/
import { download, moneyFormat } from '@/assets/js/utils'// 常用方法
/* 混合开发方法-参数字段*/
import { statisticalAnalysisGroupMixin } from '../mixins/statisticalAnalysisGroupMixin'
export default {
  name: 'TenderProjectList',
  mixins: [statisticalAnalysisGroupMixin],
  data() {
    return {
      /* 字典信息-start */
      bidTypeList: [], // 招标方式
      /* 字典信息-end */
      moneyFormat: moneyFormat, // 金额添加千分位
      loading: true,
      createTime: '',
      selectDocumentPrice: 0,
      // 搜索
      searchForm: {
        /* 时间选中绑定的字段*/
        feeDocInvoiceTime: '', // 标书费开票时间
        serviceInvoiceTime: '', // 服务费开票时间
        winNoticePushTime: '', // 通知书发出日期
        zsInvoiceTime: '', // 资审开票时间
        /* 后端需要查询的字段*/
        buyersDepartMent: '', // 招标人单位
        complateMonth: '', // 完成月份
        feeDocInvoiceEndTime: '', // 标书费开票结束时间
        feeDocInvoiceStartTime: '', // 标书费开票开始时间
        packNo: '', // 标段（包）编号
        projectIndustry: '', // 项目行业
        projectType: '', // 项目类型（00：招标，01：采购）
        purchaseLevel: '', // 采购级别
        purchaseType: '', // 系采购类型 00:基建类 01:生产类
        serviceInvoiceEndTime: '', // 服务费开票结束时间
        serviceInvoiceStartTime: '', // 服务费开票开始时间
        tenderDepart: '', // 负责部门
        tenderMethod: '', // 招标方式
        tenderName: '', // 项目名称
        tenderNo: '', // 项目编号
        winNoticePushEndTime: '', // 通知书发出结束日期
        winNoticePushStartTime: '', // 通知书发出开始日期
        zsInvoiceEndTime: '', // 资审开票结束时间
        zsInvoiceStartTime: '' // 资审开票开始时间
      },
      tableData: []
    }
  },
  created() {
    this.initGroup() // 获取字典方法
    this.initWebTypeGroup()// 字典信息
  },
  methods: {
    // 获取字典方法
    initGroup() {
      const data = [
        'bidType' // 招标方式
      ]
      this.$store.dispatch('getGroupType', data).then(res => {
        Object.keys(res.bidTypeData).forEach((key) => {
          this[key] = res.bidTypeData[key]
        })
      })
    },
    // 导出当前页面
    exportCurrentPage() {

    },
    // 导出全部
    exportAll() {

    },
    // 导出招标结果Excel
    exportExcel(feeDocIds) {
      const params = {
        feeDocIds
      }
      exportInvoiceList(params).then(res => {
        download(res, '开票记录.xls')
      }).catch(() => {
      })
    },
    // 获取数据
    loadData(params, callback) {
      queryPerformanceToMonthPage(params).then(response => {
        this.loading = false
        this.tableData = response.data.records
        callback(response.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 处理搜索时间格式-中标通知书发放
    handleWinNoticePushTime(val) {
      if (val) {
        this.searchForm.winNoticePushStartTime = this.$Moment(val[0]).format(this.momentSaveFormat)// 开始时间
        this.searchForm.winNoticePushEndTime = this.$Moment(val[1]).format(this.momentSaveFormat)// 结束时间
      }
    },
    // 处理搜索时间格式-预审非开票日期
    handlezsInvoiceTime(val) {
      if (val) {
        this.searchForm.zsInvoiceStartTime = this.$Moment(val[0]).format(this.momentSaveFormat)// 开始时间
        this.searchForm.zsInvoiceEndTime = this.$Moment(val[1]).format(this.momentSaveFormat)// 结束时间
      }
    },
    // 处理搜索时间格式-标书费开票日期
    handleFeeDocInvoiceTime(val) {
      if (val) {
        this.searchForm.feeDocInvoiceStartTime = this.$Moment(val[0]).format(this.momentSaveFormat)// 开始时间
        this.searchForm.feeDocInvoiceEndTime = this.$Moment(val[1]).format(this.momentSaveFormat)// 结束时间
      }
    },
    // 服务费开票日期
    handleServiceInvoiceTime(val) {
      if (val) {
        this.searchForm.serviceInvoiceStartTime = this.$Moment(val[0]).format(this.momentSaveFormat)// 开始时间
        this.searchForm.serviceInvoiceEndTime = this.$Moment(val[1]).format(this.momentSaveFormat)// 结束时间
      }
    }
  }
}
</script>
<style lang="less" scoped>

</style>
