<template>
  <div class="mod-config">
    <div>
        <span @click="favoriteFunction()">
         <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>
        </span>
    </div>
    <!-- 条件查询 -->
    <el-form :inline="true" label-position="top">
      <el-form-item :label="'设备编码:'">
        <el-input v-model="searchData.objectId" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'故障编码:'">
        <el-input v-model="searchData.defectId" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'故障原因:'">
        <el-input v-model="searchData.defectDesc" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'故障描述:'">
        <el-input v-model="searchData.defectDescribe" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'类型'">
        <el-select v-model="searchData.fileType" style="width: 120px">
          <el-option label="全部" value=""></el-option>
          <el-option label="点检" value="点检"></el-option>
          <el-option label="保养" value="保养"></el-option>
          <el-option label="维修" value="维修"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'上传日期：'">
        <el-date-picker style="width: 150px" v-model="searchData.startDate" type="datetime"
                        value-format='yyyy-MM-dd HH:mm' format='yyyy-MM-dd HH:mm' placeholder="开始日期">
        </el-date-picker>
        -
        <el-date-picker style="width: 150px" v-model="searchData.endDate" type="datetime"
                        value-format='yyyy-MM-dd HH:mm' format='yyyy-MM-dd HH:mm' placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" type="primary" @click="getDataList()">查询</el-button>
        <el-button v-if="!authSave" type="primary" @click="addModal()">新增</el-button>
        <el-button v-if="!authDelete" type="primary" @click="deleteSome()">删除</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <!-- 展示列表 -->
    <el-table
      :height="height"
      :data="dataList"
      ref="eamObjectTable"
      highlight-current-row
      @row-click="setCurrentRow"
      @current-change="changeCurrentRow"
      @selection-change="selectionChangeHandle"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        :selectable="selectFlag"
        width="50">
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="100"
        label="操作">
        <template slot-scope="scope">
          <a v-if="!authUpdate" type="text" size="small" @click="updateModal(scope.row)">编辑</a>
          <a v-if="!authDelete" type="text" size="small" @click="deleteModal(scope.row)">删除</a>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页栏 -->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 一级新增/编辑 -->
    <el-dialog title="设备知识库" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="321px">
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="objectId" :rules="rules.objectIdType">
          <span slot="label" style="" @click="getBaseList(200)"><a herf="#">设备编码</a></span>
          <el-input v-model="modalData.objectId" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="设备名称:" prop="objectName" :rules="rules.objectNameType">
          <el-input v-model="modalData.objectName" disabled style="width: 150px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
