<!--
  @description: 框架计划编辑-录入框架计划（新增）
  @author: lxl
  @routerPath:/procurementPlan/addFrame
  @date： 2020-8-3 13:56:01
-->
<template>
  <div class="p0-16">
    <!--标题-->
    <section v-if="!flowStatus" class="title">
      <i class="iconfont icon-fanhui pointer" @click="back()" />
      录入框架计划
    </section>
    <p class="page-title">
      1.框架计划基本信息
    </p>
    <el-form ref="form" :model="formData" :rules="rules" :inline-message="true">
      <table class="from_table">
        <tr>
          <td><el-form-item label="采购计划名称" prop="purchasePlanName" /></td>
          <td colspan="3">
            <gx-input
              v-model="formData.purchasePlanName"
              gx-maxlength="varchar50"
              show-word-limit
              clearable
            />
          </td>
          <!-- 采购单位暂时隐藏 -->
          <!-- <td><el-form-item label="采购单位" prop="belongOrgName" /></td>
          <td>
            <el-input
              v-model="formData.belongOrgName"
              placeholder="请选择"
              style="width: calc(100% - 200px)"
              disabled
            />
            <el-button type="primary" class="ml10 choose" @click="organSelect">
              选择采购单位
            </el-button>
            <el-button type="primary" plain class="ml10 choose" @click="organSelect('clear')">
              清 空
            </el-button>
          </td> -->
        </tr>
        <tr>
          <td><el-form-item label="采购计划编号" prop="purchasePlanNo" /></td>
          <td>
            <gx-input
              v-model="formData.purchasePlanNo"
              :disabled="tenderNoStatus"
              clearable
            />
          </td>
          <td><el-form-item label="采购单编号" /></td>
          <td>
            {{ formData.tenderNo }}
          </td>
        </tr>
        <tr>
          <td><el-form-item label="采购单含税总预算(元)" /></td>
          <td>
            {{ formData.budgetTotalTaxMoney && numFilter(formData.budgetTotalTaxMoney) }}
          </td>

          <td><el-form-item label="采购单净预算(元)" prop="budgetTotalMoney" /></td>
          <td>
            {{ formData.budgetTotalMoney && numFilter(formData.budgetTotalMoney) }}
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="采购方式" prop="tenderMethod" />
          </td>
          <td colspan="3">
            <el-select
              v-model="formData.tenderMethod"
              filterable
              :loading="selLoading"
              placeholder="请选择"
              @change="onHandelTender"
            >
              <el-option
                v-for="item in tenderMethodList"
                :key="item.typecode"
                :label="item.typename"
                :value="item.typecode"
              />
            </el-select>
          </td>
        </tr>

        <tr>
          <td>
            <el-form-item label="公开/邀请" prop="tenderType" />
          </td>
          <td>
            <el-radio-group v-model="formData.tenderType">
              <el-radio
                v-for="(item) in tenderTypeList"
                :key="item.typecode"
                :label="item.typecode"
                :disabled="tenderFlg"
              >
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </td>
          <td>
            <el-form-item label="评审办法" prop="reviewMethod" />
          </td>
          <td>
            <el-radio-group v-model="formData.reviewMethod">
              <el-radio
                v-for="(item) in reviewMethodList"
                :key="item.typecode"
                :label="item.typecode"
              >
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="供应商属性" prop="supplierAttribute" />
          </td>
          <td colspan="3">
            <el-checkbox v-model="attributedCheckAll" :indeterminate="attributeIsIn" @change="attrCheckAllChange">
              全选
            </el-checkbox>
            <el-checkbox-group v-model="formData.supplierAttribute" @change="attrCheckedCitiesChange">
              <el-checkbox v-for="(item) in supplierAttributeList" :key="item.typecode" :label="item.typecode">
                {{ item.typename }}
              </el-checkbox>
            </el-checkbox-group>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="供应商分类" prop="supplierCategory" />
          </td>
          <td colspan="3">
            <el-checkbox v-model="categoryCheckAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">
              全选
            </el-checkbox>
            <el-checkbox-group v-model="formData.supplierCategory" @change="handleCheckedCitiesChange">
              <el-checkbox v-for="(item) in supplierCategoryList" :key="item.typecode" :label="item.typecode">
                {{ item.typename }}
              </el-checkbox>
            </el-checkbox-group>
          </td>
        </tr>
        <tr>
          <td>
            <el-form-item label="采购方式说明" prop="tendermethodRemarks" />
          </td>
          <td colspan="3">
            <gx-input
              v-model="formData.tendermethodRemarks"
              :autosize="{ minRows: 2, maxRows: 2 }"
              type="textarea"
              show-word-limit
              gx-maxlength="varchar500"
            />
          </td>
        </tr>
        <tr>
          <td><el-form-item label="公开附件" /></td>
          <td colspan="3">
            <uploadFile :file-data="lineItemFileType" />
          </td>
        </tr>
        <tr>
          <td><el-form-item label="内部附件" /></td>
          <td colspan="3">
            <uploadFile :file-data="lnteriorFileType" />
          </td>
        </tr>
      </table>
      <!--供应商信息-->
      <template v-if="supplierIsShow">
        <p class="page-title">
          供应商信息
        </p>
        <el-button type="primary" class="mb10" @click="selSupplier">
          选择供应商
        </el-button>
        <el-table
          ref="multipleTable"
          style="marginTop:10px"
          :data="supplierList"
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="50"
          />
          <el-table-column
            prop="supplierName"
            header-align="center"
            label="供应商"
          />
          <el-table-column
            prop="businesslicence"
            header-align="center"
            label="统一社会信用代码"
            min-width="110"
          />
          <el-table-column
            prop="linkerName"
            header-align="center"
            label="联系人"
          />
          <el-table-column
            prop="linkerTel"
            align="center"
            label="联系方式"
          />
          <el-table-column
            label="操作"
            align="center"
            min-width="80"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="removeSupplier(scope.row)"
              >
                移除
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </el-form>
    <!--供应商信息-->
    <el-row :gutter="40">
      <el-col :md="24" :lg="24" class="mt10 mb10">
        <span class="page-title ">2.行项目信息</span>
        <el-button
          class="m10 btn-ml10"
          type="primary"
          icon="el-icon-plus"
          @click="addRow"
        >
          添加行项目信息
        </el-button>
        <el-upload
          ref="uploads"
          :on-success="handleSuccess"
          :on-error="handleError"
          :headers="importHeaders"
          :show-file-list="false"
          :action="action"
          :data="upLoadData"
          multiple
          class="btn-ml10"
          style="display: inline-block;"
        >
          <el-button>模板导入</el-button>
        </el-upload>
        <el-button class="btn-ml10" @click="downloadClick">
          下载模板文件
        </el-button>
      </el-col>
    </el-row>
    <!--行项目信息编辑列表-->
    <div>
      <addlineItemTable :line-project-data="lineProjectData" :detail-ider="detailIder" @planDetail="planDetail" @checkFile="onCheckFile" @deleteItem="onDeleteItem" />
      <!--分页组件-->
      <page-nation :pagination-data="paginationData" @change="initLineInfoData" />
    </div>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <!-- 提交 -->
          <el-button
            :loading="confirmStepLoading"
            type="primary"
            @click="nextStep('form')"
          >
            提 交
          </el-button>
          <!-- 保存 -->
          <el-button
            :loading="confirmLoading"
            @click="save('form')"
          >
            保 存
          </el-button>
        </div>
      </div>
    </div>
    <!--添加行项目信息弹框-->
    <addLineItemDialog
      v-if="dialogData.consignContractVisible"
      :dialog-data="dialogData"
      :planmainid="planMainId"
      @saveconsignContractInfo="saveconsignContractInfo"
    />

    <!-- 选择供应商 -->
    <selSupplierDialog :dialog-data="selSupplierDialogData" @consignContractInfo="consignContractInfo" />
    <!-- 采购单位弹框 -->
    <!-- <organTree-dialog ref="organTree" @call-back="organTree" /> -->
    <!-- 查看附件 -->
    <checkFIleCompDialog :dialog-file-data="dialogFileData" />
    <!-- 工作流 -->
    <!--工作流选择节点组件-->
    <processNode-com
      ref="processNode"
      :process-definition-key="processDefinitionKey"
      @processNodeData="processNodeData"
    />
    <!--工作流流程节点/获取审核用户-->
    <depart-dialog
      ref="departDialog"
      :process-node="processNode"
      @isSingleUser="isSingleUser"
      @processInitData="processInitData"
      @submit="submitFlow"
    />
  </div>
