<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="隐患名称" prop="hiddenTroubleName">
        <el-input
          v-model="queryParams.hiddenTroubleName"
          placeholder="请输入隐患名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上报人" prop="reportPerson">
        <el-input
          v-model="queryParams.reportPerson"
          placeholder="请输入上报人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="上报时间">
        <el-date-picker
          is-range
          v-model="reportDate"
          size="small"
          type="datetimerange"
          range-separator="至"
          @change="timeChange"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="隐患来源" prop="hiddenTroubleLevel">
        <el-select v-model="queryParams.hiddenSource" placeholder="请选择隐患等级" style="width: 100%;">
          <el-option label="巡线" value="1" />
          <el-option label="入户安检" value="2" />
        </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"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="隐患名称" align="center" prop="hiddenTroubleName" >
        <span slot-scope="scope" v-if="scope.row.hiddenTroubleName">{{scope.row.hiddenTroubleName}}</span>
        <span v-else>-</span>
      </el-table-column>
      <el-table-column label="隐患等级" align="center" prop="hiddenTroubleLevel">
        <template slot-scope="scope">
          <span v-if="scope.row.hiddenTroubleLevel == 1">一级隐患</span>
          <span v-if="scope.row.hiddenTroubleLevel == 2">二级隐患</span>
          <span v-if="scope.row.hiddenTroubleLevel == 3">三级隐患</span>
        </template>
      </el-table-column>
      <el-table-column label="隐患类型" align="center" prop="hiddenTroubleType">
        <template slot-scope="scope">
          <span v-if="scope.row.hiddenTroubleType == 1">漏气</span>
          <span v-if="scope.row.hiddenTroubleType == 2">腐蚀</span>
          <span v-if="scope.row.hiddenTroubleType == 3">裂缝</span>
          <span v-if="scope.row.hiddenTroubleType == 4">设备故障</span>
          <span v-if="scope.row.hiddenTroubleType == 5">安全距离不足</span>
          <span v-if="scope.row.hiddenTroubleType == 6">管道承重</span>
          <span v-if="scope.row.hiddenTroubleType == 7">其他</span>
        </template>

      </el-table-column>
      <el-table-column label="隐患来源" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.hiddenSource == 1">巡线</span>
          <span v-if="scope.row.hiddenSource == 2">入户安检</span>
        </template>

      </el-table-column>
      <!--      <el-table-column label="经度" align="center" prop="longitude" />-->
      <!--      <el-table-column label="纬度" align="center" prop="latitude" />-->
      <el-table-column label="隐患描述" align="center" prop="hiddenTroubleDescribe" >
        <span slot-scope="scope" v-if="scope.row.hiddenTroubleDescribe">{{scope.row.hiddenTroubleDescribe}}</span>
        <span v-else>-</span>
      </el-table-column>
      <!--<el-table-column label="照片" align="center"  >
        <template slot-scope="scope">
