<template>
  <!-- 体系文件管理 -->
  <div class="file_manage_wrap">
    <header class="header_wrap">
      <el-form :model="searchForm" :inline="true">
        <el-form-item label="文件名称" label-width="65px">
          <el-input
            type="text"
            size="mini"
            v-model="searchForm.fileName"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label-width="0">
          <el-button type="primary" size="mini" @click="fileDataSearch"
            >查询</el-button
          >
          <el-button type="primary" size="mini">重置</el-button>
        </el-form-item>
      </el-form>
    </header>
    <el-row :gutter="24" class="main_container">
      <el-col :span="4">
        <aside
          class="aside_wrap examination"
          :style="{ height: treeHeight + 'px' }"
        >
          <div class="common-title-name">
            <img
              style="width: 25px; height: 25px"
              src="../../../../assets/img/imgScreen/logo.png"
            />
            <span>文件分类</span>
          </div>
          <!-- 操作按钮区 -->
          <div style="margin-top: 8px">
            <el-button
              icon="el-icon-circle-plus-outline"
              type="primary"
              size="mini"
              style="width: 36px; padding: 8px"
              @click="showTypeDialog('add')"
            ></el-button>
            <el-button
              icon="el-icon-edit"
              type="primary"
              size="mini"
              style="width: 36px; padding: 8px"
              @click="showTypeDialog('edit')"
            ></el-button>
            <el-button
              icon="el-icon-remove-outline"
              type="danger"
              style="width: 36px; padding: 8px"
              :loading="typeDropLoading"
              size="mini"
              @click="deleteTypeData"
            ></el-button>
            <el-button
              icon="el-icon-refresh"
              type="primary"
              style="width: 36px; padding: 8px"
              :loading="typeRefreshLoading"
              size="mini"
              @click="searchTypeData"
            ></el-button>
          </div>
          <el-tree
            ref="menuTree"
            :data="menuTree"
            :props="defaultProps"
            node-key="id"
            class="tree_wrap"
            v-loading="treeLoading"
            :default-expanded-keys="expandedKeys"
            @node-expand="expandNode"
            @node-collapse="expandCollapse"
            :expand-on-click-node="true"
            @node-click="nodeClick"
            :style="{ height: treeHeight + 'px' }"
          >
            <span class="custom-tree-node" slot-scope="{ node, data }">
              <span
                :style="
                  data.status === '0' || node.parent.data.status === '0'
                    ? 'color: #a09e9e;'
                    : ''
                "
                >{{ node.label }}</span
              >
              <span class="nodeOperate contextmenu">
                <el-dropdown @command="handleCommand" :hide-on-click="false">
                  <span class="el-dropdown-link">
                    <i
                      class="el-icon-arrow-down icore-icon-size"
                      style="color: #111; background-color: #61f06e"
                    ></i>
                  </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-row>
                      <el-dropdown-item
                        :command="{ str: 'add', node: node, data: data }"
                        class="el-icon-plus addMenuPr"
                        >添加</el-dropdown-item
                      >
                    </el-row>
                    <el-row>
                      <el-dropdown-item
                        :command="{ str: 'edit', node: node, data: data }"
                        class="el-icon-edit editMenuPr"
                        >修改</el-dropdown-item
                      >
                    </el-row>
                    <el-row>
                      <el-dropdown-item
                        :command="{ str: 'delete', node: node, data: data }"
                        class="el-icon-delete delMenuPr"
                        >删除</el-dropdown-item
                      >
                    </el-row>
                  </el-dropdown-menu>
                </el-dropdown>
              </span>
            </span>
          </el-tree>
        </aside>
      </el-col>
      <el-col :span="20">
        <!-- 文件信息表 -->
        <section class="section_wrap examination">
          <div class="common-title-name section_top">
            <img
              style="width: 25px; height: 25px"
              src="../../../..//assets/img/imgScreen/logo.png"
            />
            <span>文件信息</span>
            <el-button
              icon="el-icon-circle-plus-outline"
              type="primary"
              :loading="addLoading"
              size="mini"
              @click="showFAddDialog"
              >新增</el-button
            >
            <el-button
              icon="el-icon-edit"
              type="primary"
              :loading="editLoading"
              size="mini"
              @click="showFEditDialog"
              >修改</el-button
            >
            <el-button
              icon="el-icon-remove-outline"
              type="danger"
              :loading="dropLoading"
              size="mini"
              @click="deleteFileData"
              >删除</el-button
            >
          </div>
          <el-table
            v-loading="dataLoading"
            ref="fileTable"
            highlight-current-row
            @current-change="fileRowChange"
            @selection-change="fileSelectChange"
            border
            :icore-filter-flag="icoreFilterFlag"
            :height="tableHeight"
            :data="fileDataList"
          >
            <el-table-column
              type="index"
              label="NO"
              align="center"
            ></el-table-column>
            <el-table-column type="selection" align="center"></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="className"
              label="文件分类"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="fileName"
              label="文件名称"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="fileTypeName"
              label="文件类别"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="fileLevel"
              label="文件级别"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="fileSource"
              label="文件来源"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="companyName"
              label="管理单位"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="deptName"
              label="管理车间"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="sectionName"
              label="管理班组"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="startDate"
              label="生效日期"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="endDate"
              label="失效日期"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="mdfReason"
              label="修改原因"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="memo"
              label="备注"
              align="center"
            ></el-table-column>
            <!-- <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="filePath01"
              label="文件"
              align="center"
            ></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="filePath01"
              label="下载/预览"
              align="center"
            ><template slot-scope="scope">
              <el-tooltip
                content="预览"
                placement="bottom"
                effect="light"
              >
                <el-button
                  :disabled="!scope.row.filePath01"
                  type="warning"
                  size="mini"
                  icon="el-icon-view"
                  circle
                  @click="
                      imgPreView(
                        scope.row,
                        scope.row.filePath01
                      )
                    "
                >
                </el-button>
              </el-tooltip>
            </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="createTime"
              label="创建日期"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="createMan"
              label="创建人"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="updateTime"
              label="修改时间"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="updateMan"
              label="修改人"
              align="center"
            ></el-table-column>
          </el-table>
          <div class="common-foot-style">
            <el-pagination
              v-loading="dataLoading"
              @size-change="filePageSizeChange"
              @current-change="filePageCurrentChange"
              :current-page="filePage.pageIndex"
              :page-sizes="[10, 20, 50, 100, 200]"
              :page-size="filePage.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="filePage.totalPage"
              background
            >
            </el-pagination>
          </div>
        </section>
        <!-- 记录信息表 -->
        <section class="section_wrap examination">
          <div class="common-title-name section_top">
            <img
              style="width: 25px; height: 25px"
              src="../../../..//assets/img/imgScreen/logo.png"
            />
            <span>记录信息</span>
            <el-button
              icon="el-icon-circle-plus-outline"
              type="primary"
              :loading="addLoading"
              size="mini"
              @click="showARecordDialog"
              >新增</el-button
            >
            <el-button
              icon="el-icon-edit"
              type="primary"
              :loading="editLoading"
              size="mini"
              @click="showERecordDialog"
              >修改</el-button
            >
            <el-button
              icon="el-icon-remove-outline"
              type="danger"
              :loading="dropLoading"
              size="mini"
              @click="deleteRecordData"
              >删除</el-button
            >
          </div>
          <el-table
            v-loading="recordDataLoading"
            ref="recordTable"
            highlight-current-row
            border
            @current-change="recordRowChange"
            @selection-change="recordSelectChange"
            :icore-filter-flag="icoreFilterFlag"
            :height="tableHeight"
            :data="recordDataList"
          >
            <el-table-column
              type="index"
              label="NO"
              align="center"
            ></el-table-column>
            <el-table-column type="selection" align="center"></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="fileDate"
              label="文件日期"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="fileName"
              label="文件名称"
              align="center"
            ></el-table-column>
            <!-- <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="filePath01"
              label="附件"
              align="center"
            ></el-table-column> -->
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="filePath01"
              label="下载/预览"
              align="center"
            ><template slot-scope="scope">
              <el-tooltip
                content="预览"
                placement="bottom"
                effect="light"
              >
                <el-button
                  :disabled="!scope.row.filePath01"
                  type="warning"
                  size="mini"
                  icon="el-icon-view"
                  circle
                  @click="
                      imgPreView(
                        scope.row,
                        scope.row.filePath01
                      )
                    "
                >
                </el-button>
              </el-tooltip>
            </template>
            </el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="memo"
              label="备注"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="createTime"
              label="创建日期"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="createMan"
              label="创建人"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="updateTime"
              label="修改时间"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              :show-overflow-tooltip="true"
              min-width="80px"
              prop="updateMan"
              label="修改人"
              align="center"
            ></el-table-column>
          </el-table>
          <div class="common-foot-style">
            <el-pagination
              v-loading="recordDataLoading"
              @size-change="recordPageSizeChange"
              @current-change="recordPageCurrentChange"
              :current-page="recordPage.pageIndex"
              :page-sizes="[10, 20, 50, 100, 200]"
              :page-size="recordPage.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="recordPage.totalPage"
              background
            >
            </el-pagination>
          </div>
        </section>
      </el-col>
    </el-row>
    <!-- 文件分类编辑弹窗 -->
    <el-dialog
      @close="closeTypeDialog"
      :visible.sync="typeDialogVisible"
      customClass="type_dialog_wrap"
      :close-on-click-modal="false"
    >
      <div slot="title" class="titleBox">
        <i :class="'el-icon-document'" style="font-size: 20px"></i>
        <span style="margin-left: 10px; font-size: 18px">{{ "新增分类" }}</span>
      </div>
      <el-form
        ref="typeData"
        label-width="65px"
        :inline="true"
        :model="typeData"
        :rules="typeRules"
      >
        <el-form-item
          prop="parentName"
          label="父类名称"
          v-if="typeOperateFlag === 'add'"
        >
          <el-input
            v-model="typeData.parentName"
            clearable
            size="small"
            style="width: 160px"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item prop="className" label="分类名称">
          <el-input
            v-model="typeData.className"
            clearable
            size="small"
            :style="typeOperateFlag === 'add' ? 'width: 160px' : 'width: 392px'"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item prop="isoNo" label="体系类型">
            <el-select
              v-model="typeData.isoNo"
              clearable
              filterable
              style="width: 160px"
              collapse-tags
              size="small"
            >
              <el-option
                 v-for="item in qualityType"
                :key="item.isoNo"
                :label="item.isoName"
                :value="item.isoNo"
              >
              </el-option>
            </el-select>
        </el-form-item>
        <el-form-item prop="dspOrder" label="物料顺序">
          <el-input
            v-model="typeData.dspOrder"
            clearable
            size="small"
            style="width: 160px"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item prop="memo" label="备注">
          <el-input
            v-model="typeData.memo"
            clearable
            size="small"
            style="width: 392px"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="addTypeData"
          >确定</el-button
        >
        <el-button size="mini" type="default" @click="closeTypeDialog"
          >取消</el-button
        >
      </span>
    </el-dialog>
    <!-- 文件信息编辑弹窗 -->
    <file-alert-components
      :type="fileDialogTitle"
      :fileShowFlag="fileDialogVisible"
      :baseData="selectedData"
      @close="closeDialog('file')"
      @refresh="refresh"
    >
    </file-alert-components>
    <!-- 记录信息编辑弹窗 -->
    <record-alert-components
      :type="recordDialogTitle"
      :recordShowFlag="recordDialogVisible"
      :recordObj="recordData"
      @close="closeDialog('record')"
      @refresh="refresh1"
    >
    </record-alert-components>
  </div>
