<!--
  @description:供应商-报价-填写报价明细详情组件
  @Modifier:gmy
  @date:2020/9/20-14:58
  @routerPath：procurement/procurementDriveSupplier/offferNonbidding
-->
<template>
  <div class="main">
    <el-form
      v-if="JSON.stringify(dynamicValidateForm)!=='{}'"
      ref="form"
      :model="dynamicValidateForm"
      :inline-message="true"
    >
      <p class="page-title">
        1.采购项目概况
      </p>
      <!--   采购项目基本信息   -->
      <projectBase :project-base="dynamicValidateForm.offerByPackIdVo" :stage-id="orderSupplierOfferInfo.stageId" />
      <div class="clearfix offerInfo">
        <p class="fl page-title">
          2.报价物资明细
        </p>
        <p class="fr mt10 tip-size">
          币种：<span class="mr10 currency-col">{{
            filterDictText(protproject_currencyList, dynamicValidateForm.offerByPackIdVo.currency)
          }}</span>
        </p>
      </div>
      <div>
        <!-- 供应商物资明细组件 -->
        <offerGoodsDetail
          ref="offerGoodsDetail"
          :line-item-file-click="lineItemFileClick"
          :offer-subject-matter-list="dynamicValidateForm.offerSubjectMatterList"
        />
      </div>
      <p class="page-title">
        3.应答文件
      </p>
      <!-- 应答文件列表 -->
      <responseFile
        :response-file-list="responseFileList"
        :response-other-data="responseOtherData"
      />
      <p class="page-title">
        4.附件上传
      </p>
      <table class="tableData">
        <tr class="singleRow">
          <td>
            报价单
          </td>
          <td colspan="3">
            <downloadFile :data="procurementOfferFileData" />
          </td>
        </tr>
        <tr class="singleRow">
          <td>其他附件</td>
          <td colspan="3">
            <downloadFile :data="procurementAttachFile" />
          </td>
        </tr>
      </table>
    </el-form>
    <!-- 查看附件弹框 -->
    <offerMaterials v-if="lookFileData.dialog" :dialog-data="lookFileData" />
  </div>
</template>

<script>
/* api*/
import {
  queryNoOfferByPackId,
  getProtProcurementBidReplyList
} from '@/api/procurement/procurementOffer' // 报价 saveOrUpdateOffer
/* 公共方法*/
import { commonMxin } from '@/mixins/commonMxin'
import {
  filterDictText
} from '@/assets/js/utils' // 计算总价 randomData
import { procurementGroupMixins } from '@/views/procurement/mixins/procurementGrounpMixins' // 公共字典
import { procurementOfferMixin } from '../mixins/procurementOfferMixin' // 公共方法
import { procurementMixins } from '@/views/procurement/mixins/procurementMixins'
/* 公共组件*/
import downloadFile from '@comp/common/updownload/downloadFile' // 文件回显组件
import offerGoodsDetail from './procurementOfferGoodsDetail-add' // 报价物资明细
import responseFile from './procurementOfferResponseFileComp' // 应答文件列表
import projectBase from './procurementOfferProjectBaseCpmp' // 采购项目的基本信息
import offerMaterials
  from '@/views/procurement/procurementProject/procurementProjectLineItemInfo/lookLineItemInfoAccessory-dialog.vue' // 查看附件弹框