&lt;!&ndash;          <img  :src="List.row.pictureUrl" width="100px">&ndash;&gt;
          <div class="demo-image__preview">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.Url"
              :preview-src-list="scope.row.pictureUrl">
            </el-image>
          </div>
        </template>
      </el-table-column>-->

      <el-table-column label="上报时间" align="center" prop="reportTime" width="180">
        <template slot-scope="scope" >
          <span v-if="scope.row.reportTime">{{scope.row.reportTime}}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="上报人" align="center" prop="reportPerson" >
        <span slot-scope="scope" v-if="scope.row.reportPerson">{{scope.row.reportPerson}}</span>
        <span v-else>-</span>
      </el-table-column>
      <el-table-column label="隐患处理状态" align="center" prop="hiddenTroubleDealStatus">
        <template slot-scope="scope">
          <span v-if="scope.row.hiddenTroubleDealStatus == 1" style="color: #ff7272">待处理</span>
          <span v-if="scope.row.hiddenTroubleDealStatus == 2" style="color: #ffba00">处理中</span>
          <span v-if="scope.row.hiddenTroubleDealStatus == 3" style="color: #30B46B">已完成</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="隐患处理情况" align="center" prop="hiddenTroubleDealCondition" >-->
      <!--        <span slot-scope="scope" v-if="scope.row.hiddenTroubleDealCondition">{{scope.row.hiddenTroubleDealCondition}}</span>-->
      <!--        <span v-else>-</span>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="隐患处理完成时间" align="center" prop="hiddenTroubleDealFinishTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span v-if="scope.row.hiddenTroubleDealFinishTime">{{ parseTime(scope.row.hiddenTroubleDealFinishTime, '{y}-{m}-{d} {h}:{m}:{s}') }}</span>-->
      <!--          <span v-else>-</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="备注" align="center" prop="remarks" >-->
      <!--        <span slot-scope="scope" v-if="scope.row.remarks">{{scope.row.remarks}}</span>-->
      <!--        <span v-else>-</span>-->
      <!--      </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.hiddenTroubleDealStatus == 3 && $store.state.user.roles.indexOf('gov') == '-1'"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="details(scope.row)"
          >详情</el-button>
          <el-button v-if="scope.row.hiddenTroubleDealStatus != 3"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
          <el-button v-if="scope.row.hiddenTroubleDealStatus != 3 && $store.state.user.roles.indexOf('gov') == '-1'"
                     size="mini"
                     type="text"
                     icon="el-icon-news"
                     @click="handlingHiddenDangers(scope.row)"
          >处理隐患</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.isReport == '0'"
            @click="report(scope.row)"
          >上报</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="hiddenDangertitle" :visible.sync="hiddenDanger"  width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="hiddenDangerRules" label-width="140px">

        <el-row>
          <el-col :span="11">
            <el-form-item label="隐患处理状态"  prop="hiddenTroubleDealStatus">
              <el-select v-model="form.hiddenTroubleDealStatus" placeholder="请选择隐患处理状态" style="width: 100%;">
                <!--                <el-option label="待处理" value="1" />-->
                <el-option label="处理中" value="2" />
                <el-option label="已完成" value="3" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11" >
            <el-form-item label="隐患处理完成时间" v-if="form.hiddenTroubleDealStatus==3" prop="hiddenTroubleDealFinishTime">
              <el-date-picker clearable size="small"
                              v-model="form.hiddenTroubleDealFinishTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择隐患处理完成时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
            <el-form-item label="隐患处理情况" v-if="form.hiddenTroubleDealStatus==3"  prop="hiddenTroubleDealCondition">
              <el-input v-model="form.hiddenTroubleDealCondition" type="textarea" placeholder="请输入隐患处理情况" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="23">
            <el-form-item label="上传照片"   v-if="form.hiddenTroubleDealStatus==3">
              <FileUpload 
                listType="picture"
                @resFun="getFileInfon"
                @remove="listRemoven"
                :fileArr="fileListn">
              </FileUpload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormHiddenDanger">确 定</el-button>
        <el-button @click="hiddenDangerCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 燃气隐患详情对话框 -->
    <el-dialog :title="detailsTitle" :visible.sync="detailsOpen" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="hiddenDangerRules" label-width="150px">

        <el-row>
          <el-col :span="22">
            <el-form-item label="隐患名称" prop="hiddenTroubleName">
              <el-input v-model="form.hiddenTroubleName" placeholder="请输入隐患名称" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="隐患等级" prop="hiddenTroubleLevel">
              <el-select v-model="form.hiddenTroubleLevel" placeholder="请选择隐患等级" style="width: 100%;":disabled="true">
                <el-option label="一级隐患" value="1" />
                <el-option label="二级隐患" value="2" />
                <el-option label="三级隐患" value="3" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11">
            <el-form-item label="隐患类型" prop="hiddenTroubleType">
              <el-select v-model="form.hiddenTroubleType" placeholder="请选择隐患类型" style="width: 100%;":disabled="true">
                <el-option label="漏气" value="1" />
                <el-option label="腐蚀" value="2" />
                <el-option label="裂缝" value="3" />
                <el-option label="设备故障" value="4" />
                <el-option label="安全距离不足" value="5" />
                <el-option label="管道承重" value="6" />
                <el-option label="其他" value="7" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
            <el-form-item label="隐患描述" prop="hiddenTroubleDescribe">
              <el-input v-model="form.hiddenTroubleDescribe" type="textarea" placeholder="请输入隐患描述" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="25">
            <el-form-item label="经纬度坐标" prop="longitude" :disabled="true">
              <el-col :span="9">
                <el-input v-model="form.longitude" placeholder="请输入经度" :disabled="true"/>
              </el-col>
              <el-col :span="9" style="margin-left: 13px">
                <el-input v-model="form.latitude" placeholder="请输入纬度" :disabled="true"/>
              </el-col>
              <el-col :span="4" style="margin-left: 30px">
                <el-button type="primary" plain @click="MapdialogFun" :disabled="true">选择经纬度</el-button>
              </el-col>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="23">
            <el-form-item label="上传照片" :disabled="true">
              <FileUpload
                :disabled="true"
                v-if="detailsOpen"
                listType="picture"
                @resFun="getFileInfo"
                @remove="listRemove"
                :fileArr="fileList">
              </FileUpload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="隐患处理状态"  prop="hiddenTroubleDealStatus">
              <el-select v-model="form.hiddenTroubleDealStatus" placeholder="请选择隐患处理状态" :disabled="true">
                <el-option label="待处理" value="1" />
                <el-option label="处理中" value="2" />
                <el-option label="已完成" value="3" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11">
            <el-form-item label="隐患处理完成时间" v-if="form.hiddenTroubleDealStatus==3" prop="hiddenTroubleDealFinishTime">
              <el-date-picker clearable size="small" :disabled="true"
                              v-model="form.hiddenTroubleDealFinishTime"
                              type="datetime"
                              value-format="yyyy-MM-dd HH:mm:ss"
                              placeholder="选择隐患处理完成时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="23">
            <el-form-item label="上传照片" :disabled="true"  v-if="form.hiddenTroubleDealStatus==3">
              <FileUpload
                :disabled="true"
                v-if="detailsOpen"
                listType="picture"
                @resFun="getFileInfon"
                @remove="listRemoven"
                :fileArr="fileListn">
              </FileUpload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="视频上传"  prop="videoUrl">
              <VideoUpload
                listType="picture"
                :disabled="true"
                v-if="detailsOpen"
                @resFun="getFileInfoVideo"
                @remove="listRemoveVideo"
                :fileArr="fileListVideo"
                :fileSize="20"
                :fileType="['mp4']"
              />
              <el-input v-show="false" disabled v-model="form.videoUrl"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
            <el-form-item label="隐患处理情况" v-if="form.hiddenTroubleDealStatus==3" prop="hiddenTroubleDealCondition" >
              <el-input v-model="form.hiddenTroubleDealCondition" type="textarea" placeholder="请输入隐患处理情况" :disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="22">
            <el-form-item label="所属单位" prop="beyondEnterpriseId">
              <el-select v-model="form.beyondEnterpriseId" placeholder="请选择所属单位名称" style="width: 100%" @change="selectworkAssignEnterprose($event)"  :disabled="true">
                <el-option
                  v-for="item in enterprises"
                  :key="item.enterpriseId"
                  :label="item.enterpriseName"
                  :value="item.enterpriseId"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <!--        <el-row>-->
        <!--          <el-col :span="22">-->
        <!--            <el-form-item label="备注" prop="remarks">-->
        <!--              <el-input v-model="form.remarks" type="textarea" placeholder="请输入备注" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->

      </el-form>


      <div slot="footer" class="dialog-footer">
        <el-button @click="detailsCancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改燃气隐患对话框 -->
    <el-dialog :title="title" :visible.sync="open" v-if="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">

        <el-row>
          <el-col :span="22">
            <el-form-item label="隐患名称" prop="hiddenTroubleName">
              <el-input v-model="form.hiddenTroubleName" placeholder="请输入隐患名称" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="11">
            <el-form-item label="隐患等级" prop="hiddenTroubleLevel">
              <el-select v-model="form.hiddenTroubleLevel" placeholder="请选择隐患等级" style="width: 100%;">
                <el-option label="一级隐患" value="1" />
                <el-option label="二级隐患" value="2" />
                <el-option label="三级隐患" value="3" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11">
            <el-form-item label="隐患类型" prop="hiddenTroubleType">
              <el-select v-model="form.hiddenTroubleType" placeholder="请选择隐患类型" style="width: 100%;">
                <el-option label="漏气" value="1" />
                <el-option label="腐蚀" value="2" />
                <el-option label="裂缝" value="3" />
                <el-option label="设备故障" value="4" />
                <el-option label="安全距离不足" value="5" />
                <el-option label="管道承重" value="6" />
                <el-option label="其他" value="7" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="22">
            <el-form-item label="隐患描述" prop="hiddenTroubleDescribe">
              <el-input v-model="form.hiddenTroubleDescribe" type="textarea" placeholder="请输入隐患描述" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="25">
            <el-form-item label="经纬度坐标" prop="longitude">
              <el-col :span="9">
                <el-input v-model="form.longitude" placeholder="请输入经度" />
              </el-col>
              <el-col :span="9" style="margin-left: 13px">
                <el-input v-model="form.latitude" placeholder="请输入纬度"/>
              </el-col>
              <el-col :span="4" style="margin-left: 30px">
                <el-button type="primary" plain @click="MapdialogFun">选择经纬度</el-button>
              </el-col>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="23">
            <el-form-item label="上传照片">
              <FileUpload
                listType="picture"
                v-if="open" 
                @resFun="getFileInfo"
                @remove="listRemove"
                :fileArr="fileList"
                >
              </FileUpload>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="视频上传"  prop="videoUrl">
              <VideoUpload
                listType="picture"
                v-if="open"
                @resFun="getFileInfoVideo"
                @remove="listRemoveVideo"
                :fileArr="fileListVideo"
                :fileSize="20"
                :fileType="['mp4']"
              />
              <el-input v-show="false" disabled v-model="form.videoUrl"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <!--        <el-row>-->
        <!--          <el-col :span="11">-->
        <!--           <el-form-item label="上报时间" prop="reportTime">-->
        <!--            <el-date-picker clearable size="small"-->
        <!--            v-model="form.reportTime"-->
        <!--            type="date"-->
        <!--            value-format="yyyy-MM-dd"-->
        <!--            placeholder="选择上报时间">-->
        <!--            </el-date-picker>-->
        <!--           </el-form-item>-->
        <!--          </el-col>-->

        <!--          <el-col :span="11">-->
        <!--        <el-form-item label="上报人" prop="reportPerson">-->
        <!--          <el-input v-model="form.reportPerson" placeholder="请输入上报人" />-->
        <!--        </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->

        <el-row>
          <el-col :span="11">
            <el-form-item label="隐患处理状态"  prop="hiddenTroubleDealStatus">
              <el-select v-model="form.hiddenTroubleDealStatus" placeholder="请选择隐患处理状态" style="width: 100%;":disabled="true">
                <el-option label="待处理" value="1" />
                <el-option label="处理中" value="2" />
                <el-option label="已完成" value="3" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="所属单位" prop="beyondEnterpriseId">
              <el-select v-model="form.beyondEnterpriseId" placeholder="请选择所属单位名称" style="width: 100%" @change="selectworkAssignEnterprose($event)">
                <el-option
                  v-for="item in enterprises"
                  :key="item.enterpriseId"
                  :label="item.enterpriseName"
                  :value="item.enterpriseId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <!--          <el-col :span="11">-->
          <!--            <el-form-item label="隐患处理完成时间" v-if="form.hiddenTroubleDealStatus==3" prop="hiddenTroubleDealFinishTime">-->
          <!--              <el-date-picker clearable size="small"-->
          <!--                              v-model="form.hiddenTroubleDealFinishTime"-->
          <!--                              type="datetime"-->
          <!--                              value-format="yyyy-MM-dd HH:mm:ss"-->
          <!--                              placeholder="选择隐患处理完成时间">-->
          <!--              </el-date-picker>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
        </el-row>

        <!--        <el-row>-->
        <!--          <el-col :span="22">-->
        <!--            <el-form-item label="隐患处理情况" v-if="form.hiddenTroubleDealStatus==3" prop="hiddenTroubleDealCondition">-->
        <!--              <el-input v-model="form.hiddenTroubleDealCondition" type="textarea" placeholder="请输入隐患处理情况" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->

        <!--        <el-row>-->
        <!--          <el-col :span="22">-->
        <!--            <el-form-item label="备注" prop="remarks">-->
        <!--              <el-input v-model="form.remarks" type="textarea" placeholder="请输入备注" />-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->

      </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>

    <GetPos
      :dialogVisible.sync="dialogTableVisibles"
      device=""
      :devicePos="devicePos"
      @close="dialogcancelFun"
      @getPath="getPath"
    />
  </div>