</template>

<script>
import fileAlertComponents from './fileAlertComponents.vue'
import recordAlertComponents from './recordAlertComponents.vue'
import { formatDate, getCookie } from '@/utils/util.js';
import { cookieUserId, cookieUserName } from '@/config/config.js';
export default {
  data () {
    return {
      searchForm: {
        fileName: '' // 文件名称
      },
      defaultProps: {
        children: 'children',
        label: 'className'
      },
      menuTree: [], // 分类数据
      treeLoading: false,
      expandList: [],
      expandedKeys: [],
      treeHeight: 500,
      addLoading: false,
      editLoading: false,
      dropLoading: false,
      addLoading1: false,
      editLoading1: false,
      dropLoding1: false,
      dataLoading: false,
      recordDataLoading: false,
      icoreFilterFlag: true,
      fileDataList: [],
      recordDataList: [],
      qualityType: [],//质控类型
      selectedData: {}, // 文件信息对象
      recordData: {
        fileNo: '',
        fileName: ''
      }, // 记录信息对象
      fileDialogVisible: false, // 文件操作弹窗是否可见
      selectedNode: {
        parentNo: '',
        parentName: '',
        classNo: '',
        className: '',
        memo: ''
      }, // 选中分类节点
      typeData: {
        parentNo: '',
        parentName: '',
        isoNo:'',
        isoName:'',
        dspOrder:'',
        classNo: '',
        className: '',
        memo: ''
      },
      typeDataCache: {
        parentNo: '',
        parentName: '',
        classNo: '',
        className: '',
        memo: ''
      },
      typeRules: {
        className: [{ required: true, message: '分类名称不能为空', trigger: 'blur' }]
      }, // 分类数据验证规则
      typeDialogVisible: false, // 分类信息编辑弹窗是否可见
      typeDropLoading: false, // 分类信息删除按钮是否禁用
      typeRefreshLoading: false, // 分类信息刷新按钮是否禁用
      typeOperateFlag: 'add', // 分类信息编辑状态
      selectedFileList: [], // 选中的文件数据
      selectedRecordList: [], // 选中的记录信息
      fileDialogTitle: '新增文件信息',
      recordDialogTitle: '新增文件记录信息',
      recordDialogVisible: false,
      tableHeight: 250,
      filePage: {
        pageIndex: 1,
        pageSize: 50,
        totalPage: 0
      },
      recordPage: {
        pageIndex: 1,
        pageSize: 50,
        totalPage: 0
      },
      selectByClassNo:{},
    }
  },
  created () {
    this.treeHeight = window.innerHeight - 200
    this.tableHeight = (window.innerHeight - 240) / 2 > 210 ? (window.innerHeight - 240) / 2 : 210
    this.axios
        .post(
            "pass/baseManagement/v1/limsisotmps/queryLimsIsoTmpPage",
            {},
            { individualType: "json" }
        )
        .then((res) => {
            this.qualityType = res.data.list;
        });
    this.init()
  },
  mounted () {

  },
  methods: {
    getCode(code, arr, codeKey, nameKey) {
      if (!code) {
        return "";
      }
      let targetRow = arr.find((item) => {
        return item[codeKey] === code;
      });
      // console.log(targetRow, 'targetRow');
      return targetRow ? targetRow[nameKey] : "";
    },
    // 初始化节点
    init () {
      this.searchTypeData()
      this.fileDataSearch()
    },
    // 重新查询节点数据
    async searchTypeData () {
      let param = {
        pageNum: '1',
        pageSize: 10000,
        object: {
          className: ''
        }
      }
      const data = await this.axios.post(`pass/baseManagement/v1/limsisoclasss/queryLimsClassPage`, {}, { individualType: 'json' })
      const list = this.getTypeList(data.data.list, { id: 'classNo', parentId: 'parentNo' })
      this.menuTree = [...list]
    },
    // 查询文件信息
    async fileDataSearch (fileNo,flag = true) {
      if (flag) {
        this.filePage.pageIndex = 1
      }
      let param = {
        ...this.filePage,
        object: {
          fileNo: fileNo,
          tenantNo: '1'
        }
      }
      const data = await this.axios.post(`pass/baseManagement/v1/limsisofiles/queryLimsIsoFilePage`, param, { individualType: 'json' })
      if (data.status == 'succeed') {
        this.fileDataList = [...data.data.list]
        this.filePage.totalPage = data.data.total - 0
      } else {
        this.fileDataList = []
        this.filePage.totalPage = 0
      }
    },
    async fileDataSearchByClassNo () {
      if (true) {
        this.filePage.pageIndex = 1
      }
      let param = {
        ...this.filePage,
        object: {
          classNo: this.selectByClassNo,
          tenantNo: '1'
        }
      }
      const data = await this.axios.post(`pass/baseManagement/v1/limsisofiles/queryLimsIsoFilePage`, param, { individualType: 'json' })
      if (data.status == 'succeed') {
        this.fileDataList = [...data.data.list]
        this.filePage.totalPage = data.data.total - 0
      } else {
        this.fileDataList = []
        this.filePage.totalPage = 0
      }
    },
    treeObj (o) {
      let obj = {};

      for (let key in o) {
        var val = o[key];
        // 排除为null的数据的干扰
        val = val === null ? '' : val
        obj[key] = typeof val === 'object' ? this.treeObj(val) : val;
      }
      //对象新增children键值，用于存放子树
      obj.children = [];
      return obj;
    },
    // 迭代将分类数据组成树形结构
    getTypeList (list, attributes) {
      let that = this
      let paramList = [...list]
      let topList = []
      for (let i = 0; i < paramList.length; i++) {
        if (paramList[i][attributes.parentId] === '' || paramList[i][attributes.parentId] === null) {
          topList.push(this.treeObj(paramList[i]))
          paramList.splice(i, 1);
          i--
        }
      }
      for(let i = 0; i < topList.length -1;i++){
        for(let j = 0;j < topList.length - i-1;j++){
          if(topList[j].dspOrder > topList[j+1].dspOrder){
            let arr = topList[j+1];
            topList[j+1] = topList[j];
            topList[j] = arr;
          }
        }
      }
      run(topList);
      //找寻子树
      function run (chiArr) {
        if (paramList.length !== 0) {
          for (let i = 0; i < chiArr.length; i++) {
            for (let j = 0; j < paramList.length; j++) {
              if (chiArr[i][attributes.id] === paramList[j][attributes.parentId]) {
                let obj = that.treeObj(paramList[j]);
                chiArr[i].children.push(obj);
                paramList.splice(j, 1);
                j--;
              }
            }
            run(chiArr[i].children);
          }
        }
      }
      topList.forEach(item => {
        for (let t in item) {
          if (t !== 'children' && typeof item[t] === 'object') {
            item[t] = ''
          }
        }
      })
      return topList;
    },
    // 数展开
    expandNode (data, node, item) {
      if (this.expandList.indexOf(data.id) === -1) {
        this.expandList.push(data.id)
      }
    },
    // 文件记录信息查询
    async recordDataSearch (fileNo, flag = true) {
      if (flag) {
        this.recordPage.pageIndex = 1
      }
      let param = {
        ...this.recordPage,
        object: {
          fileNo
        }
      }
      const data = await this.axios.post(`pass/baseManagement/v1/limsisofileds/queryLimsIsoFileDPage`, param, { individualType: 'json' })
      if (data.status == 'succeed') {
        this.recordDataList = [...data.data.list]
        this.recordPage.totalPage = data.data.total - 0
      } else {
        this.recordDataList = []
        this.recordPage.totalPage = 0
      }
    },
    expandCollapse (data, node, item) {
      let index = this.expandList.indexOf(data.id)
      if (index !== -1) {
        this.expandList.splice(index, 1)
      }
    },
    //  点击树事件
    nodeClick (item, el) {
      let that = this;
      //  点击时为编辑状态
      this.operateStatus = 'edit';
      // 记录点击节点id
      this.selectedNode = { ...item }
      // 查询该节点下方的子节点
      this.selectByClassNo = item.classNo
      this.fileDataSearchByClassNo()
    },
    // 查询某个节点下方子节点
    async getChildNode (classNo) {

    },
    // 显示文件信息新增窗口
    showFAddDialog () {
      // 如果没有选中的节点不允许新增文件信息
      if (!this.selectedNode.classNo || this.selectedNode.classNo - 0 === 0) {
        return this.$message.warning('请先选择要新增文件信息的文件分类')
      }
      this.fileDialogTitle = '新增文件信息'
      this.selectedData = { classNo: this.selectedNode.classNo, className: this.selectedNode.className }
      this.fileDialogVisible = true
    },
    // 显示文件信息编辑窗口
    showFEditDialog () {
      this.fileDialogTitle = '编辑文件信息'
      // 如果没有选中的数据不允许编辑文件信息
      if (!this.selectedData.fileNo || this.selectedData.fileNo - 0 === 0) {
        return this.$message.warning('请先选择要编辑的文件信息')
      }
      this.fileDialogVisible = true
    },
    // 删除文件信息
    async deleteFileData () {
      if (this.selectedFileList.length === 0) {
        return this.$message.warning('请先选择要删除的数据')
      }
      const res = await this.MessageBox.confirm('确认要删除这些选中的文件数据吗？').catch(() => 'cancel')
      if (res === 'cancel') return
      let ids = []
      this.selectedFileList.forEach(item => {
        ids.push(item.id)
      })
      const data = await this.axios.post(`pass/baseManagement/v1/limsisofiles/delete`, [...ids], { individualType: 'json' })
      if (data.status == 'succeed') {
        this.$message.success('删除成功')
        this.fileDataSearch()
      } else {
        this.$message.error(data.data)
      }
    },
    // 显示记录信息新增窗口
    showARecordDialog () {
      // 如果没有选中文件信息不允许新增记录信息
      if (!this.selectedData.id || this.selectedData.id - 0 === '') {
        return this.$message.warning('请先选择要新增记录信息的文件')
      }
      this.recordDialogTitle = '新增文件记录信息'
      this.recordData = { fileNo: this.selectedData.id}
      // this.recordData.fileName = this.selectedData.fileName
      this.recordDialogVisible = true
    },
    // 显示记录信息编辑窗口
    showERecordDialog () {
      this.recordDialogTitle = '编辑文件记录信息'
      if (JSON.stringify(this.recordData) === '{}') {
        return this.$message.warning('请先选择要进行编辑的记录信息')
      }
      this.recordDialogVisible = true
    },
    // 删除记录信息
    async deleteRecordData () {
      if (this.selectedRecordList.length === 0) {
        return this.$message.warning('请先选择要删除的数据')
      }
      const res = await this.MessageBox.confirm('确认要删除这些选中的文件记录数据吗？').catch(() => 'cancel')
      if (res === 'cancel') return
      let ids = []
      this.selectedRecordList.forEach(item => {
        ids.push(item.id)
      })
      const data = await this.axios.post(`pass/baseManagement/v1/limsisofileds/delete`, [...ids], { individualType: 'json' })
      if (data.status == 'succeed') {
        this.$message.success('删除成功')
        this.recordDataSearch(this.selectedData.fileNo)
      } else {
        this.$message.error(data.data)
      }
    },
    refresh() {
      this.fileDialogVisible = false
      this.fileDataSearch();
    },
    refresh1() {
      this.recordDialogVisible = false
      this.recordDataSearch(this.selectedData.fileNo);
    },
    // 关闭文件新增弹窗
    closeDialog (dialogFlag) {
      switch (dialogFlag) {
        case 'file':
          // 清空文件编辑弹窗选择数据
          // this.selectedData = {}
          this.selectedFileList = []
          this.$refs.fileTable.clearSelection()
          this.fileDialogVisible = false
          break;
        case 'record':
          // 清空文件编辑弹窗选择数据
          // this.recordData = {}
          this.selectedRecordList = []
          this.$refs.recordTable.clearSelection()
          this.recordDialogVisible = false
          break
      }
    },
    imgPreView(row,fileName){
      console.log(fileName)
      this.axios.get('pass/baseManagement/v1/file/download/' + fileName,{responseType: 'blob'},{headers: {'content-type': 'application/x-www-form-urlencoded'}}).then(res => {
        let blob = new Blob([res]);
        let elink = document.createElement('a');
        elink.download = fileName;
        elink.style.display = 'none';
        elink.target = "_blank";
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href); // 释放URL对象
        document.body.removeChild(elink);
      }).catch(e => {
        return this.$message.error(e.message)
      })
    },
    // 显示分类信息编辑窗口
    showTypeDialog (flag) {
      this.typeOperateFlag = flag
      if (flag === 'edit') {
        if (this.selectedNode.classNo - 0 === 0 || this.selectedNode.className - 0 === 0) {
          return this.$message.warning('请先选择要进行编辑的分类数据')
        }
        this.typeData = { ...this.selectedNode }
      } else {
        this.typeData.parentNo = this.selectedNode.classNo
        this.typeData.parentName = this.selectedNode.className
      }
      this.typeDialogVisible = true
    },
    // 删除分类信息
    async deleteTypeData () {
      if (this.selectedNode.classNo - 0 === 0 || this.selectedNode.className - 0 === 0) {
        return this.$message.warning('请先选择要进行删除的分类数据')
      }
      if (this.selectedNode.children.length !== 0) {
        return this.$message.warning('该文件分类存在下属分类，不允许删除')
      }
      const confirmResult = await this.MessageBox.confirm('确认要删除选择的文件分类数据吗？').catch(() => 'cancel')
      let ids = [this.selectedNode.id]
      if (confirmResult !== 'cancel') {
        const deleteResult = await this.axios.post('pass/baseManagement/v1/limsisoclasss/delete', ids, { individualType: 'json' })
        if (deleteResult.status == 'succeed') {
          this.$message.success('删除成功')
          this.searchTypeData()
        } else {
          this.$message.error(data.data)
        }
      }
    },
    // 关闭分类新增弹窗
    closeTypeDialog () {
      this.typeDialogVisible = false
      this.typeData = { ...this.typeDataCache }
      this.$refs.menuTree.setCurrentKey(null)
      this.selectedNode = { ...this.typeDataCache }
    },
    // 新增分类数据
    addTypeData () {
      this.$refs.typeData.validate(async valid => {
        if (!valid) {
          return this.$message.warning('请规范填写数据')
        }
        this.typeData.isoName = this.getCode(
            this.typeData.isoNo,
            this.qualityType,
            "isoNo",
            "isoName"
            );
        const data = await this.axios.post('pass/baseManagement/v1/limsisoclasss/insertupdate', { ...this.typeData }, { individualType: 'json' })
        if (data.status == 'succeed') {
          this.searchTypeData()
          this.$message.success('操作成功')
          this.typeDialogVisible = false
        } else {
          this.$message.error('操作异常请重试')
        }
      })
    },
    // 文件行点击
    fileRowChange (row) {
      if (row) {
        this.selectedData = { ...row }
        //点击选中
        // this.$refs.fileTable.toggleRowSelection(row, true);
        this.recordDataSearch(row.fileNo)
      }
    },
    // 文件行选中
    fileSelectChange (list) {
      this.selectedFileList = []
      list.forEach(item => {
        this.selectedFileList.push({ ...item })
      })
      if (list.length > 0) {
        this.$refs.fileTable.setCurrentRow(list[list.length - 1], true)
      }
    },
    // 记录行点击
    recordRowChange (row) {
      this.recordData = { ...row }
      // this.$refs.recordTable.toggleRowSelection(row, true);
    },
    // 记录行选中
    recordSelectChange (list) {
      this.selectedRecordList = []
      list.forEach(item => {
        this.selectedRecordList.push({ ...item })
      })
      if (list.length > 0) {
        this.$refs.recordTable.setCurrentRow(list[list.length - 1], true)
      }
    },
    handleContext (e, item) {
      // 唤起上下文菜单的对象
      if ((item.children && item.children.length > 0) || (item.sort_code === null && item.page_type === 'WEB')) {
        this.selectObj = item
        $('.contextmenu').css({
          left: e.pageX + 10 + 'px',
          top: e.pageY + 'px',
          display: 'block'
        })
        $('#setClick').click()
        e.preventDefault()
      }
    },
    // 上下文菜单命令选择
    handleCommand (command) {
      let that = this,
        str = command.str,
        node = command.node,
        data = command.data;
      this.selectedNode = { ...data }
      switch (str) {
        case 'add':
          that.showTypeDialog('add');
          break;
        case 'delete':
          that.deleteTypeData(node, data);
          break;
        case 'edit':
          that.showTypeDialog('edit');
          break;
      }
    },
    filePageSizeChange (size) {
      this.filePage.pageSize = size;
      this.fileDataSearch(this.selectedData.fileNo,false);
    },
    filePageCurrentChange (index) {
      this.filePage.pageIndex = index;
      this.fileDataSearch(this.selectedData.fileNo,false);
    },
    recordPageSizeChange (size) {
      this.recordPage.pageSize = size;
      this.recordDataSearch(this.selectedData.fileNo);
    },
    recordPageCurrentChange (index) {
      this.recordPage.pageIndex = index;
      this.recordDataSearch(this.selectedData.fileNo, false);
    }
  },
  computed: {
    //  选中节点数据
    menuItem () {
      return this.store.state.system.functionMain.item;
    }
  },
  components: {
    fileAlertComponents,
    recordAlertComponents
  }
}
</script>

<style>
.file_manage_wrap {
  padding: 5px 10px;
  height: inherit;
}

.header_wrap {
  padding: 5px 10px 0px 40px;
  border-bottom: 1px solid #efefef;
}

.main_container {
  padding: 12px 5px 0 10px;
  height: inherit;
}

.tree_wrap {
  padding-top: 15px;
}

.section_wrap .section_top {
  padding: 10px 5px;
}

.aside_wrap {
  padding: 10px 5px;
}

.custom-tree-node {
  -webkit-box-flex: 1;
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
  flex: 1 1 0%;
}

.type_dialog_wrap {
  width: 520px !important;
}

.file_manage_wrap .el-dialog__header {
  height: 56px;
  background: rgb(64, 158, 255);
  border-radius: 4px 4px 0 0;
  color: #fff;
  padding: 14px 24px !important;
}

.file_manage_wrap .el-dialog__footer {
  text-align: center;
}

.file_manage_wrap .el-icon-date {
  display: none;
}

.file_manage_wrap .el-input__inner {
  padding: 2px 7px !important;
}
</style>