</template>
<script>
/* 接口*/
import {
  importFramePackDetailInfoList, // 导入
  getPurchasePlanFrameDetailsList, // 行项目列表
  getTenderNoByMethod, // 获取采购单编号
  purchasePlanDetailsPackFrame, // 框架计划确定【打包
  purchasePlanFramePackPage, // 框架计划采购单页面
  queryProcurementPackFrameSupplierList, // 查询邀请供应商
  removeProcurementFrameSupplierList, // 移除邀请供应商
  deletePurchasePlanDetail // 移除行项目
} from '@/api/procurement/purchasplan'

import { downloadTemplate } from '@/api/procurement/datacenterDangtfz' // 导入接口
/* 公共方法*/
import { ListMixin } from '@/mixins/ListMixin' // 分页
import { filterDictText, numFilter } from '@/assets/js/utils' // 常用方法
import { purPlanBaleMixins } from '../../purPlanBale/mixins/purPlanBaleMixins' // 是否进入工作流配置
// import { procurementPlanGrounpMixins } from '@/views/procurement/procurementPlan/mixins/procurementPlanGroupMixins' // 采购立项 公共字典
/* 公共组件*/
import pagination from '@comp/common/pagination/pagination' // 分页组件
// import organTreeDialog from '@/views/common/user/organizationTree/organTree-dialog' // 采购单位选择
import { characters1_auto } from '@/assets/js/validate'// 校验输入内容

