<!--
  @description: 采购计划-集采计划分配列表
  @author: lxl/hdk
  @routerPath:/procurement/procurementPlanAllocationList
  @date： 2020-10-30 14:52
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :search-form.sync="searchForm"
      :tabs="assignStatusAList"
      search-label-width="110px"
      @on-load="loadData"
    >
      <template v-slot:header>
        <span>集采计划分配</span>
      </template>
      <template v-slot:search="search">
        <!-- 采购单编号 -->
        <el-form-item ref="tenderNo" label="采购单编号" prop="tenderNo">
          <el-input v-model.trim="searchForm.tenderNo" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--物资编码-->
        <el-form-item ref="purchaseCode" label="物资编码" prop="purchaseCode">
          <el-input v-model.trim="searchForm.purchaseCode" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!-- 物资名称 -->
        <el-form-item ref="purchaseName" label="物资名称" prop="purchaseName">
          <el-input v-model.trim="searchForm.purchaseName" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--行项目编号-->
        <el-form-item ref="purchaseNo" label="行项目编号" prop="purchaseNo">
          <el-input v-model.trim="searchForm.purchaseNo" @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 tenderMethodList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--公开/邀请-->
        <el-form-item ref="tenderType" label="公开/邀请" prop="tenderType">
          <el-select v-model="searchForm.tenderType" placeholder="请选择">
            <el-option
              v-for="item in tenderTypeList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--是否框架-->
        <el-form-item ref="planType" label="是否框架" prop="planType">
          <el-select v-model="searchForm.planType" placeholder="请选择">
            <el-option
              v-for="item in isFramePlanList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--供应商属性-->
        <el-form-item ref="supplierAttribute" label="供应商属性" prop="supplierAttribute">
          <el-input v-model.trim="searchForm.supplierAttribute" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--供应商分类-->
        <el-form-item ref="supplierCategory" label="供应商分类" prop="supplierCategory">
          <el-select v-model="searchForm.supplierCategory" placeholder="请选择">
            <el-option
              v-for="item in supplierCategoryList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--评审办法-->
        <el-form-item ref="reviewMethod" label="评审办法" prop="reviewMethod">
          <el-select v-model="searchForm.reviewMethod" placeholder="请选择">
            <el-option
              v-for="item in reviewMethodList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--项目负责人-->
        <el-form-item ref="tenderManager" label="项目负责人" prop="tenderManager">
          <el-input v-model.trim="searchForm.tenderManager" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--供货厂商-->
        <!-- <el-form-item ref="suppliersName" label="供货厂商" prop="suppliersName">
          <el-input v-model.trim="searchForm.suppliersName" @keyup.enter.native="search.onSearch" />
        </el-form-item> -->
        <!--品牌-->
        <el-form-item ref="purchaseBrand" label="品牌" prop="purchaseBrand">
          <el-input v-model.trim="searchForm.purchaseBrand" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--专业分类-->
        <el-form-item ref="purchaseClassification" label="专业分类" prop="purchaseClassification">
          <el-input v-model.trim="searchForm.purchaseClassification" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--物资描述-->
        <el-form-item ref="purchaseSpecification" label="物资描述" prop="purchaseSpecification">
          <el-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">
          <el-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="请选择">
            <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="purchaseUnit" label="行项目状态" prop="purchaseUnit">
          <el-select v-model="searchForm.dataStatus" placeholder="请选择">
            <el-option
              v-for="item in plan_data_statusList"
              :key="item.typecode"
              :label="item.typename"
              :value="item.typecode"
            />
          </el-select>
        </el-form-item>
        <!--预算净单价(元)-->
        <el-form-item ref="purchaseBudget" label="预算净单价(元)" prop="purchaseBudget">
          <el-input v-model.trim="searchForm.purchaseBudget" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--预算净总价(元)-->
        <el-form-item ref="purchaseTotalBudget" label="预算净总价(元)" prop="purchaseTotalBudget">
          <el-input v-model.trim="searchForm.purchaseTotalBudget" @keyup.enter.native="search.onSearch" />
        </el-form-item>
        <!--税率(%)-->
        <el-form-item ref="purchaseTaxRate" label="税率(%)" prop="purchaseTaxRate">
          <el-input v-model.trim="searchForm.purchaseTaxRate" @keyup.enter.native="search.onSearch" />
        </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>
        <!--采购单位-->
        <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>
        <!--计划管理员-->
        <el-form-item ref="createUserRealName" label="计划管理员" prop="createUserRealName">
          <gx-input v-model.trim="searchForm.createUserRealName" @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>
        <!-- 暂时隐藏 -->
        <!-- 分配日期 -->
        <el-form-item
          v-show="searchForm.assignStatus !=='00' && searchForm.assignStatus !=='01' && searchForm.assignStatus !=='03'"
          label="分配日期"
        >
          <el-date-picker
            v-model="searchForm.packAssignTime"
            :value-format="elValueFormatDate"
            type="daterange"
            placeholder="选择开始日期时间"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            style="width:200px;"
            @change="allocationTime"
          />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <!-- 寻源下可有执行采购计划和关闭采购计划 -->
          <el-button v-if="searchForm.assignStatus === '00' || searchForm.assignStatus === '03'" type="primary" plain @click="onAllocation('00')">
            分配人员
          </el-button>
          <template v-if="searchForm.assignStatus === '01'">
            <el-button type="primary" plain :loading="distributionLoading" @click="onAffirmAllocation">
              确认分配
            </el-button>
            <el-button type="primary" plain @click="onAllocation('01')">
              变更人员
            </el-button>
          </template>
          <el-button v-if="searchForm.assignStatus === '02' || searchForm.assignStatus === '01'" type="primary" plain @click="redistribution">
            重新分配
          </el-button>
          <el-button v-if="searchForm.assignStatus === '00' || searchForm.assignStatus === '03'" type="primary" plain @click="wholeBack">
            整包退回
          </el-button>
          <!-- 暂时隐藏 -->
          <el-button v-if="searchForm.assignStatus === '00' ||searchForm.assignStatus === '03'" type="primary" plain @click="lineItemBack">
            行项目退回
          </el-button>
          <template>
            <el-button type="primary" :loading="exportLoading" @click="onExportFile">
              导出
            </el-button>
          </template>
        </div>
      </template>
      <template v-slot:GXTable>
        <!-- 待分配 -->
        <stayAllocationTableCom v-if="searchForm.assignStatus==='00'" ref="stayAllocationTableCom" :loading="loading" :table-data="tableData" @orderData="onOrderData" @checkedData="checkedData" @checkFile="checkFile" @inviteSupDetail="inviteSupDetail" />
        <!-- 待确认 -->
        <stayEnterTable v-if="searchForm.assignStatus==='01'" ref="stayEnterTable" :loading="loading" :table-data="tableData" @orderData="onOrderData" @checkedData="checkedData" @checkFile="checkFile" @inviteSupDetail="inviteSupDetail" />
        <!-- 已分配 -->
        <alreadyAllocationTable v-if="searchForm.assignStatus==='02'" :loading="loading" :table-data="tableData" @orderData="onOrderData" @checkedData="checkedData" @checkFile="checkFile" @inviteSupDetail="inviteSupDetail" />
        <!-- 分配被退回 -->
        <backAllocationTableCom v-if="searchForm.assignStatus==='03'" ref="backAllocationTableCom" :loading="loading" :table-data="tableData" @orderData="onOrderData" @checkedData="checkedData" @checkFile="checkFile" @inviteSupDetail="inviteSupDetail" @backCheckFile="backCheckFile" />
        <!-- 全部 -->
        <allocationAllTable v-if="searchForm.assignStatus===''" :loading="loading" :table-data="tableData" @orderData="onOrderData" @checkFile="checkFile" @inviteSupDetail="inviteSupDetail" />
      </template>
    </table-crud>
    <!-- 分配人员弹窗 -->
    <allocationStaff :dialog-visible="dialogVisibleAllocation" :assign-type="assignType" :tender-ids="tenderIds" @onClose="close" />
    <!-- 行项目退回弹窗 -->
    <lineItemReturnDialog :dialog-data="lineItemReturnDialogData" @onClose="close" />
    <!-- 查看附件 -->
    <checkFIleCompDialog :dialog-file-data="dialogFileData" />
    <!-- 查看供应商弹框 -->
    <inviteSupDetialDialog :dialog-data="inviteSupDialog" />
    <!-- 整包退回 -->
    <wholeBackDialog :dialog-data="wholeBackData" @refreshList="close" />
  </div>
