<template>
  <div>
    <div class="collect-header contorl-header">
      <h4 :class="classType">{{ collectTitle }} </h4>
      <div class="collect-filter">
        <el-select
          v-if="!isRecycle && isTitleType !== 6 && isTitleType !== 2"
          v-model="selectStatus"
          multiple
          collapse-tags
          style="margin-right: 10px; width: 160px;"
          placeholder="请选择状态"
          @change="handleSearch(collectLevel)"
        >
          <el-option-group
            v-for="group in statusOptions"
            v-show="!(selectedCategory.arrangeType === 2 && isTitleType===3 && (group.label === '标签状态' || group.label === '借阅状态'))"
            :key="group.label"
            :label="group.label"
          >
            <el-option
              v-for="item in group.options"

              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-option-group>
        </el-select>
        <treeselect
          v-if="selectedCategory.arrangeType === 3 && isTitleType !== 4 && isTitleType !== 6"
          v-model="query.project_class"
          :options="projectOptions"
          style="width: 180px;"
          flat
          :multiple="false"
          :normalizer="normalizerProject"
          :default-expand-level="Infinity"
          :placeholder="projectPlaceholder"
          @input="handleSearch(collectLevel)"
          @select="handleSearch(collectLevel)"
        >
          <p
            slot="option-label"
            slot-scope="{node}"
            style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis; width: 100%; padding-left: 10px;"
            :title="node.label"
          >
            <template> {{ node.label }} </template>
          </p>
        </treeselect>
        <treeselect
          v-if="isTitleType !== 6"
          v-model="query.archive_ctg_no"
          :options="classifyOptions"
          style="width: 160px;"
          flat
          :multiple="false"
          :normalizer="normalizer"
          placeholder="请选择档案分类"
          @input="handleSearch(collectLevel)"
          @select="handleSearch(collectLevel)"
        ><p
          slot="option-label"
          slot-scope="{node}"
          style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis; width: 100%; padding-left: 10px;"
          :title="node.label"
        >
          <template> {{ node.label }} </template>
        </p>
        </treeselect>
      </div>
      <div v-if="isTitleType !== 6" class="head-search">
        <!-- 搜索 -->
        <el-input v-model="query.search" clearable size="small" :placeholder="placeholderType" prefix-icon="el-icon-search" style="width: 200px;" class="filter-item" @keyup.enter.native="handleSearch(collectLevel)" @clear="handleSearch(collectLevel)" />
        <el-button class="filter-item filter-search" size="mini" type="success" icon="el-icon-search" @click="handleSearch(collectLevel)">搜索</el-button>
        <el-button class="filter-item filter-refresh" size="mini" type="warning" icon="el-icon-refresh-left" @click="resetQuery">重置</el-button>
      </div>
      <div v-if="!isRecycle" class="collect-menu">
        <el-menu
          :default-active="activeMenuIndex"
          mode="horizontal"
          @select="handleSelect"
        >
          <el-submenu v-if="isTitleType !== 6" index="1">
            <template slot="title">
              <i class="iconfont icon-changgui" />
              <span>常规</span>
            </template>
            <el-menu-item-group class="collect-submenu-group">
              <el-menu-item v-if="isTitleType !== 6" index="1-1" @click="handleForm('edit')">编辑</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu v-if="isTitleType === 3" index="2">
            <template slot="title">
              <i class="iconfont icon-zhengli" />
              <span>整理</span>
            </template>
            <el-menu-item-group class="collect-submenu-group">
              <el-menu-item v-if="selectedCategory.arrangeType === 1" index="2-1" @click="bindingTag(selections)">标签绑定</el-menu-item>
              <el-menu-item-group class="collect-submenu-group submenu-tree">
                <template slot="title">档案装盒</template>
                <el-menu-item index="2-2" @click="handlePackingBox(0)">装盒</el-menu-item>
                <el-menu-item v-if="selectedCategory.arrangeType !== 1" index="2-3" @click="handlePackingBox(1)">分卷装盒</el-menu-item>
              </el-menu-item-group>
              <el-menu-item-group class="collect-submenu-group submenu-tree">
                <template slot="title">档案移交</template>
                <el-menu-item index="2-4" @click="handleOnlineHandover">在线移交</el-menu-item>
                <el-menu-item index="2-5" @click="handleOffLineHandover">离线移交</el-menu-item>
              </el-menu-item-group>
              <!-- <el-menu-item v-if="selectedCategory.isType === 2" index="2-6" @click="handleExportZip">导出ZIP包</el-menu-item> -->
              <el-menu-item index="2-7" @click="handleArcReturn">档案退回</el-menu-item>
              <el-menu-item index="2-8" @click="handleJD(0)">开放审核</el-menu-item>
              <el-menu-item index="2-9" @click="handleJD(1)">销毁鉴定</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu v-if="isTitleType === 4" index="2">
            <template slot="title">
              <i class="iconfont icon-zhengli" />
              <span>整理</span>
            </template>
            <el-menu-item-group class="collect-submenu-group">
              <el-menu-item index="2-1" @click="bindingTag(selections)">标签绑定</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
          <el-submenu v-if="isTitleType !== 6" index="3">
            <template slot="title">
              <i class="iconfont icon-gengduo" />
              <span>更多</span>
            </template>
            <el-menu-item-group class="collect-submenu-group">
              <el-menu-item v-if="isTitleType !== 6" index="3-1" @click="handleExport">导出</el-menu-item>
              <el-menu-item v-if="isTitleType === 3" index="3-2" @click="handlePrint">打印</el-menu-item>
              <el-menu-item v-if="isTitleType === 6" index="3-3" @click="handleOriginalDownload">下载</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </div>
      <!-- 利用权限操作 -->
      <div v-if="!isRecycle && isTitleType === 6" class="collect-menu">
        <el-button v-if="parentsData.authUtilize.look" class="filter-item" size="mini" type="success" @click="toPreview"><i class="iconfont icon-sulan" />预览</el-button>
        <el-button v-if="parentsData.authUtilize.download" class="filter-item" size="mini" type="success" :disabled="selections.length !== 1" @click="handleOriginalDownload"><i class="iconfont icon-xiazai" :disabled="crud.selections.length !== 1" />下载</el-button>
        <el-button v-if="parentsData.authUtilize.print" class="filter-item" size="mini" type="success" :disabled="selections.length !== 1"><i class="iconfont icon-dayin" />打印</el-button>
      </div>

      <div v-if="isRecycle && (isTitleType === 2 || isTitleType === 3)" class="collect-menu">
        <el-button class="filter-item" size="mini" type="success" @click="toRecover"><i class="iconfont icon-huifu" />恢复</el-button>
        <el-button class="filter-item" size="mini" type="success" @click="toCompletelyDelete"><i class="iconfont icon-shanchu" />彻底删除</el-button>
        <el-button class="filter-item" size="mini" type="success" :disabled="selections.length === 0" @click="handleExport"><i class="iconfont icon-daochu" />导出</el-button>
      </div>

      <!--新增 / 编辑 表单组件-->
      <el-dialog class="preview-dialog" :modal-append-to-body="false" :close-on-click-modal="false" append-to-body :before-close="handleClose" :visible="formVisible" :title="formTitle">
        <span class="dialog-right-top" />
        <span class="dialog-left-bottom" />
        <div class="setting-dialog">
          <PreviewForm
            v-if="formPreviewData.length"
            ref="previewForm"
            :is-has-code="true"
            :is-disabled="false"
            :form-preview-data.sync="formPreviewData"
            :selected-category="selectedCategory"
            :arc-id="arcId"
            :is-des-form-type="isDesFormType"
            :is-title-type="isTitleType"
            :collect-level="collectLevel"
            :category-menu="categoryMenu"
            :archives-type="archivesType"
            @close-dialog="closeDialog"
          />
          <div slot="footer" class="dialog-footer" style="margin-top: 85px !important;">
            <el-button type="primary" @click="handlerArchivesSubmit">保存</el-button>
          </div>
        </div>
      </el-dialog>

      <!-- 绑定标签 -->
      <binding-tag-dlg ref="bindingTag" :binding-id="selections[0] && selections[0].id" :binding-type="1" binding-txt="档案" @close-dialog="closeDialog" />
      <!-- 装盒 / 分卷装盒 -->
      <PackingBox ref="packingBox" :selected-category="selectedCategory" :selections="selections" :total-sum-all="totalSumAll" @close-dialog="closeDialog" />
      <!-- 在线移交 -->
      <OnlineHandover ref="onlineHandover" :selected-category="selectedCategory" :collect-level="collectLevel" :selections="selections" :total-sum-all="totalSumAll" @close-dialog="closeDialog" />
      <!-- 离线移交 -->
      <OffLineHandover ref="offLineHandover" :selected-category="selectedCategory" :collect-level="collectLevel" :selections="selections" :total-sum-all="totalSumAll" @close-dialog="closeDialog" />
      <!-- 导出zip -->
      <ExportZip ref="exportZip" :selected-category="selectedCategory" :selections="selections" @close-dialog="closeDialog" />
      <!-- 开放审核 / 销毁鉴定 -->
      <HandOverForm ref="formModule" :selected-category="selectedCategory" :collect-level="collectLevel" :selections="selections" @close-dialog="closeDialog" />
      <!-- 打印 -->
      <Print ref="printRef" :selected-category="selectedCategory" :collect-level="collectLevel" :selections="selections" @close-dialog="closeDialog" />

    </div>
    <div style="display: flex; justify-content: space-between; height: 30px; line-height: 30px; padding: 0 10px; ">
      <span v-if="(isTitleType !== 2 && selectedCategory.arrangeType === 3 ) || ((isTitleType === 4 || isTitleType === 6) && selectedCategory.arrangeType === 2) || (isTitleType === 6 && selectedCategory.arrangeType === 1)" style="font-size: 12px;">{{ test }}</span>

      <div v-if="!isRecycle && isTitleType === 6 && parentsData.authUtilize.endTime" style="font-size: 12px;">
        <!-- 利用开始时间：{{ parentsData.authUtilize.startTime | parseTime }} -->
        利用结束时间：{{ parentsData.authUtilize.endTime | parseTime }}
      </div>

      <div v-if="isTitleType !== 2 && !isRecycle && isTitleType !== 6" class="mangement-fixed-top">
        <el-checkbox v-model="parentsData.fixedStatusBar" @change="statusBarChecked">隐藏状态栏</el-checkbox>
      </div>
    </div>
  </div>
