<!--
@description: 采购单发布公告工作流pdf查看
@Modifier: lxl
@routerPath:procurementProjectList/
@date: 2020-8-25 14:43:15
-->
<template>
  <div>
    <div class="clearfix mb10">
      <div class="fr">
        <!-- 判断是否紧急采购 isEmergencyProcurement 00 否 01 是-->
        <el-button
          v-if="formData.tenderMethod === '12' && ruleData.isEmergencyProcurement==='00'"
          type="primary"
          plain
          @click="invitaitonPublicityHtml"
        >
          单一来源公示预览
        </el-button>
        <el-button type="primary" plain @click="procurementMethod">
          采购方式
        </el-button>
        <el-button v-if="formData.tenderMethod!=='00'" type="primary" plain @click="seeProjectNotice">
          {{ formData.tenderType && formData.tenderType === '00' ? '公告预览' : '邀请函预览' }}
        </el-button>
      </div>
    </div>
    <!-- 项目信息 -->
    <dl class="projectInfoDetail">
      <dt>
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-xiangguanjigouxinxi" />
        </p>
        项目信息
      </dt>
      <dd>
        <!-- 项目信息 -->
        <projectBase-detail :form-data="formData" :inside-tender-project-file-type="insideTenderProjectFileType" />
      </dd>
    </dl>
    <!-- 行项目信息 -->
    <dl class="projectInfoDetail">
      <dt>
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-xiangguanjigouxinxi" />
        </p>
        行项目信息
      </dt>
      <dd>
        <!-- 行项目信息 -->
        <lineItemInfo-detail :line-project-data="lineProjectData" />
        <!-- 分页 -->
      </dd>
    </dl>
    <!-- 项目规则 -->
    <dl class="projectInfoDetail">
      <dt>
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-biaodeqingdan" />
        </p>项目规则
      </dt>
      <dd>
        <el-form ref="form" :model="ruleData" :inline-message="true">
          <!-- 询价 -->
          <projecctRule-Enquiry
            v-if="formData.tenderMethod === '11'"
            ref="ruleDatas"
            :tender-type="formData.tenderType"
            :tender-id="tenderId"
            :data-rule="ruleData"
          />
          <!-- 单一来源 -->
          <projectRule-SingSource v-if="formData.tenderMethod === '12'" ref="ruleDatas" :data-rule="ruleData" />
          <!-- 竞争性谈判 -->
          <projectRule-Competitive v-if="formData.tenderMethod === '13'" ref="ruleDatas" :data-rule="ruleData" />
          <!-- 竞价  -->
          <projectRule-Bidding v-if="formData.tenderMethod === '14'" ref="ruleDatas" :data-rule="ruleData" />
          <!--招标-->
          <projecctBids-Rule v-if="formData.tenderMethod === '00'" ref="ruleDatas" :data-rule="ruleData" />
        </el-form>
      </dd>
    </dl>
    <!-- 查看供应商列表 只有邀请才展示 -->
    <dl v-if="formData.tenderType==='01'" class="projectInfoDetail">
      <dt>
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-biaoduanbaoxinxi" />
        </p>
        邀请供应商
      </dt>
      <dd>
        <supplierList-detail v-if="formData.tenderType==='01'" :supplier-list="procurementSuplierList" />
      </dd>
    </dl>
    <!-- 补充说明 -->
    <dl class="projectInfoDetail">
      <dt>
        <p class="projectInfoDetail_icon">
          <i class="iconfont icon-xiangguanjigouxinxi" />
        </p>
        补充说明
      </dt>
      <dd>
        <!-- 补充说明 saveNotice  公告备注 loadProcurementFile  otherData其他信息-->
        <supplement-detail
          v-if="formData.packId"
          :save-notice-data="saveNotice"
          :load-procurement-file="loadProcurementFile"
        />
      </dd>
    </dl>
    <!--公告信息弹框-->
    <procurementProjectLetterDialog ref="procurementProjectLetter" />
    <!--采购方式弹框-->
    <purPlanBaleDetailDialog ref="purPlanBaleDetail" />
    <!--单一来源公示预览-->
    <singleSourcePublicityDialog ref="singleSourcePublicity" />
  </div>
