<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" :model="searchData" @keyup.enter.native="getDataList()">
      <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: 120px"></el-input>
      </el-form-item>
<!--      <el-form-item style="margin-left: 0px" >-->
<!--        <span slot="label" style="" @click="getBaseList(201)"><a herf="#">计划执行人员编码</a></span>-->
<!--        <el-input v-model="searchData.planOperator" clearable style="width: 120px"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item :label="'状态'">
        <el-select v-model="searchData.status" 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-select v-model="searchData.documentSource" 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 @click="getDataList()">查询</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"
      style="width: 100%;">
      <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
        prop=""
        header-align="center"
        align="center"
        min-width="100"
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" v-if="scope.row.status=='未开工'" @click="chooseReachOperator(scope.row)">到达</a>
          <a type="text" size="small" v-if="scope.row.status=='已到达'" @click="reportModal(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="detailModelFlag" width="1200px">
      <el-form :inline="true" label-position="top" @keyup.enter.native="getDataList()">
        <el-form-item :label="'工单号'">
          <el-input v-model="saveData.orderNo" disabled style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item :label="'计划执行人员'">
          <el-input v-model="saveData.planOperatorName" disabled style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="设备编码">
          <el-input v-model="saveData.objectID" disabled style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="设备名称">
          <el-input v-model="saveData.objectDesc" disabled style="width: 240px"></el-input>
        </el-form-item>
      </el-form>
      <el-tabs v-model="activeTable" style="margin-top: 10px; width: 100%; height: 100%;" type="border-card" @tab-click="tabClick" class="customer-tab">
        <el-tab-pane label="维修单" name="inspection_form" style="height: 305px">
          <el-form :inline="true" label-position="top">
            <el-form-item>
              <span slot="label" @click="getBaseList(1033)"><a herf="#">故障编码</a></span>
              <el-input v-model="saveData.defectID" style="width: 221px"></el-input>
            </el-form-item>
            <el-form-item label="故障名称">
              <el-input v-model="saveData.defectDesc" disabled style="width: 221px"></el-input>
            </el-form-item>
            <el-form-item :label="'到达时间'">
              <el-date-picker
                style="width: 221px"
                v-model="saveData.reachDate"
                :picker-options="pickerOptions"
                type="datetime"
                value-format='yyyy-MM-dd HH:mm:ss'
                format='yyyy-MM-dd HH:mm:ss'
                placeholder="到达时间"
                :editable="false"
                @focus='elDatePickerOnFocus'
                @change="handleChangeTime"
                disabled>
              </el-date-picker>
            </el-form-item>
            <el-form-item :label="' '">
              <el-button type="primary" @click="uploadFaultImageModal()">故障图片</el-button>
            </el-form-item>
            <el-form-item :label="' '">
              <el-button type="primary" @click="uploadSparPartImageModal()">备件图片</el-button>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top">
            <el-form-item >
              <span slot="label" @click="getOperatorList()"><a>选择执行人员</a></span>
              <el-input v-model="saveData.operatorName" style="width: 556px"></el-input>
            </el-form-item>
            <el-form-item :label="'维修结果'">
              <el-select v-model="saveData.result" style="width: 155px">
                <el-option label="维修完成" value="维修完成"></el-option>
                <el-option label="维修失败" value="维修失败"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="this.saveData.result === '维修失败'" :label="'处置措施'">
              <el-select v-model="saveData.disposalMeasures" 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>
          <el-form :inline="true" label-position="top">
            <el-form-item label="反馈描述">
              <el-input v-model="saveData.feedBackDesc" style="width: 860px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top">
            <el-form-item :label="'故障原因'">
              <el-input type="textarea" v-model="saveData.faultReason" :rows="3" resize='none' show-word-limit style="width: 560px"></el-input>
            </el-form-item>
            <el-form-item :label="'处理方式'">
              <el-input type="textarea" v-model="saveData.handlingMethod" :rows="3" resize='none' show-word-limit style="width: 560px"></el-input>
            </el-form-item>
          </el-form>
          <el-form :inline="true" label-position="top" style="margin-top: 45px">
            <el-form-item :label="'预防措施'">
              <el-input type="textarea" v-model="saveData.preventiveMeasure" :rows="3" resize='none' show-word-limit style="width: 560px"></el-input>
            </el-form-item>
            <el-form-item :label="'执行结果备注'">
              <el-input type="textarea" v-model="saveData.remark" :rows="3" resize='none' show-word-limit style="width: 560px"></el-input>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="维修记录" name="history_record">
          <div class="rq ">
          <el-table
            :height="305"
            :data="HistoryRecordList"
            border
            v-loading="dataListLoading"
            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">
