<!--
  @description: 项目管理采购项目查看
  @author: gmy
  @routerPath: /procurement/procurementDrive/procurementView
  @routerPath:/procurement/procurementOrderBaseDetail
  @date: 2020-8-4 22:24:58
-->
<template>
  <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>
    <!-- 项目规则 不同的采购方式 展示不同的规则 11 询价 12 单一来源 13 竞争性谈判 14 竞价 -->
    <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" :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" />
        </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" />
        <!--分页组件-->
        <page-nation :pagination-data="paginationData" @change="initSupplier" />
      </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>
  </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 pagination from '@comp/common/pagination/pagination' // 分页组件
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 supplementDetail from '../procurementProjectSupplement/procurementProjectSupplement-detail'
// import pagination from '@comp/common/pagination/pagination' // 分页组件
export default {
  name: 'ProcurementView',
  components: {
    'projectBase-detail': projectBaseDetail, // 采购项目信息组件
    'lineItemInfo-detail': lineItemInfoDetail, // 行项目信息组件
    'projecctRule-Enquiry': projecctRuleEnquiry, // 询价
    'projectRule-SingSource': projectRuleSingSource, // 单一来源
    'projectRule-Competitive': projectRuleCompetitive, // 竞谈
    'projectRule-Bidding': projectRuleBidding, // 竞价
    'supplierList-detail': supplierListDetail, // 查看供应商列表
    'supplement-detail': supplementDetail, // 补充说明
    'page-nation': pagination // 分页组件
  },
  mixins: [ListMixin, procurementProjectGroupMixin, procurementProjectMixins],
  props: {
    // 订单传递参数
    projectBase: {
      type: Object,
      default: function() {
        return {
          tenderId: '' // 项目id
        }
      }
    }
  },
  data() {
    return {
      confirmLoading: false, // loading
      procfileId: '', // 业务主键id
      lineProjectData: [], // 行项目信息数据
      procurementSuplierList: [], // 供应商列表
      // 查询行项目信息
      searchForm: {
        createUser: '', // 物资创建人id
        orderBy: 0, // 排序
        tenderId: ''// 项目id
      },
      // 查询供应商列表请求参数
      getSupplier: {
        tenderId: ''
      }
    }
  },
  created() {
    // 获取项目信息
    this.initProjectData()
  },
  methods: {
    /*
       * =======================获取-页面数据 start==============================
     * */
    /*
    * 获取项目信息
    * @params {tenderId: 项目id}
    */
    initProjectData() {
      const data = { tenderId: this.projectBase.tenderId }
      queryBaseProcurementProjectInfo(data).then(res => {
        // 获取项目信息
        this.formData = res.data
        this.insideTenderProjectFileType.bizId = this.projectBase.tenderId // 获取内部附件业务id
        // 获取项目规则
        this.initRule(this.projectBase.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.queryBaseProcurementBulletinInfoData(this.projectBase.tenderId)
        // 查询供应商列表
        this.initSupplier(this.projectBase.tenderId)
      }).catch(() => {})
    },
    // 查询行项目信息条件
    getQueryParams() {
      // 获取项目id
      this.searchForm.tenderId = this.projectBase.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
      }).catch(() => {})
    },
    // 查询供应商条件
    getSupplierParams() {
      this.getSupplier.tenderId = this.projectBase.tenderId // 项目id
      const param = Object.assign({}, this.getSupplier)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)
    },
    /*
    获取供应商列表方法
    入参 params: {tenderId: 项目id pageNo 页码 pageSize 每页显示条数}
    */
    initSupplier() {
      const params = this.getSupplierParams()
      queryProcurementInvitatinDetailPage(params).then(res => {
        // 获取供应商列表数据
        this.procurementSuplierList = res.data.records
      })
    },
    // 封装获取项目公告方法
    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.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 // 采购方式

        }
      })
    }
    /*
       * =======================获取-页面数据 End==============================
     * */
  }
}
</script>

<style lang="less" scoped>

</style>
