<!--
  @description: 采购计划-计划详情组件
  @author: lxl change by haofengxian
  @routerPath:/procurement/procurementPlanIsAuditComp
  @date： 2020-11-03 10:24:19
-->
<template>
  <div>
    <p class="page-title">
      1.采购计划基本信息
    </p>
    <table class="tableData">
      <tr>
        <td>
          采购计划编号
        </td>
        <td>
          {{ formData.purchasePlanNo }}
        </td>
        <td>
          采购计划名称
        </td>
        <td>
          {{ formData.purchasePlanName }}
        </td>
      </tr>
      <tr>
        <td>
          创建人
        </td>
        <td>
          {{ formData.createUserRealName }}
        </td>
        <td>
          采购单位
        </td>
        <td>
          {{ formData.createUserDepartName }}
        </td>
      </tr>
      <tr>
        <td>
          采购组织形式
        </td>
        <td :colspan="organizaTionFlag?'0':'3'">
          {{ filterDictText(plan_purchase_organizationList,formData.purchaseOrganization) }}
        </td>
        <template v-if="organizaTionFlag">
          <td>
            执行机构
          </td>
          <td>
            {{ formData.agentDepartName }}
          </td>
        </template>
      </tr>
      <!--委托采购-是否 （00集中委托 01-代理委托）-->
      <tr v-if="formData.purchaseOrganization==='01' && whetherPurchaser==='01'">
        <td>
          项目经理
        </td>
        <td>
          {{  formData.agentRealName }}
        </td>
        <td>
          联系方式
        </td>
        <td>
          {{ formData.contactNumber }}
        </td>
      </tr>
      <tr>
        <td>
          计划类型
        </td>
        <td colspan="3">
          {{ filterDictText(plan_typeList,formData.purchaseType) }}
        </td>
      </tr>
    </table>
    <p class="page-title">
      2.行项目信息
    </p>
    <procurementPlanLineItemComp :line-item-data="lineItemData" :loading="loading" @checkFile="onCheckFile" />
    <pagination :pagination-data="paginationData" :loading="loading" @change="getPurchasePlanMainDetail" />
    <checkFIleCompDialog :dialog-file-data="dialogFileData" />
  </div>
</template>

<script>
// api
import { queryPurchasePlanMainInfo, listPurchasePlanMainDetailPages } from '@/api/procurement/purchasplan'
import { getSystemConfigValueByConfigType } from '@/api/common/systemConfigCenter'
/* 弹框组件*/
import checkFIleCompDialog from '@/views/procurement/procurementPlan/components/checkFIleComp-dialog.vue'// 查看附件
/* 公用*/
import procurementPlanLineItemComp from '@/views/procurement/procurementPlan/components/procurementPlanLineItemComp.vue' // 行项目信息
import { ListMixin } from '@/mixins/ListMixin' // 公共参数方法
import { procurementPlanGrounpMixins } from '@/views/procurement/procurementPlan/mixins/procurementPlanGroupMixins' // 字典信息
import { filterDictText } from '@/assets/js/utils' // 字典
import pagination from '@comp/common/pagination/pagination' // 分页组件
export default {
  name: 'ProcurementPlanIsAuditComp',
  components: {
    procurementPlanLineItemComp,
    pagination,
    checkFIleCompDialog
  },
  mixins: [ListMixin, procurementPlanGrounpMixins],
  data() {
    return {
      formData: {},
      loading: true,
      organizaTionFlag: false, // 自采集采展示状态
      lineItemData: [], // 行项目数据
      planMainId: '', // 采购计划id
      dialogFileData: {
        checkFileVisible: false, // 查看附件弹框状态
        bizId: ''
      },
      whetherPurchaser: '' // 委托采购-是否 （00集中委托 01-代理委托）
    }
  },
  created() {
    this.planMainId = this.$route.params.planMainId
    this.getPurchasePlanMainDetail()
    this.getPurchasePlanMainInfo()
    this.getSystemConfig()
  },
  methods: {
    filterDictText,
    // 根据键获取配置 委托采购-是否 （00-否 01-是） （00集中委托 01-代理委托）
    getSystemConfig() {
      getSystemConfigValueByConfigType('whether_assign_purchaser').then((res) => {
        this.whetherPurchaser = res.data
      })
    },
    // 录入采购计划 获取计划明细列表
    getPurchasePlanMainDetail() {
      const params = {
        planMainId: this.planMainId, // 计划id
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize
      }
      listPurchasePlanMainDetailPages(params).then(response => {
        this.loading = false
        this.lineItemData = response.data.records
        this.paginationData.total = response.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 录入，编辑，查看，采购计划 获取计划信息
    getPurchasePlanMainInfo() {
      const data = {
        planMainId: this.planMainId
      }
      queryPurchasePlanMainInfo(data).then(response => {
        // currentRoleCode=21属于自采
        if (response.data.purchaseOrganization === '00') {
          this.organizaTionFlag = false
        } else {
          this.organizaTionFlag = true
        }
        this.formData = response.data
      }).catch(() => {
      })
    },
    // 查看附件
    onCheckFile(res, flg) {
      this.dialogFileData.checkFileVisible = flg
      this.dialogFileData.bizId = res.planDetailId
    }
  }
}
</script>
<style scoped>
</style>
