<template>
  <!-- 类型管理 -->
  <div class="app-container" id="toolsType">
    <el-row :gutter="20">
      <!--树数据-->
      <el-col :span="5" :xs="24">
        <div class="head-container" style="display: flex;">
          <el-input
            v-model="archivesName"
            placeholder="请输入关键字"
            clearable
            maxlength="50"
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
          <el-button
            size="mini" style="margin: 0 10px;height: 32px;" type="primary"
            @click.stop="() => addTreeMainType()">
            新建分类
          </el-button>
        </div>
        <div class="head-container" style>
          <el-tree
            style="height: 700px; overflow: scroll"
            :data="treeOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            :default-expand-all="false"
            highlight-current
            @node-click="handleNodeClick"
          >
            <span
              class="custom-tree-node"
              slot-scope="{ node, data }"
              @mousemove="onMousemove(data)"
              @mouseleave="onMouseleave()"
            >
              <span v-if="isMousemoveId === data.id && node.label.length > 5">{{
                node.label.slice(0, 3) + "..."
              }}</span>
              <span v-else>{{ node.label }}</span>

              <span class="btn-items" v-if="isMousemoveId === data.id">
                <el-button
                  type="text"
                  size="mini"
                  icon="el-icon-plus"
                  @click.stop="() => appendTreeNode(data)"
                >
                </el-button>
                <el-button
                  type="text"
                  size="mini"
                  icon="el-icon-edit-outline"
                  style="color: #67c23a"
                  v-if="data.id !== 0"
                  @click.stop="() => editTreeNode(data)"
                >
                </el-button>
                <el-button
                  type="text"
                  size="mini"
                  icon="el-icon-delete"
                  style="color: #f56c6c"
                  v-if="data.id !== 0"
                  @click.stop="() => removeTreeNode(data)"
                >
                </el-button>
              </span>
            </span>
          </el-tree>
        </div>
      </el-col>
      <!--表格数据-->
      <el-col :span="19" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="关键字" prop="keyWord">
            <el-input v-model="queryParams.keyWord" placeholder="请输入关键字" clearable style="width: 240px" @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="14" style="margin-bottom: 20px;">
          <el-col :span="2">
            <el-button type="primary" plain icon="el-icon-upload" size="mini" @click="openUpLoadDialog">上传</el-button>
          </el-col>
          <el-col :span="2">
            <el-button type="warning" plain icon="el-icon-download" :disabled="multiple" size="mini" @click="handleExport">下载</el-button>
          </el-col>
          <el-col :span="2">
            <el-button type="success" plain icon="el-icon-download" :disabled="single" size="mini" @click="handleReName">重命名</el-button>
          </el-col>
          <el-col :span="2">
            <el-button type="danger" plain icon="el-icon-download" :disabled="multiple" size="mini" @click="handleAllDel">删除</el-button>
          </el-col>

          <el-col :span="4" style="float: right;display: flex;">
            <div style="display: flex;align-items: center;height: 32px;margin-right: 10px;" @click="changeShowType(1)">
              <img src="../../../assets/img/list1.png" v-if="showType==1" style="width: 18px;height: 18px;" alt="">
              <img src="../../../assets/img/list2.png" v-else style="width: 18px;height: 18px;" alt="">
            </div>
            <div style="display: flex;align-items: center;height: 32px;" @click="changeShowType(2)">
              <img src="../../../assets/img/grid1.png" v-if="showType==2" style="width: 18px;height: 18px;" alt="">
              <img src="../../../assets/img/grid2.png" v-else style="width: 18px;height: 18px;" alt="">
            </div>
          </el-col>
          <el-col :span="4" style="float: right;">
            <el-button type="primary" plain icon="el-icon-plus" size="mini"  @click="handleAdd">新建文件夹</el-button>
          </el-col>
        </el-row>
        <el-row :gutter="10" style="margin-bottom: 20px;">
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item v-for="(item,index) in breadcrumbList" :key="item.id" style="margin-bottom: 5px;">
              <span @click="breadClick(item,index)" style="cursor: pointer;">{{item.docName}}</span>
            </el-breadcrumb-item>
          </el-breadcrumb>
        </el-row>
        <el-table v-loading="loading" v-if="showType==1" :data="tableDataList"  @selection-change="handleSelectionChange" row-key="detailsId">
          <el-table-column type="selection" width="55" align="center" :selectable="selectable" :reserve-selection="true"/>
          <el-table-column label="序号" align="center" width="80" type="index">
                <template slot-scope="scope">
                    <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
                </template>
          </el-table-column>
          <el-table-column label="文件名称" align="left" prop="docName" show-overflow-tooltip width="300">
            <template slot-scope="scope">
              <i v-if="scope.row.docType=='文件夹'" class="el-icon-folder-opened"></i>
              <span @click="getSubDetails(scope.row)" style="cursor: pointer;margin-left: 20px;">{{ scope.row.docName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="" align="center" width="200">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-search" @click="handleView(scope.row)" v-if="scope.row.docType!='文件夹'">
                查看
              </el-button>
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">
                重命名
              </el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">
                删除
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="类 型 " align="center" prop="docType" show-overflow-tooltip/>
          <el-table-column label="文件大小" align="center" prop="docSize" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-if="scope.row.docSize">{{ scope.row.docSize }}MB</span>
            </template>
          </el-table-column>
          <el-table-column label="年 度" align="center" prop="year" show-overflow-tooltip/>
          <el-table-column label="修改时间 " align="center" prop="updateTime" show-overflow-tooltip width="180"/>
          <el-table-column label="上传人员 " align="center" prop="createBy" show-overflow-tooltip/>
        </el-table>


        <div style="width: 100%;height: 300px;display: flex;" v-if="showType==2">
          <div style="width: 140px;height: 140px;display: flex;flex-direction: column;align-items: center;margin: 10px;" v-for="item in tableDataList" :key="item.detailsId" @click="getSubDetails(item)">
            <img src="../../../assets/img/fileIcon1.png" v-if="item.docType=='文件夹'" style="width: 60px;height: 60px;">
            <img src="../../../assets/img/fileIcon3.png" v-else style="width: 50px;height: 50px;">
            <div style="font-size: 12px;margin-top: 10px;">
              {{ item.docName }}
            </div>
          </div>
        </div>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>


    <!-- 上传弹窗 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="600px" append-to-body>
      <el-upload ref="upload" :limit="20" :headers="upload.headers" :multiple="true" drag
                 :action="upload.url" style="width: 100%;" :file-list="fileList"
                 :on-success="handleSuccess" :on-error="handleError" :on-remove="handleFileRemove"
                 :before-upload="beforeUpload"
                 accept="image/*,.pdf,.doc,.docx,video/*"
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>按住Ctrl可同时多选，支持上传图片、视频、PDF、Word格式文件，单个文件不能超过20MB</span>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">上 传</el-button>
        <el-button @click="cancelUpload">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 图片查看 -->
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" height="650px" :src="dialogImageUrl" alt />
    </el-dialog>
    <!-- 新增弹框(新建弹窗) -->
    <el-dialog :title="addTitle" :visible.sync="addShowVisible" v-if="addShowVisible" width="500px" append-to-body :close-on-click-modal="false">
      <el-form label-width="80px" :model="addFormParams" :rules="addFormParamsRules" ref="addFormParamsRef">
        <el-row :gutter="24">
          <el-col :span="24" v-if="addTitle === '新增'">
            <el-form-item label="所属上级">
              <el-input style="width: 100%" disabled v-model="addFormParams.label"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="24">
            <el-form-item label="名称" prop="archivesName">
              <el-input style="width: 100%" v-model="addFormParams.archivesName" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="text-align: right">
          <el-form-item>
            <el-button size="small" type="primary" style="color: #fff;" @click="onSubmit">保 存</el-button>
            <el-button size="small" @click="onCancel">取 消</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-dialog>
    <!-- 重命名弹框-->
    <el-dialog title="重命名文件" :visible.sync="reNameShowVisible" width="500px" append-to-body :close-on-click-modal="false">
      <el-form label-width="80px" :model="reNameForm" :rules="reNameFormRules" ref="reNameForm">
        <el-row :gutter="24">
          <el-col :span="24">
            <el-form-item label="旧的名称:">
              <el-input style="width: 100%" disabled v-model="reNameForm.oldName"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="24">
            <el-form-item label="新的名称" prop="newName">
              <el-input style="width: 100%" v-model="reNameForm.newName" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="text-align: right">
          <el-form-item>
            <el-button size="small" type="primary" style="color: #fff;" @click="saveName">保 存</el-button>
            <el-button size="small" @click="reNameShowVisible=false">取 消</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </el-dialog>

  </div>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {
  getArchivesTypeListApi,getAddArchivesTypeApi,updateArchivesTypeApi,delArchivesTypeApi,
  getArchivesDetailsLstApi, addArchivesDetailsApi, updateArchivesDetailsApi, delArchivesDetailsApi,downloadFileApi
} from "@/api/archives/archives";
import { imgUpLoad, fileUpLoad } from "@/api/system/upload";
import { downloadFile } from "@/utils/download";
import { getToken } from '@/utils/auth'
export default {
  name: "Archives",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      unitValueOptions: [{id:"0",name:"整数"},{id:"1",name:"小数"}],
      // 库管员用户数据
      // keeperDataRange: [],
      KeeperOptions: [],//选择库管员数据
      repairerOptions: [],//维修员用户数据
      // 类型名称
      archivesName: undefined,
      // 左侧树-树选项
      treeOptions: undefined,
      treeTemp: [],
      //列表数据
      tableDataList: [],
      // 是否显示弹出层
      open: false,
      // 弹出层标题
      title: "",
      // 表单参数
      form: {
        companyId: "",
      },
      levelTemp: undefined,
      idTemp: undefined,
      parentId: undefined,
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单校验
      rules: {
        // leasePrice: [
        //   {
        //     required: true,
        //     message: "规格型号不能为空",
        //     trigger: "blur",
        //   },
        // ],
      },
      companyId: undefined,
      dialogImageUrl: "",
      dialogVisible: false,
      /* 新增弹框等数据源定义 */
      addShowVisible: false,
      addTitle: "", // 新增弹框标题
      addFormParams: {
        infoId: "",
        level: "",
        archivesName: ""
      },
      addFormParamsRules: {
        archivesName: [
          {
            required: true,
            message: "名称不能为空",
            trigger: "blur",
          },
        ],
      },
      isMousemoveId: null,
      breadcrumbList:[],//面包屑导航数组
      rowData:{},
      reNameShowVisible: false,
      reNameForm:{
        oldName:"",
        newName:""
      },
      reNameFormRules: {
        newName: [
          {
            required: true,
            message: "名称不能为空",
            trigger: "blur",
          },
        ],
      },
      fileList:[],
      uploadList:[],
      // 上传参数
      upload: {
        // 是否显示弹出层（上传导入）
        open: false,
        // 弹出层标题（上传导入）
        title: '上传文件',
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/file/upload'
      },
      showType:1

    };
  },
  watch: {
    // 根据名称筛选部门树
    archivesName(val) {
      this.$refs.tree.filter(val);
    },
  },
  created() {
    this.getTreeData();
  },
  methods: {
    /** 查询新增页面-上级类型下拉树结构 */
    getTreeData() {
      getArchivesTypeListApi().then((response) => {
        this.treeOptions = response.data;
        console.log(this.treeOptions)
        if (this.treeOptions.length > 0 ){
            if(this.treeOptions[0].children&&this.treeOptions[0].children.length > 0) {
              const firstNode = this.treeOptions[0].children[0];
              this.queryParams.infoId = firstNode.id;
              console.log(firstNode)
              let obj = {
                id:0,
                infoId:firstNode.id,
                detailsId:'',
                level:'',
                docName:firstNode.label
              }
              this.breadcrumbList.push(obj)
              this.getList();
            }
            // else{
            //   this.queryParams.typeId = this.treeOptions[0].id;
            //   this.queryParams.level = 0;
            //   this.getList();
            // }
        }
      });
    },
    // 获取父级名称
    getParentName(list, id) {
      try {
        list.forEach((e) => {
          if (e.id == id) {
            this.form.label = e.label;
            throw new Error();
          } else {
            if (e.children && e.children.length > 0) {
              this.getParentName(e.children, id);
            }
          }
        });
      } catch (error) {}
    },
    onMousemove(data) {
      this.isMousemoveId = data.id;
    },
    onMouseleave() {
      this.isMousemoveId = null;
    },
    // treeChange(val) {
    //   console.log(val, "树节点");
    //   this.form.companyId = val.companyId;
    // },
    //树节点新建按钮
    addTreeMainType(){
      this.addTitle = "新建类别";
      this.addFormParams.archivesName=""
      this.addShowVisible = true;
    },
    /* 树节点增加 */
    appendTreeNode(data) {
      console.log(data)
      this.levelTemp = data.level;
      this.idTemp = data.id;
      this.parentId = data.parentId;
        Object.assign(this.addFormParams, data);
        this.addFormParams.archivesName = "";
        this.addTitle = "新增";
        this.addShowVisible = true;
    },
    /* 树节点删除 */
    removeTreeNode(data) {
      // this.$message.success('删除--')
      console.log(data, "删除时的数据源--");
      let delParam = {
        infoId: data.id,
        parentId: data.parentId,
      }
      this.$modal
        .confirm("是否确认删除数据项？")
        .then(function () {
          return delArchivesTypeApi(delParam);
        })
        .then(() => {
          this.$modal.msgSuccess("删除成功");
          this.getTreeData();
        })
        .catch(() => {});
    },
    /* 树节点修改 */
    editTreeNode(data) {
      this.levelTemp = data.level;
      this.idTemp = data.id;
      this.parentId = data.parentId;
      Object.assign(this.addFormParams, data);
      this.addTitle = "修改";
      this.addFormParams.archivesName = data.label;
      this.addShowVisible = true;
    },
    /* 新增编辑弹框-确认按钮 */
    onSubmit() {
      const addParams = {
        infoId: this.idTemp,
        level: this.levelTemp,
        parentId: this.parentId,
        archivesName:this.addFormParams.archivesName
      };
      const editParams = {
        infoId: this.idTemp,
        parentId: this.parentId,
        archivesName:this.addFormParams.archivesName
      };

      const addDetailsParam = {
        infoId:this.queryParams.infoId,
        detailsId:this.queryParams.detailsId,
        level:this.queryParams.level,
        docName:this.addFormParams.archivesName
      };
      this.$refs["addFormParamsRef"].validate(async (valid) => {
        if (valid) {
          if(this.addTitle === "新建类别"){ //左侧树tree-新建类别
            const res = await getAddArchivesTypeApi({archivesName:this.addFormParams.archivesName});
            if (res.code === 200) {
              this.$message.success("新建成功！");
              this.addShowVisible = false;
              this.getTreeData();
            }
          }else if (this.addTitle === "新增") {//左侧树tree-新增类别
            const res = await getAddArchivesTypeApi(addParams);
            if (res.code === 200) {
              this.$message.success("新增成功！");
              this.addShowVisible = false;
              this.getTreeData();
            }
          }else if (this.addTitle === "新建文件夹") {//右侧table-新建文件夹
            const res = await addArchivesDetailsApi({"archivesDetails":addDetailsParam});
            if (res.code === 200) {
              this.$message.success("新建成功！");
              this.addShowVisible = false;
              this.getList();
            }
          } else {
            const res = await updateArchivesTypeApi(editParams);
            if (res.code === 200) {
              this.$message.success("修改成功！");
              this.addShowVisible = false;
              this.getTreeData();
            }
          }
        }
      });
    },
    /* 取消 */
    onCancel() {
      this.addShowVisible = false;
    },
    // 筛选节点 - 左侧树
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      getArchivesDetailsLstApi(this.queryParams).then((response) => {
        this.tableDataList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 文件夹单击事件 - 右侧
    getSubDetails(row){
      if(row.docType=='文件夹'){
        this.queryParams.detailsId=row.detailsId;
        this.queryParams.level=row.level;
        this.queryParams.infoId="";
        this.queryParams.pageNum = 1;
        let obj = {
          id:row.detailsId,
          detailsId:row.detailsId,
          level:row.level,
          docName:row.docName,
        }
        this.breadcrumbList.push(obj)
        this.getList()
      }else{
        //查看文件
        this.picturePreview(row)
      }
    },
     //上传组件-图片查看
     picturePreview(file) {
      console.log(file)
      this.dialogImageUrl = file.docUrl.replaceAll('#','%23');
      const parts = file.docName.split('.');
      const extension = parts.pop();
      console.log(extension)
      if (extension === 'doc' || extension === 'DOC' || extension === 'docx' || extension === 'DOCX' || extension === 'pdf' || extension === 'PDF') {
        const windowName = file.docName;
        window.open(file.docUrl, windowName)
      } else {
        this.dialogVisible = true
      }
    },

    beforeUpload(file) {
      // const isRarOrZip = ['.rar', '.zip'].some(ext => file.name.toLowerCase().endsWith(ext));
      // if (!isRarOrZip) {
      //   this.$message.error('仅支持上传 rar 或 zip 格式的文件');
      //   return false;
      // }
      const validExtensions = ['.pdf', '.doc', '.docx'];
      const validTypes = ['image/', 'video/'];
      const fileName = file.name.toLowerCase();
      const fileType = file.type;

      // 检查文件扩展名
      const hasValidExtension = validExtensions.some(ext => fileName.endsWith(ext));
      // 检查文件 MIME 类型
      const hasValidType = validTypes.some(type => fileType.startsWith(type));

      if (!hasValidExtension && !hasValidType) {
        this.$message.error('仅支持上传图片、视频、PDF、Word格式文件');
        return false;
      }


      const isLt5M = file.size / 1024 / 1024 < 20;
      if (!isLt5M) {
        this.$message.error('单个文件大小不能超过 20MB');
        return false;
      }
      return true;
    },

    // 节点单击事件 - 左侧树
    handleNodeClick(data, node) {
      console.log(data)
      if (data.level != 1) {
        this.queryParams.infoId = data.id;
        this.queryParams.detailsId=""
        this.queryParams.level=""
        this.queryParams.pageNum = 1;
        this.breadcrumbList=[]
        let obj = {
          id:0,
          infoId:data.id,
          detailsId:'',
          level:'',
          docName:data.label
        }
        this.breadcrumbList.push(obj)
        this.getList();
      }
    },
    // 面包屑单击事件-右侧
    breadClick(item,index){
      console.log(item)
      console.log(index)
      if(item.detailsId!=''){
        this.queryParams.detailsId=item.detailsId;
        this.queryParams.level=item.level;
        this.queryParams.infoId=item.infoId;
        this.queryParams.pageNum = 1;
        this.$set(this, 'breadcrumbList', this.breadcrumbList.slice(0,index+1));
        this.getList()
      }else{
        this.queryParams.detailsId="";
        this.queryParams.level="";
        this.queryParams.infoId=item.infoId;
        this.queryParams.pageNum = 1;
        this.$set(this, 'breadcrumbList', this.breadcrumbList.slice(0,index+1));
        this.getList()
      }
    },
    //新建文件夹按钮
    handleAdd(){
      this.addTitle = "新建文件夹";
      this.addFormParams.archivesName="";
      this.addShowVisible = true;
    },
     /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.infoId = undefined;
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;
      // this.queryParams.level = 0;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
     //是否可用勾选框
     selectable(row) {
      if (row.docType != '文件夹') {
        return true;
      } else {
        return true;
      }
    },
    //查看文件
    handleView(row) {
      // console.log(row)
      this.picturePreview(row)
    },
    //顶部重命名按钮
    handleReName(){
      this.handleUpdate(this.ids[0])
    },
    /** （表格）重命名按钮操作 */
    handleUpdate(row) {
      console.log(row)
      this.rowData=row
      this.reNameForm.oldName=row.docName;
      this.reNameForm.newName="";
      this.reNameShowVisible=true;
    },
    /** 重命名弹窗保存 */
    saveName(){
      let param = {
        detailsId:this.rowData.detailsId,
        infoId:this.rowData.detailsId,
        docName:this.reNameForm.newName,
        parentId:this.rowData.parentId
      }
      this.$refs["reNameForm"].validate(async (valid) => {
        if (valid) {
            const res = await updateArchivesDetailsApi(param);
            if (res.code === 200) {
              this.$message.success("修改成功！");
              this.reNameShowVisible = false;
              this.getList()
            }
        }
      });

    },
    /** 删除按钮操作 */
    handleDelete(row) {
      let archivesDetailsList=[
        {detailsId:row.detailsId}
      ]
      this.$modal
        .confirm("是否确认删除数据项？")
        .then(function () {
          return delArchivesDetailsApi({'archivesDetailsList':archivesDetailsList});
        })
        .then(() => {
          this.$modal.msgSuccess("删除成功");
          this.getList();
        })
        .catch(() => {});
    },
    //多选删除
    handleAllDel(){
      let arr=[]
      this.ids.forEach(item=>{
        arr.push({detailsId:item.detailsId})
      })
      this.$modal
        .confirm("是否确认删除数据项？")
        .then(function () {
          return delArchivesDetailsApi({'archivesDetailsList':arr});
        })
        .then(() => {
          this.$modal.msgSuccess("删除成功");
          this.getList();
        })
        .catch(() => {});
    },
    //打开文件上传
    openUpLoadDialog(){
      this.uploadList=[]
      this.fileList=[]
      this.upload.open=true;
    },
    //文件上传-成功
    handleSuccess(response, file, fileList) {
      console.log('File uploaded successfully:', response);
      console.log('File uploaded successfully:', file);
      if(response.code==200){
        let param = {
          docName:response.data.name,
          docUrl:response.data.url,
          docType:response.data.name.split(".").pop(),
          docSize:(file.size / 1024 / 1024).toFixed(2),
          detailsId:this.queryParams.detailsId,
          infoId:this.queryParams.infoId,
          level:this.queryParams.level
        }
        this.uploadList.push(param)
      }
      // let size = (file.size / 1024 / 1024).toFixed(2)
      // console.log(size)
    },
    //文件上传删除
    handleFileRemove(file, fileList){
      console.log(file)
      console.log(fileList)
      let index = this.uploadList.findIndex(item=>item.docName==file.name)
      this.uploadList.splice(index,1)
    },
    //文件上传失败
    handleError(err, file, fileList) {
      console.error('Error while uploading file:', err);
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
    //   this.upload.open = false
    },
    // 提交上传文件
    async submitFileForm() {
      console.log(this.uploadList)
      if(this.uploadList.length==0){
        this.$modal.msgError("请先选择上传文件");
      }else{
        let param = {
          archivesDetailsList:this.uploadList
        }
        const res = await addArchivesDetailsApi(param);
        if (res.code === 200) {
          this.$modal.msgSuccess("上传成功！");
          this.upload.open = false
          this.getList()
        }
      }

      // this.$refs.upload.submit()
    },
    //取消
    cancelUpload() {
      this.getList()
      this.upload.open=false
    },
    /** 导出按钮作 */
    handleExport() {
      let arr=[]
      let errorList = []
      this.ids.forEach(item=>{
        console.log(item)
        if(item.docType=='文件夹'){
          errorList.push(item.detailsId)
        }
        arr.push(item.detailsId)
      })
      console.log(errorList.length)
      if(errorList.length==0){
        downloadFileApi({'ids':arr.join(',')}).then((res) => {
          downloadFile({
              fileName: "文件档案下载.zip",
              fileData: res,
              fileType: "text/html;charset=UTF-8",
          });
        })
      }else{
        this.$modal.msgError("所选文件中包含文件夹，文件夹不能下载");
      }
    },

    //切换展示模式
    changeShowType(val){
      this.showType=val;
    }
  },
};
</script>
<style lang="scss" scoped>
::v-deep.el-table .fixed-width .el-button--mini {
  width: 60px !important;
  margin-bottom: 10px;
}

::v-deep .btn-items .el-button + .el-button {
  margin-left: 6px;
}
.btn-items {
  margin-left: 4px;
  .el-button--text {
    font-size: 16px;
  }
}
::v-deep .el-tree .el-tree-node__expand-icon.expanded {
  -webkit-transform: rotate(0deg);
  transform: rotate(0deg);
}
::v-deep .el-tree .el-icon-caret-right:before {
  content: "\e783";
  font-size: 16px;
}
::v-deep
  .el-tree
  .el-tree-node__expand-icon.expanded.el-icon-caret-right:before {
  content: "\e781";
  font-size: 16px;
  color: #1890ff;
}

::v-deep .el-tree-node__content > .el-tree-node__expand-icon {
  color: #1890ff !important;
}
::v-deep .el-tree-node__expand-icon.is-leaf {
  color: transparent !important;
}

::v-deep
  .el-tree--highlight-current
  .el-tree-node.is-current
  > .el-tree-node__content {
  background-color: #8decf1;
}

::v-deep .el-dialog {
  // 表单标签文字样式
  .el-form-item__label {
    font-size: 14px;
    color: #606266;
    font-weight: 500;
    line-height: 1.5;
  }

  // 输入框文字样式
  .el-input__inner {
    font-size: 14px;
    color: #303133;

    &::placeholder {
      font-size: 13px;
      color: #c0c4cc;
    }
  }

  // 单位文字样式
  span {
    font-size: 14px;
    // color: #606266;
    margin-left: 8px;
  }

  // 下拉选择框文字样式
  .el-select {
    .el-input__inner {
      font-size: 14px;
      color: #303133;
    }
  }

  // 只读输入框样式
  .el-input.is-disabled .el-input__inner {
    background-color: #f5f7fa;
    border-color: #e4e7ed;
    color: #606266;
    cursor: not-allowed;
  }
}

// 表格内文字样式
::v-deep .el-table {
  font-size: 14px;

  th {
    font-weight: 500;
    color: #303133;
  }

  td {
    color: #606266;
  }
}

// 按钮文字样式
::v-deep .el-button {
  font-size: 14px;

  &--text {
    font-size: 13px;
  }
}

// 树节点文字样式
::v-deep .el-tree-node__label {
  font-size: 14px;
  color: #606266;
}

// 搜索框文字样式
::v-deep .el-input--small {
  .el-input__inner {
    font-size: 13px;

    &::placeholder {
      font-size: 13px;
      color: #c0c4cc;
    }
  }
}


::v-deep .el-upload{
    width: 100%;
}
::v-deep .el-upload-dragger{
    width: 100%;
}
</style>
