<!--
  @description: 招标采购单查看
  @author: gmy
  @routerPath: /procurement/procBidContentDetail
  @date: 2020-8-4 22:24:58
-->
<template>
  <div>
    <div class="title title_border p0-16">
      <i class="iconfont icon-fanhui pointer" @click="back" />招标采购单查看
    </div>
    <div class="p0-16">
      <!-- 项目信息 -->
      <div class="mb16">
        <p class="page-title">
          1.项目信息
        </p>
        <projectBase-detail :form-data="formData" />
      </div>
      <!-- 行项目信息 -->
      <div class="mb16">
        <p class="page-title">
          2.行项目信息
        </p>
        <lineItemInfo-detail :line-project-data="lineProjectData" />
      </div>
      <!-- 项目规则 -->
      <div class="mb16">
        <p class="page-title">
          3.项目规则
        </p>
        <!-- 招标采购 -->
        <projecctRule-bids ef="ruleDatas" :data-rule="ruleData" />
      </div>
      <!-- 邀请供应商 -->
      <div v-if="formData.tenderType==='01'" class="mb16">
        <p class="page-title">
          4.邀请供应商
        </p>
        <supplierList-detail :supplier-list="procurementSuplierList" />
      </div>
      <!-- 补充说明 -->
      <div>
        <p v-if="formData.tenderType==='00'" class="page-title">
          4.补充说明
        </p>
        <p v-if="formData.tenderType==='01'" class="page-title">
          5.补充说明
        </p>
        <supplement-detail
          v-if="formData.packId"
          :save-notice-data="saveNotice"
          :load-procurement-file="loadProcurementFile"
        />
      </div>
      <!--关闭-->
      <div class="but_footer">
        <div class="but_footer-h">
          <div class="but_footer-but">
            <!-- 关闭 -->
            <el-button :loading="confirmLoading" @click="back">
              关 闭
            </el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
/* 接口*/
import { queryBaseProcurementProjectInfo, queryProcurementRuleRecord, listSubjectMatterPagesByTenderId } from '@/api/procurement/procurementProject' // 获取采购项目基本信息
import { queryBaseProcurementBulletinInfo } from '@/api/procurement/procurementBulletin'
import { getProcurementProcfileByPackId } from '@/api/procurement/procurementProtdoc'
import { queryProcurementInvitatinByTenderId, queryProcurementInvitatinDetailPage } from '@/api/procurement/procurementInvitation' // 保存供应商
/* 公共方法*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
import { filterObj } from '@/assets/js/utils'// 深拷贝
/* 混合开发-参数字段*/
import { procurementProjectGroupMixin } from '../mixins/procurementProjectGroupMixin' // 采购立项 公共字典
import { procurementProjectMixins } from '../mixins/procurementProjectMixins' // 采购立项 公共字典
/* 组件*/
import projectBaseDetail from '../procurementProjectBase/procurementProjectBase-detail' // 项目信息组件
import lineItemInfoDetail from '../procurementProjectLineItemInfo/procurementProjectLineItemInfo-detail' // 行项目信息组件
import projecctBidsRule from '../procurementProjectRule/projectBidsRule/projectBidsRule-detail.vue' // 招标采购项目
import supplierListDetail from '../procurementAddSupplier/procurementAddSupplier-detail' // 查看供应商列表
import supplementDetail from '../procurementProjectSupplement/procurementProjectSupplement-detail' // 补充说明

export default {
  name: 'ProcurementView',
  components: {
    'projectBase-detail': projectBaseDetail, // 采购项目信息组件
    'lineItemInfo-detail': lineItemInfoDetail, // 行项目信息组件
    'projecctRule-bids': projecctBidsRule, // 招标采购项目
    'supplierList-detail': supplierListDetail, // 查看供应商列表
    'supplement-detail': supplementDetail // 补充说明
  },
  mixins: [ListMixin, procurementProjectGroupMixin, procurementProjectMixins],

  data() {
    return {
      procfileId: '', // 业务主键id
      lineProjectData: [], // 行项目信息数据
      procurementSuplierList: [], // 供应商列表
      // 查询行项目信息
      searchForm: {
        createUser: '', // 物资创建人id
        orderBy: 0, // 排序
        tenderId: ''// 项目id
      }
    }
  },
  created() {
    // 获取项目信息
    this.initProjectData()
  },
  methods: {
    // 返回
    back() {
      this.$router.push({ path: '/procurement/biDManageList' })
    },
    /*
       * =======================获取-页面数据 start==============================
     * */
    /*
    * 获取项目信息
    * @params data = {tenderId: 项目id}
    * 返回项目基本信息
    */
    initProjectData() {
      const tenderId = this.$route.params.tenderId
      this.insideTenderProjectFileType.bizId = tenderId
      queryBaseProcurementProjectInfo({ tenderId: tenderId }).then(res => {
        // 获取项目信息
        this.formData = res.data
        // 获取项目规则
        this.initRule(tenderId)
      })
    },
    // 获取项目规则
    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.queryBaseProcurementBulletinInfoData(tenderId)
        // 查询行项目信息
        this.initLineInfoData()
        // 查询供应商列表
        this.initSupplier(tenderId)
      }).catch(() => {})
    },
    // 查询行项目信息条件
    getQueryParams() {
      this.searchForm.tenderId = this.$route.params.tenderId
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    // 获取行项目信息方法
    initLineInfoData() {
      // 查询条件
      const params = this.getQueryParams()
      listSubjectMatterPagesByTenderId(params).then(res => {
        // 获取行项目信息
        this.lineProjectData = res.data.records
        // 获取标段id
        this.formData.packId = res.data.records[0].packId
        // 获取条数
        this.paginationData.total = res.data.total
      }).catch(() => {})
    },
    // 获取供应商列表方法
    initSupplier(tenderId) {
      const data = {
        tenderId: tenderId
      }
      queryProcurementInvitatinDetailPage(data).then(res => {
        // 获取供应商列表数据
        this.procurementSuplierList = res.data.records
      })
    },
    // 封装获取项目公告方法
    queryBaseProcurementBulletinInfoData(tenderId) {
      // 获取采购公告
      if (this.$route.params.tenderType === '00') {
        // 调用获取项目类型为公开的采购公告数据信息
        this.getProcurementBulletinInfoData(tenderId)
      } else if (this.$route.params.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 || this.$route.params.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.$route.params.tenderId, // 项目id
          packId: this.$route.params.packId // 项目id
        }
      })
    }
    /*
       * =======================获取-页面数据 End==============================
     * */
  }
}
</script>

<style lang="less" scoped>

</style>
