<template>
  <div>
    <el-card>

      <el-form :model="query" v-if="showSearch" label-width="auto">
        <el-row :gutter="20">
          <!--          <el-col :span="6">-->
          <!--            <el-form-item label="负责部门">-->
          <!--              <deptSelect :value.sync="query.chargeDeptCode"/>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
        </el-row>
      </el-form>
      <div class="top-right-btn">
        <el-button-group>
          <el-button icon="el-icon-view" type="primary" @click="showSearch = !showSearch">显示/隐藏搜索栏</el-button>
          <el-button
            type="primary"
            icon="el-icon-refresh"
            @click="onReset"
          >重置
          </el-button>
          <el-button type="primary" icon="el-icon-search" @click="search"
          >查询
          </el-button>
        </el-button-group>
      </div>
      <el-divider style="margin: 15px"></el-divider>

      <el-table :data="list" @row-click="rowClick" v-loading="loading" click-row-light>
        <el-table-column label="序号" width="50" type="index"/>
        <!--        <el-table-column label="任务id" width="150" prop="taskId"/>-->
        <el-table-column label="任务名称" width="150" prop="name"/>
        <el-table-column label="计划名称" width="150" prop="planName"/>
        <el-table-column label="系统生成" width="80" prop="sysFlag">
          <template slot-scope="scope">
            {{ scope.row.sysFlag ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column label="完成情况" width="80" prop="finishFlag">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.finishFlag==true" type="success">已完成</el-tag>
            <el-tag v-if="scope.row.finishFlag==false" type="warning">未完成</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="负责部门" width="160" prop="chargeDeptName"/>
        <!--        <el-table-column label="负责人" width="160" prop="checkUserName"/>-->
        <!--        <el-table-column label="负责人联系方式" width="160" prop="checkUserPhone"/>-->
        <el-table-column label="设备数量" width="80" prop="deviceCount"/>
        <el-table-column label="完成数量" width="80" prop="finishCount"/>
        <el-table-column label="异常数量" class-name="color-red" width="80" prop="exceptionCount"/>
        <el-table-column label="创建时间" width="160" prop="createTime"/>
        <el-table-column label="创建人" width="160" prop="createUserName"/>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="query.page"
        :limit.sync="query.limit"
        @pagination="getList"
      />
    </el-card>

    <el-card>
      <div slot="header" class="clearfix">
        <div class="fl">{{
            `任务详情 ${clickRow ? '——' + clickRow.name : ''}`
          }}
        </div>
        <div v-if="clickRow" class="fr">
          <el-button @click="getDetailList">刷新</el-button>
        </div>
      </div>
      <el-form v-if="clickRow" :model="detailQuery" inline label-width="auto">
        <el-row :gutter="20">
          <el-col>
            <el-form-item label="设备编码">
              <el-input v-model.trim="detailQuery.deviceCode" clearable/>
            </el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="getDetailList"
            >查询
            </el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table :data="detailList" v-loading="detailLoading">
        <el-table-column label="序号" width="50" type="index"/>
        <el-table-column label="科室" width="150" prop="deptName"/>
        <el-table-column label="设备编码" width="150" prop="deviceCode"/>
        <el-table-column label="完成情况" width="80" prop="finishFlag">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.finishFlag==true" type="success">已完成</el-tag>
            <el-tag v-if="scope.row.finishFlag==false" type="warning">未完成</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="完成时间" width="160" prop="finishTime"/>
        <el-table-column label="最小销售标识" width="150" prop="nameCode"/>
        <el-table-column label="名称" width="150" prop="productName"/>
        <el-table-column label="项目数量" width="80" prop="itemCount"/>
        <el-table-column label="完成数量" width="80" prop="finishCount"/>
        <el-table-column label="异常数量" class-name="color-red" width="80" prop="exceptionCount"/>
        <el-table-column label="规格型号" width="160" prop="ggxh"/>
        <!--        <el-table-column label="状态" width="120" prop="statusName">-->
        <!--          <template scope="scope">-->
        <!--            <el-tag :type="deviceStatus[scope.row.status].tagType">{{ scope.row.statusName }}</el-tag>-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <el-table-column label="计量单位" width="100" prop="measname"/>
        <el-table-column label="生产企业" width="180" prop="manufactory"/>
        <el-table-column label="批次号" width="100" prop="batchNo"/>
        <el-table-column label="序列号" width="100" prop="serialNo"/>
        <el-table-column label="生产日期" width="140" prop="productionDate"/>
        <el-table-column label="过期时间" width="140" prop="expireDate"/>
        <el-table-column label="供应商" width="100" prop="supName"/>
        <el-table-column label="UDI码" width="150" prop="udi"/>
        <el-table-column label="注册/备案号" width="150" prop="zczbhhzbapzbh"/>
        <el-table-column label="操作" width="200" fixed="right">
          <template slot-scope="scope">
            <!--            <el-button type="text" @click="openItem(scope.row)"-->
            <!--            >开始巡检-->
            <!--            </el-button>-->

            <el-button type="text" @click="startUpkeep(scope.row)" v-if="!scope.row.finishFlag"
            >开始保养
            </el-button>
            <el-button type="text" @click="startUpkeep(scope.row)" v-if="scope.row.finishFlag"
            >保养详情
            </el-button>

            <el-button v-if="(scope.row.finishFlag && scope.row.exceptionCount>0 && !(scope.row.repairId || scope.row.applyId) )" type="text"
                       @click="createRepair(scope.row)"
            >报修
            </el-button>
            <el-button v-if="scope.row.applyId" type="text"
                       @click="applyIdSelect(scope.row)"
            >报修单
            </el-button>
            <el-button v-if="scope.row.repairId" type="text"
                       @click="repairId = scope.row.repairId"
            >维修单
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="detailTotal>0"
        :total="detailTotal"
        :page.sync="detailQuery.page"
        :limit.sync="detailQuery.limit"
        @pagination="getDetailList"
      />

    </el-card>

    <el-dialog
      :visible="true"
      v-if="itemDialogFlag"
      width="80%"
      :title="`保养项目${itemQuery.title?'--'+itemQuery.title:''}`"
      @close="itemDialogFlag = false"
    >
      <el-card>
        <div slot="header" class="clearfix">
          <div class="fr">
            <el-button type="" @click="getDetailItemList">刷新</el-button>
          </div>
        </div>
        <el-table :data="itemList" v-loading="itemLoading">
          <el-table-column label="序号" width="50" type="index"/>
          <el-table-column label="项目编码" width="150" prop="itemCode"/>
          <el-table-column label="完成情况" width="80" prop="finishFlag">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.finishFlag==true" type="success">已完成</el-tag>
              <el-tag v-if="scope.row.finishFlag==false" type="warning">未完成</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="完成时间" width="160" prop="finishTime"/>
          <el-table-column label="保养部门" width="100" prop="upkeepDeptName"/>
          <el-table-column label="保养人" width="100" prop="upkeepUserName"/>
          <el-table-column label="异常情况" width="80" prop="finishFlag">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.normalFlag==true" type="success">正常</el-tag>
              <el-tag v-if="scope.row.normalFlag==false" type="danger">异常</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="项目名称" width="150" prop="itemName"/>
          <el-table-column label="项目内容" width="450" prop="itemContent"/>
          <el-table-column label="保养意见" width="450" prop="suggestion"/>
          <el-table-column label="操作" width="100" fixed="right">
            <template slot-scope="scope">
              <el-button v-if="scope.row.finishFlag ===false" type="text"
                         @click="itemRow = {...scope.row,normalFlag:true}">完成
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="itemTotal>0"
          :total="itemTotal"
          :page.sync="itemQuery.page"
          :limit.sync="itemQuery.limit"
          @pagination="getDetailItemList"
        />
      </el-card>
    </el-dialog>

    <el-dialog
      :visible="true"
      v-if="itemRow"
      width="80%"
      @close="itemRow = null"
    >
      <el-card>
        <div slot="header" class="clearfix">
          <div class="fl">
            {{ `保养项目--${itemRow.itemName}[${itemRow.itemCode}]` }}
          </div>
          <div class="fr">
            <el-button @click="itemRow = null">取消</el-button>
            <el-button type="primary" @click="commitItemCheck">提交</el-button>
          </div>
        </div>
        <el-form :model="itemRow" :rules="itemRules" ref="itemForm" label-width="auto">
          <el-descriptions border :column="2" label-style="width:100px">
            <el-descriptions-item label="设备信息" :span="2">
              {{ itemQuery.title }}
            </el-descriptions-item>
            <el-descriptions-item label="项目编码">
              {{ itemRow.itemCode }}
            </el-descriptions-item>
            <el-descriptions-item label="项目名称">
              {{ itemRow.itemName }}
            </el-descriptions-item>
            <el-descriptions-item label="项目内容" label-style="height:150px;" :span="2">
              {{ itemRow.itemContent }}
            </el-descriptions-item>
            <el-descriptions-item label="异常情况" :span="2">
              <el-form-item label=" " prop="normalFlag" style="margin-bottom: 0px">
                <el-radio-group v-model="itemRow.normalFlag">
                  <el-radio :label="true">正常</el-radio>
                  <el-radio :label="false">异常</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="保养意见" :span="2">
              <el-form-item label=" " prop="suggestion" style="margin-bottom: 10px">
                <el-input type="textarea" resize="none" :autosize="{ minRows: 4, maxRows: 4 }" clearable
                          show-word-limit
                          maxlength="300" v-model.trim="itemRow.suggestion"/>
              </el-form-item>
            </el-descriptions-item>
          </el-descriptions>
        </el-form>
      </el-card>
    </el-dialog>

    <el-dialog
      :visible="true"
      title="创建报修单"
      v-if="repairRow"
      width="80%"
      @close="repairRow = null"
    >
      <el-card>
        <div slot="header" class="clearfix">
          <div class="fl">
            {{ `保养设备--${repairRow.deviceCode}--${repairRow.productName}(${repairRow.ggxh})` }}
          </div>
          <div class="fr">
            <el-button @click="repairRow = null">取消</el-button>
            <el-button type="primary" @click="commitRepair" :loading="commitRepairLoading">提交</el-button>
          </div>
        </div>
        <el-form :model="repairRow" :rules="repairRules" ref="repairForm" label-width="auto">
          <el-descriptions border label-style="width:90px" :column="3">
            <el-descriptions-item label="名称">{{ repairRow.productName }}</el-descriptions-item>
            <el-descriptions-item label="规格">{{ repairRow.ggxh }}</el-descriptions-item>
            <el-descriptions-item label="销售标识">{{ repairRow.nameCode }}</el-descriptions-item>
            <el-descriptions-item label="注册/备案号">{{ repairRow.zczbhhzbapzbh }}</el-descriptions-item>
            <el-descriptions-item label="生产企业">{{ repairRow.manufactory }}</el-descriptions-item>
            <el-descriptions-item label="供应商">{{ repairRow.supName }}</el-descriptions-item>
            <el-descriptions-item label="批次号">{{ repairRow.batchNo }}</el-descriptions-item>
            <el-descriptions-item label="序列号">{{ repairRow.serialNo }}</el-descriptions-item>
            <el-descriptions-item label="udi码">{{ repairRow.udi }}</el-descriptions-item>
            <el-descriptions-item label="生产日期">{{ repairRow.productionDate }}</el-descriptions-item>
            <el-descriptions-item label="过期时间">{{ repairRow.expireDate }}</el-descriptions-item>
            <el-descriptions-item label=""></el-descriptions-item>
            <el-descriptions-item label="问题描述" :label-style="{'height': '100px'}" :span="3">
              <el-form-item label=" " prop="description" style="margin-bottom: 10px">
                <el-input type="textarea" resize="none" :autosize="{ minRows: 4, maxRows: 4 }" clearable
                          show-word-limit
                          maxlength="300" v-model.trim="repairRow.description"/>
              </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="报修现场图片" :span="3" label-style="height:100px">
              <localImageUpload
                :fileType="['image/jpeg','image/png','image/gif']"
                :maxFiles= "this.maxFiles"
                :fileSizeLimit="this.fileSizeLimit"
                :type="deptDeviceCheck"
                :uploadedFileNames="uploadedFileNames"
                :isShowTip="false"
                @changeComponent1Data="component1DataChange"
              ></localImageUpload>

            </el-descriptions-item>
<!--            <el-descriptions-item label="维修方式" :span="3">-->
<!--              <el-form-item label=" " prop="innerFlag" style="margin-bottom: 0">-->
<!--                <el-radio-group v-model="repairRow.innerFlag">-->
<!--                  <el-radio :label="true">内部维修</el-radio>-->
<!--                  <el-radio :label="false">外部维修</el-radio>-->
<!--                </el-radio-group>-->
<!--              </el-form-item>-->
<!--            </el-descriptions-item>-->
<!--            <el-descriptions-item  label="维修部门" :span="3">-->
<!--              <el-form-item label=" " prop="repairDeptCode" style="margin-bottom: 10px">-->
<!--                <deptSelect :value.sync="repairRow.repairDeptCode" :maintenance="true" placeholder="请选择报修部门"  />-->
<!--              </el-form-item>-->
<!--            </el-descriptions-item>-->
<!--            <el-descriptions-item label="维修人姓名" :span="3">-->
<!--              <el-form-item label=" " prop="repairUserName" style="margin-bottom: 10px">-->
<!--                <el-select-->
<!--                  v-model="repairRow.repairUserName"-->
<!--                >-->
<!--                  <el-option-->
<!--                    v-for="(item, index) in userlist"-->
<!--                    :key="index"-->
<!--                    :label="item.employeeName"-->
<!--                    :value="item.employeeName"-->
<!--                  />-->
<!--                </el-select>-->
<!--              </el-form-item>-->
<!--            </el-descriptions-item>-->
              <el-descriptions-item label="报修人电话" :span="3">
              <el-form-item label=" " prop="repairUserPhone" style="margin-bottom: 10px">
                <el-input v-model.trim="repairRow.repairUserPhone" placeholder="请输入报修人电话"/>
              </el-form-item>
            </el-descriptions-item>
<!--            <el-descriptions-item label="诊断信息" :label-style="{'height': '100px'}" :span="3">-->
<!--              <el-form-item label=" " prop="diagnosisInfo" style="margin-bottom: 10px">-->
<!--                <el-input type="textarea" resize="none" :autosize="{ minRows: 4, maxRows: 4 }" clearable-->
<!--                          show-word-limit-->
<!--                          maxlength="300" v-model.trim="repairRow.diagnosisInfo"/>-->
<!--              </el-form-item>-->
<!--            </el-descriptions-item>-->
          </el-descriptions>
        </el-form>
      </el-card>
    </el-dialog>

    <el-dialog
      visible
      v-if="repairId"
      @close="repairId=null"
      title="维修单信息"
      width="80%"
    >
      <deviceRepairDialog :repairId="repairId"/>

    </el-dialog>



    <el-dialog
      visible
      v-if="applyId"
      @close="applyId=null"
      title="报修单信息"
      width="80%"
    >
      <el-card>
        <div slot="header" class="clearfix">
          <div class="fl">
            {{ `保养设备--${selectRepairRow.deviceCode}--${selectRepairRow.productName}(${selectRepairRow.ggxh})` }}
          </div>
        </div>
        <el-form :model="selectRepairRow" label-width="auto" disabled>
          <el-descriptions border label-style="width:90px" :column="3">
            <el-descriptions-item label="名称">{{ selectRepairRow.productName }}</el-descriptions-item>
            <el-descriptions-item label="规格">{{ selectRepairRow.ggxh }}</el-descriptions-item>
            <el-descriptions-item label="销售标识">{{ selectRepairRow.nameCode }}</el-descriptions-item>
            <el-descriptions-item label="注册/备案号">{{ selectRepairRow.zczbhhzbapzbh }}</el-descriptions-item>
            <el-descriptions-item label="生产企业">{{ selectRepairRow.manufactory }}</el-descriptions-item>
            <el-descriptions-item label="供应商">{{ selectRepairRow.supName }}</el-descriptions-item>
            <el-descriptions-item label="批次号">{{ selectRepairRow.batchNo }}</el-descriptions-item>
            <el-descriptions-item label="序列号">{{ selectRepairRow.serialNo }}</el-descriptions-item>
            <el-descriptions-item label="udi码">{{ selectRepairRow.udi }}</el-descriptions-item>
            <el-descriptions-item label="生产日期">{{ selectRepairRow.productionDate }}</el-descriptions-item>
            <el-descriptions-item label="过期时间">{{ selectRepairRow.expireDate }}</el-descriptions-item>
            <el-descriptions-item label=""></el-descriptions-item>
            <el-descriptions-item label="问题描述" :label-style="{'height': '100px'}" :span="3">
              <el-form-item label=" " prop="description" style="margin-bottom: 10px">
                <el-input type="textarea" resize="none" :autosize="{ minRows: 4, maxRows: 4 }" clearable
                          show-word-limit
                          maxlength="300" v-model.trim="selectRepairRow.description"/>
              </el-form-item>
            </el-descriptions-item>
            <el-descriptions-item label="报修现场图片" :span="3" label-style="height:100px">
              <localImageUpload
                :fileType="['image/jpeg','image/png','image/gif']"
                :maxFiles= "this.maxFiles"
                :fileSizeLimit="this.fileSizeLimit"
                :type="deptDeviceCheck"
                :uploadedFileNames="selectRepairRow.livePath"
                :isShowTip="false"
                @changeComponent1Data="component1DataChange"
              ></localImageUpload>

            </el-descriptions-item>
            <el-descriptions-item label="报修人电话" :span="3">
              <el-form-item label=" " prop="repairUserPhone" style="margin-bottom: 10px">
                <el-input v-model.trim="selectRepairRow.repairUserPhone" placeholder="请输入报修人电话"/>
              </el-form-item>
            </el-descriptions-item>
          </el-descriptions>
        </el-form>
      </el-card>
    </el-dialog>

    <el-dialog
      :title="`保养项目${itemQuery.title?'--'+itemQuery.title:''}`"
      :visible="true"
      v-if="checkTipDialogVisible"
      @close="checkTipDialogVisible = false"
      width="80%"
    >
      <deptDeviceUpkeepDetail
        :originData="curDeviceData"
        :closeCheckDialog="closeCheckDialog"
      />
    </el-dialog>

  </div>

</template>

<script>
import {
  deviceUpkeepPageByDept,
} from "@/api/dev/deviceUpkeepApi";
import {deviceUpkeepDetailPage, deviceCheckDetailRepair} from "@/api/dev/deviceUpkeepDetailApi";
import {deviceCheckDetailItemFinish, deviceUpkeepDetailItemPage} from "@/api/dev/deviceUpkeepDetailItemApi";
import {copyProperties, getLoading} from "@/utils";
import deptDeviceUpkeepDetail from "@/views/dev/deptDeviceUpkeepDetail";
import {filterListByDeptCode} from "@/api/system/deptUser";
import {deviceRepairApplyAdd} from "@/api/dev/deviceRepairApplyApi";
import {listByIdAndCode} from "@/api/dev/deviceRepairApplyDetailApi.js";

let query = {
  page: 1,
  limit: 10,
  chargeDeptCode: null,
  finishFlag: null,
}

let detailQuery = {
  page: 1,
  limit: 10,
  taskId: null,
  deviceCode: null,
}

let itemQuery = {
  page: 1,
  limit: 10,
  taskId: null,
  deviceCode: null,
}
let repairData = {
  taskId: null,
  deviceCode: null,
  description: null,
  diagnosisInfo: null,
  innerFlag: true,
  repairUserName: null,
  repairUserPhone: null,
  repairDeptCode: null,
}

export default {
  name: "deptDeviceUpkeep",
  computed: {},
  components: {
    deptDeviceUpkeepDetail
  },
  data() {
    return {
      clickRow: null,
      showSearch: true,
      loading: false,
      userlist:[],
      total: .0,
      list: [],
      query: {...query},
      //设备详情=============================================
      detailLoading: false,
      detailQuery: {...detailQuery},
      detailList: [],
      detailTotal: 0,
      showLog: false,
      //===================================================
      itemDialogFlag: false,
      itemQuery: {...itemQuery},
      itemList: [],
      itemTotal: 0,
      itemLoading: false,
      checkPrintData: null,
      itemRow: null,
      livePath:null,
      itemRules: {
        normalFlag: [{required: true, message: "请选择异常情况", trigger: ["change", "blur"]}],
        suggestion: [{required: true, message: "巡检意见不能为空", trigger: ["change", "blur"]}],
      },
      repairRow: null,
      selectRepairRow: null,
      repairRules: {
        innerFlag: [{
          required: true,
          message: "请选择维修方式",
          trigger: ["change", "blur"]
        }],
        repairUserName: [{
          required: true,
          message: "维修人姓名不能为空",
          trigger: ["change", "blur"]
        }],
        repairUserPhone: [{
          required: true,
          message: "维修人电话不能为空",
          trigger: ["change", "blur"]
        }],
        repairDeptCode: [{
          required: true,
          message: "维修部门不能为空",
          trigger: ["change", "blur"]
        }],
        description: [{required: true, message: "问题描述不能为空", trigger: ["change", "blur"]}],
        diagnosisInfo: [{required: true, message: "诊断信息不能为空", trigger: ["change", "blur"]}],
      },
      repairId: null,
      applyId: null,

      //  开始巡检
      checkTipDialogVisible: false,
      curDeviceData: null,
      maxFiles: 3,
      fileSizeLimit: 5,
      uploadedFileNames: '',
      commitRepairLoading: false,
    }
  },
  created() {
    this.getList()
  },
watch: {
  'repairRow.repairDeptCode': {
    handler (newV, oldV) {
      this.getUerList()
    },
    // deep: true,
    // immediate: true,
  }
},
  methods: {
    applyIdSelect(row){
      this.applyId = row.applyId;
      //查询赋值
      let load = getLoading(this)
      listByIdAndCode({applyId:row.applyId,deviceCode:row.deviceCode}).then(res => {
        load.close()
        if (res.code != 20000) {
          // this.$message.error(res.message)
          return
        }
        // this.$message.success(res.message)
        this.selectRepairRow = res.data
      }).catch(() => {
        load.close()
      })
    },
    component1DataChange(params) {
      this.uploadedFileNames = params;
    },
    commitRepair() {
      this.$refs.repairForm.validate(b => {
        if (!b) {
          return
        }
        let load = getLoading(this)
        let pData = {
          applyUserPhone:"",
          taskId:"",
          details: []
        }
        pData.details.push({
          deviceCode: this.repairRow.deviceCode,
          description: this.repairRow.description,
          livePath: this.uploadedFileNames
        })
        pData.applyUserPhone = this.repairRow.repairUserPhone
        pData.taskId = this.repairRow.taskId
        this.commitRepairLoading = true
        deviceRepairApplyAdd(pData).then(res => {
          this.commitRepairLoading = false
          load.close()
          if (res.code != 20000) {
            this.$message.error(res.message)
            return
          }
          this.$message.success(res.message)
          this.getDetailList()
          this.getList()
          this.repairRow = null
        }).catch(() => {
          this.commitRepairLoading = false
          load.close()
        })
      })
    },
    createRepair(row) {
      let data = copyProperties(row, {...repairData});
      this.uploadedFileNames = ""
      this.repairRow = _.extend({}, row, data)
    },
    commitItemCheck() {
      this.$refs.itemForm.validate(b => {
        if (!b) {
          return
        }
        let load = getLoading(this)
        deviceCheckDetailItemFinish(this.itemRow).then(res => {
          load.close()
          if (res.code != 20000) {
            this.$message.error(res.message)
            return
          }
          this.$message.success(res.message)
          this.getDetailItemList()
          this.getDetailList()
          this.getList()
          this.itemRow = null
        }).catch(() => {
          load.close()
        })
      })
    },
    openItem(row) {
      this.itemQuery = {
        ...itemQuery,
        taskId: row.taskId,
        deviceCode: row.deviceCode,
        title: `[${row.deviceCode}]--${row.productName}(${row.nameCode})`
      }
      this.itemDialogFlag = true
      this.getDetailItemList()
    },
    startUpkeep(row) {
      this.itemQuery = {
        ...itemQuery,
        taskId: row.taskId,
        deviceCode: row.deviceCode,
        title: `[${row.deviceCode}]--${row.productName}(${row.nameCode})`
      }
      this.curDeviceData = row
      this.checkTipDialogVisible = true
    },

    closeCheckDialog() {
      this.checkTipDialogVisible = false
      this.getList()
      this.getDetailItemList()
    },


    getDetailItemList() {
      this.itemLoading = true
      deviceUpkeepDetailItemPage(this.itemQuery).then(res => {
        this.itemLoading = false
        if (res.code != 20000) {
          this.$message.error(res.message)
          return
        }
        this.itemList = res.data.list || []
        this.itemTotal = res.data.total || 0
      }).catch(e => {
        this.itemLoading = false
        this.itemList = []
        this.itemTotal = 0
      })
    },
    rowClick(row) {
      if (this.clickRow && row.taskId == this.clickRow.taskId) {
        return false
      }
      this.clickRow = row
      this.detailQuery = {...detailQuery, taskId: row.taskId}
      this.getDetailList()
    },
    getDetailList() {
      this.detailLoading = true
      deviceUpkeepDetailPage(this.detailQuery).then(res => {
        console.log("chakan jihua xiangsxi")
        this.detailLoading = false
        if (res.code != 20000) {
          this.$message.error(res.message)
          return
        }
        this.detailList = res.data.list || []
        this.detailTotal = res.data.total || 0
      }).catch(e => {
        this.detailLoading = false
      })
    },
    search() {
      this.query.page = 1
      this.getList()
    },
    onReset() {
      this.query = {...query}
      this.getList()
    },
    getList() {
      this.loading = true
      deviceUpkeepPageByDept(this.query).then(res => {
        this.loading = false
        if (res.code != 20000) {
          this.$message.error(res.message)
          return
        }
        this.list = res.data.list || []
        this.total = res.data.total || 0

      }).catch(e => {
        this.list = []
        this.total = 0
        this.loading = false
      })
    },
    getUerList() {
      if (this.repairRow.repairDeptCode != null){
        let userQuery = {
          deptCode: this.repairRow.repairDeptCode,
        }
        filterListByDeptCode(userQuery).then((response) => {
          // this.loading = false;
          this.userlist = response.data.list || [];
          // this.userTotal = response.data.total;
        })
          .catch(() => {
            // this.loading = false;
            this.userlist = [];
            // this.userTotal = 0;
          });
      }
    }
  }
}

</script>
<style scoped>

/deep/ .el-dialog__body {
  padding: 0 0 20px 0;
}
</style>
