<!--
  @description: 采购计划-集采计划打包列表页
  @author: lxl change by haofengxian
  @routerPath:/procurement/procurementPlanBaleList 集采
  /procurement/procurementSourceList 自采
  purchaseOrganization: '', // 00-自行采购;01-委托采购
  @date： 2020-11-02 10:52
-->
<template>
  <div v-if="nextFlag">
    <table-crud
      ref="tableCrud"
      :menu="true"
      :tabs="tabList"
      :search-form.sync="searchForm"
      search-label-width="120px"
      @on-load="loadData"
    >
      <template v-slot:header>
        <span>{{ planTitle }}</span>
      </template>
      <template v-slot:search="search">
        <el-form-item v-if="purchaseOrganization==='01'" ref="importPackCode" label="打包序号" prop="importPackCode">
          <gx-input v-model.trim="searchForm.importPackCode" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <el-form-item ref="purchaseNo" label="行项目编号" prop="purchaseNo">
          <gx-input v-model.trim="searchForm.purchaseNo" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 物资编码 -->
        <el-form-item ref="purchaseCode" label="物资编码" prop="purchaseCode">
          <gx-input v-model.trim="searchForm.purchaseCode" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 物资名称 -->
        <el-form-item ref="purchaseName" label="物资名称" prop="purchaseName">
          <gx-input v-model.trim="searchForm.purchaseName" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 计划名称 -->
        <el-form-item ref="ykPlannoT" label="计划名称" prop="ykPlannoT">
          <gx-input v-model.trim="searchForm.ykPlannoT" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 采购方式 -->
        <el-form-item ref="tenderMethod" label="采购方式" prop="tenderMethod">
          <el-select v-model="searchForm.tenderMethod" placeholder="请选择">
            <el-option
              v-for="item in tender_methodList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--采购单编号-->
        <el-form-item ref="tenderNo" label="采购单编号" prop="tenderNo">
          <gx-input v-model.trim="searchForm.tenderNo" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--是否SAP-->
        <!--        <el-form-item ref="sourceType" label="是否SAP" prop="sourceType">
          <el-select v-model="searchForm.sourceType" placeholder="请选择">
            <el-option
              v-for="item in sourceTypeList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>-->
        <!--供货厂商-->
        <el-form-item ref="suppliersName" label="供货厂商" prop="suppliersName">
          <gx-input v-model.trim="searchForm.suppliersName" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--品牌-->
        <el-form-item ref="purchaseBrand" label="品牌" prop="purchaseBrand">
          <gx-input v-model.trim="searchForm.purchaseBrand" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--一级专业分类-->
        <el-form-item ref="purchaseClassificationParent" label="一级专业分类" prop="purchaseClassificationParent">
          <gx-input v-model.trim="searchForm.purchaseClassificationParent" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--二级专业分类-->
        <el-form-item ref="purchaseClassification" label="二级专业分类" prop="purchaseClassification">
          <gx-input v-model.trim="searchForm.purchaseClassification" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--物资描述-->
        <el-form-item ref="purchaseSpecification" label="物资描述" prop="purchaseSpecification">
          <gx-input v-model.trim="searchForm.purchaseSpecification" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--结果执行编号-->
        <!-- <el-form-item ref="resultExeNo" label="结果执行编号" prop="resultExeNo">
          <gx-input v-model.trim="searchForm.resultExeNo" @keyup.enter.native="search.onSearch" />
        </el-form-item> -->
        <!--是否集采-->
        <!-- <el-form-item ref="collectionType" label="是否集采" prop="collectionType">
          <el-select v-model="searchForm.collectionType" placeholder="请选择">
            <el-option
              v-for="item in collectionTypeList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item> -->
        <!--数量-->
        <el-form-item ref="purchaseNum" label="数量" prop="purchaseNum">
          <gx-input v-model.trim="searchForm.purchaseNum" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--计量单位-->
        <el-form-item ref="purchaseUnit" label="计量单位" prop="purchaseUnit">
          <el-select v-model="searchForm.purchaseUnit" placeholder="请选择" filterable>
            <el-option
              v-for="item in purchaseUnitList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--预算净单价(元)-->
        <el-form-item ref="purchaseBudget" label="预算净单价(元)" prop="purchaseBudget">
          <gx-input v-model.trim="searchForm.purchaseBudget" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--预算净总价(元)-->
        <el-form-item ref="purchaseTotalBudget" label="预算净总价(元)" prop="purchaseTotalBudget">
          <gx-input v-model.trim="searchForm.purchaseTotalBudget" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--税率(%)-->
        <el-form-item ref="purchaseTaxRate" label="税率(%)" prop="purchaseTaxRate">
          <el-select v-model="searchForm.purchaseTaxRate" placeholder="请选择" filterable>
            <el-option
              v-for="item in taxRateList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--交货日期-->
        <el-form-item ref="deliveryTime" label="交货日期" prop="deliveryTime">
          <el-date-picker
            v-model="searchForm.deliveryDate"
            :value-format="elValueFormatDate"
            type="daterange"
            placeholder="选择开始日期时间"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width:200px;"
            @change="handelDeliveryTime"
          />
        </el-form-item>
        <!--交货地点-->
        <el-form-item ref="deliveryAddress" label="交货地点" prop="deliveryAddress">
          <gx-input v-model.trim="searchForm.deliveryAddress" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <template v-if="purchaseOrganization==='01'">
          <!--采购单位-->
          <el-form-item ref="purchaseDepartName" label="采购单位" prop="purchaseDepartName">
            <gx-input v-model.trim="searchForm.purchaseDepartName" @keyup.enter.native="search.onSearch" />
          </el-form-item>
          <!--上报人-->
          <el-form-item ref="purchaseUserRealName" label="上报人" prop="purchaseUserRealName">
            <gx-input v-model.trim="searchForm.purchaseUserRealName" @keyup.enter.native="search.onSearch" />
          </el-form-item>
          <!--采购员-->
          <el-form-item ref="purchaseBuyer" label="采购员" prop="purchaseBuyer">
            <gx-input v-model.trim="searchForm.purchaseBuyer" @keyup.enter.native="search.onSearch" />
          </el-form-item>
        </template>
        <!--技术联系人/电话-->
        <el-form-item ref="planManagerName" label="技术联系人/电话" prop="planManagerName">
          <gx-input v-model.trim="searchForm.planManagerName" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--采购计划编号-->
        <el-form-item ref="purchasePlanNo" label="采购计划编号" prop="purchasePlanNo">
          <gx-input v-model.trim="searchForm.purchasePlanNo" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 创建日期 -->
        <el-form-item label="开始日期">
          <el-date-picker
            v-model="searchForm.datePicker"
            :value-format="elValueFormatDate"
            type="daterange"
            placeholder="选择开始日期时间"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width:200px;"
            @change="onHandelTime"
          />
        </el-form-item>
        <!-- 批准日期 -->
        <el-form-item label="批准日期">
          <el-date-picker
            v-model="searchForm.approvalTime"
            :value-format="elValueFormatDate"
            type="daterange"
            placeholder="选择开始日期时间"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width:200px;"
            @change="handelapprovalTime"
          />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <!-- 寻源下可有执行采购计划和关闭采购计划 -->
          <template v-if="searchForm.packStatus === '00'">
            <el-button type="primary" @click="onBale('00')">
              {{ purchaseOrganization==='00'?'确定采购方案':'打包' }}
            </el-button>
            <template v-if="purchaseOrganization==='01'">
              <el-button v-if="searchForm.packReady!=='01'" type="primary" plain @click="onGroupBuyingTurnDead">
                集采转自采
              </el-button>
              <el-button v-if="searchForm.packReady!=='01'" type="primary" plain @click="onBackPlan('01')">
                退回计划
              </el-button>
              <el-button v-if="searchForm.packReady!=='01'" type="primary" plain @click="onProcurementModify">
                采购方式变更
              </el-button>
              <!-- 预打包的重新打包  onAnewBale 00 预打包-->
              <el-button v-if="searchForm.packReady==='01'" type="primary" plain @click="onAnewBale('00')">
                重新打包
              </el-button>
              <el-upload
                v-if="searchForm.packReady!=='01'"
                ref="uploads"
                :on-success="handleSuccess"
                :on-error="handleError"
                :headers="importHeaders"
                :show-file-list="false"
                :action="action"
                multiple
                class="btn-ml10"
                style="display: inline-block;margin:0px 10px"
              >
                <el-button>导入</el-button>
              </el-upload>
            </template>
          </template>
          <template v-if="searchForm.packStatus==='04'">
            <el-button type="primary" plain @click="onBackPlan('03')">
              退回上报单位
            </el-button>
            <el-button type="primary" plain @click="onGroupBuyingTurnDead">
              集采转自采
            </el-button>
            <el-button type="primary" plain @click="onAnewBale('01')">
              重新打包
            </el-button>
          </template>
          <template v-if="purchaseOrganization==='01'">
            <el-button type="primary" :loading="exportLoading" @click="onExportFile">
              导出
            </el-button>
          </template>
        </div>
      </template>
      <template v-slot:GXTable>
        <!-- 待打包 -->
        <stayBaleTable
          v-if="searchForm.packStatus==='00' && searchForm.packReady!=='01'"
          :table-data="tableData"
          :loading="loading"
          :purchase-organization="purchaseOrganization"
          @delMultiple="onDelMultiple"
          @checkFile="onCheckFile"
          @orderData="onOrderData"
        />
        <!-- 预打包 -->
        <beforeBaleTable
          v-if="searchForm.packStatus==='00' && searchForm.packReady==='01'"
          :table-data="tableData"
          :loading="loading"
          @delMultiple="onDelMultiple"
          @checkFile="onCheckFile"
          @orderData="onOrderData"
        />
        <!-- 已打包 -->
        <alreadyTable
          v-if="searchForm.packStatus==='01'"
          :table-data="tableData"
          :loading="loading"
          :purchase-organization="purchaseOrganization"
          @checkFile="onCheckFile"
          @flowTrace="onFlowTrace"
          @subBaleFlow="onSubBaleFlow"
          @orderData="onOrderData"
          @handelCancel="onHandelCancel"
          @handleWithdraw="handleWithdraw"
          @viewPackInfo="viewPackInfo"
        />
        <!-- 集采转自才 -->
        <turnTable
          v-if="searchForm.packStatus==='02'"
          :table-data="tableData"
          :loading="loading"
          @checkFile="onCheckFile"
          @flowTrace="onFlowTrace"
          @subTurn="onSubTurn"
          @orderData="onOrderData"
          @handelCancel="onHandelCancel"
          @handleWithdraw="handleWithdraw"
          @checkTurnFile="checkTurnFile"
        />
        <!-- 采购方式变更 -->
        <alterationTable
          v-if="searchForm.packStatus==='03'"
          :table-data="tableData"
          :loading="loading"
          @checkFile="onCheckFile"
          @flowTrace="onFlowTrace"
          @mftCompile="onMftCompile"
          @orderData="onOrderData"
          @handelCancel="onHandelCancel"
          @handleWithdraw="handleWithdraw"
        />
        <!-- 业务回退 -->
        <baleBackTable
          v-if="searchForm.packStatus==='04'"
          :table-data="tableData"
          :loading="loading"
          @delMultiple="onDelMultiple"
          @checkFile="onCheckFile"
          @flowTrace="onFlowTrace"
          @orderData="onOrderData"
          @handelCancel="onHandelCancel"
          @returnFile="onReturnFile"
        />
        <!-- 回退上报 -->
        <appearTable
          v-if="searchForm.packStatus==='05'"
          :table-data="tableData"
          :loading="loading"
          @checkFile="onCheckFile"
          @flowTrace="onFlowTrace"
          @backCompile="onBackCompile"
          @orderData="onOrderData"
          @handelCancel="onHandelCancel"
          @handleWithdraw="handleWithdraw"
        />
      </template>
    </table-crud>
    <template>
      <!-- 打包 -->
      <baleDialog :dialog-bale-data="dialogBaleData" :params-id="planDetailId" @close="onClose" />
      <!-- 集采转自采 -->
      <turnDialog :dialog-turn-data="dialogTurnData" :params-id="planDetailId" @close="onClose" />
      <!-- 退回计划 -->
      <backPlanDialog :dialog-back-plan-data="dialogBackPlanData" :params-id="planDetailId" @close="onClose" />
      <!-- 采购方式变更 -->
      <modifyDialog :dialog-modify-data="dialogModifyData" :params-id="planDetailId" @close="onClose" />
      <!-- 重新打包 -->
      <anewBaleDialog :dialog-anew-bale-data="dialogAnewBaleData" :params-id="planDetailId" @close="onClose" />
      <!-- 查看附件 -->
      <checkFIleCompDialog :dialog-file-data="dialogFileData" />
      <!--流程追踪查看弹框-->
      <flow-detail-dialog ref="tracingFlow" />
      <!-- 查看采购编号弹框 -->
      <lookTenderNo-dialog
        v-if="lookTederNoDialog.dialog"
        :dialog-data="lookTederNoDialog"
        :look-teder-no-return="lookTederNoReturn"
      />
      <!--查看采购方式信息-->
      <purPlanBaleDetailDialog ref="purPlanBaleDetail" />
    </template>
  </div>