export default {
  name: 'OfferNoBiddingTablesDetailVue',
  components: {
    downloadFile, // 文件回显
    offerMaterials, // 查看附件弹框
    offerGoodsDetail, // 报价物资明细组件
    projectBase, // 采购项目的基本信息
    responseFile // 应答文件列表
  },
  mixins: [
    procurementGroupMixins,
    procurementOfferMixin,
    commonMxin,
    procurementMixins
  ],
  props: {
    orderSupplierOfferInfo: {
      type: Object,
      default: function() {
        return {
          packId: '',
          stageId: '',
          supplierId: ''
        }
      }
    }
  },
  data() {
    return {
      loading: true,
      confirmLoading: false,
      // 查看附件弹框
      lookFileData: {
        bizId: '',
        type: '00',
        dialog: false // 是否显示弹框按钮
      },
      // 报价数据
      dynamicValidateForm: {
        conditionList: [], // 报价响应条件
        offerByPackIdVo: {}, // 报价附件信息
        offerSubjectMatterList: [] // 报价物资明细数据
      },
      responseOtherData: {
        isShow: false
      },
      offerIds: '',
      // 报价数据
      responseFileList: [], // 应答文件
      elseFileList: [] // 其他附件

    }
  },
  watch: {
    // 监听报价弹框的打开与关闭
    'dialogData.dialog'(val) {
      if (!val) {
        // 关闭是调用查询页面数据方法
        this.getqueryNoOfferByPackId()
      }
    }
  },
  created() {
    // 查看项目信息
    this.initWebTypeGroup()
    // 查询项目字典方法
    this.initqueryProcurementProjectRuleInitInfo()
    // 调用获取供应商的数据方法
    this.getqueryNoOfferByPackId()
  },
  methods: {
    filterDictText, // 引入字典值替换文本通用方法
    // 查看附件
    lineItemFileClick(row) {
      // 获取文件主键id
      this.lookFileData.bizId = row.planDetailId
      // 打开弹框
      this.lookFileData.dialog = true
    },
    // 封装获取报价信息数据方法
    getqueryNoOfferByPackId() {
      // 获取接口请求参数
      const data = {
        stageId: this.orderSupplierOfferInfo.stageId, // 报价轮次id
        packId: this.orderSupplierOfferInfo.packId, // 项目标段id
        supplierId: this.orderSupplierOfferInfo.supplierId // 供应商id
      }
      // 校验参数是否存在
      if (data.stageId && data.packId) {
        queryNoOfferByPackId(data).then(res => {
          const { conditionList, offerSubjectMatterList, offerByPackIdVo } = res.data
          this.loading = false
          this.dynamicValidateForm.conditionList = conditionList // 采购响应信息
          this.dynamicValidateForm.offerSubjectMatterList = offerSubjectMatterList // 采购报价物资信息
          this.dynamicValidateForm.offerByPackIdVo = offerByPackIdVo // 采购项目概况
          this.offerIds = offerByPackIdVo.offerId // 报价id
          this.procurementResponseFile.bizId = this.offerIds // 应答文件主键id
          this.procurementOfferFileData.bizId = this.offerIds // 报价单文件主键id
          this.procurementAttachFile.bizId = this.offerIds // 其他文件主键id
          // 查询应答文件信息
          this.getProtProcurementresponseFileList(offerByPackIdVo.tenderId)
        })
          .catch(() => {
          })
        return
      }
      this.$message.warning({ message: '缺少参数' })
    },
    /*
     *获取应答文件列表
     *@params {packId: 项目标段id,tenderId: 项目id,stageId: 当前轮次id}
    */
    getProtProcurementresponseFileList(tenderId) {
      const params = {
        packId: this.orderSupplierOfferInfo.packId,
        tenderId: tenderId,
        supplierId: this.orderSupplierOfferInfo.supplierId,
        stageId: this.orderSupplierOfferInfo.stageId
      } // 查询条件
      getProtProcurementBidReplyList(params)
        .then(response => {
          this.responseFileList = response.data
          this.handleRespFileList()
        })
        .catch(() => {
        })
    },
    /*
    *  应答文件列表数据处理
    *  return 列表数据中增加fileList列表
    */
    handleRespFileList() {
      this.responseFileList && this.responseFileList.map(item => {
        /* 下载应答文件列表*/
        item.fileList = [{
          fileType: this.responseFileData.fileType, // 应答文件类型
          fileId: item.fileId// 应答文件附件Id
        }]
      })
    }
  }
}
</script>

<style lang="less" scoped>
@import url("~@/assets/style/common/public.less");

.offerInfo {
  .currency-col {
    color: @orange;
  }

  .tip-size;
}
</style>