</template>

<script>
import { crud } from '@crud/crud'
import { manageLibraryCrud } from '../mixins/index'
import { FetchInitCategoryInputFieldByPid, FetchCategoryMenu } from '@/api/system/category/category'
import { FetchDetailsById, FetchCompleteDelArchives, FetchRestoreArchives } from '@/api/collect/collect'
import { FetchArchivesClassTree } from '@/api/system/archivesClass'

import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import PreviewForm from '@/views/components/category/PreviewForm'
import Print from './print/index'
import BindingTagDlg from '@/views/components/BindingTagDlg'
import PackingBox from './packingBox/index'
import OnlineHandover from './onlineHandover/index'
import OffLineHandover from './offLineHandover/index'
import ExportZip from './exportZip/index'
import HandOverForm from './handOverForm'
import qs from 'qs'
import { downloadFile, exportFile } from '@/utils/index'
import { mapGetters } from 'vuex'

export default {
  name: 'CollectHeader',
  components: { Treeselect, PreviewForm, BindingTagDlg, Print, PackingBox, OnlineHandover, OffLineHandover, ExportZip, HandOverForm },
  mixins: [manageLibraryCrud, crud()],
  props: {
    selectedCategory: {
      type: Object,
      default: function() {
        return {}
      }
    },
    isTitleType: {
      type: Number,
      default: 2
    },
    test: {
      type: String,
      default: function() {
        return ''
      }
    },
    isRecycle: {
      type: Boolean,
      default: false
    },
    selections: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  inject: ['parentsData'],
  data() {
    return {
      permission: {
        convention: ['admin', 'archives:convention'],
        arrange: ['admin', 'archives:arrange'],
        more: ['admin', 'archives:more']
      },
      value: null,
      categoryMenu: [],
      statusOptions: [
        {
          label: '标签状态',
          options: [
            {
              value: 1,
              label: '未绑定'
            },
            {
              value: 2,
              label: '已绑定'
            }
          ]
        },
        {
          label: '装盒状态',
          options: [
            {
              value: 3,
              label: '未装盒'
            },
            {
              value: 4,
              label: '已装盒'
            }
          ]
        },
        {
          label: '入库状态',
          options: [
            {
              value: 5,
              label: '未入库'
            },
            {
              value: 6,
              label: '待入库'
            },
            {
              value: 7,
              label: '待出库'
            },
            {
              value: 8,
              label: '已入库'
            }
          ]
        },
        {
          label: '借阅状态',
          options: [
            {
              value: 9,
              label: '实体在库'
            },
            {
              value: 10,
              label: '实体待借'
            },
            {
              value: 11,
              label: '实体已借'
            }
          ]
        },
        {
          label: '实体状态',
          options: [
            {
              value: 12,
              label: '无实体'
            },
            {
              value: 13,
              label: '有实体'
            }
          ]
        },
        {
          label: '开放状态',
          options: [
            {
              value: 14,
              label: '未开放'
            },
            {
              value: 15,
              label: '已开放'
            }
          ]
        },
        {
          label: '审批锁定',
          options: [
            {
              value: 16,
              label: '空闲'
            },
            {
              value: 17,
              label: '退回'
            },
            {
              value: 18,
              label: '开放'
            },
            {
              value: 19,
              label: '销毁'
            }, {
              value: 20,
              label: '利用'
            }, {
              value: 21,
              label: '内部移交'
            }, {
              value: 22,
              label: '外部移交'
            }
          ]
        }
      ],
      selectStatus: null,
      activeMenuIndex: '1',
      formVisible: false,
      formTitle: '项目',
      formPreviewData: [], // 预览界面data
      projectOptions: [],
      classifyOptions: [],
      isDesFormType: 'manageArcives', // 区分是门类得还是档案得
      arcId: null,
      totalSumAll: 0,
      archivesType: null
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ]),
    collectTitle() {
      if (this.isTitleType === 2) {
        return '项目'
      } else if (this.isTitleType === 3) {
        if (this.selectedCategory.arrangeType === 1) {
          return '文件'
        } else {
          return '案卷'
        }
      } else if (this.isTitleType === 4) {
        return '卷内'
      } else if (this.isTitleType === 6) {
        return '原文'
      }
      return ''
    },
    collectLevel() {
      if (this.isTitleType === 2) {
        return 1
      } else if (this.isTitleType === 3) {
        if (this.selectedCategory.arrangeType === 1) {
          return 3
        } else {
          return 2
        }
      } else if (this.isTitleType === 4) {
        return 3
      } else if (this.isTitleType === 6) {
        return 4
      }
      return null
    },
    classType() {
      if (this.isTitleType === 2) {
        return ''
      } else if (this.isTitleType === 3) {
        return 'is-anjuan'
      } else if (this.isTitleType === 4) {
        return 'is-juannei'
      } else if (this.isTitleType === 6) {
        return 'is-file'
      }
      return ''
    },
    placeholderType() {
      if (this.isTitleType === 2) {
        return '输入项目名称或编号搜索'
      } else if (this.isTitleType === 3 || this.isTitleType === 4) {
        return '输入题名或档号搜索'
      }
      return '输入项目名称或编号搜索'
    },
    projectPlaceholder() {
      if (this.isTitleType === 2) {
        return '请选择项目分类'
      } else if (this.isTitleType === 3) {
        return '请选择项目阶段'
      }
      return '请选择项目分类'
    }
  },
  created() {
  },
  mounted() {
    this.getInitArchivesClass()
    if (localStorage.getItem('statusBarFixedType') !== 'undefined') {
      this.parentsData.fixedStatusBar = JSON.parse(localStorage.getItem('statusBarFixedType')) === true
    }
    this.getCategoryDataTree()
  },
  methods: {
    getCategoryDataTree() {
      FetchCategoryMenu().then(res => {
        this.categoryMenu = res
      })
    },
    resetQuery() {
      this.selectStatus = []
      this.query = {
        'search': null,
        'project_class': null,
        'archive_ctg_no': null
      }
      this.handleSearch(this.collectLevel)
    },
    // 筛选 - 档案分类
    getInitArchivesClass() {
      this.classifyOptions = []
      this.query = {
        'search': null,
        'project_class': null,
        'archive_ctg_no': null
      }
      const params = {
        'categoryId': this.selectedCategory.id
      }
      FetchArchivesClassTree(params).then((res) => {
        this.classifyOptions = JSON.parse(JSON.stringify(res))
      }).catch(err => {
        console.log(err)
      })
    },
    normalizer(node) {
      if (node.childArchivesClass === null) {
        delete node.childArchivesClass
      }
      return {
        id: node.code,
        label: `${node.name} - ${node.code}`,
        children: node.childArchivesClass
      }
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath)
    },
    // 著录界面-form/详情-api
    handleForm(type) {
      if (type === 'add') {
        this.formTitle = '新增' + this.collectTitle
        this.arcId = null
      } else if (type === 'edit') {
        if (this.selections.length === 0) {
          this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
          return false
        } else if (this.selections.length > 1) {
          this.$message({ message: '编辑操作只可勾选唯一目标条目，请先确认！', offset: 8 })
          return false
        } else if (this.selections[0].process_status !== 1) {
          this.$message({ message: '当前所选的档案处于流程中，不可操作编辑，请先确认！', offset: 8 })
          return false
        }
        this.arcId = this.selections[0].id
        this.formTitle = '编辑' + this.collectTitle
      }
      // this.form.dictionaryConfigId = {}
      // this.formPreviewData = []
      // 档案预编辑获取字段
      this.formVisible = true
      this.$nextTick(() => {
        this.getFormInfo(type)
      })
    },
    getFormInfo(type) {
      this.archivesType = type
      if (type === 'edit') {
        const params = {
          'categoryId': this.selectedCategory.id,
          'categoryLevel': this.collectLevel,
          'id': this.arcId
        }
        FetchDetailsById(params).then(data => {
          // const showFiledAll = data.showFiled.filter(item => item.isSequence).sort((a, b) => a.isSequence - b.isSequence)
          const showFiledAll = data.showFiled
          this.$nextTick(() => {
            this.formPreviewData = showFiledAll
            this.isDesFormType = 'manageArcives'
            this.$nextTick(() => {
              this.$refs.previewForm.addOrUpdateForm = data.echo
              this.$refs.previewForm.FetchNoFormatField(this.selectedCategory.id)
            })
          })
        })
      } else {
        const params = {
          'categoryId': this.selectedCategory.id,
          'categoryLevel': this.collectLevel
        }
        FetchInitCategoryInputFieldByPid(params).then(data => {
          this.formPreviewData = data
          this.isDesFormType = 'manageArcives'
          this.$nextTick(() => {
            this.$refs.previewForm.FetchNoFormatField(this.selectedCategory.id)
          })
        })
      }
    },
    // form - submit
    handlerArchivesSubmit() {
      this.$refs.previewForm.submitForm('addOrUpdateForm', this.selectedCategory.id,)
    },
    handleClose(done) {
      this.formVisible = false
      done()
    },
    // 绑定标签
    bindingTag(data) {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      if (this.selections.length > 1) {
        this.$message({ message: '只可勾选唯一目标条目，请先确认！', offset: 8 })
        return false
      }
      const isHasFillFormal = this.selections.some(item => item.process_status !== 1)
      if (isHasFillFormal) {
        this.$message({ message: '您所选的条目有正在流程中，不可操作绑定标签，请先确认！', offset: 8 })
        return false
      }
      if (data[0].tid) {
        // this.$refs.bindingTag.isBinding = true
        this.$refs.bindingTag.tidCode = data[0].tid
        this.$confirm('当前标签已被绑定，是否覆盖' + '<span>你是否还要继续？</span>', '提示', {
          confirmButtonText: '继续',
          cancelButtonText: '取消',
          type: 'warning',
          dangerouslyUseHTMLString: true
        }).then(() => {
          this.$refs.bindingTag.bindingVisible = true
          this.$refs.bindingTag.opened()
        }).catch(() => {
        })
      } else {
        this.$refs.bindingTag.bindingVisible = true
      }
    },
    // 导出
    handleExport() {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      this.$confirm('此操作将导出所选数据' + '<span>你是否还要继续？</span>', '提示', {
        confirmButtonText: '继续',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        const archivesIds = []
        this.selections.forEach(val => {
          archivesIds.push(val.id)
        })
        const params = {
          'categoryId': this.selectedCategory.id,
          'categoryLevel': this.collectLevel,
          'archivesIds': archivesIds
        }
        exportFile(this.baseApi + '/api/control/exportDate?' + qs.stringify(params, { indices: false }))
      }).catch(() => {
      })
    },
    // 打印
    handlePrint() {
      if (this.selections.length === 0) {
        this.$refs.printRef.form.printRange = '当页条目'
        let currentTableData = []
        if (this.collectLevel === 2) {
          currentTableData = this.parentsData.$refs.anjuanEle.$refs.ajContent.$refs.tableList.anjuanData
        } else if (this.collectLevel === 3) {
          if (this.isTitleType === 3) {
            currentTableData = this.parentsData.$refs.anjuanEle.$refs.ajContent.$refs.tableList.anjuanData
          } else {
            currentTableData = this.parentsData.$refs.juanneiEle.junneiData
          }
        }
        this.$refs.printRef.currentTable = JSON.parse(JSON.stringify(currentTableData))
      } else {
        this.$refs.printRef.form.printRange = '勾选条目'
      }
      this.$refs.printRef.printVisible = true
    },
    // 原文内的附件下载
    handleOriginalDownload() {
      if (this.selections.length > 1 || this.selections.length === 0) {
        this.$message({ message: '下载操作只可勾选唯一目标条目，请先确认！', offset: 8 })
        return false
      }
      const url = this.baseApi + '/downloadFile' + this.selections[0].file_path
      fetch(url).then(res => res.blob()).then(blob => {
        downloadFile(blob, this.selections[0].file_name.split('.')[0], this.selections[0].file_type)
      }).catch(() => {
        this.$message({ message: '下载文件失败', type: 'error', offset: 8 })
      })
    },
    // 回收站 - 恢复
    toRecover() {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      this.$confirm('此恢复将会把所选条目及其子集一并恢复' + '<span>你是否还要继续？</span>', '提示', {
        confirmButtonText: '继续',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        const archivesIds = []
        this.selections.forEach(val => {
          archivesIds.push(val.id)
        })
        const params = {
          'categoryId': this.selectedCategory.id,
          'categoryLevel': this.collectLevel,
          'archivesIds': archivesIds,
          'collectFormal': this.isTitleType === 2 ? 3 : null
        }
        FetchRestoreArchives(params).then((res) => {
          if (res.code !== 500) {
            localStorage.removeItem('currentPageSize')
            localStorage.removeItem('currentPage')
            this.$message({ message: res, type: 'success', offset: 8 })
            this.handleSearch(this.collectLevel)
          } else {
            this.$message({ message: '恢复所选档案失败', type: 'error', offset: 8 })
          }
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {
      })
    },
    // 回收站 - 彻底删除
    toCompletelyDelete() {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      this.$confirm('此删除将把会所选条目与其子集彻底删除' + '<span>你是否还要继续？</span>', '提示', {
        confirmButtonText: '继续',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        const archivesIds = []
        this.selections.forEach(val => {
          archivesIds.push(val.id)
        })
        const params = {
          'categoryId': this.selectedCategory.id,
          'categoryLevel': this.collectLevel,
          'archivesIds': archivesIds
        }
        FetchCompleteDelArchives(params).then((res) => {
          if (res.code !== 500) {
            localStorage.removeItem('currentPageSize')
            localStorage.removeItem('currentPage')
            this.$message({ message: res, type: 'success', offset: 8 })
            this.handleSearch(this.collectLevel)
          } else {
            this.$message({ message: '删除所选档案失败', type: 'error', offset: 8 })
          }
        }).catch(err => {
          console.log(err)
        })
      }).catch(() => {
      })
    },
    // 装盒 / 分卷装盒
    handlePackingBox(type) {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      const isHasFillFormal = this.selections.some(item => item.process_status !== 1)
      if (isHasFillFormal) {
        this.$message({ message: '您所选的条目有正在流程中，不可操作装盒，请先确认！', offset: 8 })
        return false
      }
      if (this.selectedCategory.arrangeType === 2) {
        if (type === 1) {
          if (this.selections.length > 1) {
            this.$message({ message: '只可勾选唯一目标条目，请先确认！', offset: 8 })
            return false
          }
        }
        if (this.selections[0].child === 0) {
          this.$message({ message: '当前选中的档案无相关卷内文件，不可装盒！', type: 'error', offset: 8 })
          return
        }
      }
      if (this.selections[0].case_no) {
        this.$message({ message: '当前档案已装盒，请勿重复操作！', type: 'error', offset: 8 })
        return
      }
      // 后面与后端对接确定字段name
      // const existsNotEmpty = this.selections.some(item => item.caseNum)
      // if (existsNotEmpty) {
      //   this.$message('所选条目中存在已装盒档案，请勿重复操作！')
      //   return false
      // }
      this.$refs.packingBox.packingVisible = true
      this.$refs.packingBox.isPackingOrPartType = type
      this.$refs.packingBox.packFileCategory = this.parentsData.listCategory
      if (type === 0) {
        this.$refs.packingBox.packingTitle = '装盒'
      } else {
        this.$refs.packingBox.packingTitle = '分卷装盒'
        this.$refs.packingBox.getViewTable()
      }
      this.getTotalSumAll()
    },
    getTotalSumAll() {
      this.totalSumAll = 0
      this.selections.map((item) => { if (!isNaN(item.child)) this.totalSumAll += item.child })
      if (isNaN(this.totalSumAll)) {
        return 0
      }
      return this.totalSumAll
    },
    // 在线移交
    handleOnlineHandover() {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      this.$refs.onlineHandover.handOverFileCategory = this.parentsData.listCategory
      this.$refs.onlineHandover.onlineHandoverVisible = true
      this.getTotalSumAll()
    },
    // 离线移交
    handleOffLineHandover() {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      // this.$refs.offLineHandover.offLineHandoverVisible = true
      this.$refs.formModule.activeIndex = 0
      this.$refs.formModule.overType = 7
      this.$refs.formModule.overDetialVisible = true
      this.$refs.formModule.overDetialTitle = '离线移交-流程'
    },
    // 导出zip包
    handleExportZip() {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      this.$refs.exportZip.exportZipVisible = true
    },
    // 档案退回
    handleArcReturn() {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      const isHasFillFormal = this.selections.some(item => item.process_status !== 1)
      if (isHasFillFormal) {
        this.$message({ message: '您所选的条目有正在流程中，不可操作档案退回，请先确认！', offset: 8 })
        return false
      }
      this.$confirm('此移出将把会所选条目退回到收集库' + '<span>你是否还要继续？</span>', '提示', {
        confirmButtonText: '继续',
        cancelButtonText: '取消',
        type: 'warning',
        dangerouslyUseHTMLString: true
      }).then(() => {
        this.$refs.formModule.overType = 2
        this.$refs.formModule.overDetialTitle = '退回审核-流程'
        this.$refs.formModule.overDetialVisible = true
      }).catch(() => {
      })
    },
    // 开放审核 / 销毁鉴定
    handleJD(type) {
      if (this.selections.length === 0) {
        this.$message({ message: '您还未勾选需要操作的条目，请先确认！', offset: 8 })
        return false
      }
      if (type === 0) {
        this.$refs.formModule.overType = 3
        this.$refs.formModule.overDetialTitle = '开放审核-流程'
      } else {
        this.$refs.formModule.overType = 4
        this.$refs.formModule.overDetialTitle = '销毁鉴定-流程'
      }
      this.$refs.formModule.activeIndex = 0
      this.$refs.formModule.overDetialVisible = true
    },

    toPreview() {
      const routeData = this.$router.resolve({ path: '/preview' })
      window.open(routeData.href, '_blank')
    },
    closeDialog(data) {
      this.formVisible = false
      setTimeout(() => {
        this.handleSearch(this.collectLevel)
      })
    }
  }
}
</script>

<style lang='scss' scoped>
.collect-header{
  border-top: none !important;
  padding: 20px 0 0 0 !important;
}
.manage-fixed-style{
  margin-bottom: 30px;
}
.contorl-header{
  flex-wrap: wrap;
  height: 94px;
  .head-search{
    height: 32px;
    margin-right: 0 !important;
    margin-bottom: 10px !important;
  }
  .collect-menu{
    width: 100%;
    display: flex;
    justify-content: flex-end;
    .el-submenu{
      margin-right: 0;
      margin-left: 10px;
    }
  }
}
::v-deep .vue-treeselect__list-item{
  width: 220px;
}
::v-deep .vue-treeselect__menu {
  padding: 20px 0;
}
::v-deep .vue-treeselect__option--highlight{
  background: #f5f9fc !important;
  color: #0348f3 !important;
}
::v-deep .vue-treeselect__option-arrow-container .vue-treeselect__option-arrow{
  color: #1c1c1c !important;
}
::v-deep .vue-treeselect__placeholder{
  font-size: 14px;
}
::v-deep .vue-treeselect__label-container{
  font-size: 14px;
  height: 34px;
  line-height: 34px;
  color: #1c1c1c;
}
::v-deep .vue-treeselect__option.vue-treeselect__option--disabled{
  .vue-treeselect__label-container{
    color: #545b65 !important;
  }
}
::v-deep.vue-treeselect--has-value .vue-treeselect__single-value{
  font-size: 14px;
}
</style>