<!--                <a type="text" size="small" @click="detailModal(scope.row)">详情</a>-->
                <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>
          </div>
        </el-tab-pane>
      </el-tabs>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveCheckReport()">保存</el-button>
        <el-button type="primary" @click="detailModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 执行人员清单 -->
    <el-dialog title="执行人员清单" @close="closeDialog" :close-on-click-modal="false" v-drag :visible.sync="operatorModelFlag" width="820px">
      <div class="rq">
        <el-form :inline="true" label-position="top" :model="operatorData">
            <el-form-item :label="'所属角色'">
              <el-select value="roleName" v-model="operatorData.roleName" clearable placeholder="请选择" style="width: 120px">
                <el-option
                  v-for = "i in roleList"
                  :key = "i.roleID"
                  :label = "i.roleName"
                  :value = "i.roleName">
                </el-option>
              </el-select>
            </el-form-item>
          <el-form-item :label="'人员编码'">
            <el-input v-model="operatorData.adminID" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="'人员姓名'">
            <el-input v-model="operatorData.adminName" clearable style="width: 120px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button type="primary" @click="getOperatorList()">查询</el-button>
          </el-form-item>
        </el-form>
        <el-table
          :height="300"
          :data="operatorList"
          ref="operatorTable"
          @row-click="operatorClickRow"
          @selection-change="selectionChangeHandle2"
          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 operatorDetailList" :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="confirmOperator()">确认</el-button>
        <el-button type="primary" @click="operatorModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="到达" :close-on-click-modal="false" v-drag :visible.sync="chooseReachModelFlag" width="410px">
      <el-form :inline="true" label-position="top">
        <el-form-item >
          <span slot="label" @click="getOperatorList()"><a>选择到达人员</a></span>
          <el-input v-model="saveData.operatorName" style="width: 389px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="reach()">保存</el-button>
        <el-button type="primary" @click="chooseReachModelFlag = 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>

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

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

