<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" :model="searchData">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buDesc" placeholder="请选择" clearable style="width: 80px">
          <el-option
            v-for="i in userBuList"
            :key="i.buNo"
            :label="i.buDesc"
            :value="i.buDesc">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'报修方式'">
        <el-select v-model="searchData.repairReportingType" placeholder="请选择" clearable style="width: 100px">
          <el-option label="设备故障" value="设备故障"></el-option>
          <el-option label="TPM红牌" value="TPM红牌"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'紧急程度'">
        <el-select v-model="searchData.urgency" placeholder="请选择" clearable style="width: 80px">
          <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-select v-model="searchData.result" placeholder="请选择" clearable style="width: 100px">
          <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="searchData.planID" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'工单编码'">
        <el-input v-model="searchData.orderNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'设备编码'">
        <el-input v-model="searchData.objectID" clearable style="width: 100px"></el-input>
      </el-form-item>
      <el-form-item :label="'人员部门'">
        <el-input v-model="searchData.departmentName" readonly style="width: 200px"></el-input>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" :model="searchData">
      <el-form-item :label="'状态'">
        <el-select v-model="searchData.status" clearable style="width: 100px">
          <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-option label="已完工" value="已完工"></el-option>
          <el-option label="已取消" value="已取消"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'单据来源'">
        <el-select v-model="searchData.documentSource" clearable style="width: 100px">
          <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: 120px"
          v-model="searchData.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item style="margin-top: 23px;">
        <laber style="margin-left: -9px;font-size: 19px">&#10142</laber>
      </el-form-item>
      <el-form-item :label="' '">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button v-if="!authSearch" @click="getDataList()">查询</el-button>
        <el-button v-if="!authCheck" @click="checkModals()">批量审核</el-button>
        <el-button v-if="!authChange" type="primary" @click="changeModel()">更改执行人员</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"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      :row-style="controlRowStyle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="urgency"
        header-align="center"
        align="center"
        label="紧急程度"
        width="70">
        <template slot-scope="scope">
          <div
            :style="{fontWeight:'bold', color: scope.row.urgency === '特急' ? 'red' : scope.row.urgency === '紧急' ? '#ffa500e0' : scope.row.urgency === '一般' ? '#47B0FF' : ''}">
            {{ scope.row.urgency }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="result"
        header-align="center"
        align="center"
        label="维修结论"
        width="80">
        <template slot-scope="scope">
          <div
            :style="{fontWeight:'bold', color: scope.row.result === '维修失败' ? 'red' : scope.row.result === '维修完成' ? '#3ac252' : ''}">
            {{ scope.row.result }}
          </div>
        </template>
      </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 type="text" size="small" v-if="scope.row.status === '待审核'" @click="checkModal(scope.row)">审核</a>-->
          <el-link style="cursor: pointer" v-if="(scope.row.status === '待审核' || scope.row.status === '已完工') && !authDetail" @click="reportModal(scope.row)">详情</el-link>
          <el-link style="cursor: pointer" v-if="scope.row.status === '待确认' && !authDetail" @click="confirmResult(scope.row)">确认</el-link>
          <el-link style="cursor: pointer" v-if="scope.row.status === '未开工' && !authCancel" @click="cancelOrder(scope.row)">取消工单</el-link>
        </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="changeModelFlag" width="300px">
      <el-form :inline="true" label-position="top">
        <el-form-item style="margin-left: 10px">
          <span style="cursor: pointer" slot="label" @click="getBaseList(201)"><a>计划执行人员</a></span>
          <el-input v-model="planOperator" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'人员名称'">
          <el-input v-model="planOperatorName" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="changeOrderOperator()">保存</el-button>
        <el-button type="primary" @click="changeModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="审核" :close-on-click-modal="false" v-drag :visible.sync="submitModelFlag" width="375px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="'难度等级'">
          <el-select filterable v-model="submitData.difficultyLevel" style="width: 130px" placeholder="请评估难度等级">
            <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="submitData.difficultyRemark" style="width: 200px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="submitModel()">确定</el-button>
        <el-button type="primary" @click="submitModelFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog top="12vh" :close-on-click-modal="false" v-drag :visible.sync="detailModelFlag" width="1000px">
      <template v-slot:title>
        <div style="padding-top: 5px;padding-left: 15px">
          <span :style="{ fontSize: '15px', fontWeight: 'bold' }">维修工单</span>
          <span :style="{
          marginTop: '-5px',
          marginLeft: '5px',
          fontSize: '15px',
          verticalAlign: 'middle',
          display: 'inline-block',
          width: '17px',
          height: '17px',
          borderRadius: '50%',
          background: detailData.urgency === '特急' ? 'red' : detailData.urgency === '紧急' ? '#ffa500e0' : detailData.urgency === '一般' ? '#47B0FF' : ''}">
        </span>
        </div>
      </template>
      <div style="margin-left: 70px">
        <el-form :inline="true" label-position="top" style="margin-top: 10px">
          <el-form-item label="工单号">
            <el-input v-model="detailData.orderNo" disabled style="width: 100px"></el-input>
          </el-form-item>
          <el-form-item label="计划执行人员" style="margin-left: 30px">
            <el-input v-model="detailData.planOperatorName" disabled style="width: 100px"></el-input>
          </el-form-item>
          <el-form-item label="计划执行日期" style="margin-left: 30px">
            <el-date-picker style="width: 100px" v-model="detailData.planDate" type="datetime" disabled value-format='yyyy-MM-dd' format='yyyy-MM-dd'></el-date-picker>
          </el-form-item>
          <el-form-item label="设备编码" style="margin-left: 30px">
            <el-input v-model="detailData.objectID" disabled style="width: 100px"></el-input>
          </el-form-item>
          <el-form-item label="设备名称" style="margin-left: 30px">
            <el-input v-model="detailData.objectDesc" disabled style="width: 150px"></el-input>
          </el-form-item>
          <el-form-item label="机台" style="margin-left: 30px">
            <el-input v-model="detailData.resourceDesc" disabled style="width: 100px"></el-input>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top">
          <el-form-item label="报修人">
            <el-input v-model="detailData.createBy" disabled style="width: 100px"></el-input>
          </el-form-item>
          <el-form-item label="报修时间" style="margin-left: 30px">
            <el-input v-model="detailData.createdDate" disabled style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item label="响应人">
            <el-input v-model="detailData.reachOperatorName" disabled style="width: 100px"></el-input>
          </el-form-item>
          <el-form-item label="响应时间" style="margin-left: 30px">
            <el-date-picker :disabled="detailData.status === '已完工'" style="width: 170px" v-model="detailData.reachDate" type="datetime" value-format='yyyy-MM-dd HH:mm:ss' format='yyyy-MM-dd HH:mm:ss'></el-date-picker>
          </el-form-item>
          <el-form-item label="响应时长(m)" style="margin-left: 30px">
            <el-input-number :controls="false" :step="0" :min="0" :disabled="detailData.status === '已完工'" v-model="detailData.responseTime" style="width: 80px"></el-input-number>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-position="top">
          <el-form-item label="维修结果">
            <el-input v-model="detailData.result" disabled style="width: 100px"></el-input>
          </el-form-item>
          <el-form-item label="处置措施" style="margin-left: 30px">
            <el-input v-model="detailData.disposalMeasures" disabled style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item label="是否停机保修">
            <el-input v-model="detailData.shutdownWarranty" disabled style="width: 100px"></el-input>
          </el-form-item>
          <el-form-item label="实际执行时间" style="margin-left: 30px">
            <el-date-picker :disabled="detailData.status === '已完工'" style="width: 170px" v-model="detailData.actualDate" type="datetime" value-format='yyyy-MM-dd HH:mm:ss' format='yyyy-MM-dd HH:mm:ss'></el-date-picker>
          </el-form-item>
          <el-form-item label="工作时长(m)" style="margin-left: 30px">
            <el-input-number :controls="false" :step="0" :min="0" v-model="detailData.workTime" :disabled="detailData.status === '已完工'" style="width: 80px"></el-input-number>
          </el-form-item>
        </el-form>
        <el-form :inline="true" :model="detailData" label-position="top">
          <el-form-item label="报修反馈描述">
            <el-input type="textarea" disabled v-model="detailData.feedBackDesc" :rows="3" resize='none' show-word-limit style="width: 900px"></el-input>
          </el-form-item>
        </el-form>
        <el-tabs v-model="activeTable" style="margin-top: 55px; width: 99%; height: 100%;" @tab-click="tabClick" class="customer-tab">
          <el-tab-pane label="维修单" name="inspection_form" style="height: 320px">
            <el-form :inline="true" label-position="top" style="margin-top: 5px">
              <el-form-item label="故障编码">
                <el-input v-model="detailData.defectID" disabled style="width: 100px"></el-input>
              </el-form-item>
              <el-form-item label="故障名称" style="margin-left: -10px">
                <el-input v-model="detailData.defectDesc" disabled style="width: 200px"></el-input>
              </el-form-item>
              <el-form-item label="实际维修人员">
                <el-input v-model="detailData.actualOperatorName" disabled style="width: 200px"></el-input>
              </el-form-item>
              <el-form-item :label="' '" style="margin-left: 20px">
                <el-checkbox v-model="detailData.knowledgeFlag" true-label="Y">维修记录移至知识库</el-checkbox>
                <el-button v-if="detailData.status === '已完工'" type="primary" @click="checkModal()" style="margin-left: 10px">取消审核</el-button>
                <el-button v-else type="primary" @click="checkModal()" style="margin-left: 10px">审核</el-button>
              </el-form-item>