</template>
<script>
/* API*/
import { queryBaseProcurementProjectInfo, queryProcurementRuleRecord, listSubjectMatterPagesByTenderId } from '@/api/procurement/procurementProject' // 获取采购项目基本信息
import { getProcurementProcfileByPackId } from '@/api/procurement/procurementProtdoc' // 获取采购文件
import { queryBaseProcurementBulletinInfo } from '@/api/procurement/procurementBulletin'
import { queryProcurementInvitatinDetailPage, queryProcurementInvitatinByTenderId } from '@/api/procurement/procurementInvitation' // 保存供应商
/* 公共方法*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
/* 混合开发-参数字段*/
import { procurementProjectGroupMixin } from '../mixins/procurementProjectGroupMixin' // 采购立项 公共字典
import { procurementProjectMixins } from '../mixins/procurementProjectMixins' // 采购立项 公共字典
/* 组件*/
import projectBaseDetail from '../procurementProjectBase/procurementProjectBase-detail' // 项目信息组件
import lineItemInfoDetail from '../procurementProjectLineItemInfo/procurementProjectLineItemInfo-detail' // 行项目信息组件
import projecctRuleEnquiry from '../procurementProjectRule/projectRuleEnquiry/projectRuleEnquiry-detail' // 询价
import projectRuleSingSource from '../procurementProjectRule/projectRuleSingleSource/projectRuleSingSource-detail' // 单一来源
import projectRuleCompetitive from '../procurementProjectRule/projectRuleCompetitive/projectRuleCompetitive-detail' // 竞争性谈判
import projectRuleBidding from '../procurementProjectRule/projectRuleBidding/projectRuleBidding-detail' // 竞价
import supplierListDetail from '../procurementAddSupplier/procurementAddSupplier-detail' // 查看供应商列表
import projecctBidsRule from '../procurementProjectRule/projectBidsRule/projectBidsRule-detail.vue' // 招标采购项目
import supplementDetail from '../procurementProjectSupplement/procurementProjectSupplement-detail'
import projectAddSupplier from '../procurementAddSupplier/procurementAddSupplier-dialog' // 添加供应商弹框
import procurementProjectLetterDialog from '@views/procurement/procurementProject/procurementProjectLetter/procurementProjectLetter-dialog' // 查看公告信息
import purPlanBaleDetailDialog from
  '@/views/procurement/procurementPlan/purPlanAllocation/purPlanBaleDetail-dialog.vue' // 查看打包信息