<script>
  import {
    eamWorkOrderSearch,
    eamWorkOrderItemSearch,
    saveOrderReportForDefect,
    checkSparPartImage,
    getOperatorList, // 获取机修人员列表
    queryHistoryRecord,
    searchFileUrl, // 查询文件路径
    reach // 到达
  } from "@/api/eam/eam.js"
  import {getTableDefaultListLanguage, getTableUserListLanguage} from "@/api/table.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  import reportImageUpload from "./report_image_upload.vue"
  export default {
    components: {
      Chooselist,
      reportImageUpload
    },
    watch: {
      saveData: {
        deep: true,
        handler: function (newV, oldV) {
          this.saveData.workTime = Math.ceil(Math.floor(this.dayjs(this.saveData.endDate).diff(this.saveData.startDate, 'seconds') / 30) / 2)
        }
      },
      searchData: {
        deep: true,
        handler: function (newV, oldV) {
          this.searchData.groupID = this.searchData.groupID.toUpperCase()
        }
      }
    },
    data () {
      return {
        // 是否收藏
        favorite: false,
        tagNo:'',
        // 导出 start
        exportData: [],
        exportName: "维修执行" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["维修执行"],
        exportFooter: [],
        exportList: [],
        // 导出 end
        searchData: {
          site: '',
          userName: this.$store.state.user.name,
          orderNo: '',
          planID: '',
          objectID: '',
          buNo: '',
          planOperator: '',
          functionType: 'C',
          status: '',
          startDate: '',
          endDate: '',
          page: 1,
          limit: 10,
          searchType: 'reportDefect',
          documentSource: ''
        },
        height: 200,
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        dataList: [],
        dataListLoading: false,
        dataListSelections: [],
        modalFlag: false,
        modalDisableFlag: false,
        departmentList: [],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1BuDesc',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'buDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: 'BU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 60,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1Urgency',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'urgency',
            headerAlign: "center",
            align: "center",
            columnLabel: '紧急程度',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 60,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1OrderNo',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'orderNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '工单编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1PlanID',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'planID',
            headerAlign: "center",
            align: "center",
            columnLabel: '反馈单号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1FeedBackDesc',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'feedBackDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '反馈描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1DefectID',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'defectID',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1DefectDesc',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'defectDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1ObjectID',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'objectID',
            headerAlign: "center",
            align: "center",
            columnLabel: '设备编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1ObjectDesc',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'objectDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '设备名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1CreateBy',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'createBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '报修人员名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1Status',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'status',
            headerAlign: "center",
            align: "center",
            columnLabel: '状态',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1PlanOperatorName',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'planOperatorName',
            headerAlign: "center",
            align: "center",
            columnLabel: '计划执行人员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1PlanDate',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'planDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '计划执行日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1Remark',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'remark',
            headerAlign: "center",
            align: "center",
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table1DocumentSource',
            tableId: "101004003Table1",
            tableName: "维修执行表",
            columnProp: 'documentSource',
            headerAlign: "center",
            align: "center",
            columnLabel: '单据来源',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 107,
          },
        ],
        detailModelFlag: false,
        detailList: [],
        saveData: {
          site: '',
          buNo: '',
          functionType: 'C',
          orderNo: '',
          planOperatorName: '',
          startDate: '',
          endDate: '',
          workTime: '',
          remark: '',
          mesUser: '',
          planID: '',
          itemList: [],
          result: '',
          defectID: '',
          defectDesc: '',
          operator: '',
          operatorName: '',
          disposalMeasures: '',
          objectID: '',
          objectDesc: '',
          checkWorkPlanId: '',
          checkItemNo: '',
          reachDate: '',
          finishDate: '',
          handlingMethod: '',
          feedBackDesc: '',
          faultReason: '',
          preventiveMeasure: ''
        },
        operatorData: {
          site: '',
          bu: '',
          adminID: '',
          adminName: '',
          departmentName: '',
          roleID: '',
          roleName: '机修人员',
        },
        operatorModelFlag: false,
        operatorList: [],
        roleList: [],
        dataListSelections2: [],
        operatorDetailList: [
          {
            columnProp: 'adminID',
            headerAlign: "center",
            align: "center",
            columnLabel: '用户账号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'adminName',
            headerAlign: "center",
            align: "center",
            columnLabel: '用户名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'email',
            headerAlign: "center",
            align: "center",
            columnLabel: '邮箱',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            columnProp: 'phone',
            headerAlign: "center",
            align: "center",
            columnLabel: '手机号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
        ],
        // 日期限制
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
        },
        activeTable: 'inspection_form',
        HistoryRecordList: [],
        columnHistoryList: [
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2OrderNo',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'orderNo',
            headerAlign: "center",
            align: "center",
            columnLabel: '工单编号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2PlanDesc',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'planDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2DefectDesc',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'defectDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2Result',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'result',
            headerAlign: "center",
            align: "center",
            columnLabel: '维修结论',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2DisposalMeasures',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'disposalMeasures',
            headerAlign: "center",
            align: "center",
            columnLabel: '处置措施',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2ActualOperatorName',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'actualOperatorName',
            headerAlign: "center",
            align: "center",
            columnLabel: '维修人员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2WorkTime',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'workTime',
            headerAlign: "center",
            align: "right",
            columnLabel: '工作时长',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2ActualDate',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'actualDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '维修时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004003,
            serialNumber: '101004003Table2Remark',
            tableId: "101004003Table2",
            tableName: "维修记录表",
            columnWidth: 114,
            columnProp: 'remark',
            headerAlign: "center",
            align: "center",
            columnLabel: '工单备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
          },
        ],
        descImages: [],
        imageModalFlag: false,
        chooseReachModelFlag: false,
        reachData: {}
      }
    },

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

    created() {
      this.getDataList()
      this.favoriteIsOk()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      this.getTableUserColumn(this.$route.meta.menuId+'table2',2)
    },

    methods: {


      // 时间处理函数
      getStandTime (data) {
        let value =
          data.getFullYear() +
          "-" +
          this.checkTime(data.getMonth() + 1) +
          "-" +
          this.checkTime(data.getDate()) +
          " " +
          this.checkTime(data.getHours()) +
          ":" +
          this.checkTime(data.getMinutes()) +
          ":" +
          this.checkTime(data.getSeconds());
        return value;
      },

      // 时间处理,如果时间小于10 则再前面加一个'0'
      checkTime (i) {
        if (i < 10) {
          i = "0" + i
        }
        return i
      },

      // 日期时间选择器改变
      handleChangeTime () {
        // 当选择的时间大于当前时间，自动填充为当前时间
        // 设备开始时间
        let start = (new Date(this.saveData.startDate) * 1000) / 1000
        if (start > Date.now()) {
          this.saveData.startDate = this.getStandTime(new Date())
          this.$message({
            message: "时间超出范围！",
            type: "warning",
          })
        }
        // 设备结束时间
        let end = (new Date(this.saveData.endDate) * 1000) / 1000
        if (end > Date.now()) {
          this.saveData.endDate = this.getStandTime(new Date())
          this.$message({
            message: "时间超出范围！",
            type: "warning",
          })
        }
        // 结束时间小于开始时间
        if (start > end) {
          this.saveData.endDate = this.saveData.startDate
          this.$message({
            message: "结束时间小于开始时间！",
            type: "warning",
          })
        }
      },

      // 点击行选中复选框
      operatorClickRow (row) {
        this.$refs.operatorTable.toggleRowSelection(row)
      },

      // 获取机修人员列表
      getOperatorList () {
        this.operatorData.bu = this.saveData.site + '_' + this.saveData.buNo
        this.operatorData.site = this.$store.state.user.site
        this.getRoleNameList()
        if (this.saveData.operator == null) {
          this.saveData.operator = ''
          this.saveData.operatorName = ''
        }
        // 先清空缓存选中
        this.$nextTick(() => this.$refs.operatorTable.clearSelection())
        // 拿到选中的人员编号
        let tempDataList = this.saveData.operator.split(';')
        // 查询人员
        getOperatorList(this.operatorData).then(({data}) => {
          if (data && data.code === 0) {
            this.operatorList = data.rows
            this.operatorList.forEach(val => {
              // 回显选中的人员
              if (tempDataList.includes(val.adminID)) {
                this.$nextTick(() => this.$refs.operatorTable.toggleRowSelection(val, true))
              }
            })
            this.operatorModelFlag = true
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 获取数据列表
      getRoleNameList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/sys/role/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
          })
        }).then(({data}) => {
          let temp = []
          if (data && data.code === 0) {
            this.roleList = data.page.list
            temp = this.roleList[0]
            this.roleList[0] = this.roleList[1]
            this.roleList[1] = temp
            this.totalPage = data.page.totalCount
          } else {
            this.roleList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },

      // 多选
      selectionChangeHandle2 (val) {
        this.dataListSelections2 = val
      },

      selectFlag () {
        return true
      },

      // 确认多选机修人员
      confirmOperator () {
        this.saveData.operatorName = ''
        this.saveData.operator = ''
        for (let i = 0; i < this.dataListSelections2.length; i++) {
          this.saveData.operatorName = this.saveData.operatorName + ";" + this.dataListSelections2[i].adminName
          this.saveData.operator = this.saveData.operator + ";" + this.dataListSelections2[i].adminID
        }
        this.saveData.operator = this.saveData.operator.substring(1)
        this.saveData.operatorName = this.saveData.operatorName.substring(1)
        this.operatorModelFlag = false
      },

      // 校验用户是否收藏
      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.searchData.planOperator
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1033) {
            strVal = this.saveData.defectID
            this.$refs.baseList.init(val, strVal)
          }
        })
      },

      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 201) {
          this.searchData.planOperator = val.username
        }
        if (this.tagNo === 1033) {
          this.saveData.defectID = val.DefectID
          this.saveData.defectDesc = val.DefectDesc
        }
      },

      //导出excel
      async createExportData () {
        this.searchData.limit = -1
        this.searchData.page = 1
        await eamWorkOrderSearch(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
        eamWorkOrderSearch(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()
      },

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

      // 选择到达人员
      chooseReachOperator (row) {
        this.saveData.site = row.site
        this.saveData.buNo = row.buNo
        this.saveData.operator = ''
        this.saveData.operatorName = ''
        this.operatorData.bu = row.site + '_' + row.buNo
        this.reachData = row
        this.chooseReachModelFlag = true
      },

      // 到达
      reach () {
        let tempData = {
          site: this.saveData.site,
          buNo: this.saveData.buNo,
          functionType: 'C',
          orderNo: this.reachData.orderNo,
          status: '已到达',
          reachOperator: this.saveData.operator,
          reachOperatorName: this.saveData.operatorName
        }
        reach(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.chooseReachModelFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 执行
      reportModal (row) {
        this.saveData = {
          site: row.site,
          buNo: row.buNo,
          functionType: 'C',
          orderNo: row.orderNo,
          planID: row.planID,
          planOperatorName: row.planOperatorName,
          workTime: '',
          remark: '',
          disposalMeasures: '',
          mesUser: this.$store.state.user.name,
          itemList: [],
          defectID: row.defectID,
          defectDesc: row.defectDesc,
          objectID: row.objectID,
          objectDesc: row.objectDesc,
          checkWorkPlanId: row.checkWorkPlanId,
          checkItemNo: row.checkItemNo,
          reachDate: row.reachDate,
          operator: row.reachOperator,
          operatorName: row.reachOperatorName,
          handlingMethod: '',
          feedBackDesc: row.feedBackDesc,
          faultReason: '',
          preventiveMeasure: '',
          result: ''
        }
        this.queryHistoryRecord()
        this.detailModelFlag = true
      },

      saveCheckReport () {
        if (this.saveData.defectID === '' || this.saveData.defectID == null) {
          this.$message.warning('请选择故障编码！')
          return
        }
        if (this.saveData.result === '' || this.saveData.result == null) {
          this.$message.warning('请选择维修结果！')
          return
        }
        if (this.saveData.result === '维修失败' && (this.saveData.disposalMeasures == null || this.saveData.disposalMeasures === '')) {
          this.$message.warning('请选择处置措施！')
          return
        }
        if (this.saveData.operator == null || this.saveData.operator === '') {
          this.$message.warning('请选择维修人员！')
          return
        }
        if (this.saveData.handlingMethod == null || this.saveData.handlingMethod === '') {
          this.$message.warning('请填写处理方式！')
          return
        }
        saveOrderReportForDefect(this.saveData).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: '确定'
            })
          }
        })
      },

      // 上传故障图片
      uploadFaultImageModal () {
        let currentData = {
          site: this.saveData.site,
          buNo: this.saveData.buNo,
          createBy: this.$store.state.user.name,
          orderNo: this.saveData.orderNo,
          folder: 'reportFault',
        }
        // 打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.reportImageUpload.init(currentData)
        })
      },

      // 上传备件图片
      uploadSparPartImageModal () {
        let currentData = {
          site: this.saveData.site,
          buNo: this.saveData.buNo,
          createBy: this.$store.state.user.name,
          orderNo: this.saveData.orderNo,
          folder: 'reportSparPart',
        }
        // 打开组件 去做新增业务
        this.$nextTick(() => {
          this.$refs.reportImageUpload.init(currentData)
        })
      },

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

      // 刷新页签的table数据
      refreshCurrentTabTable () {
        // 区分不同的页签刷新不同的列表数据
        if (this.activeTable === 'inspection_form') {
          this.getInspectionFormData()
        } else if (this.activeTable === 'history_record') {
          this.queryHistoryRecord()
        }
      },

      // 维修记录
      queryHistoryRecord () {
        let tempData = {
          site: this.saveData.site,
          buNo: this.saveData.buNo,
          objectID: this.saveData.objectID,
          functionType: 'C'
        }
        queryHistoryRecord(tempData).then(({data}) => {
          if (data && data.code === 0) {
            this.HistoryRecordList = data.rows
          } else {
            this.HistoryRecordList = []
          }
        })
      },

      /**
       * 查看故障图片
       */
      checkFaultImageModal (row) {
        this.descImages = []
        let tempData = {
          site: this.saveData.site,
          buNo: this.saveData.buNo,
          orderNo: row.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 (row) {
        this.descImages = []
        let tempData = {
          site: this.saveData.site,
          buNo: this.saveData.buNo,
          orderNo: row.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
      },

      //去掉input框获得的焦点
      elDatePickerOnFocus () {
        document.activeElement.blur()
      },

      closeDialog () {
        this.operatorData = {
          site: '',
          adminName: '',
          adminID: '',
          roleName: '机修人员',
        }
      },

      // 动态列开始 获取 用户保存的 格式列
      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.columnHistoryList = 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.columnHistoryList = data.rows
                break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            // this.showDefault = true.
          }
        })
      },
    }
  }
</script>

<style>
</style>