<!--              <el-form-item :label="' '">-->
<!--                <el-button type="primary" @click="coreComponentModal">核心备件</el-button>-->
<!--              </el-form-item>-->
            </el-form>
            <el-form :inline="true" label-position="top" style="margin-top: 0px">
              <el-form-item label="故障原因">
                <el-input :readonly="detailData.status === '已完工'" type="textarea" v-model="detailData.faultReason" :rows="3" resize='none' show-word-limit style="width: 431px"></el-input>
              </el-form-item>
              <el-form-item label="处理方式">
                <el-input :readonly="detailData.status === '已完工'" type="textarea" v-model="detailData.handlingMethod" :rows="3" resize='none' show-word-limit style="width: 431px"></el-input></el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" style="margin-top: 45px">
              <el-form-item label="预防措施">
                <el-input :readonly="detailData.status === '已完工'" type="textarea" v-model="detailData.preventiveMeasure" :rows="3" resize='none' show-word-limit style="width: 431px"></el-input>
              </el-form-item>
              <el-form-item label="备注说明">
                <el-input :readonly="detailData.status === '已完工'" type="textarea" v-model="detailData.remark" :rows="3" resize='none' show-word-limit style="width: 431px"></el-input>
              </el-form-item>
            </el-form>
            <el-form :inline="true" label-position="top" style="margin-top: 45px">
              <el-form-item label="车间评估结论">
                <el-select v-model="detailData.confirmAssessment" disabled style="width: 100px;margin-top: 20px">
                  <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-input readonly type="textarea" v-model="detailData.confirmRemark" :rows="3" resize='none' show-word-limit style="width: 318px"></el-input>
              </el-form-item>
              <el-form-item label="维修评估结论">
                <el-select v-model="detailData.checkAssessment" :disabled="detailData.status === '已完工'" style="width: 100px;margin-top: 20px">
                  <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-input :readonly="detailData.status === '已完工'" type="textarea" v-model="detailData.checkNotes" :rows="3" resize='none' show-word-limit style="width: 318px"></el-input>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane label="故障图片" name="feed_back_img">
            <div class="rq ">
              <el-table
                :height="325"
                :data="feedBackImages"
                border
                style="width: 100%;">
                <el-table-column
                  v-for="(item,index) in columnFeedBackImages" :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="120"
                  label="操作">
                  <template slot-scope="scope">
                    <el-link style="cursor:pointer" @click="previewFile(scope.row)">预览</el-link>
                    <el-link style="cursor:pointer" @click="downloadFile(scope.row)">下载</el-link>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <el-tab-pane label="备件图片" name="spar_part_img">
            <div class="rq ">
              <el-table
                :height="325"
                :data="sparPartImages"
                border
                style="width: 100%;">
                <el-table-column
                  v-for="(item,index) in columnSparPartImages" :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="120"
                  label="操作">
                  <template slot-scope="scope">
                    <el-link style="cursor:pointer" @click="previewFile(scope.row)">预览</el-link>
                    <el-link style="cursor:pointer" @click="downloadFile(scope.row)">下载</el-link>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </el-tab-pane>
          <el-tab-pane label="备品备件清单" name="part_spare_list">
            <div class="rq ">
              <el-table
                :height="325"
                :data="partSpareList"
                border
                style="width: 100%;">
                <el-table-column
                  v-for="(item,index) in columnPartSpareList" :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>
            </div>
          </el-tab-pane>
          <el-tab-pane label="维修记录" name="history_record">
            <div class="rq ">
              <el-table
                :height="295"
                :data="historyRecordList"
                border
                style="width: 100%;">
                <el-table-column
                  v-for="(item,index) in columnHistoryList" :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="120"
                  label="图片">
                  <template slot-scope="scope">
                    <el-button type="primary" @click="checkFaultImageModal(scope.row)">故障</el-button>
                    <el-button type="primary" @click="checkSparPartImageModal(scope.row)">备件</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!-- 分页插件 -->
              <el-pagination
                style="margin-top: 0px"
                @size-change="sizeChangeHandle2"
                @current-change="currentChangeHandle2"
                :current-page="pageIndex2"
                :page-sizes="[20, 50, 100, 200, 500]"
                :page-size="pageSize2"
                :total="totalPage2"
                layout="total, sizes, prev, pager, next, jumper">
              </el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="核心备件" name="core_component">
            <div class="rq ">
              <el-table
                :height="280"
                :data="corePartSpareList"
                border
                style="width: 100%;">
                <el-table-column
                  v-for="(item,index) in columnCoreComponent" :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>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button style="margin-left: -12px" type="primary" @click="updateResult()">保存</el-button>
        <el-button type="primary" @click="detailModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="核心备件" :close-on-click-modal="false" v-drag :visible.sync="coreComponentFlag" width="450px">
      <el-form :inline="true" label-position="top">
        <el-form-item label="备件编码">
          <el-select v-model="coreComponentData.partNo" placeholder="请选择" style="width: 120px">
            <el-option
              v-for = "i in corePartSpareList"
              :key = "i.partNo"
              :label = "i.partNo"
              :value = "i.partNo">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备件名称">
          <el-input v-model="coreComponentData.partDescription" disabled style="width: 280px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="老序列号">
          <el-input v-model="coreComponentData.oldSerialNo" disabled style="width: 200px"></el-input>
        </el-form-item>
        <el-form-item label="新序列号">
          <el-input v-model="coreComponentData.newSerialNo" disabled style="width: 200px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="coreComponentFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 部门 -->
    <el-dialog title="部门清单" :close-on-click-modal="false" v-drag :visible.sync="departmentModelFlag" width="520px">
      <div class="rq">
        <el-form :inline="true" label-position="top" :model="departmentData">
          <el-form-item :label="'部门编码'">
            <el-input v-model="departmentData.deptId" style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'部门名称'">
            <el-input v-model="departmentData.deptName" style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="getDepartmentList()">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :height="300"
          :data="departmentList"
          ref="departmentTable"
          @row-click="departmentClickRow"
          @selection-change="selectionDepartment"
          :row-key="getRowKeys"
          border
          v-loading="dataListLoading"
          style="width: 100%;">
          <el-table-column
            type="selection"
            header-align="center"
            align="center"
            :reserve-selection="true"
            width="50">
          </el-table-column>
          <el-table-column
            v-for="(item,index) in departmentDetailList" :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>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="confirmDepartment()">确认</el-button>
        <el-button type="primary" @click="departmentModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="图片查看" :close-on-click-modal="false" v-drag :visible.sync="imageModalFlag" width="390px" style="height: 550px;">
      <div v-viewer>
        <img v-for="(item, index) in descImages" :src="item" :key="index" style="width: 100px;height: 100px"/>
      </div>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="imageModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="维修确认" top="22vh" :close-on-click-modal="false" v-drag :visible.sync="confirmDefectModal" width="320px">
      <el-form :inline="true" label-position="top">
        <el-form-item :label="'确认结果'">
          <el-select v-model="confirmData.confirmResult" style="width: 135px">
            <el-option label="成功" value="Y"></el-option>
            <el-option label="失败" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="'维修评估'">
          <el-select v-model="confirmData.confirmAssessment" style="width: 135px">
            <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>
      <el-form :inline="true" label-position="top">
        <el-form-item :label="'生产维修评估说明'">
          <el-input type="textarea" v-model="confirmData.confirmRemark" :rows="3" resize='none' show-word-limit style="width: 285px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:30px;margin-top: 50px;text-align:center">
        <el-button style="margin-left: -12px" type="primary" @click="confirmDefectOrder()">保存</el-button>
        <el-button type="primary" @click="confirmDefectModal = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="批量审核" top="25vh" :close-on-click-modal="false" v-drag :visible.sync="submitModelsFlag" width="340px">
      <el-form :inline="true" label-position="top">
        <el-form-item label="难度等级">
          <el-select filterable v-model="submitData.difficultyLevel" style="width: 130px" placeholder="请评估难度等级">
            <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=" " style="margin-left: 20px">
          <el-checkbox v-model="knowledgeFlag" true-label="Y">维修记录移至知识库</el-checkbox>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top">
        <el-form-item label="备注">
          <el-input v-model="submitData.difficultyRemark" style="width: 300px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="submitModels()">确定</el-button>
        <el-button type="primary" @click="submitModelsFlag = false">取消</el-button>
      </el-footer>
    </el-dialog>

    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>

  </div>
