<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 scope="scope">
            {{ scope.row.sysFlag ? '是' : '否' }}
          </template>
        </el-table-column>
        <el-table-column label="完成情况" width="80" prop="finishFlag">
          <template 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="50" prop="deviceCount"/>
        <el-table-column label="完成数量" width="50" prop="finishCount"/>
        <el-table-column label="异常数量" class-name="color-red" width="50" 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 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="50" prop="itemCount"/>
        <el-table-column label="完成数量" width="50" prop="finishCount"/>
        <el-table-column label="异常数量" class-name="color-red" width="50" 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="170" fixed="right">
          <template scope="scope">
            <el-button type="text" @click="openItem(scope.row)"
            >查看巡检项目
            </el-button>
            <el-button v-if="scope.row.finishFlag&&scope.row.exceptionCount>0&&!scope.row.repairId" type="text"
                       @click="createRepair(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 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="checkDeptName"/>
          <el-table-column label="巡检人" width="100" prop="checkUserName"/>
          <el-table-column label="异常情况" width="80" prop="finishFlag">
            <template 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 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">提交</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">
              <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="repairUserName" style="margin-bottom: 10px">
                <el-input v-model.trim="repairRow.repairUserName" placeholder="请输入维修人姓名"/>
              </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>

  </div>

</template>

<script src="./js/deptDeviceCheck.js"/>

<style scoped>

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