import singleSourcePublicityDialog from '@views/procurement/procurementProject/procurementProjectRule/projectRuleSingleSource/singleSourcePublicity-dialog.vue' // 单一来源公示预览
export default {
  name: 'PublishFlowDetail',
  components: {
    singleSourcePublicityDialog, // 单一来源公示预览
    purPlanBaleDetailDialog, // 查看（打包信息）采购方式
    'projectBase-detail': projectBaseDetail, // 采购项目信息组件
    'lineItemInfo-detail': lineItemInfoDetail, // 行项目信息组件
    'projecctRule-Enquiry': projecctRuleEnquiry, // 询价
    'projectRule-SingSource': projectRuleSingSource, // 单一来源
    'projectRule-Competitive': projectRuleCompetitive, // 竞谈
    'projectRule-Bidding': projectRuleBidding, // 竞价
    'projecctBids-Rule': projecctBidsRule,
    'supplierList-detail': supplierListDetail, // 查看供应商列表
    'addSupplier-dialog': projectAddSupplier, // 添加供应商弹框
    'supplement-detail': supplementDetail, // 补充说明
    procurementProjectLetterDialog // 查看公告信息
  },
  mixins: [ListMixin, procurementProjectGroupMixin, procurementProjectMixins],
  data() {
    return {
      formData: {}, // 项目信息
      lineProjectData: [], // 行项目信息数据
      tenderId: this.$route.query.id, // 项目id
      procurementSuplierList: [] // 供应商列表
    }
  },
  created() {
    this.initProjectData()
  },
  methods: {
    // 单一来源公示预览
    invitaitonPublicityHtml() {
      this.$refs.singleSourcePublicity.projectNoticeLoad()
    },
    // 采购方式
    procurementMethod() {
      // 查看打包信息
      this.$refs.purPlanBaleDetail.openDialogPurPlanBaleDetail(this.tenderId)
    },
    // 公告预览
    seeProjectNotice() {
      this.$refs.procurementProjectLetter.projectNoticeLoad()
    },
    // 监听附件上传的回调
    fileListType(val) {
      this.isUpload = val
    },
    // 获取项目信息
    initProjectData() {
      this.insideTenderProjectFileType.bizId = this.tenderId
      queryBaseProcurementProjectInfo({ tenderId: this.tenderId }).then(res => {
        // 获取项目信息
        this.formData = res.data
        // 获取项目规则
        this.initRule(this.tenderId)
        // 查询行项目信息
        this.initLineInfoData()
      })
    },
    /*
    * 获取项目规则
    * @params { tenderId: 项目id}
    * 返回项目规则数据
    */
    initRule(tenderId) {
      const data = { tenderId: tenderId }
      queryProcurementRuleRecord(data).then(res => {
        this.ruleData = {
          ...res.data
        }
        this.ruleData.supplierAttribute = this.ruleData.supplierAttribute.split(',') // 供应商属性
        this.ruleData.supplierCategory = this.ruleData.supplierCategory.split(',') // 供应商分类
        // 查询供应商列表
        this.initSupplier()
        // 查询公告方法
        this.queryBaseProcurementBulletinInfoData(this.tenderId)
      }).catch(() => {})
    },
    // 获取供应商列表方法
    initSupplier() {
      const data = {
        tenderId: this.tenderId
      }
      queryProcurementInvitatinDetailPage(data).then(res => {
        // 获取供应商列表数据
        this.procurementSuplierList = res.data.records
      })
    },
    // 获取行项目信息方法
    initLineInfoData() {
      // 查询条件
      const params = {
        tenderId: this.tenderId
      }
      listSubjectMatterPagesByTenderId(params).then(res => {
        // 获取行项目信息
        this.lineProjectData = res.data.records
        // 获取标段id
        this.formData.packId = res.data.records[0].packId
      }).catch(() => {})
    },
    // 封装获取项目公告方法
    queryBaseProcurementBulletinInfoData(tenderId) {
      // 获取采购公告
      if (this.formData.tenderType === '00') {
        // 调用获取项目类型为公开的采购公告数据信息
        this.getProcurementBulletinInfoData(tenderId)
      } else if (this.formData.tenderType === '01') {
        // 调用项目类型为邀请的采购公告数据信息
        this.getProcurementInvitatinInfoData(tenderId)
      }
    },
    // 获取项目类型为公开的采购公告数据信息
    getProcurementBulletinInfoData(tenderId) {
      queryBaseProcurementBulletinInfo(tenderId).then(res => {
        // 获取采购公告id
        this.saveNotice.id = res.data.id
        // 获取备注信息
        this.saveNotice.mattersNeedingAttention = res.data.mattersNeedingAttention
      })
        .catch(() => {})
    },
    // 获取项目类型为邀请的采购公告数据信息
    getProcurementInvitatinInfoData(tenderId) {
      // 获取邀请函
      queryProcurementInvitatinByTenderId(tenderId).then(response => {
        const { id, mattersNeedingAttention, excludeSupplierIds, publicityEndTime, materialContactPerson, materialContactPhone, materialContactEmail, materialContactAddress } = response.data
        this.ruleData = {
          ...this.ruleData,
          publicityEndTime: publicityEndTime, // 公示结束时间
          materialContactPerson: materialContactPerson, // 物资公司联系人
          materialContactPhone: materialContactPhone, // 联系电话
          materialContactEmail: materialContactEmail, // 邮箱
          materialContactAddress: materialContactAddress // 地址
        }
        // 获取邀请函公告id
        this.saveNotice.id = id
        this.giveFileData.bizId = this.saveNotice.id
        // 获取备注信息
        this.saveNotice.mattersNeedingAttention = mattersNeedingAttention
        // 获取邀请函id
        this.supplerlist.invitationId = id
        // 已被邀请供应商所有id拼接的字符串
        this.addSupplierDialogData.excludeSupplierIds = excludeSupplierIds
        // 响应条件初始化为null默认空数组
        this.procurementBulletinConditionList = response.data.procurementInvitationConditionList ? response.data.procurementInvitationConditionList : []
      })
        .catch(() => {})
    },
    // 获取采购文件
    async  loadProcurementFile() {
      const packId = this.formData.packId
      return await getProcurementProcfileByPackId(packId).then(res => {
        this.procfileId = res.data.procfileId
        return {
          id: res.data.procfileId, // 采购文件业务主键id
          makeWay: res.data.makeWay ? res.data.makeWay : '01', // 是否使用采购工具
          tenderId: this.formData.id, // 项目id
          packId: this.formData.packId, // 项目id
          giveId: this.saveNotice.id, // 单一来源批复文件主键id
          tenderMethod: this.formData.tenderMethod // 采购方式
        }
      })
    }
  }

}

</script>