/* ==========工作流===========*/
import { workCommonMixins } from '@/views/work/mixins/workCommonMixins' // 工作流公共配置
import workconstant from '@/assets/js/workutils/workconstant/procurement' // 配置流程key
import processNodeCom from '@/views/work/processNodeCom' // 工作流选择节点组件
import departDialog from '@/views/work/depart-dialog' // 选择审核人员
/* ============================*/
/*  弹框 */
import addLineItemDialog from './addLineItem-dialog' // 录入物资弹框
import checkFIleCompDialog from '@/views/procurement/procurementPlan/components/checkFIleComp-dialog.vue'// 查看附件
/* 表格*/
import addlineItemTable from './addlineItemTable' // 行项目物资组件
import Cookies from 'js-cookie' // cookies
import { download } from '@/assets/js/utils/index' // 文件回显组件
/* =============== 打包================*/
import selSupplierDialog from '@/views/procurement/components/selSupplier-dialog.vue' // 选择供应商
import { lineItemBackAdd } from '@/views/procurement/procurementPlan/mixins/lineItemBackAdd.js' // 打包混入
import uploadFile from '@/views/procurement/procurementPlan/components/uploadFile' // 附件上传
/* =============================================*/
export default {
  name: 'AddFrameAdd',
  components: {
    addLineItemDialog, // 录入物资弹框
    addlineItemTable, // 行项目物资组件
    'page-nation': pagination, // 分页组件
    checkFIleCompDialog, // 查看附件
    'processNode-com': processNodeCom, // 工作流节点信息组件
    'depart-dialog': departDialog, // 工作流审批人组件
    selSupplierDialog, // 选择供应商
    uploadFile // 附件上传
    // organTreeDialog // 组织机构选择
  },
  mixins: [ListMixin, workCommonMixins, lineItemBackAdd, purPlanBaleMixins],
  data() {
    return {
      /* -----------数据字典start-------------*/
      tenderMethodList: [], // 采购方式
      tenderTypeList: [], // 公开/邀请
      supplierAttributeList: [], // 供应商属性
      supplierCategoryList: [], // 供应商分类
      reviewMethodList: [], // 评审办法
      dictionaryType: ['tenderMethod', 'tenderType', 'supplierAttribute', 'supplierCategory', 'reviewMethod'],
      /* -----------数据字典end-------------*/
      action: importFramePackDetailInfoList, // 导入接口
      // createURL: createURL,
      importHeaders: {}, // cookit
      upLoadData: { // 模板导入数据
        planMainId: ''
      },
      selLoading: false, // 选择采购方式loading
      tenderFlg: false, // 公开邀请disbale状态
      /* ------供应商分类和属性复选框数据 start--------*/
      categoryCheckAll: false, // 供应商分类全选
      attributedCheckAll: false, // 供应商属性全选
      attributeIsIn: false, // 供应商属性全选样式控制
      isIndeterminate: false, // 供应商分类全选样式控制
      /* ------供应商分类和属性复选框数据 End--------*/
      supplierList: [], // 供应商选择数据
      supplierid: '', //  供应商选择数据id
      supIsShow: false, // 选择供应商状态
      // 选择供应商参数
      selSupplierDialogData: {
        departId: '', // 当前登录人的机构id
        tenderId: '',
        tenderMethod: '', // 采购方式
        tenderType: '', // 公开/邀请
        purPlanType: '01', // 集采计划打包 00 框架计划编制 01
        consignContractVisible: false // 弹框状态
      },
      /* -----------------------*/
      processDefinitionKey: '', // 工作流流程id
      operation: '00', // 00保存/01提交
      detailIder: this.$route.params.detailIder, // 00查看标识 01编辑
      confirmLoading: false, // 保存button confirmLoading状态
      confirmStepLoading: false, // 提交button confirmLoading状态
      tenderNoStatus: true, // 采购计划编号禁用状态 默认禁用 二次进入时可编辑
      planMainId: '', // 计划id
      // 添加行项目信息-展示/隐藏状态 true 展示/false 隐藏
      dialogData: { // 添加行项目信息弹框数据
        consignContractVisible: false,
        planDetailId: '', // 行项目id
        planAdd: '', // 保存/编辑
        purchasePlanNo: '', // 计划编号
        purchasePlanName: '' // 计划名称
        // operation: '00' // 保存 00 编辑 01
      },
      // 查看附件
      dialogFileData: {
        checkFileVisible: false, // 查看附件弹框状态
        bizId: '' // 附件id
      },
      lineProjectData: [], // 行项目信息
      tenderId: this.$route.params.tenderId || this.$route.query.id,
      formData: {
        purchaseOrganization: '00', // 采购形式组织
        tenderType: '00', // 公开/邀请
        tenderMethod: '', // 采购方式
        supplierAttribute: [], // 供应商属性保存传入后端数据
        supplierCategory: [], // 供应商分类保存传入后端数据
        reviewMethod: '02', // 评审办法
        tendermethodRemarks: '', // 采购方式说明
        // belongOrgName: '', // 采购单位
        belongOrgId: '' // 代理单位ID
      },
      // 校验规则
      rules: {
        purchasePlanNo: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 采购计划编码
        purchasePlanName: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 采购计划名称
        // belongOrgName: [{ required: true, validator: characters1_auto, trigger: 'blur' }], // 采购单位
        tenderMethod: [{ required: true, message: '请选择', trigger: 'change' }], // 采购方式
        tenderType: [{ required: true, message: '请选择', trigger: 'change' }], // 公开/邀请
        supplierAttribute: [{ required: true, message: '请选择', trigger: 'change' }], // 供应商属性
        supplierCategory: [{ required: true, message: '请选择', trigger: 'change' }], // 供应商分类
        reviewMethod: [{ required: true, message: '请选择', trigger: 'change' }], // 评审办法
        tendermethodRemarks: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 采购方式说明
      }
    }
  },
  computed: {
    // 采购单净预算
    // budgetTotalMoney() {
    //   const totalMoney = this.lineProjectData.reduce((cur, pre) => {
    //     cur += Number(pre.purchaseTotalBudget)
    //     return cur
    //   }, 0)
    //   return totalMoney
    // }
  },
  watch: {
    'paginationData.total'(val) {
      if (this.paginationData.pageSize * (this.paginationData.pageNo - 1) === val && val !== 0) {
        this.paginationData.pageNo -= 1
        this.initLineInfoData()
      }
    }
  },
  created() {
    this.purchasplanPackAudit() // 框架计划确定【打包】获取是否进入工作流
    this.importHeaders['X-AUTH-TOKEN'] = Cookies.get('X-AUTH-TOKEN')
    this.initData() // 采购计划基本信息
    this.getNodeId() // 工作流id/key
    this.getGroupType()// 字典请求初始化
  },
  methods: {
    filterDictText, // 数据字典方法
    numFilter, // 金额千位符
    // 数据字典查询
    getGroupType() {
      this.$store.dispatch('getGroupType', this.dictionaryType).then((data) => {
        // 遍历key存储相应的数据
        for (const key in data.bidTypeData) {
          /* 是否有数据*/
          if (data.bidTypeData[key]) {
            this[key] = data.bidTypeData[key]
          }
        }
      })
    },
    // 下载计划详情模板
    downloadClick() {
      //  模板类型
      const data = {
        templateType: 'P_T_P_PURCHASPLAN_PLANFRAMEDETAILTEMPLATE'
      }
      downloadTemplate(data).then(res => {
        download(res, '计划详情模板.xls')
      })
    },
    // 模板导入成功后的回调
    handleSuccess(response, file, fileList) {
      // 模板导入成功后
      if (response.header.ret === '0') {
        this.$message.success(response.header.msg)
      } else {
        // 上传失败
        this.$message.warning(response.header.msg)
      }
      //  清空
      this.$refs.uploads.clearFiles()
      // 加载行项目数据列表方法
      this.initLineInfoData()
    },
    // 模板导入失败后的回调
    handleError(response, file, fileList) {
      this.$message.error(response.header.msg)
      this.$refs.uploads.clearFiles()
      this.initLineInfoData()
    },
    /*
     * 选择新增物资回调函数
     *
     * */
    saveconsignContractInfo(data) {
      this.formData.budgetTotalMoney = data.budgetTotalMoney // 采购单净预算
      this.formData.budgetTotalTaxMoney = data.budgetTotalTaxMoney // 含税总预算
      this.initLineInfoData()
    },
    // 查看附件
    onCheckFile(res, flg) {
      this.dialogFileData.checkFileVisible = flg // 弹框状态
      this.dialogFileData.bizId = res.planDetailId // 计划详情id
    },
    // 开启行项目信息开启弹框
    addRow() {
      // 开启弹框
      this.dialogData.planAdd = '00' // 00 保存 01 编辑
      // this.dialogData.operation = this.$route.params.operation || this.operation // 保存/提交
      this.dialogData.purchasePlanNo = this.formData.purchasePlanNo // 计划编号
      this.dialogData.purchasePlanName = this.formData.purchasePlanName // 计划名称
      this.dialogData.consignContractVisible = true
    },
    /*
    * 行项目信息编辑触发
    * */
    planDetail(data) {
      this.dialogData.planDetailId = data.planDetailId // 计划详情id
      this.dialogData.planAdd = data.planAdd // 保存：00 编辑：01
      this.dialogData.purchasePlanNo = this.formData.purchasePlanNo // 计划编号
      this.dialogData.purchasePlanName = this.formData.purchasePlanName // 计划名称
      this.dialogData.consignContractVisible = true // 弹框状态
    },
    // 移除行项目信息
    onDeleteItem(row) {
      this.$confirm('此操作将删除该行项目信息, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      })
        .then(() => {
          if (row.planDetailId) {
            const params = {
              planDetailId: row.planDetailId
            }
            deletePurchasePlanDetail(params).then(res => {
              this.formData.budgetTotalMoney = res.data.budgetTotalMoney // 采购单净预算
              this.formData.budgetTotalTaxMoney = res.data.budgetTotalTaxMoney // 含税总预算
              this.initLineInfoData()
              this.$message.success(res.header.msg)
            }).catch((error) => {
              this.$message.warning(error)
            })
          }
        })
        .catch(() => {})
    },
    // 保存提交数据
    assetsData() {
      // 采购计划基本信息
      const projectInfo = {
        ...this.formData,
        budgetTotalMoney: this.formData.budgetTotalMoney, // 采购单净预算
        budgetTotalTaxMoney: this.formData.budgetTotalTaxMoney, // 采购单含税预算
        tenderId: this.tenderId, // 采购单id
        purchaseType: '00', // 采购类型
        planType: '01', // 计划类型
        operationType: this.operation, // 保存
        planMainId: this.planMainId, // 项目id
        // belongOrgId: this.formData.belongOrgId, // 采购单位id
        // belongOrgName: this.formData.belongOrgName, // 采购单位名称
        supplierCategory: this.formData.supplierCategory.join(','), // 供应商分类
        supplierAttribute: this.formData.supplierAttribute.join(','), // 供应商属性
        tenderMethod: this.formData.tenderMethod // 采购方式
      }
      return projectInfo
    },
    // 获取工作流：id/key
    getNodeId() {
      this.processDefinitionKey = workconstant.purPlanFrame
    },
    // 保存
    save(formName) {
      this.confirmLoading = true
      // 获取保存参数
      const data = this.assetsData()
      // 调用保存数据方法
      this.saveData(data)
    },
    // 提交
    nextStep(formName) {
      // 供应商校验
      if (!this.supplierVerify().flag) {
        this.$message.warning(this.supplierVerify().msg)
        return false
      }
      if (this.lineProjectData.length <= 0) {
        this.$message.warning('请添加行项目信息')
        return false
      }
      this.confirmStepLoading = true
      this.$refs[formName].validate((valid, field) => {
        if (valid) {
          // 获取保存参数
          this.operation = '01'// 提交
          this.$confirm('提交之后将不能更改，确认提交吗?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn'
          }).then(() => {
            this.confirmStepLoading = false
            // 判断是否进入工作流
            if (this.purchasplanPackAuditConfig) {
              // 调用保存数据方法
              if (JSON.stringify(this.processNode) !== '{}' && this.processNode.nodeId) {
                this.$refs.departDialog.getUserDepart(this.processNode)
              }
            } else {
              // 直接提交
              this.submitFlow()
            }
          }).catch(() => {
            this.confirmStepLoading = false
          })
        } else {
          this.confirmStepLoading = false
          this.$message({ type: 'warning', message: '请注意页面提示！' })
          return false
        }
      })
    },
    // 审批流提交
    submitFlow() {
      const data = this.assetsData()
      data.operation = this.operation // 保存 00 提交 01
      data.processDefinitionKey = this.processDefinitionKey // 工作流节点key
      // this.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
      // data.processInitDto = this.processInitDto // 审核人信息传回得信息
      // 判断是否进入工作流
      if (this.purchasplanPackAuditConfig) {
        data.processDefinitionKey = this.processDefinitionKey // 工作流节点key
        data.processInitDto = this.processInitDto // 审核人信息传回得信息
      }
      this.saveData(data)
    },
    // 封装保存数据请求方法
    saveData(data) {
      purchasePlanDetailsPackFrame(data)
        .then(res => {
          this.confirmLoading = false
          this.back()
        })
        .catch(() => {
          this.confirmLoading = false
        })
    },
    // 封装获取项目基本信息请求方法
    initData() {
      const params = {
        tenderId: this.tenderId || ''
      }
      // 页面初始化
      purchasePlanFramePackPage(params).then((res) => {
        // 判断supplierCategory/supplierAttribute：如果是null或者是undefined时则赋值为空数组
        res.data.supplierCategory = res.data.supplierCategory ?? []
        res.data.supplierAttribute = res.data.supplierAttribute ?? []
        this.formData = {
          ...res.data,
          ...res.data.planMainInfo
        }
        // 判断采购方式是否等于单一来源
        if (this.formData.tenderMethod === '12') {
          this.formData.tenderType = this.formData.tenderType ? this.formData.tenderType : '01' // 公开邀请默认值初始化
          this.tenderFlg = true
        } else {
          this.formData.tenderType = this.formData.tenderType ? this.formData.tenderType : '00' // 公开邀请默认值初始化
          this.tenderFlg = false
        }
        this.tenderId = this.formData.tenderId
        this.planMainId = this.formData.id // 项目id
        this.upLoadData.planMainId = this.planMainId // 模板导入的 planMainId
        this.lineItemFileType.bizId = this.formData.tenderId // 公开上传附件id
        this.lnteriorFileType.bizId = this.formData.tenderId // 内部上传附件id
        this.formData.tenderType = this.formData.tenderType ? this.formData.tenderType : '00' // 公开邀请
        this.formData.reviewMethod = this.formData.reviewMethod ? this.formData.reviewMethod : '02' // 评审办法
        // 供应商分类
        this.formData.supplierCategory = this.formData.supplierCategory instanceof Array ? this.formData.supplierCategory : this.formData.supplierCategory.toString().split(',') || []
        // 供应商属性
        this.formData.supplierAttribute = this.formData.supplierAttribute instanceof Array ? this.formData.supplierAttribute : this.formData.supplierAttribute.toString().split(',') || []
        // =============  供应商属性和分类的初始化渲染情况 supplierCategory||supplierAttribute 数组为空首次加载页面 否则未以保存或者提交的数据 start ==========
        if (this.formData.supplierCategory.length > 0) {
          this.handleCheckedCitiesChange(this.formData.supplierCategory)
        }
        if (this.formData.supplierAttribute.length > 0) {
          this.attrCheckedCitiesChange(this.formData.supplierAttribute)
        }
        // ============= 供应商属性和分类的初始化渲染情况 supplierCategory ||supplierAttribute  数组为空首次加载页面 否则未以保存或者提交的数据 End ==========
        this.initLineInfoData() // 获取行项目信息
        this.queryProcurementSupplierList() // 获取供应商
      })
    },
    /* =========================================采购单位暂时隐藏Start===============================================*/
    // 选择采购单位 type 有值为清空 无值为新增
    // organSelect(type) {
    //   if (type === 'clear') {
    //     this.formData.belongOrgName = ''
    //   } else {
    //     this.$refs.organTree.open({
    //       title: '选择采购单位', // 弹框标题
    //       dialog: true, // 弹窗状态
    //       selectCodes: this.formData.belongOrgId ? this.formData.belongOrgId.split(',') : this.formData.belongOrgId // 当前选中的供货范围Code
    //     })
    //   }
    // },
    // 选择/清空采购单位
    // organTree(data) {
    //   // 清空
    //   if (data === 'clear') {
    //     this.formData.belongOrgName = '' // 采购单位名称
    //     this.formData.belongOrgId = '' // 采购单位id
    //   } else {
    //     // 选择
    //     this.$set(this.formData, 'belongOrgName', data.labels)
    //     this.$set(this.formData, 'belongOrgId', data.keys)
    //   }
    // },
    /* =========================================采购单位暂时隐藏End===============================================*/
    // 封装行项目信息请求方法
    initLineInfoData() {
      // 查询条件
      const params = {
        planMainId: this.planMainId, // 计划id
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize
      }
      getPurchasePlanFrameDetailsList(params)
        .then(res => {
          this.lineProjectData = res.data.records
          // 获取条数
          this.paginationData.total = res.data.total
        })
        .catch(() => {})
    },
    // 返回按钮
    back() {
      if (this.flowStatus) {
        const routePathStatus = sessionStorage.getItem('routePathStatus') // 工作流处理 00桌面进入 01待办列表进入
        this.$router.push({
          path: routePathStatus === '00' ? '/home' : '/work/todo'
        })
      } else {
        this.$router.push('procurementPlanFrameList')
      }
    },
    /* =================打包===================*/
    // 采购方式
    onHandelTender(val) {
      // selLoading：选择采购方式loading，为确保与采购单编号统一
      this.selLoading = true
      if (val === '12') {
        this.formData.tenderType = '01' // 邀请
        this.tenderFlg = true
      } else {
        this.formData.tenderType = '00' // 公开
        this.tenderFlg = false
      }
      // 获取采购单编号
      const paramsData = {
        tenderId: this.tenderId || '', // 采购单id
        tenderMethod: val, // 采购方式
        planType: '01' // 01 框架
      }
      getTenderNoByMethod(paramsData).then((res) => {
        this.selLoading = false
        this.formData.tenderNo = ''
        this.formData.tenderNo = res.data
      }).catch(() => {
        this.selLoading = false
      })
    },
    /* =============选择供应商=================*/
    // 选择供应商
    selSupplier() {
      this.selSupplierDialogData.tenderId = this.formData.tenderId // 采购单id
      this.selSupplierDialogData.tenderMethod = this.formData.tenderMethod // 采购方式
      this.selSupplierDialogData.tenderType = this.formData.tenderType // 采购类型
      this.selSupplierDialogData.single = this.single // 单选/多选
      this.selSupplierDialogData.departId = this.$store.getters.info.companyId // 当前登录角色的机构id
      this.selSupplierDialogData.consignContractVisible = true // 弹框状态
    },
    // 移除选择供应商
    removeSupplier(row) {
      const params = {
        id: row.id
      }
      removeProcurementFrameSupplierList(params).then((res) => {
        this.queryProcurementSupplierList()
      })
    },
    // 选择供应商弹框关闭时再次请求
    consignContractInfo() {
      this.queryProcurementSupplierList()
    },
    // 查询供应商
    queryProcurementSupplierList() {
      const params = {
        tenderId: this.formData.tenderId
      }
      queryProcurementPackFrameSupplierList(params).then((res) => {
        this.supplierid = res.data.map(item => item.id).join(',')
        this.supplierList = res.data
      })
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.show-word-limit-padding {
  .el-input__inner {
    padding-right: 70px;
  }
}
/deep/.el-table {
  .el-table__fixed {
    height:auto !important; // 此处的important表示优先于element.style
    bottom:12px; //..度后，设置与父容器的底部距离，则高度会动态改变
  }
}
/deep/.el-table__body-wrapper::-webkit-scrollbar{
  padding-top: 5px;
  height:12px;
}
.btn-ml10{
  margin-left: 10px;
}
</style>