</template>

<script>
  import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo, reportGovernment } from "@/api/system/info";
  import GetPos from '@/components/GetPos';
  import FileUpload from '@/components/FileSuperviseUpload';
  import { enterpriseLists } from "@/api/regulation/info";
  import { getInspectionUsers } from "@/api/system/user";
  import VideoUpload from "@/components/VideoUpload";
  export default {
    name: "Info",
    components: {
      FileUpload,
      GetPos,
      VideoUpload,
    },
    data() {
      return {
        url: 'http://192.168.2.16:8905/gassafety/profile/upload/2023/09/08/c55c2d49-2839-46a0-b3cd-7ec1e344efba.jpg',
        srcList: [],
        pictureUrlList:[],
        pictureUrlListn:[],
        //头像
        fileList: [],
        fileListn:[],
        /**--------------地图使用数据---------------*/
        dialogTableVisibles: false,
        devicePos: [],
        /**--------------地图使用数据---------------*/
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        enterprises: [],
        // isDetail: false,
        // isEnterproser: true,
        // 总条数
        total: 0,
        // 燃气隐患表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        //处理隐患弹出层标题
        hiddenDangertitle:"",
        //详情弹出层标题
        detailsTitle:"",
        // 是否显示弹出层
        open: false,
        // 是否显示处理隐患弹出层
        hiddenDanger:false,
        //详情弹出层
        detailsOpen:false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          hiddenTroubleName: null,
          reportPerson: null,
          hiddenSource: null,
          reportBeginTime: null,
          reportEndTime: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          hiddenTroubleLevel: [
            { required: true, message: "请选择隐患等级", trigger: "blur" },
          ],
          hiddenTroubleName: [
            { required: true, message: "请输入隐患名称", trigger: "blur" },
          ],
          hiddenTroubleType: [
            { required: true, message: "请选择隐患类型", trigger: "blur" },
          ],
          beyondEnterpriseId: [
            { required: true, message: "所属单位必选", trigger: "blur" },
          ],
        },
        //隐患处理表单效验
        hiddenDangerRules: {
          hiddenTroubleDealFinishTime: [
            { required: true, message: "请选择隐患处理完成时间", trigger: "blur" },
          ],
          hiddenTroubleDealCondition: [
            { required: true, message: "请输入隐患处理情况", trigger: "blur" },
          ],
        },
        fileListVideo: [],
        reportDate: []
      };
    },
    created() {
      this.getList();
      this.getEnterpriseLists();
    },
    methods: {
      // 处理隐患时上传图片组合
      // pictureUrlListn
      // fileListn

      // 隐患信息 上传图片组合
      // pictureUrlList
      // fileList
      /**上传图片*/
      getFileInfo(res){ 
        this.form.dealPlan = res.fileName;
        this.pictureUrlList.push(res.url)
        this.form.pictureUrl=this.pictureUrlList.join(",");
        this.form.burl=res.burl;
        this.fileList.push({
          name: res.fileName,
          url: uploadfile,
          burl:res.burl,
        });
      },
      
      /**处理隐患 上传图片*/
      getFileInfon(res){ 
        this.form.dealPlan = res.fileName;
        this.pictureUrlListn.push(res.url)
        this.form.dealUrl=this.pictureUrlListn.join(",");
        this.form.burl=res.burl;
        this.fileListn.push({
          name: res.fileName,
          url: uploadfile,
          burl:res.burl,
        });
      },
      listRemove(e) {
        this.form.dealPlan = "";
        this.fileList.delete(e.uid)
        // this.fileList = [];
      },
      listRemoven(e) {
        this.form.dealPlan = "";
        this.fileListn.delete(e.uid)
        // this.fileList = [];
      },
      //所属单位
      getEnterpriseLists(){
        const param = {};
        // this.judgeOperateType(param);
        enterpriseLists(param).then(response => {
          if (response.rows.length>1){
            this.enterprises = response.rows;
          }else {
            this.form.beyondEnterpriseId=response.rows[0].enterpriseId
            this.enterprises = response.rows;
          }

      });
      },
      getInspectionUserList(enterpriseId){
        getInspectionUsers(enterpriseId,"se").then(response =>{
          this.inspectors = response.data;
      })
      },
      selectworkAssignEnterprose(enterpriseId){
        // this.form.workAssignManId = "";
        // this.workForm.workAssignManId = "";
        // this.workForm.workAssignMan="";
        // this.form.workAssignMan = "";
        this.getInspectionUserList(enterpriseId);
        // let enterpriseName = this.enterprises.find(val=>val.enterpriseId == enterpriseId).enterpriseName;
        // this.form.beyondEnterpriseId = enterpriseName;
      },
      /**
       * 经纬度 选择
       * @param res
       */
      getPath(res){
        //确认选择经纬度
        this.form.longitude = res[0];
        this.form.latitude = res[1];
      },
      /**
       * 地图关闭方法
       */
      dialogcancelFun() {
        this.dialogTableVisibles = false;
      },
      /**
       * 经纬度坐标方法
       */
      MapdialogFun() {
        this.dialogTableVisibles = true;
      },
      /**
       * 经纬度 选择
       * @param res
       */
      getPath(res){
        //确认选择经纬度
        this.form.longitude = res[0];
        this.form.latitude = res[1];
      },

      /** 查询燃气隐患列表 */
      getList() {
        this.loading = true;
        listInfo(this.queryParams).then(response => {
          for(var i = 0; i < response.rows.length; i++){
            if (response.rows[i].pictureUrl){
              response.rows[i].pictureUrl=response.rows[i].pictureUrl.split(",");
              response.rows[i].Url=response.rows[i].pictureUrl[0]
            }
          }
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.fileList = [];
      },
      //详情燃气框关闭
      detailsCancel(){
        this.detailsOpen = false;
        this.reset();
        this.fileList = [];
        this.getEnterpriseLists();
      },
      // 处理隐患表单取消按钮
      hiddenDangerCancel() {
        this.hiddenDanger=false;
        this.reset();
        this.fileList = [];
      },
      // 表单重置
      reset() {
        this.form = {
          hiddenTroubleId: null,
          workId: null,
          hiddenTroubleName: null,
          hiddenTroubleLevel: null,
          hiddenTroubleType: null,
          longitude: null,
          latitude: null,
          pictureUrl: null,
          hiddenTroubleDescribe: null,
          reportTime: null,
          reportPerson: null,
          hiddenTroubleDealStatus: '1',
          hiddenTroubleDealCondition: null,
          hiddenTroubleDealFinishTime: null,
          isDel: null,
          remarks: null,
          beyondEnterpriseId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.hiddenSource = null;
        this.queryParams.reportBeginTime = null;
        this.queryParams.reportEndTime = null;
        this.reportDate = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.hiddenTroubleId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();

        // 隐患信息 上传照片清空
        this.fileList = [];
        this.pictureUrlList = [];
        
        // 隐患处理 上传照片清空
        this.fileListn = [];
        this.pictureUrlListn = [];

        // 上传视频 清空
        this.fileListVideo = [];
        this.open = true;
        this.title = "添加隐患信息";
        this.getEnterpriseLists();
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.fileList=[]
        this.reset();
        const hiddenTroubleId = row.hiddenTroubleId || this.ids
        getInfo(hiddenTroubleId).then(response => {
          this.form = response.data;
        this.open = true;
          //图片回显
          if (this.form.pictureUrl){
            for(var i = 0; i < this.form.pictureUrl.split(',').length; i++){
              this.fileList.push({
                name: '照片',
                url: this.form.pictureUrl.split(',')[i],
              });
            }
          }

          if(this.form.videoUrl){
            this.fileListVideo = this.form.videoUrl.split(',');
          }


        //图片回显
        // if (this.form.pictureUrl) {
        //   this.fileList.push({
        //     name: '照片',
        //     url: this.form.pictureUrl,
        //   });
        // }
        this.title = "修改燃气隐患";
        this.getEnterpriseLists();
        this.devicePos = [response.data.longitude, response.data.latitude];
        // this.getInspectionUserList(response.data.beyondEnterpriseId);
      });
      },
      /**处理隐患按钮操作*/
      handlingHiddenDangers(row){
        this.fileListn=[]
        const hiddenTroubleId = row.hiddenTroubleId || this.ids
        getInfo(hiddenTroubleId).then(response => {
          this.form = response.data;
        this.form.hiddenTroubleDealStatus='2';
        this.hiddenDanger=true;
        this.hiddenDangertitle = "处理隐患信息";
      });
      },
      /**详情按钮操作*/
      details(row){
        this.fileList=[]
        this.fileListn=[]
        this.reset();
        const hiddenTroubleId = row.hiddenTroubleId || this.ids
        getInfo(hiddenTroubleId).then(response => {
          this.form = response.data;
        this.detailsOpen = true;
          //图片回显
          if (this.form.pictureUrl){
            for(var i = 0; i < this.form.pictureUrl.split(',').length; i++){
              this.fileList.push({
                name: '照片',
                url: this.form.pictureUrl.split(',')[i],
              });
            }
          }
          if (this.form.dealUrl){
            for(var i = 0; i < this.form.dealUrl.split(',').length; i++){
              this.fileListn.push({
                name: '照片',
                url: this.form.dealUrl.split(',')[i],
              });
            }
          }
          if(this.form.videoUrl){
            this.fileListVideo = this.form.videoUrl.split(',');
          }
        //图片回显
        // if (this.form.pictureUrl) {
        //   this.fileList.push({
        //     name: '照片',
        //     url: this.form.pictureUrl,
        //   });
        // }
        this.detailsTitle = "燃气隐患详情";
        this.devicePos = [response.data.longitude, response.data.latitude];
        // this.getInspectionUserList(response.data.beyondEnterpriseId);
      });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.form.videoUrl = this.fileListVideo.join(",");
            if (this.form.hiddenTroubleId != null) {
              updateInfo(this.form).then(response => {
                this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
            } else {
              this.form.hiddenTroubleDealStatus='1'
              addInfo(this.form).then(response => {
                this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
            }
          }
        });
      },
      /**处理隐患提交按钮*/
      submitFormHiddenDanger(){
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.hiddenTroubleId != null) {
              // this.form.hiddenTroubleDealStatus = '3';
              updateInfo(this.form).then(response => {
                this.msgSuccess("修改成功");
              this.hiddenDanger = false;
              this.getList();
            });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const hiddenTroubleIds = row.hiddenTroubleId || this.ids;
        this.$confirm('是否确认删除隐患名称为"' + row.hiddenTroubleName + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(hiddenTroubleIds);
        }).then(() => {
          this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有燃气隐患数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
        return exportInfo(queryParams);
      }).then(response => {
          this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
      },
      getFileInfoVideo(res){
        this.fileListVideo.push(res.url)
      },
      listRemoveVideo(index){
        this.fileListVideo.splice(index,1);
      },
      report(row){
        this.$confirm('是否确认上报隐患标题为"' + row.hiddenTroubleName + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return reportGovernment({hiddenTroubleId:row.hiddenTroubleId,isReport:"1",hiddenTroubleDealStatus:row.hiddenTroubleDealStatus});
        }).then(() => {
          this.getList();
          this.msgSuccess("上报成功");
        }).catch(() => {});
      },
      timeChange(val){
        this.queryParams.reportBeginTime = val[0];
        this.queryParams.reportEndTime = val[1];
      },
    }
  };
</script>