</template>
<script>
/* api*/
import { getPurchasePlanDetailAssignList, purchasePlanDetailsPackConfirmAssign, downProcurementPlanDetailAssignList, purchasePlanDetailsPackRestartAssign, getPurchasePlanDetailAssignReturnList, purchasePlanDetailsWaitConfirmRestartAssign } from '@/api/procurement/purchasplan'
import { cancelPurchase } from '@/api/procurement/procurementProject'// 项目列表 项目删除

/* 公共混入*/
import { planAllocationMixins } from './mixins/planAllocationMixins'
/* 表格组件 */
import stayAllocationTableCom from './stayAllocationTableCom.vue' // 待分配
import stayEnterTable from './stayEnterTable.vue' // 待确认
import alreadyAllocationTable from './alreadyAllocationTable.vue' // 已分配
import allocationAllTable from './allocationAllTable.vue' // 全部
import backAllocationTableCom from './backAllocationTableCom.vue' // 分配被退回
/* 弹框组件*/
import allocationStaff from './allocationStaff-dialog.vue' // 分配人员弹窗
import lineItemReturnDialog from './lineItemReturn-dialog.vue' // 行项目退回弹窗
import checkFIleCompDialog from '@/views/procurement/procurementPlan/components/checkFIleComp-dialog.vue'// 查看附件
import inviteSupDetialDialog from './InviteSupplier-dialog.vue' // 查看邀请的供应商弹框
import wholeBackDialog from './wholeBack-dialog.vue' // 整包退回
/* 公共方法*/
import { filterDictText, download, filterObj } from '@/assets/js/utils' // 字典方法
// import { characters1_auto } from '@/assets/js/validate'// 校验输入内容

