<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item v-if="false" label="计划id" prop="planId">
        <el-input
          v-model="queryParams.planId"
          placeholder="请输入计划id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划编码" prop="planCode">
        <el-input
          v-model="queryParams.planCode"
          placeholder="请输入计划编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入工单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车间编码" prop="planWorkshop">
        <el-select v-model="queryParams.planWorkshop" placeholder="请选择车间" clearable>
          <el-option
            v-for="work in workCenterList"
            :key="work.factoryCode"
            :label="work.factoryName"
            :value="work.factoryCode"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="false" label="产线" prop="planProdLine">
        <el-input
          v-model="queryParams.planProdLine"
          placeholder="请输入产线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单状态" prop="orderStatus">
        <el-select v-model="queryParams.planStatus" placeholder="请选择工单状态" clearable>
          <el-option
            v-for="dict in dict.type.device_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="循环周期" prop="planLoop">
        <el-select v-model="queryParams.planLoopType" placeholder="请选择循环周期" clearable>
          <el-option
            v-for="dict in dict.type.device_loop_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item v-if="false" label="循环周期" prop="planLoop">
        <el-input
          v-model="queryParams.planLoop"
          placeholder="请输入循环周期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="循环执行时间开始" prop="planLoopStart">
        <el-date-picker clearable
                        v-model="queryParams.planLoopStart"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择循环执行时间开始">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="false" label="循环执行时间结束" prop="planLoopEnd">
        <el-date-picker clearable
                        v-model="queryParams.planLoopEnd"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择循环执行时间结束">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="false" label="实际开始时间" prop="orderStart">
        <el-date-picker clearable
                        v-model="queryParams.orderStart"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择实际开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="false" label="实际结束时间" prop="orderEnd">
        <el-date-picker clearable
                        v-model="queryParams.orderEnd"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择实际结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="设备编码" prop="equipmentCode">
        <el-input
          v-model="queryParams.equipmentCode"
          placeholder="请输入设备编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备名称" prop="equipmentCode">
        <el-input
          v-model="queryParams.equipmentName"
          placeholder="请输入设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="工单费用" prop="orderCost">
        <el-input
          v-model="queryParams.orderCost"
          placeholder="请输入工单费用"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="点检人" prop="planPerson">
        <el-input
          v-model="queryParams.planPerson"
          placeholder="请输入点检人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="工单用时" prop="orderCostTime">
        <el-input
          v-model="queryParams.orderCostTime"
          placeholder="请输入工单用时"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="签字" prop="orderSignPerson">
        <el-input
          v-model="queryParams.orderSignPerson"
          placeholder="请输入签字"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="工厂" prop="factoryCode">
        <el-input
          v-model="queryParams.factoryCode"
          placeholder="请输入工厂"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="备用字段1" prop="attr1">
        <el-input
          v-model="queryParams.attr1"
          placeholder="请输入备用字段1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="备用字段2" prop="attr2">
        <el-input
          v-model="queryParams.attr2"
          placeholder="请输入备用字段2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="备用字段3" prop="attr3">
        <el-input
          v-model="queryParams.attr3"
          placeholder="请输入备用字段3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="删除标志" prop="delFlag">
        <el-input
          v-model="queryParams.delFlag"
          placeholder="请输入删除标志"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="创建人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="创建时间" prop="createTime">
        <el-date-picker clearable
                        v-model="queryParams.createTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="false" label="更新人" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="false" label="更新时间" prop="updateTime">
        <el-date-picker clearable
                        v-model="queryParams.updateTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label-width="100px" label="循环范围开始" prop="planLoopStart">
        <el-date-picker
          v-model="queryParams.loopStartArray"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label-width="100px" label="循环范围结束" prop="planLoopEnd">
        <el-date-picker
          v-model="queryParams.loopEndArray"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label-width="100px" label="执行开始时间" prop="orderStart">
        <el-date-picker
          v-model="queryParams.orderStartArray"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label-width="100px" label="执行结束时间" prop="orderEnd">
        <el-date-picker
          v-model="queryParams.orderEndArray"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="保养类型" prop="upkeep">
        <el-select v-model="queryParams.upkeep" placeholder="请选择保养类型" clearable>
          <el-option
            v-for="dict in dict.type.device_upkeep_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="检验状态" prop="orderInspect">
        <el-select v-model="queryParams.orderInspect" placeholder="请选择保养类型" clearable>
          <el-option
            v-for="dict in dict.type.device_inspect_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="cilckFastWork"
          v-hasPermi="['device:upkeepOrder:add']"
        >快速工单
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="clickInspect"
          v-hasPermi="['device:upkeepOrder:edit']"
        >结果检验
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['device:upkeepOrder:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['device:upkeepOrder:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="upkeepOrderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column v-if="false" label="主键" align="center" prop="orderId" />
      <el-table-column v-if="false" label="计划id" align="center" prop="planId" />
      <el-table-column width="150" label="计划编码" align="center" prop="planCode" />
      <el-table-column v-if="false" label="计划类型" align="center" prop="planType" />
      <el-table-column width="150" label="保养单号" align="center" prop="orderCode" fixed>
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="showWork(scope.row)"
          >{{ scope.row.orderCode }}</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="车间编码" align="center" prop="planWorkshop" />
      <el-table-column width="150" label="车间" align="center" prop="workCenterName"/>
      <el-table-column v-if="false" label="产线" align="center" prop="planProdLine" />
      <el-table-column label="循环周期" align="center" prop="planLoop" />
      <el-table-column width="120" label="循环周期类型" align="center" prop="planLoopType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.device_loop_type" :value="scope.row.planLoopType"/>
        </template>
      </el-table-column>
      <el-table-column width="120" label="循环范围开始" align="center" prop="planLoopStart">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planLoopStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="循环范围结束" align="center" prop="planLoopEnd">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planLoopEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="执行开始时间" align="center" prop="orderStart">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column width="120" label="执行结束时间" align="center" prop="orderEnd">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column width="100" label="设备编码" align="center" prop="equipmentCode" />
      <el-table-column width="120" label="设备名称" align="center" prop="equipmentName" />
      <el-table-column width="80" label="保养类型" align="center" prop="upkeep" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.device_upkeep_type" :value="scope.row.upkeep"/>
        </template>
      </el-table-column>
      <el-table-column label="工单状态" align="center" prop="orderStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.device_order_status" :value="scope.row.orderStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="检验状态" align="center" prop="orderInspect">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.device_inspect_status" :value="scope.row.orderInspect"/>
        </template>
      </el-table-column>
      <el-table-column label="工单费用" align="center" prop="orderCost"/>
      <el-table-column label="保养人" align="center" prop="planPerson"/>
      <el-table-column width="120" label="工单用时(min)" align="center" prop="orderCostTime"/>
      <el-table-column v-if="false" label="签字" align="center" prop="orderSignPerson"/>
      <el-table-column v-if="false" label="工厂" align="center" prop="factoryCode"/>
      <el-table-column v-if="false" label="备用字段1" align="center" prop="attr1"/>
      <el-table-column v-if="false" label="备用字段2" align="center" prop="attr2"/>
      <el-table-column v-if="false" label="备用字段3" align="center" prop="attr3"/>
      <el-table-column v-if="false" label="删除标志" align="center" prop="delFlag"/>
      <el-table-column label="创建人" align="center" prop="createBy"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column width="180" label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.upkeep != '1' "
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['device:upkeepOrder:edit']"
          >填写记录
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['device:upkeepOrder:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 结果检验 -->
    <el-dialog
      title="保养结果检验"
      :visible.sync="inspectDialog"
      width="30%">
      <el-radio v-model="inspect" label="waiting">待检验</el-radio>
      <el-radio v-model="inspect" label="noPass">未通过</el-radio>
      <el-radio v-model="inspect" label="pass">通过</el-radio>
      <span slot="footer" class="dialog-footer">
    <el-button @click="inspectDialog = false">取 消</el-button>
    <el-button type="primary" @click="subInspect">确 定</el-button>
  </span>
    </el-dialog>

    <!-- 快速工单弹出框 -->
    <el-dialog
      title="快速工单"
      :visible.sync="orderDialog"
      width="800px"
    >
      <el-tabs type="border-card">
        <el-tab-pane label="工单基本信息">
          <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-row>
              <el-col :span="7">
                <el-form-item label="工作中心:">
                  <el-select v-model="form.planWorkshop" placeholder="工作中心" clearable>
                    <el-option
                      v-for="item in workCenterList"
                      :key="item.factoryCode"
                      :label="item.factoryName"
                      :value="item.factoryCode">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="10" :offset="1">
                <el-form-item label-width="100px" label="循环时间范围">
                  <el-date-picker
                    @change="changeArray"
                    v-model="form.planTimeArray"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span=12>
                <el-form-item label-width="110px" label="是否停机保养:">
                  <el-radio v-model="form.shutDown" label="1">停机保养</el-radio>
                  <el-radio v-model="form.shutDown" label="0">开机保养</el-radio>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="设备、保养项、备件">
          <el-row>
            <el-col class="my-step-mar" :span="1.5">
              <el-button
                type="primary"
                plain
                size="mini"
                @click="selectEquBtn">
                选择设备
              </el-button>
            </el-col>
          </el-row>
          <el-table
            :data="form.equipmentItem"
            stripe
            style="width: 100%">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column
              prop="equipmentCode"
              label="设备编码"
              width="180">
            </el-table-column>
            <el-table-column
              prop="equipmentName"
              label="设备名称"
              width="180">
            </el-table-column>
            <el-table-column
              prop="itemTempName"
              label="巡检项"
              width="300">
            </el-table-column>
            <el-table-column
              width="150"
              fixed="right"
              label="操作"
            >
              <template slot-scope="scope">
                <el-button @click="editorTheItem(scope.row)" type="text" size="small">标准</el-button>
                <el-button @click="selectSpareBtn(scope.row)" type="text" size="small">备件</el-button>
                <el-button @click="delTheEquItem(scope.row)" type="text" size="small">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <!-- 编辑检查项弹窗 -->
          <el-dialog
            title="编辑检查项"
            :visible.sync="editorItem"
            width="50%"
            append-to-body
          >
            <!-- 编辑检查标准 -->
            <el-table
              :data="itemDetailList"
              v-loading="detailLoading"
              stripe
              @selection-change="selectChangeEqu"
              style="width: 100%">
              <el-table-column width="55" align="center"/>
              <el-table-column
                prop="itemName"
                label="检查项">
              </el-table-column>
              <el-table-column
                prop="standardName"
                label="检查标准">
              </el-table-column>
              <el-table-column
                prop="standardTypeName"
                label="标准类型">
              </el-table-column>
              <el-table-column
                fixed="right"
                label="操作"
              >
                <template slot-scope="scope">
                  <el-button @click="delStandard(scope.row)" type="text" size="small">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="standardBtn">确 定</el-button>
              </span>
          </el-dialog>
          <!-- 选择设备弹窗 -->
          <el-dialog
            title="选择设备"
            :visible.sync="selectEqu"
            width="800px"
            append-to-body
          >
            <el-form :model="equipmentQuery" ref="queryBPForm" size="small" :inline="true" v-show="showSearch"
                     label-width="68px">
              <el-form-item label="设备编码">
                <el-input
                  v-model="equipmentQuery.equipmentCode"
                  placeholder="请输入设备编码"
                  clearable
                />
              </el-form-item>
              <el-form-item label="设备名称">
                <el-input
                  v-model="equipmentQuery.equipmentName"
                  placeholder="请输入设备名称"
                  clearable
                />
              </el-form-item>
              <el-form-item v-if="false" label="设备类型">
                <el-input
                  v-model="equipmentQuery.equipmentName"
                  placeholder="请输入设备类型"
                  clearable
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="getEquList">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetEqu">重置</el-button>
              </el-form-item>
            </el-form>
            <!-- 搜索-设备列表 -->
            <el-table
              :data="queryEquipment"
              v-loading="equLoading"
              stripe
              @selection-change="selectChangeEqu"
              style="width: 100%">
              <el-table-column type="selection" width="55" align="center"/>
              <el-table-column
                prop="equipmentCode"
                label="设备编码">
              </el-table-column>
              <el-table-column
                prop="equipmentName"
                label="设备名称">
              </el-table-column>
              <el-table-column
                prop="equipmentTypeName"
                label="设备类型">
              </el-table-column>
              <el-table-column
                prop="workshopName"
                label="工作中心">
              </el-table-column>
            </el-table>

            <pagination
              v-show="equTotal>0"
              :total="equTotal"
              :page.sync="equipmentQuery.pageNum"
              :limit.sync="equipmentQuery.pageSize"
              @pagination="getEquList"
            />

            <span slot="footer" class="dialog-footer">
                <el-button @click="selectEqu = false">取 消</el-button>
                <el-button type="primary" @click="confirmSelectEquBtn">确 定</el-button>
              </span>
          </el-dialog>

          <!-- 选择备件弹窗 -->
          <el-dialog
            title="备件领用"
            :visible.sync="spareDialog"
            width="900px"
            append-to-body
          >
            <el-tabs type="border-card">
              <el-tab-pane label="备件选择">
                <el-form :model="spareQuery" ref="queryBPForm" size="small" :inline="true" v-show="showSearch"
                         label-width="68px">
                  <el-form-item label="备件编码">
                    <el-input
                      v-model="spareQuery.materialCode"
                      placeholder="请输入备件编码"
                      clearable
                    />
                  </el-form-item>
                  <el-form-item label="备件名称">
                    <el-input
                      v-model="spareQuery.materialDesc"
                      placeholder="请输入备件名称"
                      clearable
                    />
                  </el-form-item>
                  <el-form-item v-if="false" label="备件类型">
                    <el-input
                      v-model="spareQuery.spareType"
                      placeholder="请输入备件类型"
                      clearable
                    />
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="getSpareList">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetSpare">重置</el-button>
                  </el-form-item>
                </el-form>
                <!-- 搜索-备件列表 -->
                <el-table
                  :data="spareList"
                  v-loading="spareLoading"
                  stripe
                  @selection-change="selectChangeSpare"
                  style="width: 100%">
                  <el-table-column v-if="false" type="selection" width="55" align="center"/>
                  <el-table-column
                    prop="materialCode"
                    label="备件号">
                  </el-table-column>
                  <el-table-column
                    prop="materialDesc"
                    label="备件名称">
                  </el-table-column>
                  <el-table-column
                    prop="spareType"
                    label="备件类型">
                  </el-table-column>
                  <el-table-column
                    prop="amount"
                    label="库存数量">
                  </el-table-column>
                  <el-table-column
                    width="150"
                    fixed="right"
                    label="操作"
                  >
                    <template slot-scope="scope">
                      <el-button @click="addSpareList(scope.row)" type="text" size="small">添加</el-button>
                    </template>
                  </el-table-column>
                </el-table>

                <pagination
                  v-show="spareTotal>0"
                  :total="spareTotal"
                  :page.sync="spareQuery.pageNum"
                  :limit.sync="spareQuery.pageSize"
                  @pagination="getSpareList"
                />

                <span slot="footer" class="dialog-footer">
                <el-button @click="spareDialog = false">取 消</el-button>
                <el-button type="primary" @click="confirmSelectSpareBtn">确 定</el-button>
              </span>
              </el-tab-pane>
              <el-tab-pane label="备件数量">
                <el-row>
                  <el-col class="my-step-mar" :span="1.5">
                    <el-button
                      type="primary"
                      plain
                      size="mini"
                      @click="applyNumDialog = true , applyNum = null">
                      领用数量
                    </el-button>
                  </el-col>
                </el-row>
                <el-table
                  :data="chooseSpareList"
                  v-loading="spareLoading"
                  stripe
                  @selection-change="selectChangeSpare"
                  style="width: 100%">
                  <el-table-column type="selection" width="55" align="center"/>
                  <el-table-column
                    prop="materialCode"
                    label="备件号">
                  </el-table-column>
                  <el-table-column
                    prop="materialDesc"
                    label="备件名称">
                  </el-table-column>
                  <el-table-column
                    prop="spareType"
                    label="备件类型">
                  </el-table-column>
                  <el-table-column
                    prop="amount"
                    label="库存数量">
                  </el-table-column>
                  <el-table-column
                    prop="applyNum"
                    label="领用数量">
                    <template slot-scope="scope">
                      <el-input size="small" v-model="scope.row.applyNum" @change="handleEdit(scope.$index,scope.row)"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column
                    width="150"
                    fixed="right"
                    label="操作"
                  >
                    <template slot-scope="scope">
                      <el-button @click="delSpareList(scope.row)" type="text" size="small">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-dialog
                  title="申领数量"
                  :visible.sync="applyNumDialog"
                  width="30%"
                  append-to-body
                >
                  <el-row>
                    <el-col :span="8" :offset="7">
                      <el-input-number v-model="applyNum" @change="changeApplySpareNum" :min="1" label="描述文字"></el-input-number>
                    </el-col>
                  </el-row>
                  <span slot="footer" class="dialog-footer">
                      <el-button v-if="false" @click="applyNumDialog = false">取 消</el-button>
                      <el-button type="primary" @click="applyNumDialog = false">确 定</el-button>
                    </span>
                </el-dialog>
              </el-tab-pane>
              <el-button type="primary" class="dialog-footer" @click="spareChangeCom">完成</el-button>
            </el-tabs>

          </el-dialog>
        </el-tab-pane>
        <el-tab-pane label="保养人员">
          <el-row>
            <el-col :span="24" :offset="1">
              <el-transfer
                :titles="['人员','已选择人员']"
                filterable
                :filter-method="filterMethod"
                filter-placeholder="请输入人员名称"
                v-model="selectPersonList"
                :data="personList">
              </el-transfer>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <span slot="footer" class="dialog-footer">
    <el-button @click="orderDialog = false">取 消</el-button>
    <el-button type="primary" @click="subOrder">确 定</el-button>
  </span>
    </el-dialog>

    <!-- 添加或修改保养工单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-tabs type="border-card">
          <el-tab-pane label="基础信息">
            <el-descriptions title="" border>
              <el-descriptions-item label="计划编码">{{ this.form.planCode }}</el-descriptions-item>
              <el-descriptions-item label="计划名称">{{ this.form.planName }}</el-descriptions-item>
              <el-descriptions-item label="循环周期">{{ this.form.planLoop }}{{ this.form.planLoopType }}
              </el-descriptions-item>
              <el-descriptions-item label="工单编码">{{ this.form.orderCode }}</el-descriptions-item>
              <el-descriptions-item label="车间编码">{{ this.form.planWorkshop }}</el-descriptions-item>
              <el-descriptions-item label="工作中心">{{ this.form.workCenterName }}</el-descriptions-item>
            </el-descriptions>
          </el-tab-pane>
          <el-tab-pane label="记录">
            <el-table
              :data="recordList"
              border
              style="width: 100%">
              <el-table-column
                width="180"
                prop="itemName"
                label="检查项"
              >
              </el-table-column>
              <el-table-column
                width="170"
                prop="standardName"
                label="标准名称"
              >
              </el-table-column>
              <el-table-column
                width="110"
                prop="detailReach"
                label="是否达标">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.detailReach" placeholder="请选择">
                    <el-option
                      v-for="item in dict.type.device_reach_standard"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column
                width="80"
                prop="detailUpLimit"
                label="上限">
              </el-table-column>
              <el-table-column
                width="80"
                prop="detailDownLimit"
                label="下限">
              </el-table-column>
              <el-table-column
                prop="actualValue"
                label="实际值">
                <template slot-scope="scope">
                  <el-input v-if="scope.row.standardType == 'quantify' " size="small" v-model="scope.row.actualValue" @change="handleEdit(scope.$index,scope.row)"></el-input>
                </template>
              </el-table-column>
              <el-table-column
                width="60"
                prop="detailUnit"
                label="单位">
              </el-table-column>
              <el-table-column
                width="300"
                prop="detailUnit"
                label="图片上传">
                <template slot-scope="scope">
                  <FileUpload v-model="scope.row.picturePath" />
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="备件">
            <el-table
              :data="form.spareList"
              stripe
              style="width: 100%">
              <el-table-column
                prop="applyCode"
                label="申领单号">
              </el-table-column>
              <el-table-column
                prop="spareCode"
                label="备件编码"
              >
              </el-table-column>
              <el-table-column
                prop="spareName"
                label="备件名称"
              >
              </el-table-column>
              <el-table-column
                prop="spareQuantity"
                label="申领数量">
              </el-table-column>
              <el-table-column
                prop="spareModel"
                label="备件类型">
              </el-table-column>
              <el-table-column
                prop="applyTime"
                label="申领时间"
                width="180">
              </el-table-column>
            </el-table>
          </el-tab-pane>
          <el-tab-pane label="工单信息">
            <el-row>
              <el-col :span="8">
                <el-form-item label="工单状态">
                  <el-select v-model="form.orderStatus" placeholder="计划状态" clearable>
                    <el-option
                      v-for="dict in dict.type.device_order_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="16">
                <el-form-item label="保养时间">
                  <el-date-picker
                    v-model="form.timeArray"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="保养费用">
                  <el-input v-model="form.orderCost" placeholder="请输入费用"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="16">
                <el-form-item label="保养图片">
                  <FileUpload v-model="form.picturePath" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 保养详情 -->
    <el-dialog
      title="保养详情"
      :visible.sync="workDetail"
      width="1000px"
    >
      <el-tabs type="border-card">
        <el-tab-pane label="保养信息">
          <el-descriptions title="" border :column="2">
            <el-descriptions-item label="计划编码">{{ workVO.order.planCode }}</el-descriptions-item>
            <el-descriptions-item label="计划名称">{{ workVO.order.planName }}</el-descriptions-item>
            <el-descriptions-item label="循环周期">{{ workVO.order.planLoop }}{{ workVO.order.planLoopType }}
            </el-descriptions-item>
            <el-descriptions-item label="工单编码">{{ workVO.order.orderCode }}</el-descriptions-item>
            <el-descriptions-item label="车间编码">{{ workVO.order.planWorkshop }}</el-descriptions-item>
            <el-descriptions-item label="循环开始时间">{{ workVO.order.planLoopStart }}</el-descriptions-item>
            <el-descriptions-item label="循环结束时间">{{ workVO.order.planLoopEnd }}</el-descriptions-item>
            <el-descriptions-item label="执行开始时间">{{ workVO.order.orderStart }}</el-descriptions-item>
            <el-descriptions-item label="执行结束时间">{{ workVO.order.orderEnd }}</el-descriptions-item>
            <el-descriptions-item label="保养类型">{{ workVO.order.upkeep }}</el-descriptions-item>
            <el-descriptions-item label="是否停机保养">{{ workVO.order.shutDown }}</el-descriptions-item>
            <el-descriptions-item label="保养人">{{ workVO.order.planPerson }}</el-descriptions-item>
<!--            <el-descriptions-item label="报修单号">{{ workVO.order.repairCode }}</el-descriptions-item>-->
            <el-descriptions-item label="保养图片">
              <div class="demo-image__lazy">
                <el-empty :image-size="200" v-if="workVO.order.upkeepPictures.length == 0"></el-empty>
                <div v-for="(url, index) in workVO.order.upkeepPictures" :key="index">
                  <el-image
                    :src="url"
                  ></el-image>
                </div>
              </div>
            </el-descriptions-item>
          </el-descriptions>
        </el-tab-pane>
        <el-tab-pane label="设备信息">
          <el-descriptions class="my-margin-top" title="" :column="2" border>
            <el-descriptions-item label="设备编码">{{ workVO.equ.equipmentCode }}</el-descriptions-item>
            <el-descriptions-item label="设备名称">{{ workVO.equ.equipmentName }}</el-descriptions-item>
            <el-descriptions-item label="设备位置">{{ workVO.equ.equipmentLocation }}</el-descriptions-item>
            <el-descriptions-item label="设备类型编码">{{ workVO.equ.equipmentTypeCode }}</el-descriptions-item>
            <el-descriptions-item label="设备类型名称">{{ workVO.equ.equipmentTypeName }}</el-descriptions-item>
            <el-descriptions-item label="所属工作中心编码">{{ workVO.equ.workshopCode }}</el-descriptions-item>
            <el-descriptions-item label="所属工作中心名称">{{ workVO.equ.workshopName }}</el-descriptions-item>
          </el-descriptions>
        </el-tab-pane>
        <el-tab-pane label="备件信息">
          <el-table
            :data="workVO.spareList"
            border
            style="width: 100%">
            <el-table-column
              prop="applyCode"
              label="申领单号">
            </el-table-column>
            <el-table-column
              prop="spareCode"
              label="备件编码"
              >
            </el-table-column>
            <el-table-column
              prop="spareName"
              label="备件名称"
              >
            </el-table-column>
            <el-table-column
              prop="spareQuantity"
              label="申领数量">
            </el-table-column>
            <el-table-column
              prop="spareModel"
              label="备件类型">
            </el-table-column>
            <el-table-column
              prop="applyTime"
              label="申领时间"
              width="180">
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="检查项信息">
            <el-table
              :data="standardListVo"
              border
              style="width: 100%">
              <el-table-column
                prop="itemName"
                label="检查项"
                width="180">
              </el-table-column>
              <el-table-column
                prop="standardName"
                label="标准名称"
                width="180">
              </el-table-column>
              <el-table-column
                prop="standardTypeName"
                label="标准类型"
                width="80">
              </el-table-column>
              <el-table-column
                prop="detailReach"
                label="是否达标">
              </el-table-column>
              <el-table-column
                prop="actualValue"
                label="实际值">
              </el-table-column>
              <el-table-column
                prop="detailUpLimit"
                label="上限">
              </el-table-column>
              <el-table-column
                prop="detailDownLimit"
                label="下限">
              </el-table-column>
              <el-table-column
                prop="detailUnit"
                label="单位">
              </el-table-column>
              <el-table-column
                prop="picturePath"
                label="图片">
                <template slot-scope="scope">
                  <el-popover
                    placement="right"
                    width="300"
                    trigger="hover">
                    <div class="demo-image__lazy">
                      <el-empty :image-size="200" v-if="scope.row.checkPictrueList.length == 0"></el-empty>
                      <div v-for="(url, index) in scope.row.checkPictrueList" :key="index">
                        <el-image
                          :src="url"
                        ></el-image>
                      </div>
                    </div>
                    <el-button slot="reference" type="primary" icon="el-icon-picture" circle></el-button>
                  </el-popover>
                </template>
              </el-table-column>
            </el-table>
        </el-tab-pane>
      </el-tabs>
      <span slot="footer" class="dialog-footer">
    <el-button @click="workDetail = false">取 消</el-button>
    <el-button type="primary" @click="workDetail = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  listUpkeepOrder,
  getUpkeepOrder,
  delUpkeepOrder,
  addUpkeepOrder,
  updateUpkeepOrder, subInspect
} from "@/api/device/upkeepOrder";
import {formatEquItem, querySpareList} from "@/api/device/upkeepPlan";
import {getEquList, getPersonList, getWorkCenter} from "@/api/device/plan";
import {delDeviceOrder, getDeviceOrder, listDeviceOrder, updateDeviceOrder} from "@/api/device/deviceOrder";
import {getInspectionWork, updateInspectionWork} from "@/api/device/inspectionWork";

export default {
  name: "UpkeepOrder",
  dicts: ['device_order_status', 'device_loop_type','device_reach_standard','device_upkeep_type','device_inspect_status'],
  data() {
    return {
      standardListVo:[],
      workDetail:false,
      // 初始化VO
      workVO: {
        order: {
          planCode:null,
          planName:null,
          planLoop:null,
          planLoopType:null,
          orderCode:null,
          planWorkShop:null,
          planLoopStart:null,
          planLoopEnd:null,
          orderStart:null,
          orderEnd:null,
          planPerson:null,
          upkeepPictures:[],
        },equ: {
          equipmentCode:null,
          equipmentName: null,
          equipmentLocation:null,
          equipmentTypeCode:null,
          equipmentTypeName:null,
          workshopCode:null,
          workshopName:null,
        },
        detailList:[],
        spareList:[],
      },
      // 日期范围选择快捷
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // 记录
      recordList: [],
      // 检验结果
      inspect: '0',
      // 结果检验弹窗
      inspectDialog: false,
      // 选中的备件
      selOnSpare: [],
      // 申领数量
      applyNum: null,
      // 申领数量弹出层
      applyNumDialog: false,
      // 已经选择的备件数
      chooseSpareList: [],
      // 备件总条数
      spareTotal: 0,
      // 备件table加载
      spareLoading: false,
      // 选择备件弹窗
      spareDialog: false,
      // 备件list
      spareList: [],
      // 保养人员选择穿梭框
      personList: [],
      selectPersonList: [],
      // 工作中心list
      workCenterList: [],
      // 编辑检查标准list
      itemDetailList: [],
      // 编辑检查标准loading
      detailLoading: false,
      // 选中的设备信息
      selectEquList: [],
      // 设备信息loading
      equLoading: false,
      // 搜索到的设备总数
      equTotal: 0,
      // 搜索到的设备list
      queryEquipment: [],
      // 备件弹窗搜索条件
      spareQuery: {
        materialCode: null,
        materialDesc: null,
        pageNum: 1,
        pageSize: 10,
      },
      // 设备弹窗搜索条件
      equipmentQuery: {
        equipmentCode: null,
        equipmentName: null,
        workshopCode: null,
        pageNum: 1,
        pageSize: 10,
      },
      // 选择设备弹窗
      selectEqu: false,
      // 编辑检查项弹窗
      editorItem: false,
      // 快速工单弹出层
      orderDialog: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 保养工单表格数据
      upkeepOrderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        planId: null,
        planCode: null,
        planType: "maintenance",
        orderCode: null,
        planWorkshop: null,
        planProdLine: null,
        planLoop: null,
        planLoopType: null,
        planLoopStart: null,
        planLoopEnd: null,
        orderStart: null,
        orderEnd: null,
        equipmentCode: null,
        orderStatus: null,
        orderCost: null,
        planPerson: null,
        orderCostTime: null,
        orderSignPerson: null,
        factoryCode: null,
        attr1: null,
        attr2: null,
        attr3: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        equ: {equipmentName: null},
        loopStartArray: [],
        orderStartArray: [],
        orderEndArray: [],
        loopEndArray: [],
      },
      // 表单参数
      form: {
        equ: {equipmentName: null},
        selectSpareList: [],
        equipmentItem: [],
        shutDown: '0',
        calculationRule: '0',
        planLoopType: 'day',
        planLoop: null,
        upkeep: '1',
        planName: null,
        planWorkshop: null,
        personList:[],
        planTimeArray:[],
        timeArray:[],
        picturePath: null,
      },
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.setWorkCenter();
    this.getList();
  },
  methods: {
    // 重置设备搜索
    resetEqu() {
      this.equipmentQuery = {
        equipmentCode: null,
        equipmentName: null,
        workshopCode: null,
        pageNum: 1,
        pageSize: 10,
      };
      this.getEquList();
    },
    // 备件数量
    handleEdit(index, row) {
      if (row.amount < Number(row.applyNum)) {
        this.$message({
          message: '超过库存数量！',
          type: 'warning'
        })
        row.applyNum = row.amount;
      }
    },
    // 展示
    showWork(row) {
      this.reset();
      const orderId = row.orderId || this.ids
      getInspectionWork(orderId).then(response => {
        this.workVO = response.data;
        if (this.workVO.order.upkeep == 0) {
          this.workVO.order.upkeep = '内部';
        }else {
          this.workVO.order.upkeep = '委外';
        }
        if (this.workVO.order.shutDown == 0) {
          this.workVO.order.shutDown = '开机保养';
        }else {
          this.workVO.order.shutDown = '停机保养';
        }
        for (let i = 0; i < this.workVO.detailList.length; i++) {
          for (let j = 0; j < this.workVO.detailList[i].standardList.length; j++) {
            this.workVO.detailList[i].standardList[j].itemName = this.workVO.detailList[i].itemName;
            this.standardListVo.push(this.workVO.detailList[i].standardList[j]);
          }
        }
        this.workDetail = true;
      });

    },
    // 点击结果检验按钮
    clickInspect() {
      if (this.ids.length == 0 || this.ids == null) {
        this.$message({
          message: '请勾选工单！',
          type: 'warning'
        })
        return;
      }
      this.inspect = "0";
      this.inspectDialog = true;
    },
    // 提交检验信息
    subInspect() {
      const data = {
        ids : this.ids,
        inspect : this.inspect,
      }

      subInspect(data).then(response => {
        this.getList();
        this.inspectDialog = false;
        this.$message({
          message: '提交成功！',
          type: 'success'
        })
      })
    },
    // 获取工作中心
    setWorkCenter() {
      getWorkCenter().then(response => {
        this.workCenterList = response.data;
      })
    },
    // 点击快速工单按钮
    cilckFastWork(){
      this.reset();
      this.selectPersonList = [];
      this.personList = [];
      this.setPerson();
      this.setWorkCenter();
      this.orderDialog = true;
    },
    // 保养人员穿梭框
    filterMethod(query, item) {
      return item.label.indexOf(query) > -1;
    },
    // 快速工单提交按钮操作
    subOrder() {
      this.form.personList = this.selectPersonList;
      addUpkeepOrder(this.form).then(response => {
        this.$modal.msgSuccess("新增成功");
        this.orderDialog = false;
        this.getList();
      });
    },
    // 编辑标准确认按钮
    standardBtn() {
      this.editorItem = false;
    },
    // 获取人员List-置入穿梭框信息
    setPerson() {
      getPersonList().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.personList.push({
            label: response.data[i].nickName + '(' + response.data[i].userName + ')',
            key: response.data[i].userId,
          })
        }
      });
    },
    // 删除标准
    delStandard(e) {
      e.showFlag = false;
      for (let i = 0; i < this.itemDetailList.length; i++) {
        if (this.itemDetailList[i].detailCode == e.detailCode) {
          this.itemDetailList[i].showFlag = false;
          this.itemDetailList.splice(i, 1);
        }
      }
    },
    // 点击编辑设备-巡检项目
    editorTheItem(e) {

      // 清除缓存
      this.itemDetailList = [];

      for (let i = 0; i < this.form.equipmentItem.length; i++) {
        if (e.code == this.form.equipmentItem[i].code) {
          for (let j = 0; j < this.form.equipmentItem[i].equPlanDetailList.length; j++) {
            var itemName = this.form.equipmentItem[i].equPlanDetailList[j].itemName;
            for (let k = 0; k < this.form.equipmentItem[i].equPlanDetailList[j].equPlanStandardList.length; k++){
              this.form.equipmentItem[i].equPlanDetailList[j].equPlanStandardList[k].itemName = itemName;
              if (this.form.equipmentItem[i].equPlanDetailList[j].equPlanStandardList[k].standardType == "qualitative") {
                this.form.equipmentItem[i].equPlanDetailList[j].equPlanStandardList[k].standardTypeName = "定性";
              }else {
                this.form.equipmentItem[i].equPlanDetailList[j].equPlanStandardList[k].standardTypeName = "定量";
              }

              this.itemDetailList.push(this.form.equipmentItem[i].equPlanDetailList[j].equPlanStandardList[k]);
            }
          }
        }
      }

      this.editorItem = true;
    },
    // 删除设备-巡检项
    delTheEquItem(e) {
      for (let i = 0; i < this.form.equipmentItem.length; i++) {
        if (this.form.equipmentItem[i].equipmentCode == e.equipmentCode) {
          this.form.equipmentItem.splice(i, 1);
        }
      }
    },
    // 选择设备确认按钮
    confirmSelectEquBtn() {

      if (this.selectEquList.length > 1) {
        this.$message({
          message: "只能选择一个设备！",
          type: "warning"
        })
        return
      }

      this.form.equipmentItem = [];
      // 处理信息
      formatEquItem(this.selectEquList).then(response => {

        for (let i = 0; i < response.data.length; i++) {
          this.form.equipmentItem.push(response.data[i]);
        }

        this.selectEqu = false;
      })

    },
    // 选择设备多选操作
    selectChangeEqu(e) {
      this.selectEquList = e;
    },
    // 获取设备信息
    getEquList() {
      this.equLoading = true;
      this.equipmentQuery.workshopCode = this.form.planWorkshop;
      getEquList(this.equipmentQuery).then(response => {
        this.equTotal = response.total;
        this.queryEquipment = response.rows;
        this.equLoading = false;
      })
    },
    // 点击选择设备按钮
    selectEquBtn() {
      this.getEquList();
      this.selectEqu = true;
    },
    // 备件选择完成按钮
    spareChangeCom() {
      this.spareDialog = false;
    },
    // 备件数量改变
    changeApplySpareNum(e) {
      for (let i = 0; i < this.selOnSpare.length; i++) {
        this.selOnSpare[i].applyNum = e;
      }
    },
    // 删除备件-备件数量
    delSpareList(e) {
      for (let i = 0; i < this.chooseSpareList.length; i++){
        if (this.chooseSpareList[i].materialCode == e.materialCode) {
          this.chooseSpareList.splice(i,1);
          this.$message({
            message: '删除成功！',
            type: 'success'
          })
        }
      }
    },
    // 选择备件-添加备件
    addSpareList(e) {
      for (let i = 0; i < this.chooseSpareList.length; i++){
        if (this.chooseSpareList[i].materialCode == e.materialCode) {
          this.$message({
            message: '不可重复添加！',
            type: 'warning'
          })
          return;
        }
      }
      this.chooseSpareList.push(e);
      this.$message({
        message: '添加成功！',
        type: 'success'
      })
    },
    // 改变巡检周期事件
    changeArray(e) {
    },
    // 选择备件确定按钮
    confirmSelectSpareBtn() {
    },
    // 多选备件按钮
    selectChangeSpare(e) {
      this.selOnSpare = e;
    },
    // 备件搜索重置按钮
    resetSpare() {
      this.spareQuery = {
        materialCode: null,
        materialDesc: null,
        pageNum: 1,
        pageSize: 10,
      };
      this.setSpareList();
    },
    // 获取备件信息
    setSpareList() {
      querySpareList(this.spareQuery).then(response => {
        this.spareTotal = response.total;
        this.spareList = response.rows;
        // 设置库存：总量-冻结数量
        for (let i = 0; i < this.spareList.length; i++) {
          this.spareList[i].amount = Number(this.spareList[i].amount) - Number(this.spareList[i].storageAmount)
        }
        this.spareLoading = false;
      })
    },
    // 搜索备件按钮
    getSpareList() {
      this.setSpareList()
    },
    // 选择备件按钮操作
    selectSpareBtn(e) {
      this.setSpareList();
      if (e.spareList == null) {
        e.spareList = [];
      }
      this.chooseSpareList = e.spareList;
      this.spareDialog = true;
    },
    /** 查询保养工单列表 */
    getList() {
      this.loading = true;
      listDeviceOrder(this.queryParams).then(response => {
        this.upkeepOrderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderId: null,
        planId: null,
        planCode: null,
        planType: "maintenance",
        orderCode: null,
        planWorkshop: null,
        planProdLine: null,
        planLoop: null,
        planLoopType: null,
        planLoopStart: null,
        planLoopEnd: null,
        orderStart: null,
        orderEnd: null,
        equipmentCode: null,
        orderStatus: null,
        orderCost: null,
        planPerson: null,
        orderCostTime: null,
        orderSignPerson: null,
        factoryCode: null,
        attr1: null,
        attr2: null,
        attr3: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        equ: {equipmentName: null},
        timeArray:[],
        loopStartArray: [],
        orderStartArray: [],
        orderEndArray: [],
        loopEndArray: [],
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.loopStartArray = [];
      this.queryParams.orderStartArray = [];
      this.queryParams.orderEndArray = [];
      this.queryParams.loopEndArray = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 快速工单按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "快速工单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.recordList = [];
      const orderCode = row.orderCode || this.ids
      getDeviceOrder(orderCode).then(response => {
        this.form = response.data;
        if (response.data.timeArray[0] == null) {
          response.data.timeArray = []
        }
        for (let i = 0; i < this.form.detailList.length; i++) {
          for (let j = 0; j < this.form.detailList[i].standardList.length; j++) {
            this.form.detailList[i].standardList[j].itemName = this.form.detailList[i].itemName;
            this.recordList.push(this.form.detailList[i].standardList[j]);
          }
        }
        this.open = true;
        this.title = "填写记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderId != null) {
            updateDeviceOrder(this.form).then(response => {
              this.$modal.msgSuccess("提交成功");
              this.open = false;
              this.getList();
            });
          } else {
            // addUpkeepOrder(this.form).then(response => {
            //   this.$modal.msgSuccess("新增成功");
            //   this.open = false;
            //   this.getList();
            // });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;

      var orderCodes = '';
      // 处理信息
      for (let i = 0; i < this.upkeepOrderList.length; i++) {
        for (let j = 0; j < orderIds.length; j++) {
          if (orderIds[j] == this.upkeepOrderList[i].orderId) {
            orderCodes = orderCodes + this.upkeepOrderList[i].orderCode + ',';
          }
        }
      }

      if (orderCodes == '') {
        for (let i = 0; i < this.upkeepOrderList.length; i++) {
          if (orderIds == this.upkeepOrderList[i].orderId) {
            orderCodes = this.upkeepOrderList[i].orderCode;
          }
        }
      }

      this.$modal.confirm('是否确认删除保养工单编号为"' + orderCodes + '"的数据项？').then(function () {
        delDeviceOrder(orderIds).then(response => {
          if (response.code != 500) {
            this.$modal.msgSuccess("删除成功");
            this.getList();
          }
        }).catch(() => {
        });
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('device/upkeepOrder/export', {
        ...this.queryParams
      }, `upkeepOrder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.my-step-mar {
  margin-left: 10px;
  margin-right: 10px;
}

.my-step-body {
  margin-top: 15px;
}

.el-transfer-panel {
  width: 250px;
}
.demo-image__lazy{
  height: 350px;
  overflow-y: auto;
}
</style>