</template>
<script>
/* api*/
import {
  getPurchasePlanDetailsPackList, // 打包列表
  getPurchasePlanDetailPackedList, // 已打包列表
  downProcurementPlanDetailPackList, // 导出
  importPlanDetailWaitPackInfoList, // 导入
  purchasePlanDetailsCancelAudit, // 取消审核
  getPurchasePlanDetailsWaitPackList, // 查询集采计划打包【待打包】【业务部退回计划】列表
  rebackPurchasePlanPack, // 集采计划记录待审核下撤回已打包计划
  getPurchasePlanDetailsBusinessReturnPlanList // 查询集采计划打包【业务部退回计划】
} from '@/api/procurement/purchasplan'
import { getSystemConfigValueByConfigType } from '@/api/common/systemConfigCenter'
/* 弹框组件*/
import baleDialog from './bale/bale-dialog.vue' // 打包弹框
import turnDialog from './purPlanTurn/turn-dialog.vue' // 集采转自采
import backPlanDialog from './backPlan/backPlan-dialog.vue' // 退回计划
import modifyDialog from './purPlanModify/modify-dialog.vue'// 采购方式变更
import anewBaleDialog from './purPlanAnewBale/anewBale-dialog.vue'// 重新打包
import checkFIleCompDialog from '@/views/procurement/procurementPlan/components/checkFIleComp-dialog.vue'// 查看附件
import lookTenderNo from '@views/procurement/procurementPlan/procerementPlanSource/procurementLookTenderNo-dialog.vue'
import flowDetailDialog from '@views/work/process/flowDetail-dialog' //  流程追踪组件
import purPlanBaleDetailDialog from '@views/procurement/procurementPlan/purPlanAllocation/purPlanBaleDetail-dialog.vue' // 打包信息
/* 表格组件*/
import stayBaleTable from './stayBaleTable.vue' // 待打包表格数据
import beforeBaleTable from './beforeBaleTable.vue' // 预打包表格数据
import alreadyTable from './alreadyTable.vue' // 已打包表格数据
import turnTable from './purPlanTurn/turnTable.vue' // 集采转自才表格数据
import alterationTable from './purPlanModify/alterationTable.vue' // 采购方式变更表格数据
import baleBackTable from './baleBackTable.vue' // 业务回退表格数据
import appearTable from './appearTable.vue' // 回退上报表格数据
/* 公用方法*/
import { procurementPlanDictMixins } from '@views/procurement/procurementPlan/mixins/procurementPlanDictMixins' // 字典信息
import { filterDictText, download, filterObj } from '@/assets/js/utils' // 字典方法
import Cookies from 'js-cookie'
/* ==========工作流===========*/
/* ============================*/
export default {
  name: 'ProcurementPlanBaleList',
  components: {
    purPlanBaleDetailDialog, // 打包信息
    'lookTenderNo-dialog': lookTenderNo, // 查看采购单编号
    baleDialog, // 打包弹框
    turnDialog, // 集采转自采弹框
    backPlanDialog, // 退回计划弹框
    modifyDialog, // 采购方式变更弹框
    stayBaleTable, // 待打包表格
    beforeBaleTable, // 预打包
    alreadyTable, // 已打包表格
    turnTable, // 集采转自采表格
    alterationTable, // 采购方式便更表格
    baleBackTable, // 业务回退表格
    appearTable, // 回退上报表格
    anewBaleDialog, // 重新打包表格
    checkFIleCompDialog, // 查看附件
    flowDetailDialog // 流程追踪查看
  },
  mixins: [procurementPlanDictMixins],
  data() {
    return {
      purchaseOrganization: this.$route.meta.purchaseOrganization, //  00-自行采购;01-委托采购
      // 查看采购单编号弹框
      lookTederNoDialog: {
        dialog: false,
        tenderNo: ''// 采购单编号
      },
      // 打包弹框
      dialogBaleData: {
        dialogVisibleBale: false,
        tenderId: '', // 采购单id
        planDetailIds: '',
        purchaseOrganization: '', // 组织形式 00-自行采购;01-委托采购
        baleKey: '00'// 区分提交状态  00普通提交 01再次提交
      },
      // 采购方式变更弹框
      dialogModifyData: {
        dialogVisibleModify: false,
        bizAuditId: '', // 再次提交参数
        purchaseOrganization: '', // 组织形式 00-自行采购;01-委托采购
        modifyKey: '00'// 区分提交状态  00普通提交 01再次提交
      },
      // 集采转自采弹框状态
      dialogTurnData: {
        dialogVisibleTurn: false,
        bizAuditId: '', // 再次提交参数
        purchaseOrganization: '', // 组织形式 00-自行采购;01-委托采购
        turnKey: '00' // 区分提交状态  00普通提交 01再次提交
      },
      // 退回计划弹框状态
      dialogBackPlanData: {
        dialogVisibleBackPlan: false,
        // bizTypeCode: 00-集采转自采;01-退回计划;02-采购方式变更;03-业务部退回计划;04-【结果执行确认】重新打包采购
        bizTypeCode: '01',
        purchaseOrganization: '', // 组织形式 00-自行采购;01-委托采购
        backKey: '00', // 区分提交状态  00普通提交 01再次提交
        bizAuditId: ''// 再次提交参数
      },
      // 重新打包弹框状态
      dialogAnewBaleData: {
        dialogVisibleAnew: false,
        planDetailIds: '', // 计划详情id集合 仅在预打包tab下传递
        purchaseOrganization: '', // 组织形式 00-自行采购;01-委托采购
        predictPackType: '' // 区分预打包的重新打 业务退回的重新打包 00 预打包 01业务退回
      },
      dialogFileData: {
        checkFileVisible: false, // 查看附件弹框状态
        bizId: '', // 附件id
        fileType: '' // 附件类型
      },
      planDetailId: '', // 弹框打包接口参数
      tenderId: '', // 已打包提交接口参数
      action: importPlanDetailWaitPackInfoList, // 导入接口
      importHeaders: {}, // 导入用户信息
      selMethods: [], // 存储选择数据
      loading: true,
      exportLoading: false, // 导出loading
      selectFlg: false, // 存贮数据状态
      tableData: [], // 表格数据
      searchForm: {
        importPackCode: '', // 打包序号
        datePicker: [], // 选择开始时间结束时间
        approvalTime: [], // 批准日期
        deliveryDate: [], // 交货日期
        tenderMethod: '', // 采购方式
        tenderNo: '', // 采购单编号
        purchaseName: '', // 物资名称
        purchaseCode: '', // 物资编码
        purchaseNo: '', // 行项目编号
        createTimeStart: '', // 创建开始时间
        createTimeEnd: '', // 创建结束时间
        packStatus: '00', // tabs默认值
        // collectionType: '', // 是否集采
        deliveryAddress: '', // 交货地点
        deliveryTime: '', // 交货日期
        planManagerName: '', // 技术联系人/电话
        purchaseBrand: '', // 品牌
        purchaseBudget: '', // 预算净单价(元)
        purchaseClassification: '', // 二级专业分类
        purchaseClassificationParent: '', // 一级专业分类
        purchaseDepartName: '', // 采购单位
        purchaseNum: '', // 数量
        purchasePlanNo: '', // 采购计划编号
        purchaseSpecification: '', // 物资描述
        purchaseTaxRate: '', // 税率(%)
        purchaseTotalBudget: '', // 预算净总价(元)
        purchaseUnit: '', // 计量单位
        purchaseUserRealName: '', // 上报人
        // resultExeNo: '', // 结果执行编号
        suppliersName: '', // 供货厂商
        sourceType: '', // 是否SAP
        packReady: '', // 预打包接口字段 01 其他默认 ''
        ykPlannoT: '' // 计划名称
      },
      nextFlag: true, // 页面刷新
      orderData: {}, // 排序参数
      /* --------------字典----------------*/
      tender_methodList: [], // 采购方式
      collectionTypeList: [], // 是否集采
      purchaseUnitList: [], // 计量单位
      taxRateList: [], // 税率
      dictionaryType: ['tender_method', 'collectionType', 'purchaseUnit', 'taxRate'], // 字典请求参数
      /* ------------------------------*/
      tabList: [
        { name: '待打包', typecode: '00', index: '0' },
        { name: '预打包', typecode: '00', index: '1' },
        { name: '已打包', typecode: '01', index: '2' },
        { name: '集采转自采', typecode: '02', index: '3' },
        { name: '采购方式变更记录', typecode: '03', index: '4' },
        { name: '业务部退回计划', typecode: '04', index: '5' },
        { name: '退回上报记录', typecode: '05', index: '6' }
      ],
      whetherPurchaser: '' // 委托采购-是否 （00集中委托 01-代理委托）
    }
  },
  created() {
    this.handlePurchaseOrganization()
    this.importHeaders['X-AUTH-TOKEN'] = Cookies.get('X-AUTH-TOKEN') // 获取用户token
    this.getGroupType() // 字典请求初始化
  },
  methods: {
    filterDictText,
    // 字典请求
    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]
          }
        }
      })
    },
    nextDoc() {
      this.nextFlag = false
      this.$nextTick(() => {
        this.nextFlag = true
      })
    },
    // 导出
    onExportFile() {
      const params = {
        packStatus: this.searchForm.packStatus,
        ...this.searchForm
      }
      if (this.searchForm.packReady === '01') {
        params.packReady = '01'
      }
      const index = this.tabList.findIndex((item) => this.searchForm.packStatus === item.typecode) // 拿到tabList下标
      if (this.tableData.length <= 0) {
        this.$message.warning('没有可导出的数据!')
        return false
      } else {
        this.exportLoading = true
        downProcurementPlanDetailPackList(filterObj(params)).then((res) => {
          this.exportLoading = false
          download(res, `集采计划打包${this.tabList[index].name}.xls`)
        }).catch(() => {
          this.exportLoading = false
        })
      }
    },
    // 导入成功后的回调
    handleSuccess(response, file, fileList) {
      // 导入成功后
      if (response.header.msg === '0') {
        this.$message.success(response.header.ret)
        //  清空
        this.$refs.uploads.clearFiles()
        this.$refs.tableCrud.onSearchChange(this.searchForm)
        return
      }
      // 上传失败
      this.$message.warning(response.header.msg)
    },
    // 导入失败后的回调
    handleError(response, file, fileList) {
      this.$message.error(response.header.msg)
      this.$refs.uploads.clearFiles()
      this.$refs.tableCrud.onSearchChange(this.searchForm)
    },
    // 查看附件
    onCheckFile(res) {
      this.dialogFileData.bizId = res.planDetailId
      this.dialogFileData.checkFileVisible = true
    },
    // 集采转自采附件查看
    checkTurnFile(res) {
      this.dialogFileData.bizId = res.explainFileId
      this.dialogFileData.fileType = 'biz_type_transfer_to_self_gateway'
      this.dialogFileData.checkFileVisible = true
    },
    // 退回附件查看
    onReturnFile(res) {
      this.dialogFileData.bizId = res.bizId
      this.dialogFileData.fileType = 'biz_type_assign_return_plan_file'
      this.dialogFileData.checkFileVisible = true
    },
    // 选择时间触发事件-创建日期
    onHandelTime(val) {
      if (val) {
        this.searchForm.createTimeStart = val[0]
        this.searchForm.createTimeEnd = val[1]
      }
    },
    // 交货日期
    handelDeliveryTime(val) {
      if (val) {
        this.searchForm.deliveryTimeStart = val[0]
        this.searchForm.deliveryTimeEnd = val[1]
      }
    },
    // 选择时间触发事件-批准日期
    handelapprovalTime(val) {
      if (val) {
        this.searchForm.approvalTimeStart = val[0]
        this.searchForm.approvalTimeEnd = val[1]
      }
    },
    // 打包
    onBale(baleKey) {
      /*
      *baleKey：区分提交状态 00 普通提交 01 再次提交
      */
      this.dialogBaleData.baleKey = baleKey
      this.dialogBaleData.tenderId = this.tenderId // 采购单id
      this.dialogBaleData.planDetailIds = this.planDetailId
      this.dialogBaleData.purchaseOrganization = this.purchaseOrganization
      if (baleKey === '01') {
        this.dialogBaleData.dialogVisibleBale = true
      } else {
        if (this.selFlg()) {
          this.dialogBaleData.dialogVisibleBale = true
        }
      }
    },
    // 判断选择数据返回状态
    selFlg() {
      if (this.selMethods.length > 0) {
        return true
      } else {
        this.$message.warning('请选择数据')
        return false
      }
    },
    // 集采转自采弹框
    onGroupBuyingTurnDead() {
      if (this.selFlg()) {
        this.dialogTurnData.dialogVisibleTurn = true
      }
    },
    // 退回计划
    onBackPlan(res) {
      if (this.selFlg()) {
        this.dialogBackPlanData.bizTypeCode = res
        this.dialogBackPlanData.dialogVisibleBackPlan = true
      }
    },
    // 采购方式变更
    onProcurementModify() {
      if (this.selFlg()) {
        this.dialogModifyData.dialogVisibleModify = true
      }
    },
    // 重新打包 predictPackType 00 预打包的重新打包 01 业务退回的重新打包
    onAnewBale(predictPackType) {
      if (this.selFlg()) {
        this.dialogAnewBaleData.predictPackType = predictPackType
        this.dialogAnewBaleData.planDetailIds = this.planDetailId
        this.dialogAnewBaleData.dialogVisibleAnew = true
      }
    },
    // 数据请求
    loadData(params, callback, tabData) {
      this.loading = true
      if (tabData) {
        params.packStatus = tabData.typecode
        this.searchForm.packStatus = tabData.typecode
      }
      if (tabData.name === '预打包') {
        this.searchForm.packReady = '01'
        params.packReady = this.searchForm.packReady
      } else {
        this.searchForm.packReady = ''
        params.packReady = this.searchForm.packReady
      }
      if (params.packStatus === '01') { // 已打包
        getPurchasePlanDetailPackedList(params).then(response => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
          this.tableData = response.data.records
          callback(response.data.total)
        }).catch(() => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
        })
      } else if (params.packStatus === '00') { // 待打包 退回
        getPurchasePlanDetailsWaitPackList(params).then((response) => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
          this.tableData = response.data.records
          callback(response.data.total)
        }).catch(() => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
        })
      } else if (params.packStatus === '04') {
        getPurchasePlanDetailsBusinessReturnPlanList(params).then((response) => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
          this.tableData = response.data.records
          callback(response.data.total)
        }).catch(() => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
        })
      } else {
        // 打包列表
        getPurchasePlanDetailsPackList(params).then(response => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
          this.tableData = response.data.records
          callback(response.data.total)
        }).catch(() => {
          this.searchForm.column = ''
          this.searchForm.orderSort = ''
          this.loading = false
        })
      }
    },
    // 弹框点击关闭是取消选中状态 val: 00提交成功关闭弹框 purchasePlanDetailsData 提交成功反参
    /* purchasePlanDetailsData{
        purchaseOrganization: '', // 00-自行采购;01-委托采购
        tenderNo: ''// 采购单编号
    }
    * */
    // 根据键获取配置 委托采购-是否 （00-否 01-是） （00集中委托 01-代理委托）
    getSystemConfig() {
      getSystemConfigValueByConfigType('whether_assign_purchaser').then((res) => {
        this.whetherPurchaser = res.data
      })
    },
    onClose(val, purchasePlanDetailsData) {
      this.selMethods = [] // 清空选中数据
      // 刷新页面
      this.nextDoc()
      if (val === '00' && purchasePlanDetailsData.purchaseOrganization === '00' && this.whetherPurchaser === '01') {
        this.lookTederNoDialog.tenderNo = purchasePlanDetailsData.tenderNo // 获取采购单编号
        setTimeout(() => {
          this.lookTederNoDialog.dialog = true // 打开查看采购单编号弹框
        }, 400)
      }
      // this.$refs.tableCrud.onSearchChange()
    },
    // 选择表格数据方法
    onDelMultiple(res) {
      const bales = []
      this.selMethods = res
      res.filter((item) => {
        bales.push(item.planDetailId)
      })
      this.planDetailId = bales.join(',')
    },
    // 排序
    onOrderData(res) {
      this.searchForm.column = res.column
      this.searchForm.orderSort = res.orderSort
      this.$refs.tableCrud.onSearchChange(this.searchForm)
    },
    // 已打包审核不通过时再次提交打包
    onSubBaleFlow(res) {
      this.tenderId = res.tenderId
      this.onBale('01') // 01 重新打包
    },
    // 集采转自采不通过时再次提交
    onSubTurn(res) {
      this.dialogTurnData.bizAuditId = res.bizAuditId
      this.dialogTurnData.turnKey = '01' // 01 再次提交
      this.dialogTurnData.dialogVisibleTurn = true // 调用集采转自采
    },
    // 取消审核
    onHandelCancel(row) {
      const params = {
        planDetailId: row.planDetailId, // 行项目id
        bizAuditId: row.bizAuditId // 审核主表id
      }
      this.$confirm('是否确定取消？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        purchasePlanDetailsCancelAudit(params).then((res) => {
          this.$refs.tableCrud.onSearchChange(this.searchForm)
        })
      }).catch(() => {
      })
    },
    // 已打包撤回
    handleWithdraw(row) {
      const params = {
        bizAuditId: row.bizAuditId
      }
      rebackPurchasePlanPack(params).then(() => {
        this.$refs.tableCrud.onSearchChange(this.searchForm)
      })
    },
    // 退回上报编辑
    onBackCompile(row) {
      this.dialogBackPlanData.bizTypeCode = row.bizCode
      this.dialogBackPlanData.backKey = '01'
      this.dialogBackPlanData.bizAuditId = row.bizAuditId
      this.dialogBackPlanData.dialogVisibleBackPlan = true
    },
    // 采购方式变更编辑
    onMftCompile(row) {
      this.dialogModifyData.modifyKey = '01'
      this.dialogModifyData.bizAuditId = row.bizAuditId
      this.dialogModifyData.dialogVisibleModify = true
    },
    // 流程追踪
    onFlowTrace(row) {
      this.$refs.tracingFlow.openDialogInitData(row.bizId)
    },
    // 查看采购单编号确认
    lookTederNoReturn() {
      this.lookTederNoDialog.dialog = false
    },
    // 查看采购方案
    viewPackInfo(row) {
      this.$refs.purPlanBaleDetail.openDialogPurPlanBaleDetail(row.tenderId)
    },
    // 根据采购组织形式区分页面展示情况 00-自行采购;01-委托采购
    handlePurchaseOrganization() {
      const purchaseTabs = [
        { name: '待确定采购方案', typecode: '00', index: '0' },
        { name: '已确定采购方案', typecode: '01', index: '1' }
      ]
      if (this.purchaseOrganization === '00') {
        this.planTitle = '采购寻源'
        this.tabList = purchaseTabs
      }
      if (this.purchaseOrganization === '01') {
        this.planTitle = '采购计划打包'
      }
    }
  }
}
</script>
