<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="隐患名称" prop="troubleName">
        <el-input
          v-model="queryParams.troubleName"
          placeholder="请输入隐患名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="隐患时间"  prop="findTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.findTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="隐患上报开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="" prop="rectificationTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.rectificationTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="隐患上报结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="隐患状态 " prop="state">
        <el-select v-model="queryParams.state" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </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="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:book:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleFastAdd"
        >快速录入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['system:book:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="bookList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="隐患名称" align="center" prop="troubleName" />
      <el-table-column label="隐患类型" align="center" prop="troubleType" :formatter="troubleTypeFormat" />
      <el-table-column label="隐患等级" align="center" prop="troubleLevel" :formatter="troubleLevelFormat" />
      <el-table-column label="隐患上报人" align="center" prop="escalationName" />
      <el-table-column label="隐患发现时间" align="center" prop="findTime" width="180">
      </el-table-column>
      <el-table-column label="责任部门" align="center" prop="deptName" />
      <el-table-column label="整改人" align="center" prop="rectificationName" />
      <el-table-column label="整改时间" align="center" prop="rectificationTime" width="180">
      </el-table-column>
      <el-table-column label="隐患状态 " align="center" prop="state" >
        <template slot-scope="scope">
          <span v-if="scope.row.state==0"> 待整改</span>
          <span v-if="scope.row.state==1"> 待复查</span>
          <span v-if="scope.row.state==2"> 已闭环</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.state==0"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:book:edit']"
          >整改</el-button>
          <el-button
            v-if="scope.row.state==1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handlecha(scope.row)"
            v-hasPermi="['system:book:edit']"
          >复查</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:book:edit']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:book: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="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-divider content-position="left"><i class="el-icon-info"></i><span class="boxx">隐患信息</span></el-divider>
        <el-form-item label="隐患名称" prop="troubleName">
          <el-input v-model="form.troubleName" placeholder="请输入隐患名称" />
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="隐患类型" prop="troubleType" width="50%" >
              <el-select v-model="form.troubleType" placeholder="请选择隐患类型" >
                <el-option
                  v-for="dict in troubleTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="隐患等级" prop="troubleLevel">
              <el-select v-model="form.troubleLevel" placeholder="请选择隐患等级" @change="changeType">
                <el-option
                  v-for="dict in troubleLevelOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="隐患描述" prop="measures">
          <el-input v-model="form.measures" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="隐患危害" prop="troubleHarm">
          <el-input v-model="form.troubleHarm" placeholder="请输入隐患危害" />
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="上报人" prop="escalation">
              <!--<el-input v-model="form.escalation" placeholder="请输入隐患上报人" />-->
              <el-select v-model="form.escalation" filterable placeholder="请选择">
                <el-option
                  v-for="item in staffList"
                  :key="item.staffId"
                  :label="item.staffName"
                  :value="item.staffId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发现时间" prop="findTime">
              <el-date-picker clearable size="small"
                              v-model="form.findTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择隐患上报时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <!--<el-form-item label="现场照片" prop="picture">-->
        <!--<el-input v-model="form.picture" placeholder="请输入现场照片" />-->
        <!--</el-form-item>-->
        <el-form-item label="现场照片" v-if="!readOnly" prop="picture">
          <MyFileUpload
            listType="picture-card"
            @resFun="getFileInfo($event,0)"
            @remove="listRemove($event,0)"
            :fileArr="fileList"
          />
          <el-input v-show="false" disabled v-model="form.picture"></el-input>
        </el-form-item>

        <el-form-item label="隐患附件" prop="enclosure" v-if="zhong==1">
          <!--<el-input v-model="form.enclosure" placeholder="请输入隐患附件" />-->
          <FileUpload
            listType="picture"
            @resFun="getFileInfo($event,3)"
            @remove="listRemove($event,3)"
            :fileArr="fileList3"
          />
          <el-input v-show="false" disabled v-model="form.enclosure"></el-input>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="责任部门" prop="deptId">
              <!--<el-input v-model="form.deptId" placeholder="请输入部门id" />-->
              <el-select v-model="form.deptId" filterable placeholder="请选择责任部门">
                <el-option
                  v-for="dict in deptList"
                  :key="dict.deptId"
                  :label="dict.deptName"
                  :value="parseInt(dict.deptId)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改时限" prop="rectificationTerm">
              <el-date-picker clearable size="small"
                              v-model="form.rectificationTerm"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择整改时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="整改建议" prop="proposal">
          <el-input type="textarea" v-model="form.proposal" placeholder="请输入整改建议" />
        </el-form-item>

        <!--<el-form-item label="投入费用" prop="investmentCost" v-if="zhong==1">-->
        <!--<el-input v-model="form.investmentCost" placeholder="请输入投入费用" />-->
        <!--</el-form-item>-->
        <!--<el-form-item label="投入物资" prop="investmentMaterial" v-if="zhong==1">-->
        <!--<el-input v-model="form.investmentMaterial" placeholder="请输入投入物资" />-->
        <!--</el-form-item>-->
        <el-divider content-position="left" v-if="zhong==2||fast"><i class="el-icon-info"></i><span class="boxx">整改信息</span></el-divider>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="整改人" prop="rectification" v-if="zhong==2||fast">
              <el-select v-model="form.rectification" filterable placeholder="请选择">
                <el-option
                  v-for="item in staffList"
                  :key="item.staffId"
                  :label="item.staffName"
                  :value="item.staffId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改时间" prop="rectificationTime" v-if ="zhong==2||fast">
              <el-date-picker clearable size="small"
                              v-model="form.rectificationTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择整改时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="整改图片" v-if="!readOnly &&( zhong==2 || fast)" prop="rectificationPictrue" >
          <MyFileUpload
            listType="picture-card"
            @resFun="getFileInfo($event,1)"
            @remove="listRemove($event,1)"
            :fileArr="fileList1"
          />
          <el-input v-show="false" disabled v-model="form.rectificationPictrue"></el-input>
        </el-form-item>


        <el-form-item label="整改描述" prop="rectificationText" v-if="zhong==2||fast">
          <el-input v-model="form.rectificationText" placeholder="请输入整改描述" />
        </el-form-item>
        <!--
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        -->
        <el-divider content-position="left" v-if="!readOnly &&  fast"><i class="el-icon-info"></i><span class="boxx">复查信息</span></el-divider>
        <el-form-item label="复查图片" v-if="!readOnly &&  fast" prop="picture">
          <MyFileUpload
            listType="picture-card"
            @resFun="getFileInfo($event,2)"
            @remove="listRemove($event,2)"
            :fileArr="fileList2"
          />
          <el-input v-show="false" disabled v-model="form.inspectPictrue"></el-input>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="复查时间" prop="inspectTime" v-if ="fast">
              <el-date-picker clearable size="small"
                              v-model="form.inspectTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择复查时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="复查人" prop="personLiable" v-if ="fast">
              <el-select v-model="form.personLiable" filterable placeholder="请选择">
                <el-option
                  v-for="item in staffList"
                  :key="item.staffId"
                  :label="item.staffName"
                  :value="item.staffId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="复查描述" prop="inspectResult" v-if ="fast">
          <el-input type="textarea" v-model="form.inspectResult" placeholder="请输入复查结果描述" />
        </el-form-item>



      </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="title" :visible.sync="open2" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-divider content-position="left"><i class="el-icon-info"></i><span class="boxx">隐患信息</span></el-divider>
        <el-form-item label="隐患名称">
          <el-input v-model="form.troubleName" placeholder="请输入隐患名称" disabled/>

        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="隐患类型" prop="troubleType" width="50%" >
              <el-select v-model="form.troubleType" placeholder="请选择隐患类型" disabled >
                <el-option
                  v-for="dict in troubleTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="隐患等级" prop="troubleLevel">
              <el-select v-model="form.troubleLevel" placeholder="请选择隐患等级" disabled>
                <el-option
                  v-for="dict in troubleLevelOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="隐患描述" prop="measures">
          <el-input v-model="form.measures" type="textarea" placeholder="请输入内容" disabled/>
        </el-form-item>
        <el-form-item label="隐患危害" prop="troubleHarm">
          <el-input v-model="form.troubleHarm" placeholder="请输入隐患危害" disabled/>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="上报人" prop="escalation">
              <!--<el-input v-model="form.escalation" placeholder="请输入隐患上报人" />-->
              <el-select v-model="form.escalation" filterable placeholder="请选择" disabled>
                <el-option
                  v-for="item in staffList"
                  :key="item.staffId"
                  :label="item.staffName"
                  :value="item.staffId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发现时间" prop="findTime" >
              <el-date-picker clearable size="small"
                              v-model="form.findTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择隐患上报时间" disabled>
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <!--<el-form-item label="现场照片" prop="picture">-->
        <!--<el-input v-model="form.picture" placeholder="请输入现场照片" />-->
        <!--</el-form-item>-->

        <el-form-item label="现场照片"  prop="picture">
          <img :src="form.picture" style="width: 20%;vertical-align:middle;cursor:pointer;" @click="showPicture(form)"/>
          <el-image :zIndex="9999" :ref="'a'+form.id" :src="form.picture" v-show="false" :preview-src-list="[form.picture]" v-if="form.picture != '' && form.picture != null"></el-image>
        </el-form-item>
        <el-form-item label="隐患附件" prop="enclosure" v-if="zhong==1">
          <!--<el-input v-model="form.enclosure" placeholder="请输入隐患附件" />-->
            <span
              style="padding-top: 10px;"
              class="dbtn"
              @click="checkFile(form.enclosure)"
              v-if="form.enclosure != null && form.enclosure!=''"
            >
                    <i class="el-icon el-icon-view"></i>查看/下载
                  </span>
            <span v-else>-</span>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="责任部门"  prop="deptId">
              <!--<el-input v-model="form.deptId" placeholder="请输入部门id" />-->
              <el-select v-model="form.deptId"  filterable  placeholder="请选择责任部门" disabled>
                <el-option
                  v-for="dict in deptList"
                  :key="dict.deptId"
                  :label="dict.deptName"
                  :value="dict.deptId"
                ></el-option>
              </el-select>

            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改时限" prop="rectificationTerm">
              <el-date-picker clearable size="small"
                              v-model="form.rectificationTerm"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择整改时间" disabled>

              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="整改建议" prop="proposal">
          <el-input type="textarea" v-model="form.proposal" placeholder="请输入整改建议" disabled/>
        </el-form-item>

      <el-divider content-position="left"><i class="el-icon-info"></i><span class="boxx">整改信息</span></el-divider>
        <!--<el-form-item label="投入费用" prop="investmentCost" v-if="zhong==1">-->
          <!--<el-input v-model="form.investmentCost" placeholder="请输入投入费用" disabled/>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="投入物资" prop="investmentMaterial" v-if="zhong==1">-->
          <!--<el-input v-model="form.investmentMaterial" placeholder="请输入投入物资" disabled/>-->
        <!--</el-form-item>-->
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
          <el-form-item label="整改人" prop="rectification" >
            <el-select v-model="form.rectification" filterable placeholder="请选择" disabled>
              <el-option
                v-for="item in staffList"
                :key="item.staffId"
                :label="item.staffName"
                :value="item.staffId">
              </el-option>
            </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="整改时间" prop="rectificationTime" >
            <el-date-picker clearable size="small"
                            v-model="form.rectificationTime"
                            type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="选择整改时间" disabled>
            </el-date-picker>
          </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="整改图片"  prop="picture">
          <img :src="form.rectificationPictrue" style="width: 20%;vertical-align:middle;cursor:pointer;" @click="showPicture(form)"/>
          <el-image :zIndex="9999" :ref="'a'+form.id" :src="form.rectificationPictrue" v-show="false" :preview-src-list="[form.rectificationPictrue]" v-if="form.rectificationPictrue != '' && form.rectificationPictrue != null"></el-image>
        </el-form-item>
        <el-form-item label="整改描述" prop="rectificationText" >
          <el-input v-model="form.rectificationText" placeholder="请输入整改描述" disabled/>
        </el-form-item>
        <!--
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" disabled/>
        </el-form-item>
        -->
      <el-divider content-position="left"><i class="el-icon-info"></i><span class="boxx">复查信息</span></el-divider>
        <el-form-item label="复查图片" prop="picture">
          <img :src="form.inspectPictrue" style="width: 20%;vertical-align:middle;cursor:pointer;" @click="showPicture(form)"/>
          <el-image :zIndex="9999" :ref="'a'+form.id" :src="form.inspectPictrue" v-show="false" :preview-src-list="[form.inspectPictrue]" v-if="form.picture != '' && form.inspectPictrue != null"></el-image>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
                <el-form-item label="复查人"  >
                  <el-select v-model="form.personLiable" filterable placeholder="请选择" disabled>
                    <el-option
                      v-for="item in staffList"
                      :key="item.staffId"
                      :label="item.staffName"
                      :value="item.staffId">
                    </el-option>
                  </el-select>
                </el-form-item>
          </el-col>
          <el-col :span="12">
          <el-form-item label="复查时间" prop="inspectTime" >
            <el-date-picker clearable size="small"
                            v-model="form.inspectTime"
                            type="datetime"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            placeholder="选择复查时间" disabled>
            </el-date-picker>
          </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="复查描述" prop="inspectResult" style="padding-bottom: 16px;">
          <el-input type="textarea" v-model="form.inspectResult" placeholder="请输入复查结果描述" disabled/>
        </el-form-item>



      </el-form>
    </el-dialog>
    <!--整改复查-->
    <el-dialog :title="title" :visible.sync="open3" width="900px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
      <el-divider content-position="left"><i class="el-icon-info"></i><span class="boxx">隐患信息</span></el-divider>
        <el-form-item label="隐患名称" prop="troubleName">
          <el-input v-model="form.troubleName" placeholder="请输入隐患名称" disabled/>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="隐患类型" prop="troubleType" width="50%" >
              <el-select v-model="form.troubleType" placeholder="请选择隐患类型" @change="changeType" disabled>
                <el-option
                  v-for="dict in troubleTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="隐患等级" prop="troubleLevel">
              <el-select v-model="form.troubleLevel" placeholder="请选择隐患等级" disabled>
                <el-option
                  v-for="dict in troubleLevelOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-form-item label="隐患描述" prop="measures">
          <el-input v-model="form.measures" type="textarea" placeholder="请输入内容" disabled/>
        </el-form-item>
        <el-form-item label="隐患危害" prop="troubleHarm">
          <el-input v-model="form.troubleHarm" placeholder="请输入隐患危害" disabled/>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="上报人" prop="escalation">
              <!--<el-input v-model="form.escalation" placeholder="请输入隐患上报人" />-->
              <el-select v-model="form.escalation" filterable placeholder="请选择" disabled>
                <el-option
                  v-for="item in staffList"
                  :key="item.staffId"
                  :label="item.staffName"
                  :value="item.staffId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发现时间" prop="findTime" >
              <el-date-picker clearable size="small" disabled
                              v-model="form.findTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择隐患上报时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <!--<el-form-item label="现场照片" prop="picture">-->
        <!--<el-input v-model="form.picture" placeholder="请输入现场照片" />-->
        <!--</el-form-item>-->
        <el-form-item label="现场照片" v-if="!readOnly" prop="picture">
          <img style="width: 150px;height: 150px" :src="form.picture">

          </img>
        </el-form-item>

        <el-form-item label="隐患附件" prop="enclosure" v-if="zhong==1">
          <!--<el-input v-model="form.enclosure" placeholder="请输入隐患附件" />-->
          <span
            style="padding-top: 10px;"
            class="dbtn"
            @click="checkFile(form.enclosure)"
            v-if="form.enclosure != null && form.enclosure!=''"
          >
                    <i class="el-icon el-icon-view"></i>查看/下载
                  </span>
          <span v-else>-</span>
        </el-form-item>
        <el-row :gutter="24" class="mb8">
          <el-col :span="12">
            <el-form-item label="责任部门" prop="deptId">
              <!--<el-input v-model="form.deptId" placeholder="请输入部门id" />-->
              <el-select v-model="form.deptId" filterable placeholder="请选择责任部门" disabled>
                <el-option
                  v-for="dict in deptList"
                  :key="dict.deptId"
                  :label="dict.deptName"
                  :value="parseInt(dict.deptId)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改时限" prop="rectificationTerm">
              <el-date-picker clearable size="small" disabled
                              v-model="form.rectificationTerm"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择整改时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="整改建议" prop="proposal">
          <el-input type="textarea" v-model="form.proposal" placeholder="请输入整改建议" disabled/>
        </el-form-item>
        <!--
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" disabled/>
        </el-form-item>
        -->
        <!--<el-form-item label="投入费用" prop="investmentCost" v-if="zhong==1">
        <!--<el-input v-model="form.investmentCost" placeholder="请输入投入费用" />-->
        <!--</el-form-item>-->
        <!--<el-form-item label="投入物资" prop="investmentMaterial" v-if="zhong==1">-->
        <!--<el-input v-model="form.investmentMaterial" placeholder="请输入投入物资" />-->
        <!--</el-form-item>-->
        <el-divider content-position="left" ><i class="el-icon-info"></i><span class="boxx">整改信息</span></el-divider>
                <el-row :gutter="24" class="mb8">
                  <el-col :span="12">
                    <el-form-item label="整改人" prop="rectification"  >
                      <el-select v-model="form.rectification" filterable placeholder="请选择" :disabled="disabled">
                        <el-option
                          v-for="item in staffList"
                          :key="item.staffId"
                          :label="item.staffName"
                          :value="item.staffId">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="整改时间" prop="rectificationTime" >
                      <el-date-picker clearable size="small"
                                      :disabled="disabled"
                                      v-model="form.rectificationTime"
                                      type="datetime"
                                      value-format="yyyy-MM-dd HH:mm:ss"
                                      placeholder="选择整改时间">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  </el-row>
        <el-form-item label="整改图片" v-if="!disabled" prop="rectificationPictrue" >
          <MyFileUpload
            listType="picture-card"
            @resFun="getFileInfo($event,1)"
            @remove="listRemove($event,1)"
            :fileArr="fileList1"
          />
          <el-input v-show="false" disabled v-model="form.rectificationPictrue"></el-input>
        </el-form-item>
        <el-form-item label="整改照片" v-if="disabled" prop="picture">
          <img style="width: 150px;height: 150px" :src="form.rectificationPictrue">

          </img>
        </el-form-item>

        <el-form-item label="整改描述" prop="rectificationText" >
          <el-input type="textarea" v-model="form.rectificationText" placeholder="请输入整改描述" :disabled="disabled" />
        </el-form-item>

        <el-divider content-position="left"  v-if="disabled" ><i class="el-icon-info"></i><span class="boxx">复查信息</span></el-divider>
          <el-row :gutter="24" class="mb8">
            <el-col :span="12">
              <el-form-item label="复查人" prop="personLiable" v-if="disabled">
                <el-select v-model="form.personLiable" filterable placeholder="请选择">
                  <el-option
                    v-for="item in staffList"
                    :key="item.staffId"
                    :label="item.staffName"
                    :value="item.staffId">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="复查时间" prop="inspectTime" v-if="disabled">
                <el-date-picker clearable size="small"
                                v-model="form.inspectTime"
                                type="datetime"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                placeholder="选择复查时间" >
                </el-date-picker>
              </el-form-item>
            </el-col>
           </el-row>

        <el-form-item label="复查图片" v-if="disabled" prop="picture">
          <MyFileUpload
            listType="picture-card"
            @resFun="getFileInfo($event,2)"
            @remove="listRemove($event,2)"
            :fileArr="fileList2"
          />
          <el-input v-show="false" disabled v-model="form.inspectPictrue"></el-input>
        </el-form-item>

        <el-form-item label="复查时间" prop="inspectTime" v-if ="fast">
          <el-date-picker clearable size="small"
                          v-model="form.inspectTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="选择复查时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="复查描述" prop="inspectResult" v-if="disabled">
          <el-input type="textarea" v-model="form.inspectResult" placeholder="请输入复查结果描述" />
        </el-form-item>



      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import MyFileUpload from '@/components/MyFileUpload';
  import FileUpload from '@/components/FileUpload';
import { listBook, getBook, delBook, addBook, updateBook, exportBook } from "@/api/system/book";
import { listDept } from "@/api/system/dept";
  import { listStaff } from "@/api/safetyManagement/staff";
  let uploadfile = require("@/assets/uploadfile.png");
export default {
  name: "Book",
  components: {
    MyFileUpload,FileUpload
  },
  data() {
    return {
      readOnly:false,
      disabled:false,
      disabled2:false,
      fast:false,
      fileList:[],
      fileList1:[],
      fileList2:[],
      fileList3:[],
      options: [{
        value: '0',
        label: '待整改'
      }, {
        value: '1',
        label: '待复查'
      }, {
        value: '2',
        label: '已闭环'
      }],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 隐患台账表格数据
      bookList: [],
      // 弹出层标题
      title: "",
      //重大隐患项 0 一般隐患 1重大隐患 2现改隐患
      zhong: 0,
      // 是否显示弹出层
      open: false,
      open2:false,
      open3:false,
      // 隐患类型字典
      troubleTypeOptions: [],
      // 隐患等级字典
      troubleLevelOptions: [],
      deptList:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        troubleName: null,
        findTime: null,
        rectificationTime: null,
        state: null,
      },
      queryParams2:{
        pageNum: 1,
        pageSize: 2000,
        staffName:""
      },
      staffList:[],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        troubleName: [
          { required: true, message: "隐患名称不能为空", trigger: "blur" }
        ],
        troubleType:[
          { required: true, message: "隐患类型不能为空", trigger: "change" }
        ],
        troubleLevel: [
          { required: true, message: "隐患等级不能为空", trigger: "change" }
        ],
        escalation: [
          { required: true, message: "上报人不能为空", trigger: "blur" }
        ],
        findTime: [
          { required: true, message: "上报时间不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "责任部门不能为空", trigger: "blur" }
        ],
        rectificationTerm:[
          { required: true, message: "整改时限不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getDeptList();
    this.getStaffList();
    this.getDicts("t_trouble_type").then(response => {
      this.troubleTypeOptions = response.data;
    });
    this.getDicts("t_trouble_level").then(response => {
      this.troubleLevelOptions = response.data;
    });
  },
  methods: {
    /** 查询隐患台账列表 */
    getList() {
      this.loading = true;
      listBook(this.queryParams).then(response => {
        this.bookList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    checkFile(url) {
      window.open(url,'_blank');
    },
    /** 查询员工列表 */
    getStaffList() {
      this.loading = true;
      listStaff(this.queryParams2).then(response => {
        this.staffList = response.rows;
      this.loading = false;
    }
    );
    },
    getDeptList() {
      listDept({status: undefined}).then(response => {
        this.deptList = response.data;
      console.log(this.deptList)
    });
    },
    // 隐患类型字典翻译
    troubleTypeFormat(row, column) {
      return this.selectDictLabel(this.troubleTypeOptions, row.troubleType);
    },
    // 隐患等级字典翻译
    troubleLevelFormat(row, column) {
      return this.selectDictLabel(this.troubleLevelOptions, row.troubleLevel);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.fileList=[];
      this.fileList1=[];
      this.fileList2=[];
    },
    cancel2() {
      this.open3 = false;
      this.reset();
      this.fileList=[];
      this.fileList1=[];
      this.fileList2=[];
     },
    // 表单重置
    reset() {
      this.form = {
        bookId: null,
        troubleName: null,
        troubleType: null,
        troubleLevel: null,
        measures: null,
        troubleHarm: null,
        escalation: null,
        findTime: null,
        picture: null,
        enclosure: null,
        proposal: null,
        rectificationTerm:null,
        investmentCost: null,
        investmentMaterial: null,
        rectification: null,
        rectificationPictrue: null,
        rectificationText: null,
        rectificationTime: null,
        remarks: null,
        finishDay: null,
        inspectPictrue: null,
        inspectTime: null,
        inspectResult: null,
        personLiable: null,
        state: null,
        deptId: null,
        workId: null,
        createTime: null,
        createBy: null,
        isDel: null
      };
      this.resetForm("form");
      this.fileList=[];
      this.fileList1=[];
      this.fileList2=[];
      this.fileList3=[];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.bookId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.zhong = 0;
      this.fast = false;
      this.reset();
      this.open = true;
      this.title = "添加隐患台账";
    },
    handleFastAdd() {
      this.reset();
      this.fast=true;
      this.open = true;
      this.title = "添加隐患台账";
      this.zhong = 3;
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const bookId = row.bookId || this.ids
      getBook(bookId).then(response => {
        this.form = response.data;
        if(this.form.troubleLevel==1){
          this.zhong = 1
        }else{
          this.zhong = 0
        }
        if (this.form.picture) {
          this.fileList.push({
            url: this.form.picture,
          });
        }
      if (this.form.rectificationPictrue) {
        this.fileList1.push({
          url: this.form.rectificationPictrue,
        });
      }
      if (this.form.inspectPictrue) {
        this.fileList2.push({
          url: this.form.inspectPictrue,
        });
      }
      if (this.form.enclosure) {
        this.fileList3 = [{name: 'file', url:uploadfile}];
      }
        this.open3 = true;
        this.title = "隐患台账整改";
      });
    },
    /** 修改按钮操作 */
    handlecha(row) {
      this.reset();
      const bookId = row.bookId || this.ids
      getBook(bookId).then(response => {
        this.form = response.data;
      if(this.form.troubleLevel==1){
        this.zhong = 1
      }else{
        this.zhong = 0
      }
      if (this.form.picture) {
        this.fileList.push({
          url: this.form.picture,
        });
      }
      if (this.form.rectificationPictrue) {
        this.fileList1.push({
          url: this.form.rectificationPictrue,
        });
      }
      if (this.form.inspectPictrue) {
        this.fileList2.push({
          url: this.form.inspectPictrue,
        });
      }
      if (this.form.enclosure) {
        this.fileList3 = [{name: 'file', url:uploadfile}];
      }
      this.open3 = true;
      this.disabled = true;
      this.title = "隐患台账复查";
    });
    },
    handleDetail(row) {
      this.reset();
      const bookId = row.bookId || this.ids
      getBook(bookId).then(response => {
        this.form = response.data;
      if(this.form.troubleLevel==1){
        this.zhong = 1
      }
      if (this.form.picture) {
        this.fileList.push({
          url: this.form.picture,
        });
      }
      if (this.form.inspectPictrue) {
        this.fileList2.push({
          url: this.form.inspectPictrue,
        });
      }
      if (this.form.rectificationPictrue) {
        this.fileList1.push({
          url: this.form.rectificationPictrue,
        });
      }
      if (this.form.enclosure) {
        this.fileList3 = [{name: 'file', url:uploadfile}];
      }
      this.open2 = true;
      this.title = "隐患详细信息";
    });
    },
    getFileInfo(res,num){
      if(num==0){
        this.form.picture = res.url;
      }else  if(num==1){
        this.form.rectificationPictrue = res.url;
      }else if(num==2){
        this.form.inspectPictrue = res.url;
      }else if(num==3){
        this.form.enclosure = res.url;
        this.fileList3.push({
          name: res.fileName,
          url: uploadfile,
        });
        console.log(this.fileList3)
      }
      //this.form.picture = res.url;
      //this.$set(this.feedBookForm,'iconUrl',res.url)
    },
    listRemove(e,num) {
      console.log(e)
      if(num==0){
        this.fileList = [];
        this.form.picture="";
      }else  if(num==1){
        this.fileList1 = [];
        this.form.rectificationPictrue="";
      }else if(num==2){
        this.fileList2 = [];
        this.form.inspectPictrue = "";
      }else if(num==3){
        this.fileList3 = [];
        this.form.enclosure = "";
      }
    },
    showPicture(row){
      this.$refs['a'+row.id].showViewer = true;
      console.log("===",row.id);
    },
    changeType(){
      console.log(this.form.troubleLevel);
      if(this.form.troubleLevel==4){
        this.zhong = 2;
      }else if(this.form.troubleLevel==1){
        this.zhong = 1;
      }else{
        this.zhong = 0;
      }
    },
    /** 提交按钮 */
    submitForm() {
      console.log(this.form);
      if(this.fast){
        this.form.state = 2;
      }else if(this.form.troubleLevel==4){
        this.form.state = 1;
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.bookId != null) {
            if(this.disabled){
              this.form.state = 2;
            }else {
              this.form.state = 1;
            }
            updateBook(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.open3 = false;
              this.getList();
            });
          } else {
            addBook(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const bookIds = row.bookId || this.ids;
      this.$confirm('是否确认删除隐患台账编号为"' + bookIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBook(bookIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有隐患台账数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportBook(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style lang="scss" scoped>
  .allone{
    display:flex;
    flex-direction:row;
    justify-content:flex-start;
  }
  ::v-deep .el-select{
    width: 100%;
  }
  ::v-deep .el-dialog__header{
    border-bottom: 1px solid #ccc;
  }
  ::v-deep .el-date-editor.el-input{
    width: 100%;
  }
  ::v-deep .el-input.is-disabled .el-input__inner {
    color: #606266;
  }
  ::v-deep .el-form-item {
    margin-bottom: 18px;
  }
.boxd{
  width: 100%;
  height: 30px;
  display: flex;
  justify-content: center;
  margin-bottom: 10px;

}
  .dbtn {
    display: inline-block;
    line-height: normal;
    padding-left: 2px;
    padding-right: 2px;
    cursor: pointer;
    border-radius: 3px;
    border-style: solid;
    border-width: 0;
    color: rgb(48, 180, 107);
  }
.boxx {
    font-size: 17px;
    font-weight: bold;
    padding-left: 5px;
  }
::v-deep .el-dialog__body{
  padding:0px 20px!important;
}
</style>