export default {
  name: 'PurPlanAllocationList',
  components: {
    allocationStaff, // 分配人员弹窗
    lineItemReturnDialog, // 行项目退回弹窗
    checkFIleCompDialog, // 查看附件
    stayAllocationTableCom, // 待分配
    backAllocationTableCom, // 分配被退回
    stayEnterTable, // 待确认
    alreadyAllocationTable, // 已分配
    allocationAllTable, // 分配被退回
    inviteSupDetialDialog, // 查看邀请的供应商弹框
    wholeBackDialog // 整包退回弹框
  },
  mixins: [planAllocationMixins],
  data() {
    return {
      // 执行状态
      assignStatusAList: [{
        index: '00',
        name: '待分配'
      }, {
        index: '01',
        name: '待确认'
      }, {
        index: '02',
        name: '已分配'
      },
      {
        index: '03',
        name: '分配被退回'
      },
      {
        index: '',
        name: '全部'
      }],
      lineItemReturnDialogData: { // 行项目退回弹窗数据
        dialogVisible: false, // 弹窗状态
        packList: [] // 行项目id
      },
      // 整包退回弹框数据
      wholeBackData: {
        dialogVisible: false,
        tenderIds: ''
      },
      distributionLoading: false, // 确认分配btnloading
      redistributionLoading: false, // 重新分配btnloading
      exportLoading: false,
      assignType: '00', // 00-分配人员;01-变更人员
      tableData: [], // 列表数据
      tenderIds: '',
      loading: true,
      dialogVisibleAllocation: false, // 分配人员弹框状态
      dialogFileData: {
        checkFileVisible: false, // 查看附件弹框状态
        bizId: '',
        fileType: ''
      },
      // 查看邀请的供应商弹框
      inviteSupDialog: {
        dialog: false,
        tenderId: '' // 项目id
      },
      searchForm: {
        datePicker: [], // 选择开始时间结束时间
        approvalTime: [], // 批准日期
        deliveryDate: [], // 交货日期
        assignStatus: '00', // 00–待分配、01–待确认、02–已分配
        purchaseName: '', // 物资名称
        purchaseNo: '', // 行项目编号
        tenderNo: '', // 采购单编号
        collectionType: '', // 是否集采
        deliveryAddress: '', // 交货地点
        deliveryTime: '', // 交货日期
        planManagerName: '', // 计划负责人
        purchaseBrand: '', // 品牌
        purchaseBudget: '', // 预算净单价(元)
        purchaseClassification: '', // 专业分类
        purchaseClassificationParent: '',
        purchaseDepartName: '', // 采购单位
        purchaseNum: '', // 数量
        purchasePlanNo: '', // 采购计划编号
        purchaseSpecification: '', // 物资描述
        purchaseTaxRate: '', // 税率(%)
        dataStatus: '', // 行项目状态
        purchaseTotalBudget: '', // 预算净总价(元)
        purchaseUnit: '', // 计量单位
        purchaseUserRealName: '', // 上报人
        resultExeNo: '', // 结果执行编号
        suppliersName: '', // 供货厂商
        createUserRealName: '' // 计划管理员
      },
      planReallocateManIndex: '' // 重新分配时选择的数据的最后一个下标值
    }
  },
  methods: {
    // 字典检索
    filterDictText,
    // 附件查看
    checkFile(row) {
      this.dialogFileData.checkFileVisible = true
      this.dialogFileData.bizId = row.planDetailId
    },
    // 退回附件查看
    backCheckFile(row) {
      this.dialogFileData.bizId = row.tenderId
      this.dialogFileData.fileType = 'biz_type_assign_return_plan_file'
      this.dialogFileData.checkFileVisible = true
    },
    // 当前选择的信息
    checkedData(data) {
      const tenderIds = []
      data.map((item) => {
        tenderIds.push(item.tenderId)
      })
      this.tenderIds = tenderIds.join(',')
      this.lineItemReturnDialogData.packList = data.map((item) => {
        return {
          planDetailId: item.planDetailId,
          auditPlanDetailId: item.auditPlanDetailId
        }
      })
    },
    // 刷新列表
    refreshList() {
      // 查询列表
      this.$refs.tableCrud.onSearchChange(this.searchForm)
    },
    // 行项目退回
    lineItemBack() {
      if (this.verification()) {
        this.lineItemReturnDialogData.dialogVisible = true
      }
    },
    // 获取列表数据
    loadData(params, callback, tabData) {
      if (tabData) {
        params.assignStatus = tabData.index
        this.searchForm.assignStatus = tabData.index
      }
      if (this.searchForm.assignStatus === '03') {
        getPurchasePlanDetailAssignReturnList(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 {
        getPurchasePlanDetailAssignList(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
        })
      }
    },
    // 导出
    onExportFile() {
      const params = {
        assignStatus: this.searchForm.assignStatus,
        ...this.searchForm
      }
      const index = this.assignStatusAList.findIndex(item => item.index === this.searchForm.assignStatus)
      if (this.tableData.length <= 0) {
        this.$message.warning('没有可导出的数据!')
        return false
      } else {
        this.exportLoading = true
        downProcurementPlanDetailAssignList(filterObj(params)).then((res) => {
          this.exportLoading = false
          download(res, `集采计划分配${this.assignStatusAList[index].name}.xls`)
        }).then(() => {
          this.exportLoading = false
        })
      }
    },
    // 校验是否选择
    verification() {
      if (this.tenderIds && this.tableData.length > 0) {
        return true
      } else {
        this.$message({
          type: 'warning',
          message: '请选择要操作的采购单'
        })
        return false
      }
    },
    // 已分配重新分配
    redistribution() {
      // 校验是否选择
      this.verification() && this.$confirm('您确定重新分配？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const params = {
          tenderIds: this.tenderIds
        }
        // 重新分配分配btnloading
        this.redistributionLoading = true
        if (this.searchForm.assignStatus === '02') {
          // 已分配重新分配接口调用
          purchasePlanDetailsPackRestartAssign(params).then(response => {
            this.redistributionLoading = false
            const { data } = response
            this.planReallocateManIndex = data.length - 1 // 获取重新分配的最大下标值
            // 需要退回的项目数组
            data.forEach((tenderId, index) => {
            // 重新退回请求
              this.cancelPurchaseMethods(tenderId, index)// tenderId项目id
            })
          }).catch(() => {
          // 重新分配btnloading
            this.redistributionLoading = false
          })
        } else {
          // 待确认重新分配
          purchasePlanDetailsWaitConfirmRestartAssign(params).then((response) => {
            this.redistributionLoading = false
            // 刷新列表
            this.refreshList()
          }).catch(() => {
            // 重新分配btnloading
            this.redistributionLoading = false
          })
        }
      }).catch(() => {
        this.$refs.stayEnterTable.clearSel()
      })
    },
    // 整包退回
    wholeBack() {
      if (this.verification()) {
        this.wholeBackData.tenderIds = this.tenderIds
        this.wholeBackData.dialogVisible = true
      }
      // this.verification() && this.$prompt('整包退回原因', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消',
      //   confirmButtonClass: 'confirmBtn',
      //   cancelButtonClass: 'cancelBtn',
      //   inputValidator: function(value) {
      //     if (!value) {
      //       return false
      //     }
      //   },
      //   inputErrorMessage: '请输入退回原因！'
      // }).then(({ value }) => {
      //   this.wholeLoading = true
      //   const params = {
      //     tenderIds: this.tenderIds,
      //     bizReason: value
      //   }
      //   returnBackToRtPlanMenuAtAssignList(params).then((response) => {
      //     this.wholeLoading = false
      //     this.$message.success(response.header.msg)
      //     // 刷新列表
      //     this.refreshList()
      //   }).catch((error) => {
      //     this.wholeLoading = false
      //     this.$message.warning(error)
      //   })
      // }).catch(() => {
      //   this.wholeLoading = false
      //   // this.$refs.stayAllocationTableCom.clearSel()
      // })
    },
    // 退回计划管控平台
    cancelPurchaseMethods(tenderId, index) {
      const data = {
        tenderId: tenderId, // 项目id
        reason: '' // 删除说明
      }
      cancelPurchase(data).then(res => {
        if (this.planReallocateManIndex === index) {
          // 重新分配btnloading
          this.redistributionLoading = false
          // 成功提示语
          this.$message.success({
            message: res.header.msg
          })
          this.planReallocateManIndex = ''
          // 刷新列表
          this.refreshList()
        }
      }).catch(() => {
        this.planReallocateManIndex = ''
      })
    },
    // 分配人员 变更人员
    onAllocation(type) {
      // 校验是否选择
      if (this.verification()) {
        // 00–待分配、01–待确认、02–已分配
        this.assignType = type
        // 打开人员分配
        this.dialogVisibleAllocation = true
      }
    },
    // 确认分配
    onAffirmAllocation() {
      this.verification() && this.$confirm('确认分配？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const params = {
          tenderIds: this.tenderIds
        }
        // 确认分配btnloading
        this.distributionLoading = true
        // 确认分配接口调用
        purchasePlanDetailsPackConfirmAssign(params).then(response => {
          // 成功提示语
          this.$message({
            message: '确认分配成功',
            type: 'success'
          })
          // 确认分配btnloading
          this.distributionLoading = false
          // 刷新列表
          this.refreshList()
        }).catch(() => {
          // 确认分配btnloading
          this.distributionLoading = false
        })
      }).catch(() => {
        this.$refs.stayEnterTable.clearSel()
      })
    },
    close() {
      // 确认刷新列表
      this.dialogVisibleAllocation = false
      this.refreshList()
      const status = this.searchForm.assignStatus
      switch (status) {
        case '00':
          this.$refs.stayAllocationTableCom.clearSel()
          break
        case '03':
          this.$refs.backAllocationTableCom.clearSel()
          break
        case '01':
          this.$refs.stayEnterTable.clearSel()
          break
      }
    },
    // 创建日期
    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]
      }
    },
    // 分配时间
    allocationTime(val) {
      if (val) {
        this.searchForm.packAssignTimeStart = val[0]
        this.searchForm.packAssignTimeEnd = val[1]
      }
    },
    // 查看供应商
    inviteSupDetail(row) {
      this.inviteSupDialog.tenderId = row.tenderId // 获取项目id
      this.inviteSupDialog.dialog = true // 打开弹框
    },
    // 排序
    onOrderData(res) {
      if (this.tableData.length > 0) {
        this.searchForm.column = res.column
        this.searchForm.orderSort = res.orderSort
        // 刷新列表
        this.refreshList()
      }
    }
  }
}
</script>