<!--        <el-form-item label="故障编码" prop="defectId" :rules="rules.defectIdType">-->
<!--          <el-select v-model="modalData.defectId" @change="defectIdChange()" placeholder="请选择" style="width: 120px">-->
<!--            <el-option-->
<!--              v-for = "i in defectList"-->
<!--              :key = "i.defectId"-->
<!--              :label = "i.defectId"-->
<!--              :value = "i.defectId">-->
<!--            </el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item prop="defectId" :rules="rules.defectIdType">
          <span slot="label" @click="getBaseList(1054)"><a herf="#">故障编码</a></span>
          <el-input v-model="modalData.defectId" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="故障原因:" prop="defectDesc" :rules="rules.defectDescType">
          <el-input v-model="modalData.defectDesc" disabled style="width: 150px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" :rules="rules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="类型" prop="fileType" :rules="rules.fileTypeType">
          <el-select v-model="modalData.fileType" placeholder="请选择" style="width: 120px">
            <el-option label="点检" value="点检"></el-option>
            <el-option label="保养" value="保养"></el-option>
            <el-option label="维修" value="维修"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="故障描述:">
          <el-input v-model="modalData.defectDescribe" style="width: 150px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="modalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="处置措施:">
          <el-input v-model="modalData.disposalMeasures" style="width: 284px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="备注:">
          <el-input
            type="textarea"
            v-model="modalData.remark"
            :rows="3"
            resize='none'
            maxlength="300"
            show-word-limit
            style="width: 284px;height: 60px">
          </el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 60px;text-align:center">
        <el-button type="primary" @click="saveData()">保存</el-button>
        <el-button type="primary" @click="modalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 二级列表 -->
    <el-tabs v-model="activeTable" style="margin-top: 0px; width: 100%; height: 100%;" type="border-card" @tab-click="tabClick" class="customer-tab">
      <!-- 文档 -->
      <el-tab-pane label="文档" name="file_content">
        <!--文件上传-->
        <el-form label-position="top" style="margin-top: 5px; margin-left: 0px;">
          <el-form :inline="true" label-position="top" style="margin-top: 5px">
            <el-button type="primary" @click="addUploadFileModal()">上传文件</el-button>
          </el-form>
        </el-form>
        <el-table
          :data="fileContentList"
          :height="secondHeight"
          border
          v-loading="dataListLoading"
          style="width: 100%; ">
          <el-table-column
            v-for="(item,index) in columnFileContentArray" :key="index"
            :sortable="item.columnSortable"
            :prop="item.columnProp"
            :header-align="item.headerAlign"
            :show-overflow-tooltip="item.showOverflowTooltip"
            :align="item.align"
            :fixed="item.fixed==''?false:item.fixed"
            :min-width="item.columnWidth"
            :label="item.columnLabel">
            <template slot-scope="scope">
              <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
              <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            header-align="center"
            align="center"
            width="100"
            label="操作">
            <template slot-scope="scope">
              <a @click="downloadFile(scope.row)">下载</a>
              <a type="text" size="small" @click="deleteFile(scope.row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <!-- 上传文件的modal   -->
    <comEamKnowledgeBaseUploadFile ref="comEamKnowledgeBaseUploadFile" @refreshPageTables="getDataList()" v-drag></comEamKnowledgeBaseUploadFile>
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>
  </div>
</template>