</template>

<script>
import {
  eamWorkOrderSearchForDefect,
  cancelOrder,
  changeOrderOperator,
  submitDefect,
  searchFileUrl,
  getEmpyDeptList,
  getDeptList,
  updateReportResult, // 修改执行结果
  getSiteAndBuByUserName,
  confirmDefectOrder, // 维修确认
  submitDefects, // 批量审核
  getFeedBackImages, // 获取故障图片
  queryHistoryRecord, // 查看维修历史
  getSparPartImages, // 获取备件图片
} from "@/api/eam/eam.js"
import {
  downLoadObjectFile,
  getDeviceCorePartList,
  getDevicePartList,
  getKnowledgeBaseList,
  getFileContentList
} from '@/api/eam/eam_object_list.js';
import {
  getTableDefaultListLanguage,
  getTableUserListLanguage,
} from "@/api/table.js"
import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
import Chooselist from '@/views/modules/common/Chooselist_eam'
import {isAuth} from '../../../utils'

export default {
  components: {
    Chooselist
  },
  watch: {
    searchData: {
      deep: true,
      handler: function (newV, oldV) {
        this.searchData.groupID = this.searchData.groupID.toUpperCase()
      }
    },
    "detailData.actualDate"(newV, oldV) {
      this.detailData.workTime = Math.ceil(Math.floor(this.dayjs(this.detailData.actualDate).diff(this.detailData.reachDate, 'seconds') / 30) / 2)
    },
    "detailData.reachDate"(newV, oldV) {
      this.detailData.workTime = Math.ceil(Math.floor(this.dayjs(this.detailData.actualDate).diff(this.detailData.reachDate, 'seconds') / 30) / 2)
      this.detailData.responseTime = Math.ceil(Math.floor(this.dayjs(this.detailData.reachDate).diff(this.detailData.createDate, 'seconds') / 30) / 2)
    }
  },
  data() {
    return {
      // 是否收藏
      favorite: false,
      // 导出 start
      exportData: [],
      exportName: "维修工单" + this.dayjs().format('YYYYMMDDHHmmss'),
      exportHeader: ["维修工单"],
      exportFooter: [],
      exportList: [],
      // 导出 end
      tagNo: '',
      coreComponentData: {
        site: '',
        orderNo: '',
        buNo: '',
        objectID: '',
        partNo: '',
        partDescription: '',
        createdBy: '',
        oldSerialNo: '',
        newSerialNo: '',
      },
      coreComponentFlag: false,
      searchData: {
        site: '',
        userName: this.$store.state.user.name,
        orderNo: '',
        planID: '',
        objectID: '',
        planOperator: '',
        planOperatorName: '',
        functionType: 'C',
        status: '',
        startDate: '',
        endDate: '',
        departmentName: '',
        documentSource: '',
        page: 1,
        limit: 10,
        urgency: '',
        result: '',
        repairReportingType: '',
        repairType: '换线专家组'
      },
      height: 200,
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      pageIndex2: 1,
      pageSize2: 20,
      totalPage2: 0,
      dataList: [],
      dataListLoading: false,
      dataListSelections: [],
      modalFlag: false,
      modalDisableFlag: false,
      departmentList: [],
      // 展示列集
      columnList: [
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1BuDesc',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'buDesc',
          headerAlign: "center",
          align: "center",
          columnLabel: 'BU',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1DisposalMeasures',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'disposalMeasures',
          headerAlign: "center",
          align: "center",
          columnLabel: '处置措施',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1OrderNo',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'orderNo',
          headerAlign: "center",
          align: "left",
          columnLabel: '工单编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1PlanID',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'planID',
          headerAlign: "center",
          align: "left",
          columnLabel: '反馈单号',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1FeedBackDesc',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'feedBackDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '反馈描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1DefectID',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'defectID',
          headerAlign: "center",
          align: "left",
          columnLabel: '故障编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1DefectDesc',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'defectDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '故障名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1ObjectID',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'objectID',
          headerAlign: "center",
          align: "left",
          columnLabel: '设备编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1ObjectDesc',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'objectDesc',
          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: 101004002,
          serialNumber: '101004002Table1ResourceDesc',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'resourceDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '机台名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1DepartmentName',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'departmentName',
          headerAlign: "center",
          align: "left",
          columnLabel: '设备部门',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1CreateBy',
          tableId: "101004002Table1",
          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: 101004002,
          serialNumber: '101004002Table1Status',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'status',
          headerAlign: "center",
          align: "center",
          columnLabel: '状态',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1PlanOperatorName',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'planOperatorName',
          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: 101004002,
          serialNumber: '101004002Table1ActualOperatorName',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'actualOperatorName',
          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: 101004002,
          serialNumber: '101004002Table1PlanDate',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'planDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '计划执行日期',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 100,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1CreatedDate',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'createdDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '故障时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1ReachDate',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'reachDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '到达时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1ActualDate',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'actualDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '实际执行时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: true,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 140,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1ResponseTime',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'responseTime',
          headerAlign: "center",
          align: "right",
          columnLabel: '维修响应时长(m)',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 110,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1WorkTime',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'workTime',
          headerAlign: "center",
          align: "right",
          columnLabel: '工作时长(m)',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1DifficultyLevel',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'difficultyLevel',
          headerAlign: "center",
          align: "center",
          columnLabel: '难度等级',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 80,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1DifficultyRemark',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'difficultyRemark',
          headerAlign: "center",
          align: "left",
          columnLabel: '难度备注',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 120,
        },
        {
          userId: this.$store.state.user.name,
          functionId: 101004002,
          serialNumber: '101004002Table1DocumentSource',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'documentSource',
          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: 101004002,
          serialNumber: '101004002Table1FaultReason',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'faultReason',
          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: 101004002,
          serialNumber: '101004002Table1HandlingMethod',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'handlingMethod',
          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: 101004002,
          serialNumber: '101004002Table1PreventiveMeasure',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'preventiveMeasure',
          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: 101004002,
          serialNumber: '101004002Table1Remark',
          tableId: "101004002Table1",
          tableName: "维修工单表",
          columnProp: 'remark',
          headerAlign: "center",
          align: "left",
          columnLabel: '备注说明',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
          columnWidth: 200,
        },
      ],
      changeModelFlag: false,
      planOperator: '',
      planOperatorName: '',
      submitData: {
        site: '',
        buNo: '',
        orderNo: '',
        planID: '',
        objectID: '',
        checker: '',
        checkerName: '',
        difficultyLevel: '',
        difficultyRemark: '',
        status: '',
        updateBy: this.$store.state.user.name,
        createBy: this.$store.state.user.name,
        planDesc: '',
        disposalMeasures: '',
        defectID: '',
        defectDesc: '',
        remark: '',
        faultReason: '',
        handlingMethod: '',
        preventiveMeasure: '',
        feedbackBy: '',
        actualOperatorName: '',
        knowledgeFlag: '',
      },
      submitModelFlag: false,
      detailData: {
        site: '',
        buNo: '',
        orderNo: '',
        planID: '',
        objectID: '',
        objectDesc: '',
        status: '',
        remark: '',
        workTime: '',
        result: '',
        defectID: '',
        defectDesc: '',
        actualOperatorName: '',
        planDate: '',
        reachDate: '',
        actualDate: '',
        planDesc: '',
        disposalMeasures: '',
        handlingMethod: '',
        functionType: '',
        resourceDesc: '',
        feedBackDesc: '',
        faultReason: '',
        preventiveMeasure: '',
        corePartNo: '',
        corePartDescription: '',
        oldSerialNo: '',
        newSerialNo: '',
        planOperatorName: '',
        createBy: '',
        createdDate: '',
        reachOperator: '',
        reachOperatorName: '',
        responseTime: '',
        createDate: '',
        confirmAssessment: '',
        confirmRemark: '',
        checkAssessment: '',
        checkNotes: '',
        knowledgeFlag: '',
        shutdownWarranty: ''
      },
      detailModelFlag: false,
      descImages: [],
      imageModalFlag: false,
      departmentModelFlag: false,
      departmentData: {
        site: '',
        buNo: '',
        deptId: '',
        deptName: '',
      },
      departmentListSelections: [],
      departmentDetailList: [
        {
          columnProp: 'deptId',
          headerAlign: "center",
          align: "center",
          columnLabel: '部门编码',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnProp: 'deptName',
          headerAlign: "center",
          align: "center",
          columnLabel: '部门名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      userBuList: [],
      authSearch: false,
      authChange: false,
      authDetail: false,
      authCancel: false,
      authCheck: false,
      menuId: this.$route.meta.menuId,
      confirmData: {
        site: '',
        buNo: '',
        orderNo: '',
        functionType: '',
        confirmResult: '',
        confirmAssessment: '',
        confirmRemark: '',
        confirmBy: ''
      },
      confirmDefectModal: false,
      submitModelsFlag: false,
      activeTable: 'inspection_form',
      feedBackImages: [],
      sparPartImages: [],
      partSpareList: [],
      historyRecordList: [],
      columnFeedBackImages: [
        {
          columnProp: 'fileName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false
        },
        {
          columnProp: 'typeFlag',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '图片来源',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false
        },
        {
          columnProp: 'createdBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false
        },
        {
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false
        }
      ],
      columnSparPartImages: [
        {
          columnProp: 'fileName',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '文件名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false
        },
        {
          columnProp: 'createdBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传人',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false
        },
        {
          columnProp: 'createDate',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '上传时间',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false
        }
      ],
      columnPartSpareList: [
        {
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '备品备件编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 120,
        },
        {
          columnProp: 'partDescription',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '备品备件名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 150,
        },
        {
          columnProp: 'spec',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '规格型号',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 120,
        },
        {
          columnProp: 'umid',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '单位',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 100,
        },
      ],
      columnHistoryList: [
        {
          columnWidth: 100,
          columnProp: 'orderNo',
          headerAlign: "center",
          align: "left",
          columnLabel: '工单编号',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 200,
          columnProp: 'planDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '故障描述',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 120,
          columnProp: 'defectDesc',
          headerAlign: "center",
          align: "left",
          columnLabel: '故障名称',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 100,
          columnProp: 'result',
          headerAlign: "center",
          align: "center",
          columnLabel: '维修结论',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 100,
          columnProp: 'disposalMeasures',
          headerAlign: "center",
          align: "left",
          columnLabel: '处置措施',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 100,
          columnProp: 'actualOperatorName',
          headerAlign: "center",
          align: "center",
          columnLabel: '维修人员',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 80,
          columnProp: 'workTime',
          headerAlign: "center",
          align: "right",
          columnLabel: '工作时长(m)',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 130,
          columnProp: 'actualDate',
          headerAlign: "center",
          align: "center",
          columnLabel: '维修时间',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
        {
          columnWidth: 200,
          columnProp: 'remark',
          headerAlign: "center",
          align: "left",
          columnLabel: '备注说明',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: '',
        },
      ],
      columnCoreComponent: [
        {
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '备件编码',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 120,
        },
        {
          columnProp: 'partDescription',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '备件名称',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 200,
        },
        {
          columnProp: 'oldSerialNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '老序列号',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 120,
        },
        {
          columnProp: 'newSerialNo',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '新序列号',
          columnHidden: false,
          columnImage: false,
          status: true,
          fixed: false,
          columnWidth: 120,
        },
      ],
      knowledgeFlag: '',
      corePartSpareList: []
    }
  },

  mounted() {
    this.$nextTick(() => {
      this.height = window.innerHeight - 210
    })
  },

  created() {
    // 按钮控制
    this.getButtonAuthData()
    // 获取用户的 site 和 bu
    this.getSiteAndBuByUserName()
    this.favoriteIsOk()
    // 动态列
    this.getTableUserColumn(this.$route.meta.menuId + 'table1', 1)
    if (!this.authSearch) {
      // 查询登陆人员的部门,并过滤出相应工单
      this.getUserDept()
    }
  },

  methods: {

    // ======= 正则校验 =======
    handleInput(value, type) {
      // 大于等于0，且只能输入4位小数
      let val = value.replace(/^\D*([0-9]\d*\.?\d{0,4})?.*$/, '$1')
      if (val === null || val === undefined || val === '') {
        val = 0
      }
      if (type === 1) {
        this.detailData.workTime = val
      } else if (type === 2) {
        this.detailData.responseTime = val
      }
    },

    // 获取用户的bu
    getSiteAndBuByUserName() {
      let tempData = {
        username: this.$store.state.user.name,
      }
      getSiteAndBuByUserName(tempData).then(({data}) => {
        if (data.code === 0) {
          this.userBuList = data.rows
        }
      })
    },

    // 控制单行的背景颜色
    controlRowStyle({row, rowIndex}) {
      // 区分不同的样式对应不同的颜色
      if (row.status === '待审核') {
        return "background-color: #D8ECF1"
      }
    },

    // 查询登陆人员的部门
    getUserDept() {
      let tempDate = {
        site: '',
        username: this.$store.state.user.name,
      }
      getDeptList(tempDate).then(({data}) => {
        if (data.code === 0) {
          data.rows.forEach(val => {
            this.searchData.departmentName = this.searchData.departmentName + ";" + val
          })
          this.searchData.departmentName = this.searchData.departmentName.substring(1)
          this.getDataList()
        }
      })
    },

    // 校验用户是否收藏
    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++) {
          if (this.$route.meta.menuId === data.list[i].menuId) {
            this.favorite = 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
        })
      }
    },

    // 获取基础数据列表S
    getBaseList(val, type) {
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = ''
        if (val === 201) {
          strVal = this.planOperator
          this.$refs.baseList.init(val, strVal)
        }
      })
    },

    /* 列表方法的回调 */
    getBaseData(val) {
      if (this.tagNo === 201) {
        this.planOperator = val.username
        this.planOperatorName = val.user_display
      }
    },

    //导出excel
    async createExportData() {
      this.searchData.limit = -1
      this.searchData.page = 1
      await eamWorkOrderSearchForDefect(this.searchData).then(({data}) => {
        this.exportList = data.page.list
      })
      return this.exportList
    },

    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
    },

    // 获取数据列表
    getDataList() {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      eamWorkOrderSearchForDefect(this.searchData).then(({data}) => {
        if (data.code === 0) {
          this.dataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
        }
        this.dataListLoading = false
      })
    },

    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },

    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },

    // 每页数
    sizeChangeHandle2 (val) {
      this.pageSize2 = val
      this.pageIndex2 = 1
      this.queryHistoryRecord()
    },

    // 当前页
    currentChangeHandle2 (val) {
      this.pageIndex2 = val
      this.queryHistoryRecord()
    },

    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },

    cancelOrder(row) {
      this.$confirm(`是否取消选定工单?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        cancelOrder(row).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      }).catch(() => {
      })
    },

    // 更改执行人员
    changeModel() {
      let tempData1 = '' // 记录不是未开工的单号
      if (this.dataListSelections.length === 0) {
        this.$message.warning('请勾选要更改的工单！')
        return
      }
      for (let i = 0; i < this.dataListSelections.length; i++) {
        if (this.dataListSelections[i].status !== '未开工') {
          tempData1 = tempData1 + this.dataListSelections[i].orderNo + '、'
        }
      }
      if (tempData1 !== '') {
        tempData1 = tempData1.substring(0, tempData1.length - 1)
        this.$message.warning('工单编码 [' + tempData1 + '] 不是未开工状态！')
        return
      }
      this.planOperator = ''
      this.planOperatorName = ''
      this.changeModelFlag = true
    },

    changeOrderOperator() {
      let inList = JSON.parse(JSON.stringify(this.dataListSelections))
      for (let i = 0; i < inList.length; i++) {
        inList[i].planOperator = this.planOperator
      }
      changeOrderOperator(inList).then(({data}) => {
        if (data && data.code === 0) {
          this.changeModelFlag = false
          this.getDataList()
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
            }
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 批量审核按钮
    checkModals() {
      let tempData1 = '' // 记录不是待审核的单号
      if (this.dataListSelections.length === 0) {
        this.$message.warning('请勾选要审核的工单！')
        return
      }
      for (let i = 0; i < this.dataListSelections.length; i++) {
        if (this.dataListSelections[i].status !== '待审核') {
          tempData1 = tempData1 + this.dataListSelections[i].orderNo + '、'
        }
      }
      if (tempData1 !== '') {
        tempData1 = tempData1.substring(0, tempData1.length - 1)
        this.$message.warning('工单编码 [' + tempData1 + '] 不是待审核状态！')
        return
      }
      this.submitData.difficultyLevel = ''
      this.submitData.difficultyRemark = ''
      this.submitModelsFlag = true
    },

    submitModels() {
      if (this.submitData.difficultyLevel === '' || this.submitData.difficultyLevel == null) {
        this.$message.warning('请选择难度等级！')
        return
      }
      const list = this.dataListSelections.map(item => ({
        ...item,
        checker: '',
        checkerName: '',
        status: '已完工',
        updateBy: this.$store.state.user.name,
        createBy: this.$store.state.user.name,
        difficultyLevel: this.submitData.difficultyLevel,
        difficultyRemark: this.submitData.difficultyRemark,
        planDesc: item.feedBackDesc,
        feedbackBy: item.createBy,
        knowledgeFlag: ''
      }))
      submitDefects(list).then(({data}) => {
        if (data && data.code === 0) {
          this.getDataList()
          this.submitModelsFlag = false
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {}
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 审核按钮
    checkModal() {
      if (this.authCheck) {
        this.$message.warning('无审核权限！')
        return
      }
      this.submitData.site = this.detailData.site
      this.submitData.buNo = this.detailData.buNo
      this.submitData.orderNo = this.detailData.orderNo
      this.submitData.planID = this.detailData.planID
      this.submitData.objectID = this.detailData.objectID
      this.submitData.planDesc = this.detailData.feedBackDesc
      this.submitData.disposalMeasures = this.detailData.disposalMeasures
      this.submitData.defectID = this.detailData.defectID
      this.submitData.defectDesc = this.detailData.defectDesc
      this.submitData.remark = this.detailData.remark
      this.submitData.difficultyLevel = ''
      this.submitData.difficultyRemark = ''
      this.submitData.faultReason = this.detailData.faultReason
      this.submitData.handlingMethod = this.detailData.handlingMethod
      this.submitData.preventiveMeasure = this.detailData.preventiveMeasure
      this.submitData.feedbackBy = this.detailData.createBy
      this.submitData.actualOperatorName = this.detailData.actualOperatorName
      this.submitData.knowledgeFlag = this.detailData.knowledgeFlag
      this.submitData.updateBy = this.$store.state.user.name
      if (this.detailData.status === '已完工') {
        this.$confirm(`是否取消审核?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.submitData.status = '待审核'
          submitDefect(this.submitData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.detailData.status = '待审核'
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        })
      } else {
        this.submitData.status = '已完工'
        this.submitModelFlag = true
      }
    },

    // 确认审核
    submitModel () {
      if (this.submitData.difficultyLevel === '' || this.submitData.difficultyLevel == null) {
        this.$message.warning('请选择难度等级！')
        return
      }
      submitDefect(this.submitData).then(({data}) => {
        if (data && data.code === 0) {
          this.getDataList()
          this.detailData.status = '已完工'
          this.submitModelFlag = false
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {}
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 详情
    reportModal(row) {
      this.detailData = {
        ...row,
        shutdownWarranty: row.repairReportingType === '设备故障' ? '是' : '否'
      }
      this.activeTable = 'inspection_form'
      this.detailModelFlag = true
    },

    updateResult() {
      if (this.authCheck) {
        this.$message.warning('无审核权限！')
        return
      }
      if (this.detailData.reachDate === '' || this.detailData.reachDate == null) {
        this.$message.warning('请选择到达时间！')
        return
      }
      if (this.detailData.actualDate === '' || this.detailData.actualDate == null) {
        this.$message.warning('请选择实际执行时间！')
        return
      }
      if (this.detailData.reachDate > this.detailData.actualDate) {
        this.$message.warning('到达时间不能大于实际执行时间！')
        return
      }
      if (this.detailData.checkAssessment === '' || this.detailData.checkAssessment == null) {
        this.$message.warning('请选择维修评估结论！')
        return
      }
      if (this.detailData.checkNotes === '' || this.detailData.checkNotes == null) {
        this.$message.warning('请填写维修评估的备注说明！')
        return
      }
      updateReportResult(this.detailData).then(({data}) => {
        if (data && data.code === 0) {
          this.getDataList()
          this.detailModelFlag = false
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
            }
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 维修确认
    confirmResult(row) {
      this.confirmData = {
        site: row.site,
        buNo: row.buNo,
        orderNo: row.orderNo,
        planID: row.planID,
        functionType: row.functionType,
        confirmResult: 'Y',
        confirmAssessment: '优秀',
        confirmRemark: '',
        confirmBy: this.$store.state.user.name
      }
      this.confirmDefectModal = true
    },

    // 确认结果
    confirmDefectOrder() {
      if (this.confirmData.confirmResult === '' || this.confirmData.confirmResult == null) {
        this.$message.warning('请选择确认结果！')
        return
      }
      if (this.confirmData.confirmAssessment === '' || this.confirmData.confirmAssessment == null) {
        this.$message.warning('请选择维修评估！')
        return
      }
      if (this.confirmData.confirmRemark === '' || this.confirmData.confirmRemark == null) {
        this.$message.warning('请填写生产维修评估说明！')
        return
      }
      confirmDefectOrder(this.confirmData).then(({data}) => {
        if (data && data.code === 0) {
          this.getDataList()
          this.confirmDefectModal = false
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
            }
          })
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 查看故障图片
    checkFaultImageModal() {
      this.descImages = []
      let tempData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        orderNo: this.detailData.orderNo,
        folder: 'reportFault',
      }
      searchFileUrl(tempData).then(({data}) => {
        if (data.code === 0) {
          for (let i = 0; i < data.rows.length; i++) {
            this.descImages.push(data.rows[i].url)
          }
        } else {
          this.$message.warning(data.msg)
        }
      })
      this.imageModalFlag = true
    },

    // 查看备件图片
    checkSparPartImageModal() {
      this.descImages = []
      let tempData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        orderNo: this.detailData.orderNo,
        folder: 'reportSparPart',
      }
      searchFileUrl(tempData).then(({data}) => {
        if (data.code === 0) {
          for (let i = 0; i < data.rows.length; i++) {
            this.descImages.push(data.rows[i].url)
          }
        } else {
          this.$message.warning(data.msg)
        }
      })
      this.imageModalFlag = true
    },

    // 获取部门列表
    getDepartmentList() {
      // 先清空缓存选中
      this.$nextTick(() => this.$refs.departmentTable.clearSelection())
      // 拿到选中的部门编号
      let tempDataList = (this.searchData.departmentName == null ? '' : this.searchData.departmentName).split(';')
      // 查询部门
      getEmpyDeptList(this.departmentData).then(({data}) => {
        if (data && data.code === 0) {
          this.departmentList = data.rows
          this.departmentList.forEach(val => {
            // 回显选中的部门
            if (tempDataList.includes(val.deptName)) {
              this.$nextTick(() => this.$refs.departmentTable.toggleRowSelection(val, true))
            }
          })
          this.departmentModelFlag = true
        } else {
          this.$alert(data.msg, '错误', {
            confirmButtonText: '确定'
          })
        }
      })
    },

    // 部门
    departmentClickRow(row) {
      this.$refs.departmentTable.toggleRowSelection(row)
    },

    // 多选
    selectionDepartment(val) {
      this.departmentListSelections = val
    },

    getRowKeys(row) {
      // 唯一值，一般都为id
      return row.deptId
    },

    // 确认多选部门
    confirmDepartment() {
      this.searchData.departmentName = ''
      for (let i = 0; i < this.departmentListSelections.length; i++) {
        this.searchData.departmentName = this.searchData.departmentName + ";" + this.departmentListSelections[i].deptName
      }
      this.searchData.departmentName = this.searchData.departmentName.substring(1)
      this.departmentModelFlag = false
    },

    // 清空搜索框部门
    clearDepartmentName() {
      this.searchData.departmentName = ''
    },

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

    // 刷新页签的table数据
    refreshCurrentTabTable() {
      // 区分不同的页签刷新不同的列表数据
      if (this.activeTable === 'inspection_form') {
        //this.getInspectionFormData()
      } else if (this.activeTable === 'history_record') {
        this.queryHistoryRecord()
      } else if (this.activeTable === 'feed_back_img') {
        this.getFeedBackImages()
      } else if (this.activeTable === 'part_spare_list') {
        this.getPartSpareList()
      } else if (this.activeTable === 'eam_knowledge') {
        this.queryKnowledgeRecord()
      } else if (this.activeTable === 'spar_part_img') {
        this.getSparPartImages()
      } else if (this.activeTable === 'core_component') {
        this.getCorePartSpareList()
      }
    },

    // 获取故障图片
    getFeedBackImages () {
      let tempData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        orderNo: this.detailData.orderNo
      }
      getFeedBackImages(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.feedBackImages = data.rows
        } else {
          this.feedBackImages = []
        }
      })
    },

    // 获取备件图片
    getSparPartImages () {
      let tempData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        orderNo: this.detailData.orderNo,
        folder: 'reportSparPart'
      }
      getSparPartImages(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.sparPartImages = data.rows
        } else {
          this.sparPartImages = []
        }
      })
    },

    // 获取备品备件信息
    getPartSpareList () {
      let tempData = {
        site: this.detailData.site,
        objectID: this.detailData.objectID
      }
      getDevicePartList(tempData).then(({data}) => {
        // 区分请求成功和失败的状况
        if (data && data.code === 200) {
          this.partSpareList = data.rows
        } else {
          this.partSpareList = []
        }
      })
    },

    // 维修记录
    queryHistoryRecord () {
      let tempData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        objectID: this.detailData.objectID,
        functionType: 'C',
        limit: this.pageSize2,
        page: this.pageIndex2
      }
      queryHistoryRecord(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.historyRecordList = data.page.list
          this.pageIndex2 = data.page.currPage
          this.pageSize2 = data.page.pageSize
          this.totalPage2 = data.page.totalCount
        } else {
          this.historyRecordList = []
        }
      })
    },

    // 预览
    previewFile (row) {
      // 预览文件
      let image = ['jpg', 'jpeg', 'png', 'gif', 'bmp']
      let type = ''
      if (image.includes(row.fileType.toLowerCase())) {
        type = 'image/' + row.fileType
      }
      let video = ['mp4', 'avi', 'mov', 'wmv', 'flv']
      if (video.includes(row.fileType.toLowerCase())) {
        type = 'video/' + row.fileType
      }
      let txt = ['txt']
      if (txt.includes(row.fileType.toLowerCase())) {
        type = 'text/plain;charset=utf-8'
      }
      let office = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx']
      if (office.includes(row.fileType.toLowerCase())) {
        if (row.fileType.toLowerCase() === 'doc' || row.fileType.toLowerCase() === 'docx') {
          type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        } else if (row.fileType.toLowerCase() === 'ppt' || row.fileType.toLowerCase() === 'pptx') {
          type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'
        } else {
          type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        }
      }
      let pdf = ['pdf']
      if (pdf.includes(row.fileType.toLowerCase())) {
        type = 'application/pdf'
      }
      downLoadObjectFile(row).then(({data}) => {
        const blob = new Blob([data], { type: type });
        // 创建URL来生成预览
        const fileURL = URL.createObjectURL(blob);
        // 在新标签页中打开文件预览
        const newTab = window.open(fileURL, '_blank')
      })
    },

    // 下载
    downloadFile (row) {
      downLoadObjectFile(row)
        .then(({data}) => {
          // 不限制文件下载类型
          const blob = new Blob([data], {type:'application/octet-stream;charset=utf-8'})
          // 下载文件名称
          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() // 模拟在按钮上的一次鼠标单击
          URL.revokeObjectURL(linkNode.href) // 释放URL 对象
          document.body.removeChild(linkNode)
        })
    },

    // 动态列开始 获取 用户保存的 格式列
    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) {
          switch (columnId) {
            case 1:
              this.columnList = 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;
          }
        }
      })
    },

    //获取按钮的权限数据
    getButtonAuthData() {
      let searchFlag = this.isAuth(this.menuId + ":search")
      let changeFlag = this.isAuth(this.menuId + ":change")
      let detailFlag = this.isAuth(this.menuId + ":detail")
      let cancelFlag = this.isAuth(this.menuId + ":cancel")
      let checkFlag = this.isAuth(this.menuId + ":check")
      //处理页面的权限数据
      this.authSearch = !searchFlag
      this.authChange = !changeFlag
      this.authDetail = !detailFlag
      this.authCancel = !cancelFlag
      this.authCheck = !checkFlag
    },

    coreComponentModal() {
      this.coreComponentData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        orderNo: this.detailData.orderNo,
        objectID: this.detailData.objectID,
        partNo: this.detailData.corePartNo,
        partDescription: this.detailData.corePartDescription,
        createdBy: this.$store.state.user.name,
        oldSerialNo: this.detailData.oldSerialNo,
        newSerialNo: this.detailData.newSerialNo,
      }
      this.coreComponentFlag = true
    },

    getCorePartSpareList () {
      let tempData = {
        site: this.detailData.site,
        buNo: this.detailData.buNo,
        objectID: this.detailData.objectID,
        orderNo: this.detailData.orderNo,
      }
      getDeviceCorePartList(tempData).then(({data}) => {
        if (data && data.code === 0) {
          this.corePartSpareList = data.rows
        } else {
          this.corePartSpareList = []
        }
      })
    },

  }
}
</script>
<style scoped>
.numInput /deep/ .el-input__inner {
  text-align: right;
}

/deep/ .customer-tab .el-tabs__content {
  padding: 5px !important;
}
</style>

