import ElImageViewer from "../../components/VabUpload/image-viewer";
import settingConfig from "@/settings";
import {treeScollx} from "../../utils/global";

let modules = {};
modules = {
  components: {
    ElImageViewer
  },
  provide() {
    return {
      current_prefix: this.current_prefix,
      storeAreaCode: this.storeAreaCode,
      billConfig: this.billConfig,
      isBillEnabled: this.isBillEnabled,
      billRowField: this.billRowField,
      billDialogParam: this.billDialogParam,
      dataId: this.dataId,
      getTitle: () => {
        return this.title;
      },
      getIsPrivate: () => {
        return this.isPrivate;
      },
      getObjectForeignId: () => {
        return this.objectForeignId;
      },
    };
  },
  created() {

  },
  async mounted() {
    if (this.isPrivate) {
      await this.getCurrentUser();
    }
    //初始化单据弹框
    if (this.isBillEnabled) {
      this.billDialogContent = this.billConfig.billDialog;
    }

    this.initTitle();
    this.initTableList();
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
  data() {
    let pageSize = 1000;
    let categoryPageSize = 1000;
    return {
      showFileObjAuthDialog: false,
      fileObjAuth: {},
      showDialog: true,
      option: {
        private: true,
        isCategoryEdit: true,
        mouseCheck: true,
        storeAreaCode: settingConfig.privateProfileCode,
        current_prefix: USER_PREFIX
      },
      showBillDialog: false,
      billDialogContent: null,
      checkBillDatas: [],
      title: "",
      folderStatus: false,
      filterText: "",
      defaultProps: {
        children: "children",
        label: "fileName",
        isLeaf: "leaf",
      },
      resolveFunc: function () {
      },
      fileAttachmentCategorys: [],
      currentFileCategoryCode: null,
      chooseIndex: -1,
      imageDTOs: [],
      showViewer: false,
      showPropertiesDialog: false,
      editAttachment: null,
      vxeOption: {},
      showType: 2,
      formData: {},
      showAdvancedSearch: false,
      advancedFormData: {},
      pageSize: pageSize,
      page: {
        current: 1,
        size: pageSize,
        total: 0,
        records: [],
      },
      categoryPageSize: categoryPageSize,
      categoryPage: {
        current: 1,
        size: categoryPageSize,
        total: 0,
        records: [],
      },
      showEditCategoryDialog: false,
      editCategory: {},
      currentFileCategory: null,
      rootCategory: false,
      currentNode: null,
      treeNodeArr: [],
      checkRows: [],
      showCategoryMoveDialog: false,
      checkList: [],
      handleType: 1, //1移动，2复制
      showFileHistoryDialog: false,
      operateFileHistory: null,
      showShareDialog: false,
      shareAttachment: null,
      checkAll: false,
      fileArr: [],
      checkList2: [],
      showRecycleBinDialog: false,

      showVideoDialog: false,
      videoOption: null,

      //个人文档
      userInfo: {
        id: null,
        nickName: null,
      },
      treeFlag: false,
      currentUser: {},
      showUserDialog: false,
      isDocAdmin: false,

      //圈选
      is_show_mask: false,
      box_screen_left: 0,
      box_screen_top: 0,
      start_x: 0,
      start_y: 0,
      end_x: 0,
      end_y: 0,
      scrollTop1: 0,
      scrollTop2: 0,
    };
  },
  computed: {
    isEdit() {
      //默认可编辑
      return this.option.isEdit !== false ? true : false;
    },
    isCategoryEdit() {
      if (this.isEdit === false) {
        return false;
      }
      //文件夹默认不可编辑
      return this.option.isCategoryEdit === true ? true : false;
    },
    mouseCheck() {
      //鼠标框选默认不开启
      return this.option.mouseCheck === true ? true : false;
    },
    dataId() {
      // return this.option.dataId;
      let dataId = this.isBillEnabled
        ? this.checkBillDatas.map((row) => row.id)
        : this.option.dataId
          ? [this.option.dataId]
          : [0];
      return dataId;
    },
    objectForeignId() {
      if (this.option.private) {
        return [this.userInfo.id || 0];
      } else {
        return this.dataId && this.dataId.length ? this.dataId : [0];
      }
    },
    current_prefix() {
      return this.option.current_prefix;
    },
    storeAreaCode() {
      return this.option.storeAreaCode;
    },
    pictureDtoList() {
      return this.page.records.filter((row) => {
        return row.url && this.$commonFileUtil.isPictureFile(row.url);
      });
    },
    //圈选
    getMaskStyle: function () {
      return this.getStyle();
    },
    checkAllDisabled() {
      return this.page.records.filter(row => !row.dirs).length == 0;
    },
    checkAllIndeterminate() {
      return (
        this.checkList.length > 0 &&
        this.checkList.length < this.page.records.filter(row => !row.dirs).length
      );
    },
    billConfig() {
      return this.option.billConfig || {};
    },
    billRowField() {
      let billConfig = this.billConfig;
      return billConfig.rowField || "id";
    },
    isBillEnabled() {
      return this.billConfig.enabled || false;
    },
    billDialogParam() {
      if (this.isBillEnabled && this.billConfig.billDialogParam) {
        return this.billConfig.billDialogParam();
      }
    },
    checkBillNames: {
      get() {
        let dataProps = this.billConfig.dataProps;
        return this.checkBillDatas
          .map((row) => {
            return row[dataProps.label];
          })
          .join(",");
      },
      set(val) {
        if (!val) {
          this.checkBillDatas = [];
        }
      },
    },
    isPrivate() {
      return this.option.private || false;
    },
    currentCategoryId() {
      return this.currentFileCategory &&
      this.currentFileCategory.id &&
      this.currentFileCategory.id > 0
        ? this.currentFileCategory.id
        : 0;
    },
    target() {
      return this.$refs.privateProfileDialog;
    }
  },
  methods: {
    dialogPrimary() {
      let checkRows = this.getCheckRows();
      this.handleClose();
      this.$emit('confirm', checkRows);
    },
    handleClose() {
      this.$emit('update:visiable', false)
    },
    getTopNode() {
      return this.$refs.tree.root.childNodes[0];
    },
    getFileName(row) {
      if (row.extension) {
        let index = row.fileName.lastIndexOf("." + row.extension);
        return row.fileName.substring(0, index);
      } else {
        return row.fileName;
      }
    },
    openShareDialog(shareAttachment) {
      this.showShareDialog = true;
      this.shareAttachment = shareAttachment;
    },
    getCheckRows() {
      let checkRows = [];
      if (this.showType == 1) {
        let checkList = this.checkList;
        checkRows = this.page.records.filter((row) =>
          checkList.includes(row.id)
        );
      } else {
        checkRows = this.$refs["table-m1"].getCheckboxRecords(true);
      }
      return checkRows;
    },
    getRows() {
      let rows = [];
      if (this.showType == 1) {
        rows = this.page.records;
      } else {
        rows = this.$refs["table-m1"].getTableData().fullData;
      }
      return rows;
    },
    changeShowType() {
      this.showType = this.showType == 1 ? 2 : 1;
      this.searchEvent();
    },
    changeCategory(row, node) {
      if (!node) {
        node = this.$refs.tree.getNode(row.id + "");
        this.$refs.tree.setCurrentKey(row);
      }
      if (row.id) {
        node.expand();
      }
      this.formData = {};
      this.advancedFormData = {};
      this.handleNodeData(node);
      this.searchEvent();
    },
    searchEvent() {
      this.doSearch();
    },
    resetEvent() {
      this.formData = {};
      this.doSearch();
    },
    doSearch() {
      this.checkList = [];
      this.checkAll = false;
      this.initAttchInfo();
      /*if (this.showType == 1) {
        this.initAttchInfo();
      } else if (this.showType == 2) {
        this.$refs['table-m1'].commitProxy('reload');
      }*/
    },
    openPropertiesDialog(attachment) {
      this.editAttachment = attachment;
      this.showPropertiesDialog = true;
    },
    getShowUrl(attachment, field) {
      if (!field) field = "medium";
      return this.$commonFileUtil.getShowUrl(
        attachment.domain +
        (attachment[field] ? attachment[field] : attachment.url)
      );
    },
    isVideo(fileSuffix) {
      let videoTypes = ["webm", "ogg", "3gp", "mp4"];
      return videoTypes.includes(fileSuffix);
    },
    hasPreview(attachment) {
      let fileSuffix = this.$commonFileUtil.getFileSuffix(attachment.url);
      return (
        this.$commonFileUtil.isPictureFile(attachment.url) ||
        this.$commonFileUtil.isPreviewFile(attachment.url)
      );
    },
    openPreview(attachment) {
      if (this.$commonFileUtil.isPictureFile(attachment.url)) {
        this.imageDTOs = this.pictureDtoList;
        this.chooseIndex = this.pictureDtoList.findIndex(
          (row) => row.id == attachment.id
        );
        this.showViewer = true;
      } else if (this.$commonFileUtil.isPreviewFile(attachment.url)) {
        this.$openFilePreview(attachment);
      }
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.fileName.indexOf(value) !== -1;
    },
    initAttchInfo(page) {
      let defaultPage = {
        current: 1,
        size: this.pageSize,
        total: 0,
        records: [],
      };
      page = page || {
        current: 1,
        size: this.pageSize,
      };

      let parent = this.currentCategoryId;
      this.target.$http({
        method: "post",
        url: this.current_prefix + "/file_obj/listPage",
        data: {
          parent: parent,
          objectForeignId: this.objectForeignId,
          privateDir: this.isPrivate ? 1 : 0,
          storeAreaCode: this.storeAreaCode,
          ...this.formData,
          ...this.advancedFormData,
          ...page,
        },
        isLoading: true,
        success: (res) => {
          this.page = res.objx ? res.objx : defaultPage;
        },
      });
    },
    initTableList() {
      let that = this;
      let tableOption = {
        vue: this,
        tableRef: "table-m1",
        tableName: "pcp_product_file_list-m1",
        config: {
          height: "auto",
          pagerConfig: {
            autoHidden: false,
            enabled: true,
          },
          checkboxConfig: {
            checkMethod: ({row}) => {
              return !row.dirs;
            }
          }
        },
        columns: [
          {type: "checkbox", width: 48, resizable: false, fixed: "left"},
          {
            title: "文件名称",
            field: "fileName",
            width: 250,
            fixed: "left",
            slots: {
              default: ({row, $rowIndex}) => {
                let h = this.$createElement;
                if (!row.dirs) {
                  let showUrl = that.getShowUrl(row, "thumbnail");
                  return [
                    h(
                      "a",
                      {
                        staticClass: "a-link img",
                        on: {
                          click: (event) => {
                            event.stopPropagation();
                            that.openPreview(row);
                          },
                        },
                      },
                      [
                        h(
                          "el-tooltip",
                          {
                            props: {
                              enterable: false,
                              effect: "dark",
                              content: "预览",
                              placement: "top",
                              "popper-class": "tooltip-skin",
                            },
                          },
                          [
                            h("el-image", {
                              props: {
                                src: showUrl,
                              },
                            }),
                          ]
                        ),
                      ]
                    ),
                    h("span", row.fileName),
                  ];
                } else {
                  return [
                    h(
                      "a",
                      {
                        staticClass: "a-link img",
                        on: {
                          click: (event) => {
                            event.stopPropagation();
                            that.changeCategory(row);
                          },
                        },
                      },
                      [
                        h(
                          "div",
                          {
                            staticClass: "img",
                          },
                          [
                            h("svg-icon", {
                              props: {"icon-class": "ico-wenjianjia"},
                            }),
                            h("span", row.fileName),
                          ]
                        ),
                      ]
                    ),
                  ];
                }
              },
            },
          },
          {
            title: "文件大小",
            field: "fileSize",
            width: 150,
            slots: {
              default: ({row, $rowIndex}) => {
                if (!row.dirs) {
                  return this.formatFileSize(row.fileSize);
                }
              },
            },
          },
          {
            title: "版本号",
            field: "rev",
            width: 150,
            slots: {
              default: ({row, $rowIndex}) => {
                if (!row.dirs) {
                  return row.rev;
                }
              },
            },
          },
          {title: "说明", field: "note", width: 250},
          /*{
            title: '状态',
            field: 'status',
            width: 150,
            slots: {
              default: ({row, $rowIndex}) => {
                if (!row.dirs) {
                  return row.status == 1 ? '已归档' : '未归档';
                }
              }
            }
          },*/
          {title: "创建人", field: "createBy", width: 150},
          {
            field: "createDate",
            title: "创建时间",
            width: 150,
          },
          {
            width: 47,
            fixed: "right",
            title: "",
            sortable: false,
            slots: {
              default: ({row, $rowIndex, items}) => {
                let isEdit = this.isEdit;
                let isCategoryEdit = this.isCategoryEdit;
                let fileObjAuth = this.fileObjAuth;
                if (!row.dirs) {
                  return [
                    this.getBtnVnode({
                      class: "el-icon-download",
                      title: "下载",
                      show: fileObjAuth.downloadAuth == 1,
                      click: (event) => {
                        this.$commonFileUtil.downloadFile(
                          row.domain + row.url,
                          row.fileName
                        );
                      },
                    })
                  ];
                }
              },
            },
          },
        ],
        callback(a, b) {
        },
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
        this.vxeOption = opts;
      });
    },
    getBtnVnode(opt) {
      let h = this.$createElement;
      let show = opt.show === false ? false : true;
      if (show) {
        return h(
          "a",
          {
            staticClass: "a-link",
            on: {
              click: (event) => {
                opt.click && opt.click(event);
              },
            },
          },
          [
            h(
              "el-tooltip",
              {
                props: {
                  enterable: false,
                  effect: "dark",
                  content: opt.title,
                  placement: "top",
                  "popper-class": "tooltip-skin",
                },
              },
              [
                h("i", {
                  staticClass: opt.class,
                }),
              ]
            ),
          ]
        );
      }
    },
    changePageNew({type, currentPage, pageSize, $event}) {
      this.checkList = [];
      this.checkAll = false;
      this.initAttchInfo({
        current: currentPage,
        size: pageSize,
      });
    },
    handleNodeClick(data, node, v) {
      if (!data.moreBtn) {
        this.changeCategory(data, node);
      } else {
        this.showModeCategory(data, node, v);
      }
    },
    doNav(t) {
      let node = this.$refs.tree.getNode(t.data.id + "");
      this.$refs.tree.setCurrentKey(node.data);
      this.handleNodeClick(node.data, node, this);
    },
    showModeCategory(data, node, v) {
      let param = {
        parent: data.parent,
        dirs: true,
        storeAreaCode: this.storeAreaCode,
        size: this.categoryPageSize,
        current: data.next,
      };
      if (this.isPrivate) {
        param.objectForeignId = this.objectForeignId;
        param.privateDir = 1;
      }
      this.target.$http({
        url: this.current_prefix + "/file_obj/listPage",
        method: "post",
        data: param,
        isLoading: true,
        success: (res) => {
          let page = res.objx;
          let rows = page && page.records ? page.records : [];
          this.$refs.tree.remove(node);
          if (page.pages > page.current) {
            rows.push({
              parent: param.parent,
              fileName: "更多",
              moreBtn: true,
              leaf: true,
              pages: page.pages,
              current: page.current,
              next: page.current + 1,
            });
          }
          rows.forEach((value) => {
            value.leaf = !value.hasChild;
          });
          rows.forEach((row) => {
            this.$refs.tree.append(row, param.parent);
          });
        },
      });
    },
    // 异步树叶子节点懒加载逻辑
    loadNode(node, resolve, callback) {
      let id = node && node.data && node.data.id ? node.data.id || "" : "";
      node.resolve = resolve;
      let url, param;
      url = this.current_prefix + "/file_obj/listPage";
      if (!id) {
        param = {
          dirs: true,
          storeAreaCode: this.storeAreaCode,
          size: this.categoryPageSize,
        };
      } else {
        param = {
          dirs: true,
          parent: id,
          storeAreaCode: this.storeAreaCode,
          size: this.categoryPageSize,
        };
      }
      if (this.isPrivate) {
        param.objectForeignId = this.objectForeignId;
        param.privateDir = 1;
      }
      this.target.$http({
        url: url,
        method: "post",
        data: param,
        success: (res) => {
          let page = res.objx;
          let rows = page && page.records ? page.records : [];
          if (page.pages > page.current) {
            rows.push({
              parent: param.parent,
              fileName: "更多",
              moreBtn: true,
              leaf: true,
              pages: page.pages,
              current: page.current,
              next: page.current + 1,
            });
          }

          // moreBtn
          rows.forEach((value) => {
            value.leaf = !value.hasChild;
          });
          if (node.level === 0) {
            setTimeout(() => {
              this.$refs.tree.setCurrentKey(node.childNodes[0].data);
              this.handleNodeData(node.childNodes[0]);
              node.childNodes[0].expand();
            }, 200);
            this.$nextTick(() => {
              callback && callback();
            });
            this.searchEvent();
          } else {
            this.$nextTick(() => {
              callback && callback();
            });
          }
          let items = [];
          if (node.level === 0) {
            let item = {
              parent: null,
              fileName: this.title,
              leaf: rows.length == 0,
              allFileBtn: true,
              id: 0,
              children: rows,
            };
            items.push(item);
          } else {
            items = rows;
          }

          resolve(items);
        },
      });
    },
    editFileCategory(category) {
      let currentFileCategory = category || this.currentFileCategory;
      if (!currentFileCategory) {
        this.$message({
          message: "请选择文件夹",
          type: "error",
          showClose: true,
          duration: 3000,
        });
        return;
      }
      this.editCategory = Object.assign({}, currentFileCategory);
      this.showEditCategoryDialog = true;
    },
    handleNodeData(node) {
      let treeNodeArr = [];
      let tree = this.$refs.tree;
      // let firstNode = tree.root.childNodes[0];
      if (node) {
        treeNodeArr.push(node);
        let end = false;
        let pNode = node;
        while (!end) {
          pNode = pNode.parent;
          if (pNode && pNode.data) {
            let pData = pNode.data;
            treeNodeArr.push(pNode);
            end = pNode.level <= 1;
          } else {
            end = true;
          }
        }
        treeNodeArr = treeNodeArr.reverse();
      }
      /*treeNodeArr.unshift(firstNode)
      if (!node) {
        node = firstNode;
      }*/
      this.currentFileCategory = node ? node.data : null;
      this.currentNode = node;
      this.$set(this, "treeNodeArr", treeNodeArr);
      this.getFileObjAuth();
    },
    getFileObjAuth() {
      this.target.$http({
        url: this.current_prefix + `/file_obj_auth/getFileObjAuth`,
        method: `post`,
        data: {
          fileObjId: this.currentCategoryId,
          storeAreaCode: this.storeAreaCode,
        },
        isLoading: true,
        modalStrictly: true,
        success: (res) => {
          this.fileObjAuth = res.objx || {};
        },
      });
    },
    mulDownload() {
      let checkRows = this.getCheckRows();
      if (!checkRows.length) {
        this.$message({
          message: "请选择需要下载的文件",
          type: "error",
          showClose: true,
          duration: 3000,
        });
        return;
      }
      checkRows.forEach((row) => {
        this.$commonFileUtil.downloadFile(row.domain + row.url, row.fileName);
        // this.downLoadFile(row);
      });
    },
    mulDownload2() {
      let checkRows = this.getCheckRows();
      if (!checkRows.length) {
        this.$message({
          message: "请选择需要下载的文件",
          type: "error",
          showClose: true,
          duration: 3000,
        });
        return;
      }
      /*let dirFile = checkRows.find(row => row.dirs);
      if (dirFile) {
        this.$message({
          message: '文件夹不支持下载',
          type: 'error',
          showClose: true,
          duration: 3000,
        });
        return;
      }*/
      this.getDownloadDomian((domain) => {
        this.getFileWhole(checkRows, (fileWhole) => {
          // let fileName = this.$moment().format('YYYYMMDDHHmmss');
          this.target.$http({
            method: "post",
            url: domain + "/docfile/download",
            /*data: {
              "fileName": fileName,
              "children": checkRows,
              "dirs": true
            },*/
            data: fileWhole,
            isLoading: true,
            success: (res) => {
              // this.downLoadFile2(res.objx.url)
              window.open(res.objx.url);
            },
          });
        });
      });
      /*checkRows.forEach(row => {
        this.$commonFileUtil.downloadFile(row.domain + row.url, row.fileName);
      })*/
    },
    getDownloadDomian(callback) {
      this.target.$http({
        method: "post",
        url: USER_PREFIX + "/common/fileDownloadUrl",
        data: {},
        isLoading: true,
        success: (res) => {
          callback(res.objx);
        },
      });
    },
    getFileWhole(rows, callback) {
      let ids = rows.map((row) => row.id);
      this.target.$http({
        method: "post",
        url: this.current_prefix + "/file_obj/getFileWhole",
        data: ids,
        isLoading: true,
        success: (res) => {
          callback(res.objx);
        },
      });
    },
    downLoadFile2(fileUrl) {
      let that = this;
      that.target.$http({
        method: "get",
        url: fileUrl,
        data: {},
        /*headers: {
          'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        },*/
        responseType: "blob",
        resultType: "other",
        isLoading: true,
        callback: (res, response) => {
          let fileName = fileUrl.slice(fileUrl.lastIndexOf("/") + 1);
          const blobUrl = window.URL.createObjectURL(res);
          const a = document.createElement("a");
          a.download = fileName;
          a.href = blobUrl;
          a.click();
        },
      });
    },
    downLoadFile(row) {
      let that = this;
      let fileUrl = row.domain + row.url;
      that.target.$http({
        method: "get",
        url: fileUrl,
        data: {},
        /*headers: {
          'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        },*/
        responseType: "blob",
        resultType: "other",
        isLoading: true,
        callback: (res, response) => {
          const blobUrl = window.URL.createObjectURL(res);
          const a = document.createElement("a");
          a.download = row.fileName;
          a.href = blobUrl;
          a.click();
        },
      });
    },
    checkChange() {
      let rows = this.getRows().filter(row => !row.dirs);
      let checkRows = this.getCheckRows();
      this.checkAll = rows.length && rows.length == checkRows.length;
    },
    changeCheckAll(val) {
      let rows = this.getRows();
      this.checkList = val ? rows.filter(row => !row.dirs).map((row) => row.id) : [];
      if (this.showType == 2) {
        this.$refs["table-m1"].setAllCheckboxRow(val);
      }
    },
    tableCheckChange() {
      let checkRows = this.getCheckRows();
      this.checkList = checkRows.map((row) => row.id);
      this.checkChange();
    },
    tableCheckAll(val) {
      let checkRows = this.getCheckRows();
      this.checkList = checkRows.map((row) => row.id);
      this.checkChange();
    },
    initTitle() {
      this.target.$http({
        method: "post",
        url: USER_PREFIX + "/file_store_area/getByCode",
        data: {
          stringOne: this.storeAreaCode,
        },
        isLoading: true,
        success: (res) => {
          let fileStoreArea = res.objx;
          if (fileStoreArea) {
            this.title = fileStoreArea.storeAreaName;
            this.$nextTick(() => {
              treeScollx({target: this.$refs.privateProfileDialog, type: "default"});
              this.treeFlag = true;
            });
          } else {
            this.$baseAlert("文档工作区未维护");
          }
        },
      });
    },
    formatFileSize(fileSize) {
      fileSize = fileSize || 0;
      if (fileSize < 1024) {
        return fileSize + "B";
      } else if (fileSize < 1024 * 1024) {
        var temp = fileSize / 1024;
        temp = temp.toFixed(2);
        return temp + "KB";
      } else if (fileSize < 1024 * 1024 * 1024) {
        var temp = fileSize / (1024 * 1024);
        temp = temp.toFixed(2);
        return temp + "MB";
      } else {
        var temp = fileSize / (1024 * 1024 * 1024);
        temp = temp.toFixed(2);
        return temp + "GB";
      }
    },
    deleteBillData(index) {
      this.checkBillDatas.splice(index, 1);
      this.searchEvent();
    },
    getBillLabel(item) {
      let billConfig = this.billConfig;
      let dataProps = billConfig.dataProps;
      return item[dataProps.label];
    },
    openBillDialog() {
      this.showBillDialog = true;
    },
    confirmBillDialog(rows) {
      // this.checkBillDatas = rows;

      let billRowField = this.billRowField;
      let checkBillDatas = this.checkBillDatas;
      let fieldDatas = checkBillDatas.map((row) => {
        return row[billRowField];
      });
      let newRows = rows.filter((row) => {
        return !fieldDatas.includes(row[billRowField]);
      });
      this.checkBillDatas.push(...newRows);
      this.searchEvent();
    },
    clearBill() {
      this.checkBillDatas = [];
      this.searchEvent();
    },
    //个人文档
    async getCurrentUser() {
      return this.target.$http({
        url: USER_PREFIX + "/user/currentUser",
        method: "post",
        success: (res) => {
          this.currentUser = res.objx;
          this.confirmUser([this.currentUser]);
          this.getIsDocAdmin();
        },
      });
    },
    confirmUser(rows) {
      if (rows) {
        let row = rows[0];
        this.userInfo.id = row.id;
        this.userInfo.nickName = row.nickName;
        this.reflushTree();
      }
    },
    setCurrentUser(flag) {
      this.confirmUser([this.currentUser]);
      this.reflushTree();
    },
    reflushTree() {
      this.treeFlag = false;
      setTimeout(() => {
        this.treeFlag = true;
      }, 200);
    },
    getIsDocAdmin() {
      return this.target.$http({
        url: USER_PREFIX + "/file_obj/isDocAdmin",
        method: "post",
        success: (res) => {
          this.isDocAdmin = res.objx || false;
        },
      });
    },
  },
};
export default modules;
