<!--
  @description: 计划打包编辑组件-新增弹框、工作流编辑共用
  @author: lxl
  @date： 2020-11-02 14:32
-->
<template>
  <div>
    <el-form ref="formData" :rules="rules" :model="formData" :inline-message="true">
      <table class="from_table">
        <tr class="singleRow">
          <td><el-form-item label="采购单编号" prop="tenderNo" /></td>
          <td colspan="3">
            <el-input
              v-model="formData.tenderNo"
              :disabled="true"
              placeholder="采购单编号"
              clearable
            />
          </td>
        </tr>
        <tr class="singleRow">
          <td>
            <el-form-item label="采购方式" prop="tenderMethod" />
          </td>
          <td colspan="3">
            <span v-if="!formData.select && dialogBaleData.baleKey==='00'">
              {{ filterDictText(tenderMethodList,formData.tenderMethod) }}
            </span>
            <el-radio-group v-else v-model="formData.tenderMethod" @change="onHandelTender">
              <el-radio
                v-for="(item) in tenderMethodList"
                :key="item.typecode"
                :label="item.typecode"
              >
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr class="singleRow">
          <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 class="singleRow">
          <td>
            <el-form-item label="公开/邀请" prop="tenderType" />
          </td>
          <td colspan="3">
            <el-radio-group v-model="formData.tenderType">
              <el-radio
                v-for="(item) in changeTenderTypeList"
                v-if="item.typecode === '02' && formData.tenderMethod === '00'?false:true"
                :key="item.typecode"
                :label="item.typecode"
                :disabled="tenderFlg"
              >
                {{ item.typename }}
              </el-radio>
            </el-radio-group>
          </td>
          <!-- <td>
              <el-form-item label="是否优先" prop="priorityOrderBy" />
            </td>
            <td>
              <el-radio-group v-model="formData.priorityOrderBy">
                <el-radio
                  v-for="(item) in priorityOrderByList"
                  :key="item.typecode"
                  :label="item.typecode"
                >
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td> -->
        </tr>
        <!--
            tenderMethod 11询价 tenderType 01邀请
             formData.tenderMethod==='11' && formData.tenderType==='01'
          -->
        <template v-if="false">
          <tr>
            <td>
              <el-form-item label="是否联合体" prop="ifCombo" />
            </td>
            <td colspan="3">
              <el-radio-group v-model="formData.ifCombo" @change="changeIfCombo">
                <el-radio
                  v-for="(item) in ifComboTypeList"
                  :key="item.typecode"
                  :label="item.typecode"
                >
                  {{ item.typename }}
                </el-radio>
              </el-radio-group>
            </td>
          </tr>
          <tr v-if="formData.ifCombo==='01'">
            <td>
              <el-form-item label="联合体协议" prop="invitationComboFileType" />
            </td>
            <td colspan="3">
              <uploadFile
                ref="invitationComboFileType"
                :file-data="invitationComboFileType"
                :on-change="changeInvitationComboFile"
              />
            </td>
          </tr>
        </template>
        <!--招标不显示-->
        <template v-if="formData.tenderMethod!=='00'">
          <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="reviewMethod" />
            </td>
            <td colspan="3">
              <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="budgetTotalMoney" /></td>
            <td>
              {{ formData.budgetTotalMoney && numFilter(formData.budgetTotalMoney) }}
            </td>
            <td><el-form-item label="采购单含税总预算(元)" prop="budgetTotalTaxMoney" /></td>
            <td>
              {{ formData.budgetTotalTaxMoney && numFilter(formData.budgetTotalTaxMoney) }}
            </td>
          </tr>
        </template>
        <tr class="singleRow">
          <td><el-form-item :label="formData.tenderMethod!=='00'?'公开附件':'公告文件'" /></td>
          <td colspan="3">
            <uploadFile :file-data="lineItemFileType" />
          </td>
        </tr>
        <tr class="singleRow">
          <td><el-form-item :label="formData.tenderMethod!=='00'?'内部附件':'采购立项文件'"/></td>
          <td colspan="3">
            <uploadFile :file-data="lnteriorFileType" />
          </td>
        </tr>
      </table>
    </el-form>
    <!--供应商信息-->
    <template v-if="supplierIsShow">
      <p class="page-title">
        供应商信息
      </p>
      <!--联合体-->
      <consortiumSupplier
        v-if="formData.ifCombo==='01'"
        ref="consortiumSupplier"
        :form-data="formData"
        @getSupplierList="getSupplierList"
      />
      <template v-if="formData.ifCombo==='00'">
        <el-button type="primary" class="mb10" @click="selSupplier">
          选择供应商
        </el-button>
        <el-table ref="multipleTable" :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"
            align="left"
          />
          <el-table-column
            prop="linkerName"
            header-align="center"
            label="联系人"
          />
          <el-table-column
            prop="linkerTel"
            align="center"
            label="联系方式"
          />
          <el-table-column
            label="操作"
            align="center"
            fixed="right"
            min-width="80"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click.stop="removeSupplier(scope.row.id)"
              >
                移除
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </template>
    <!--行项目信息-->
    <template>
      <p class="page-title">
        行项目信息
      </p>
      <el-button type="primary" class="mb10" @click="addLineIten">
        新增行项目
      </el-button>
      <el-table :data="tableData">
        <el-table-column fixed="left" type="index" label="序号" align="center" />
        <el-table-column fixed="left" prop="purchaseNo" label="行项目编号" min-width="150" header-align="center" align="left" />
        <el-table-column prop="purchaseCode" label="物资编码" min-width="120" align="center" />
        <el-table-column prop="purchaseName" label="物资名称" min-width="220" header-align="center" align="left" />
        <el-table-column prop="purchaseSpecification" label="物资规格说明" min-width="220" header-align="center" align="left" />
        <el-table-column prop="purchaseDepartName" label="上报单位" min-width="220" header-align="center" align="left" />
        <el-table-column prop="purchaseNum" label="采购数量" min-width="100" header-align="center" align="right" />
        <el-table-column label="预算净单价(元)" min-width="130" header-align="center" align="right">
          <template slot-scope="scope">
            {{ scope.row.purchaseBudget && numFilter(scope.row.purchaseBudget) }}
          </template>
        </el-table-column>
        <el-table-column label="预算净总价(元)" min-width="130" header-align="center" align="right">
          <template slot-scope="scope">
            {{ scope.row.purchaseTotalBudget && numFilter(scope.row.purchaseTotalBudget) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" min-width="80" align="center">
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click.stop="deleteHandel(scope.row)"
            >
              移除
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <pagination :pagination-data="paginationData" @change="loadData" />
    </template>
    <!--保存按钮-->
    <div class="but_footer">
      <div class="but_footer-h">
        <div class="but_footer-but">
          <el-button type="primary" :loading="confirmLoading" @click="ensure('formData')">
            提 交
          </el-button>
          <el-button @click="handleClose">
            关 闭
          </el-button>
        </div>
      </div>
    </div>
    <!-- 选择供应商 -->
    <selSupplierDialog :dialog-data="selSupplierDialogData" @consignContractInfo="consignContractInfo" />
    <!-- 新增行项目 -->
    <addLientItemDialog :dialog-data="addLientItemData" @onStart="onStart" />
    <!-- 查看附件 -->
    <checkFIleCompDialog :dialog-file-data="dialogFileData" />
    <!-- 工作流 -->
    <!--工作流选择节点组件-->
    <processNodeCom
      ref="processNode"
      :process-definition-key="processDefinitionKey"
      @processNodeData="processNodeData"
    />
    <!--工作流流程节点/获取审核用户-->
    <departDialog
      ref="departDialog"
      :process-node="processNode"
      @isSingleUser="isSingleUser"
      @processInitData="processInitData"
      @submit="submit"
    />
  </div>
</template>

<script>
/* api*/
import {
  purchasePlanDetailsPack, // 打包
  queryProcurementPackInvitatinSupplierList, // 供应商查询
  removeProcurementPackInvitatinSupplierList, // 移除供应商
  purchasePlanDetailsPackPage, // 新增数据初始化
  getPurchasePlanDetailsPacked, // 编辑数据数据初始化
  removeProcurementPackedDetailList, // 移除
  getPurchasePlanPackDetailsList, // 新增行项目数据
  deleteProcurementPackedDetailList, // 移除行项目
  getTenderNoByMethod // 获取采购单号
} from '@/api/procurement/purchasplan' // 打包
/* 公用组件*/
import selSupplierDialog from '@/views/procurement/components/selSupplier-dialog.vue' // 选择供应商
import uploadFile from '@/views/procurement/procurementPlan/components/uploadFile' // 附件上传
import checkFIleCompDialog from '@/views/procurement/procurementPlan/components/checkFIleComp-dialog.vue'// 查看附件
import consortiumSupplier from './consortiumSupplier' // 联合体供应商

import addLientItemDialog from './addLientItem-dialog.vue' // 新增行项目弹框
/* ==========工作流===========*/
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 { purPlanBaleMixins } from '../mixins/purPlanBaleMixins' // 工作流配置（是否启用工作流）
/* ============================*/
import { lineItemBackAdd } from '@/views/procurement/procurementPlan/mixins/lineItemBackAdd.js' // 打包混入
import { characters1_auto } from '@/assets/js/validate'// 校验输入内容
import { ListMixin } from '@/mixins/ListMixin' // 分页
import { paging } from '@/assets/js/utils/index.js' // 前端分页
import { filterDictText, restoreInitialValue, numFilter } from '@/assets/js/utils' // 公用方法
import pagination from '@comp/common/pagination/pagination' // 分页组件
export default {
  name: 'BaleAdd',
  components: {
    pagination, // 分页
    processNodeCom, // 工作流节点信息组件
    departDialog, // 工作流审批人组件
    selSupplierDialog, // 选择供应商
    uploadFile, // 文件上传组件
    addLientItemDialog, // 新增行项目弹框
    checkFIleCompDialog, // 查看附件
    consortiumSupplier // 联合体供应商组件
  },
  mixins: [ListMixin, workCommonMixins, lineItemBackAdd, purPlanBaleMixins],
  props: {
    dialogBaleData: {
      type: Object,
      default: () => {
        return {
          tenderId: ''
        }
      }
    }
  },
  data() {
    return {
      flowStatus: this.$route.query.flowStatus, // true 工作流进入驳回编辑
      tableData: [], // 表格数据
      tenderFlg: false, // 公开邀请disbale状态
      processDefinitionKey: '', // 工作流流程key
      confirmLoading: false,
      selLoading: false, // 选择采购方式loading
      /* ------供应商分类和属性复选框数据 start--------*/
      categoryCheckAll: false, // 供应商分类全选
      attributedCheckAll: false, // 供应商属性全选
      attributeIsIn: false, // 供应商属性全选样式控制
      isIndeterminate: false, // 供应商分类全选样式控制
      // allSupAttributeArr: [], // 全选供应商属性用于全选的判断
      // allSupCategoryArr: [], // 全选供应商分类 用于全选的判断
      /* ------供应商分类和属性复选框数据 End--------*/
      supplierList: [], // 供应商选择数据
      supplierid: '', //  供应商选择数据id
      supIsShow: false, // 选择供应商状态
      // 选择供应商参数
      selSupplierDialogData: {
        departId: '', // 当前登录人的机构id
        tenderId: '',
        tenderMethod: '', // 采购方式
        tenderType: '', // 公开/邀请
        purPlanType: '00', // 集采计划打包 00 框架计划编制 01
        consignContractVisible: false // 弹框状态
      },
      // 新增行项目弹框数据
      addLientItemData: {
        dialogVisible: false,
        tenderId: '' // 采购单id
      },
      formData: {
        ifCombo: '00', // 是否联合体 00-否;01-是
        invitationComboFileType: '', // 联合体协议
        tenderType: '00', // 公开邀请
        tenderMethod: '', // 采购方式
        supplierAttribute: [], // 供应商属性
        supplierCategory: [], // 供应商分类
        reviewMethod: '02', // 评审办法
        tendermethodRemarks: '', // 采购方式说明
        tenderNo: '', // 采购单编号
        priorityOrderBy: '00' // 是否优先
      },
      // 附件查看弹框
      dialogFileData: {
        checkFileVisible: false, // 查看附件弹框状态
        bizId: '' // 附件id
      },
      // 采购单详情
      purchasePlanDetailsData: {
        purchaseOrganization: '', // 00-自行采购;01-委托采购
        tenderNo: ''// 采购单编号
      },
      changeTenderTypeList: [], // 公开/邀请根据采购方式动态变更
      rules: {
        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' }], // 评审办法
        invitationComboFileType: [{ required: true, message: '请上传', trigger: 'change' }], // 联合体协议
        tendermethodRemarks: [{ required: true, validator: characters1_auto, trigger: 'blur' }] // 采购方式说明
      }
    }
  },
  watch: {
    // 数量发生变化时页数自动减一
    'paginationData.total'() {
      if (this.paginationData.total === (this.paginationData.pageNo - 1) * this.paginationData.pageSize && this.paginationData.total !== 0) {
        this.paginationData.pageNo -= 1
        // 重新获取数据
        this.onStart()
      }
    }
  },
  created() {
    this.purchasplanPackAudit() // 获取是否工作流提交
    this.processDefinitionKey = workconstant.purPlanDetailsPack // 工作流流程key
    this.handelFlow() //  处理是否工作流进入
    this.getGroupType() // 字典请求初始化
  },
  methods: {
    filterDictText, // 字典
    numFilter, // 金额
    // 处理是否工作流进入
    handelFlow() {
      // flowStatus true 工作流进入
      if (this.flowStatus) {
        this.dialogBaleData.tenderId = this.$route.query.bizId
        this.initialize()
      }
    },
    // 字典请求
    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]
          }
        }
      })
    },
    // 选择采购方式改变公开/邀请
    onHandelTender(val) {
      // 00 公开招标不显示合格供应商公开
      if (val === '00') {
        this.changeTenderTypeList = this.tenderTypeList.filter(i => i.typecode !== '02')
      } else {
        this.changeTenderTypeList = this.tenderTypeList
      }
      // 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.formData.tenderId,
        tenderMethod: val, // 采购方式
        planType: '00' // 框架 01 打包 00
      }
      getTenderNoByMethod(paramsData).then((res) => {
        this.selLoading = false
        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 }
      removeProcurementPackInvitatinSupplierList(params).then((res) => {
        this.queryProcurementSupplierList()
      })
    },
    // 选择供应商弹框关闭时再次请求
    consignContractInfo() {
      this.queryProcurementSupplierList()
    },
    // 行项目数据分页
    loadData() {
      this.tableData = paging({}, this.formData.packList, this.paginationData)
    },
    // 查询供应商
    queryProcurementSupplierList() {
      const params = {
        tenderId: this.formData.tenderId
      }
      // 查询选择供应商
      queryProcurementPackInvitatinSupplierList(params).then((res) => {
        this.supplierid = res.data.map(item => item.id).join(',')
        this.supplierList = res.data
      })
    },
    // 数据初始化
    initialize() {
      const params = {
        planDetailIds: this.dialogBaleData.planDetailIds
      }
      // baleKey： 00 新增 01编辑
      if (this.dialogBaleData.baleKey === '00') {
        purchasePlanDetailsPackPage(params).then((res) => {
          this.purchasePlanDetailsData.purchaseOrganization = res.data.purchaseOrganization //  00-自行采购;01-委托采购
          this.formData = Object.assign({ ...this.formData }, {
            ...res.data
          })
          if (!this.formData.ifCombo) {
            this.formData.ifCombo = '00'
          }
          this.dataCom()
        }).catch(() => {
          setTimeout(() => {
            this.handleClose()
          }, 2000)
        })
      } else {
        const data = {
          tenderId: this.dialogBaleData.tenderId
        }
        getPurchasePlanDetailsPacked(data).then((res) => {
          this.formData = Object.assign({ ...this.formData }, {
            ...res.data
          })
          this.dataCom()
        })
      }
    },
    // 数据组合
    dataCom() {
      this.queryProcurementSupplierList() // 供应商请求初始化
      if (this.formData.ifCombo === '01') {
        this.$nextTick(() => {
          this.$refs.consortiumSupplier.queryProcurementSupplierList()
        })
      }
      this.formData.tenderMethod = this.formData.tenderMethod ? this.formData.tenderMethod : ''
      this.lineItemFileType.bizId = this.formData.tenderId // 公开上传附件id
      this.lnteriorFileType.bizId = this.formData.tenderId // 内部上传附件id
      this.invitationComboFileType.bizId = this.formData.tenderId // 联合体协议id
      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(',')
      this.tableData = paging({}, this.formData.packList, this.paginationData)
      // 判断采购方式是否等于单一来源
      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
      }
      // =============  供应商属性和分类的初始化渲染情况 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 ==========
    },
    // 新增行项目
    addLineIten() {
      this.addLientItemData.tenderId = this.formData.tenderId
      this.addLientItemData.dialogVisible = true
    },
    // 新增行项目弹框组件返回状态
    onStart(data) {
      const params = { tenderId: this.formData.tenderId }
      if (data) {
        this.formData.budgetTotalMoney = data.budgetTotalMoney
        this.formData.budgetTotalTaxMoney = data.budgetTotalTaxMoney
      }
      getPurchasePlanPackDetailsList(params).then((res) => {
        this.formData.packList = res.data
        this.loadData() // 分页处理
      })
    },
    // 打包数据
    submitBale() {
      this.confirmLoading = true
      const supplierAttribute = this.formData.supplierAttribute.join(',') // 供应商属性
      const supplierCategory = this.formData.supplierCategory.join(',') // 供应商分类
      // this.processInitDto.type = '01' // 01：初次提交 02：审核驳回再次提交
      const params = Object.assign({ ...this.formData }, {
        supplierAttribute, // 供应商属性
        supplierCategory, // 供应商分类
        budgetTotalMoney: this.formData.budgetTotalMoney, // 采购单净预算
        tenderMethod: this.formData.tenderMethod // 采购方式
      })
      // purchasplanPackAuditConfig true进入工作流 false不走工作流 如果进入工作流需要传审核人信息
      if (this.purchasplanPackAuditConfig) {
        params.processInitDto = this.processInitDto // 审核人信息传回得信息
      }
      purchasePlanDetailsPack(params).then(response => {
        this.purchasePlanDetailsData = response.data
        this.confirmLoading = false
        this.handleClose('00') // 提交成功
      }).catch(() => {
        this.confirmLoading = false
      })
    },
    // 移除
    deleteHandel(row) {
      const params = {
        planDetailIds: row.planDetailId, // 计划详情id
        tenderId: this.formData.tenderId, // 采购单id
        optLocation: this.flowStatus ? '00' : '01' // 打包/代办区分
      }
      if (this.paginationData.total <= 1) {
        this.$confirm('移除此条数据后，将删除整个采购单，是否确认移除？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          confirmButtonClass: 'confirmBtn',
          cancelButtonClass: 'cancelBtn',
          type: 'warning'
        }).then(() => {
          removeProcurementPackedDetailList(params).then((res) => {
            this.formData.budgetTotalMoney = res.data.budgetTotalMoney
            this.formData.budgetTotalTaxMoney = res.data.budgetTotalTaxMoney
            this.handleClose()
          })
        }).catch(() => {

        })
      } else {
        removeProcurementPackedDetailList(params).then((res) => {
          this.formData.budgetTotalMoney = res.data.budgetTotalMoney
          this.formData.budgetTotalTaxMoney = res.data.budgetTotalTaxMoney
          this.onStart()
        })
      }
    },
    // 确定
    ensure(formName) {
      if (this.tableData.length <= 0) {
        this.$message.warning('没有可打包的数据')
        this.handleClose()
        return false
      }
      // 供应商校验
      if (!this.supplierVerify().flag) {
        this.$message.warning(this.supplierVerify().msg)
        return false
      }
      this.$refs[formName].validate((valid, field) => {
        // 校验通过
        if (valid) {
          this.$confirm('是否确定提交？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            confirmButtonClass: 'confirmBtn',
            cancelButtonClass: 'cancelBtn',
            type: 'warning'
          }).then(() => {
            this.handleSubmit()
          }).catch(() => {
          })
        } else {
          this.$message.warning('请注意页面提示信息')
          return false
        }
      })
    },
    // 提交判断自行采购或委托采购 00-自行采购;01-委托采购(
    handleSubmit() {
      if (this.purchasePlanDetailsData.purchaseOrganization === '00') {
        // 直接提交
        this.submit()
      }
      if (this.purchasePlanDetailsData.purchaseOrganization === '01') {
        // 判断是否进入工作流程 true进入工作流 false不进入工作流直接提交
        if (this.purchasplanPackAuditConfig) {
          // 启动工作流
          if (JSON.stringify(this.processNode) !== '{}' && this.processNode.nodeId) {
            this.$refs.departDialog.getUserDepart(this.processNode)
          }
        } else {
          // 直接提交
          this.submit()
        }
      }
    },
    // 审批流提交
    submit() {
      this.submitBale() // 调起打包接口
    },
    // 弹框关闭回退处理 val 00提交成功关闭弹框
    backLog(val) {
      if (this.flowStatus) {
        const routePathStatus = sessionStorage.getItem('routePathStatus') // 工作流处理 00桌面进入 01待办列表进入
        this.$router.push({
          path: routePathStatus === '00' ? '/home' : '/work/todo'
        })
      } else {
        restoreInitialValue(this.formData) // 清空表单数据
        this.$refs.formData.clearValidate() // 清除表单验证
        this.$emit('handleCloseDialog', val, this.purchasePlanDetailsData)
      }
    },
    // 附件查看
    checkAccessory(row) {
      this.dialogFileData.bizId = row.planDetailId
      this.dialogFileData.checkFileVisible = true
    },
    // 弹框关闭
    handleClose(val) {
      // 移除行项目
      const params = {
        tenderId: this.formData.tenderId
      }
      if (val !== '00' && !this.flowStatus && params.tenderId) {
        deleteProcurementPackedDetailList(params).then((res) => {
          this.backLog()
        })
      } else {
        // 提交成功关闭弹框
        this.backLog(val)
      }
    },
    /* ===========================联合体==================*/
    // 切换联合体协议 是否联合体 00-否;01-是
    changeIfCombo() {
      let id = ''
      if (this.supplierList.length > 0) {
        id = this.supplierList.map(item => item.id).join(',')
      }
      if (id) {
        this.removeSupplier(id)
      }
    },
    // 已添加联合体供应商
    getSupplierList(supplierList) {
      this.supplierList = supplierList
    },
    // 联合体协议
    changeInvitationComboFile(file, fileList) {
      if (fileList.length > 0) {
        this.$set(this.formData, 'invitationComboFileType', 'true')// 上传了
      } else {
        this.$set(this.formData, 'invitationComboFileType', '')// 未上传
      }
    }
  }
}
</script>

<style scoped>

</style>