<script>
  import {
    getKnowledgeBaseList, // 查询知识库文件列表
    getDefectList, // 获取故障列表
    saveKnowledgeBase, // 新增知识库文件
    knowledgeBaseUpdate, // 修改知识库文件
    knowledgeBaseDelete, // 删除知识库文件
    knowledgeBaseDeleteSome, // 批量删除
    getFileContentList, // 刷新派设备文档的列表
    downLoadObjectFile
  } from '@/api/eam/eam_object_list.js';
  import { userFavoriteList, saveUserFavorite, removeUserFavorite } from '@/api/userFavorite.js'
  import { deleteObjectFile } from '@/api/eam/eam.js';
  import { deleteResourceSpare } from '@/api/partspare/resourcespare.js'
  /*引入組件*/
  import comEamKnowledgeBaseUploadFile from "./com_eam_knowledge_base_upload_file";/*上传文件的組件*/
  import {
    getTableDefaultListLanguage,
    getTableUserListLanguage,
  } from "@/api/table.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import axios from "axios";
  import Vue from "vue";
  export default {

    data () {
      return {
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "设备知识库" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["设备知识库"],
        exportFooter: [],
        exportList:[],
        // 导出 end
        tagNo:'',
        activeTable: 'file_content',
        folder: 'eamObject',
        eamObjectId: '',
        uploadUrl: "",
        currentRow: {},
        searchData: {
          site: this.$store.state.user.site,
          objectId: '',
          defectId: '',
          defectDesc: '',
          defectDescribe: '',
          fileType: '',
          startDate: '',
          endDate: '',
          page: 1,
          limit: 10
        },
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        height: 200,
        secondHeight: 200,
        dataList: [],
        fileContentList: [],
        columnFileContentArray: [
          {
            columnProp: 'fileName',
            headerAlign: "center",
            align: "left",
            columnLabel: '文件名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            columnProp: 'createdBy',
            headerAlign: "center",
            align: "left",
            columnLabel: '上传人',
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            columnProp: 'createDate',
            align: 'center',
            columnLabel: '上传时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
          {
            columnProp: 'orderRef3',
            headerAlign: "center",
            align: "left",
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: true,
            sortLv: 0,
            status: true,
            fixed: false
          },
        ],
        dataListLoading: false,
        modalFlag: false,
        modalDisableFlag: false,
        modalData: {
          flag: '',
          site: this.$store.state.user.site,
          createBy: '',
          updateBy: '',
          num: '',
          objectId: '',
          objectName: '',
          fileType: '',
          defectId: '',
          defectDesc: '',
          defectDescribe: '',
          disposalMeasures: '',
          fileId: '',
          fileName: '',
          remark: '',
        },
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1Num',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'num',
            headerAlign: "center",
            align: 'center',
            columnLabel: '编号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1FileType',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'fileType',
            align: 'center',
            columnLabel: '类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1ObjectId',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'objectId',
            headerAlign: "center",
            align: "center",
            columnLabel: '设备编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1ObjectName',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'objectName',
            headerAlign: "center",
            align: "left",
            columnLabel: '设备名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1DefectId',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'defectId',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1DefectDesc',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'defectDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '故障原因',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1DefectDescribe',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'defectDescribe',
            headerAlign: "center",
            align: "left",
            columnLabel: '故障描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1DisposalMeasures',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'disposalMeasures',
            headerAlign: "center",
            align: "left",
            columnLabel: '处置措施',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1OrderNo',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'orderNo',
            align: 'center',
            columnLabel: '单据号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1Remark',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'remark',
            headerAlign: "center",
            align: "left",
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1CreateDate',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'createDate',
            align: 'center',
            columnLabel: '上传时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 170,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1CreateBy',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'createBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '上传人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1UpdateDate',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'updateDate',
            align: 'center',
            columnLabel: '更新时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 170,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101001011,
            serialNumber: '101001011Table1UpdateBy',
            tableId: "101001011Table1",
            tableName: "设备知识库表",
            columnProp: 'updateBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '更新人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
        ],
        defectList: [],
        dataListSelections: [],
        rules:{
          objectIdType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          objectNameType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          defectIdType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          defectDescType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ],
          fileTypeType:[
            {
              required: true,
              message: ' ',
              trigger: ['blur','change']
            }
          ]
        },
        authSearch: false,
        authSave: false,
        authUpdate: false,
        authDelete: false,
        menuId: this.$route.meta.menuId,
      }
    },
    components: {
      comEamKnowledgeBaseUploadFile,/*文件上传的组件*/
      Chooselist,
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight / 2 - 30;
        /*第二个表格高度的动态调整*/
        this.secondHeight = window.innerHeight / 2  - 190;
      })
    },
    created () {
      // 按钮控制
      this.getButtonAuthData()
      this.favoriteIsOk()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      if (!this.authSearch) {
        // 获取数据列表
        this.getDataList()
      }
    },
    methods: {
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      selectFlag(){
        return true;
      },
      // 故障ID改变事件
      defectIdChange(){
        for (let i = 0; i < this.defectList.length; i++) {
          if (this.defectList[i].defectId = this.modalData.defectId){
            this.modalData.defectDesc = this.defectList[i].defectDesc
          }
        }
      },
      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 200) {
            strVal = this.modalData.objectId
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1054) {
            strVal = this.modalData.defectId
            this.$refs.baseList.init(val, strVal)
          }
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 200) {
          this.modalData.objectId = val.ObjectID
          this.modalData.objectName = val.ObjectDesc
          // this.defectList = []
          // this.modalData.defectId = ''
          // this.modalData.defectDesc = ''
          // this.getDefectList()
        }
        if (this.tagNo === 1054) {
          this.modalData.defectId = val.DefectID
          this.modalData.defectDesc = val.DefectDesc
        }
      },
      // 获取故障列表
      getDefectList(){
        getDefectList(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.defectList = data.rows
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      // 获取数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        getKnowledgeBaseList(this.searchData).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            //判断是否全部存在数据
            if(this.totalPage > 0){
              //设置选中行
              this.$refs.eamObjectTable.setCurrentRow(this.dataList[0]);
              this.refreshCurrentTabTable();//加载当前的页签的table
            }
          }
          this.dataListLoading = false;
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 一级新增
      addModal(){
        this.modalData = {
          flag: '1',
          site: this.$store.state.user.site,
          createBy: this.$store.state.user.name,
          num: '',
          objectId: '',
          objectName: '',
          fileType: '',
          defectId: '',
          defectDesc: '',
          defectDescribe: '',
          disposalMeasures: '',
          fileId: '',
          fileName: '',
          remark: '',
        };
        this.modalDisableFlag = false;
        this.modalFlag = true;
      },
      // 一级修改
      updateModal(row){
        this.modalData = {
          flag:'2',
          site: this.$store.state.user.site,
          updateBy: this.$store.state.user.name,
          num: row.num,
          objectId: row.objectId,
          objectName: row.objectName,
          fileType: row.fileType,
          defectId: row.defectId,
          defectDesc: row.defectDesc,
          defectDescribe: row.defectDescribe,
          disposalMeasures: row.disposalMeasures,
          fileId: row.fileId,
          fileName: row.fileName,
          remark: row.remark
        };
        this.modalDisableFlag = true;
        this.modalFlag = true;
      },
      // 新增/修改设备知识库
      saveData(){
        if (this.modalData.objectId === '' || this.modalData.objectId == null) {
          this.$alert('请选择设备编码！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.objectName === '' || this.modalData.objectName == null) {
          this.$alert('请选择设备名称！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.defectId === '' || this.modalData.defectId == null) {
          this.$alert('请选择故障编码！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.fileType === '' || this.modalData.fileType == null) {
          this.$alert('请选择类型！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.modalData.flag === '1'){
          saveKnowledgeBase(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.defectList = []
              this.modalFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }else {
          knowledgeBaseUpdate(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.modalFlag = false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },
      // 一级删除
      deleteModal(row) {
        this.$confirm('确定要删除该内容?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          knowledgeBaseDelete(row).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.getFileContentData();
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      // 二级删除
      deleteFile(row){
        this.$confirm('确定要删除此文件?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteObjectFile(row).then(({data}) => {
            if (data && data.code === 0) {
              this.getFileContentData();
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      // 批量删除
      deleteSome() {
        if(this.dataListSelections.length === 0){
          this.$alert('请勾选要删除的内容！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        this.$confirm('确定要删除所选内容?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          knowledgeBaseDeleteSome(this.dataListSelections).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.getFileContentData();
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      // 刷新页签的table数据
      refreshCurrentTabTable () {
        this.getFileContentData();
      },
      // 刷新派设备文档的列表
      getFileContentData() {
        let currentData = {
          orderRef1: this.$store.state.user.site,
          orderRef2: this.currentRow.num
        }
        getFileContentList(currentData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code == 200) {
            this.fileContentList = data.rows;
          } else {
            this.fileContentList = [];
          }
        });
      },

      // 列表表格选择替换
      tabClick (tab, event) {
        // 刷新列表数据
        this.refreshCurrentTabTable()
      },

      // 上传文件
      addUploadFileModal(){
        let currentData = {
          site: this.$store.state.user.site,
          createBy: this.$store.state.user.name,
          num: this.currentRow.num,
          objectId: this.currentRow.objectId,
          objectName: this.currentRow.objectName,
          defectId: this.currentRow.defectId,
          defectDesc: this.currentRow.defectDesc,
        }
        //打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.comEamKnowledgeBaseUploadFile.init(currentData)
        })
      },

      // 设置当前的行
      setCurrentRow(row, column, event) {
        this.currentRow = JSON.parse(JSON.stringify(row))
      },
      // 当前值发生变化的时候修改
      changeCurrentRow(row, oldRow){
        // 判断是否是获取焦点的事件
        if(row){
          this.currentRow = JSON.parse(JSON.stringify(row));
          this.eamObjectId = row.objectId;
          this.uploadUrl = this.$http.adornUrl(`/api/sys/file/upload?token=${this.$cookie.get('token')}&folder=` + this.folder + `&objectId=` + this.eamObjectId);
          //刷新当前页表
          this.refreshCurrentTabTable();
        }
      },

      // 校验用户是否收藏
      favoriteIsOk() {
        let userFavorite = {
          userId: this.$store.state.user.id,
          languageCode: this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) => {
          for (let i = 0; i < data.list.length; i++) {
            // let flag=false;
            if(this.$route.meta.menuId==data.list[i].menuId){
              this.favorite = true
              // flag=true;
            }
          }
        })
      },
      // 收藏 OR 取消收藏
      favoriteFunction() {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          removeUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = false
          })
        } else {
          // 收藏
          saveUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = true
          })
        }
      },
      //导出excel
      async createExportData() {
        this.searchData.limit = -1
        this.searchData.page = 1
        await getKnowledgeBaseList(this.searchData).then(({data}) => {
          this.exportList= data.page.list;
        })
        return this.exportList;
      },
      downloadFile(row){
        downLoadObjectFile(row)
          .then(({data}) => {
          // 不限制文件下载类型
          const blob = new Blob([data], {type: "application/octet-stream"})
          // 下载文件名称
          const fileName = row.fileName
          // a标签下载
          const linkNode = document.createElement('a')
          linkNode.download = fileName // a标签的download属性规定下载文件的名称
          linkNode.style.display = 'none'
          linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
          document.body.appendChild(linkNode)
          linkNode.click() // 模拟在按钮上的一次鼠标单击
          console.log(linkNode)
          URL.revokeObjectURL(linkNode.href) // 释放URL 对象
          document.body.removeChild(linkNode)
        })
      },
      startDownload() {
      },
      finishDownload() {
      },
      fields() {
        let json = "{"
        this.columnList.forEach((item, index) => {
          if (index == this.columnList.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")
        return s
      },

      // 动态列开始 获取 用户保存的 格式列
      async getTableUserColumn (tableId, columnId) {
        let queryTableUser = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          status: true,
          languageCode: this.$i18n.locale
        }
        await getTableUserListLanguage(queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList1 = []
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.detailColumnList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }

          } else {
            this.getColumnList(tableId, columnId)
          }
        })
      },

      // 获取 tableDefault 列
      async getColumnList (tableId, columnId) {
        let queryTable= {
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          languageCode: this.$i18n.locale
        }
        await getTableDefaultListLanguage(queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.detailColumnList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            // this.showDefault = true.
          }
        })
      },

      //获取按钮的权限数据
      getButtonAuthData () {
        let searchFlag = this.isAuth(this.menuId+":search")
        let saveFlag = this.isAuth(this.menuId+":save")
        let updateFlag = this.isAuth(this.menuId+":update")
        let deleteFlag = this.isAuth(this.menuId+":delete")
        //处理页面的权限数据
        this.authSearch = !searchFlag
        this.authSave = !saveFlag
        this.authUpdate = !updateFlag
        this.authDelete = !deleteFlag
      },
    }
  }
</script>

<style scoped lang="scss">
/deep/ .customer-tab .el-tabs__content {
padding: 0px !important;
}

/*修改上传图标的样式*/
.el-upload-dragger .el-icon-upload {
  font-size: 36px;
  color: #c0c4cc;
  margin: 10px 10px;
  line-height: 20px;
}

/*修改上传框的样式*/
/deep/ .customer-upload .el-upload-dragger {
  background-color: #fff;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  margin-left: 10px;
  width: 240px;
  height: 42px;
  text-align: left;
  position: relative;
  overflow: hidden;
}

/*修改上传文字的样式*/
.customer-upload .el-upload__text{
  margin-top: -32px;
  margin-left: 40px;

}

.el-table /deep/ .cell{
  height: auto;
  line-height: 1.5;
}
</style>
