<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="装置" prop="plantId">
        <el-select v-model="queryParams.plantId" @change="handleQuery,getAllRegion(queryParams.plantId)"
                   placeholder="请选择装置" clearable size="small">
          <el-option
            v-for="plant in plantOperation"
            :key="plant.plantId"
            :label="plant.plantName"
            :value="plant.plantId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="区域" prop="regionId">
        <el-select v-model="queryParams.regionId" @change="handleQuery,getAllDeviceByRegionId(queryParams.regionId)"
                   placeholder="请选择区域" clearable size="small">
          <el-option
            v-for="dict in regionOperation"
            :key="dict.regionId"
            :label="dict.regionName"
            :value="dict.regionId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备" prop="devId">
        <el-select v-model="queryParams.devId" @change="handleQuery" placeholder="请选择设备" clearable size="small">
          <el-option
            v-for="dict in deviceOperation"
            :key="dict.devId"
            :label="dict.devDescribe"
            :value="dict.devId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="群组编码" prop="groupCode">
        <el-input
          v-model="queryParams.groupCode"
          placeholder="请输入群组编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="介质" prop="medium">
        <el-input
          v-model="queryParams.medium"
          placeholder="请输入介质"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="泄漏程度" prop="leakageDegree">
        <el-select v-model="queryParams.leakageDegree" @change="handleQuery" placeholder="请选择泄漏程度" clearable
                   size="small">
          <el-option
            v-for="dict in leakageDegreeOperation"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是/否不可达点" prop="unarrive">
        <el-select v-model="queryParams.unarrive" @change="handleQuery" placeholder="请选择是/否" clearable
                   size="small">
          <el-option
            v-for="dict in yesOrNoOperation"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="密封点类型" prop="pointType">
        <el-select v-model="queryParams.pointType" @change="handleQuery" placeholder="请选择密封点类型" clearable
                   size="small">
          <el-option
            v-for="dict in pointOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="approveStatus">
        <el-select v-model="queryParams.approveStatus" @change="handleQuery" placeholder="请选择审核状态" clearable
                   size="small">
          <el-option
            v-for="dict in approveStatusOperation"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </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="['base:point:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['base:point:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['base:point:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['base:device:add']"
        >导入
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['base:point:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-position"
          size="mini"
          :disabled="multiple"
          @click="handleToApprove"
        >送审
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-position"
          size="mini"
          @click="handleApproveAll(1)"
        >全部送审
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-s-check"
          size="mini"
          :disabled="multiple"
          @click="handleApprove"
          v-hasPermi="['base:point:approve']"
        >审核
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-s-check"
          size="mini"
          @click="handleApproveAll(2)"
          v-hasPermi="['base:point:approve']"
        >全部审核
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="habdleUpdload('上传PID图',1)"
        >上传PID图
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-upload"
          size="mini"
          @click="habdleUpdload('上传组件照片',0)"
        >上传组件照片
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pointList" :cell-style="tableCellStyle"
              @selection-change="handleSelectionChange" :height="clientHeight" border>
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="检测净值(ppm)" align="center" prop="netTestValue" width="110"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="泄漏程度" align="center" prop="leakageDegree" :formatter="leakageFormat"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="装置名称" align="center" prop="plantName" :show-overflow-tooltip="true"/>
      <el-table-column label="装置编码" align="center" prop="plantCode" :show-overflow-tooltip="true"/>
      <el-table-column label="装置类别" align="center" prop="plantType" :formatter="plantTypeFormat"/>
      <el-table-column label="区域名称" align="center" prop="regionName" :show-overflow-tooltip="true"/>
      <el-table-column label="区域编码" align="center" prop="regionCode" :show-overflow-tooltip="true"/>
      <el-table-column label="设备/管线名称" align="center" prop="devName" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="设备/管线编码" align="center" prop="devCode" width="150" :show-overflow-tooltip="true"/>
      <el-table-column label="介质" align="center" prop="medium" :show-overflow-tooltip="true"/>
      <el-table-column label="介质状态" align="center" prop="mediumType" :formatter="mediumTypeFormat"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="密封点类型" align="center" prop="pointType" width="100" :formatter="pointFormat"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="平台(层)" align="center" prop="layer" :show-overflow-tooltip="true"/>
      <el-table-column label="群组位置" align="center" prop="groupPosition" :show-overflow-tooltip="true"/>
      <el-table-column label="密封点位置" align="center" prop="pointPosition" width="110"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="群组编码" align="center" prop="groupCode" :show-overflow-tooltip="true"/>
      <el-table-column label="扩展编码" align="center" prop="extendCode" :show-overflow-tooltip="true"/>
      <el-table-column label="密封点子类型" align="center" prop="subPointType" width="110"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="公称直径(mm)" align="center" prop="dia" width="110" :show-overflow-tooltip="true"/>
      <el-table-column label="是否不可达点" align="center" prop="unarrive" width="110" :formatter="unarriveFormat"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="不可达原因" align="center" prop="unarriveReason" width="110"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="是否保温/保冷" align="center" prop="keepWarm" width="110" :formatter="keepWarmFormat"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="工艺温度(℃)" align="center" prop="temperature" width="110" :show-overflow-tooltip="true"/>
      <el-table-column label="工艺压力(Mpa)" align="center" prop="pressure" width="110" :show-overflow-tooltip="true"/>
      <el-table-column label="运行时间" align="center" prop="runTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.runTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="PID图号" align="center" prop="pidNo" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.pidUrl"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleSee(scope.row,true)"
          >{{ $t('预览') }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="群组照片号" align="center" prop="picNo" width="110" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.picUrl"
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleSee(scope.row,false)"
          >{{ $t('预览') }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="TOC质量分数" align="center" prop="tocMark" width="110" :show-overflow-tooltip="true"/>
      <el-table-column label="甲烷质量分数" align="center" prop="methaneMark" width="110"
                       :show-overflow-tooltip="true"/>
      <el-table-column label="VOCs质量分数" align="center" prop="vocsMark" width="110" :show-overflow-tooltip="true"/>
      <el-table-column label="审核状态" align="center" fixed="left" prop="approveStatus"
                       :formatter="approveStatusFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="最后维护人" align="center" prop="updater" width="110" :show-overflow-tooltip="true"/>
      <el-table-column label="最后维护时间" align="center" prop="updatedate" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updatedate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="描述" align="center" prop="remarks" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" width="160px" fixed="right" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['base:point:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['base:point:remove']"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-tickets"
            @click="openDetail(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="title" :visible.sync="open" width="800px" append-to-body :before-close="cleanRegion">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="装置" prop="plantId">
              <el-select v-model="form.plantId" placeholder="请选择装置" clearable size="small" style="width: 100%"
                         @change="getAllRegion(form.plantId)">
                <el-option
                  v-for="dict in plantOperation"
                  :key="dict.plantId"
                  :label="dict.plantName"
                  :value="dict.plantId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区域" prop="regionId">
              <el-select v-model="form.regionId" placeholder="请选择区域" clearable size="small" style="width: 100%"
                         @change="getAllDeviceByRegionId(form.regionId)">
                <el-option
                  v-for="dict in regionOperation"
                  :key="dict.regionId"
                  :label="dict.regionName"
                  :value="dict.regionId"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备" prop="devId">
              <el-select v-model="form.devId" placeholder="请选择设备" clearable size="small" style="width: 100%">
                <el-option
                  v-for="dict in deviceOperation"
                  :key="dict.devId"
                  :label="dict.devDescribe"
                  :value="dict.devId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="介质状态" prop="mediumType">
              <el-select v-model="form.mediumType" placeholder="请选择介质状态" clearable size="small"
                         style="width: 100%">
                <el-option
                  v-for="dict in mediumTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="密封点类型" prop="pointType">
              <el-select v-model="form.pointType" placeholder="请选择密封点类型" clearable size="small"
                         style="width: 100%">
                <el-option
                  v-for="dict in pointOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="介质" prop="medium">
              <el-input v-model="form.medium" placeholder="请输入介质"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="公称直径(mm)" prop="dia">
              <el-input v-model="form.dia" placeholder="请输入公称直径(mm)"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="密封点子类型" prop="subPointType">
              <el-input v-model="form.subPointType" placeholder="请输入密封点子类型"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="平台(层)" prop="layer">
              <el-input v-model="form.layer" placeholder="请输入平台"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="群组位置" prop="groupPosition">
              <el-input v-model="form.groupPosition" placeholder="请输入群组位置"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="群组编码" prop="groupCode">
              <el-input v-model="form.groupCode" placeholder="请输入群组编码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="扩展编码" prop="extendCode">
              <el-input v-model="form.extendCode" placeholder="请输入扩展编码"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="密封点位置" prop="pointPosition">
              <el-input v-model="form.pointPosition" placeholder="请输入密封点位置"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="VOCs质量分数" prop="vocsMark">
              <el-input v-model="form.vocsMark" placeholder="请输入VOCs质量分数"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是/否不可达点" prop="unarrive">
              <el-select v-model="form.unarrive" placeholder="请选择是/否" clearable size="small" style="width: 100%">
                <el-option
                  v-for="dict in yesOrNoOperation"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="不可达原因" prop="unarriveReason">
              <el-input v-model="form.unarriveReason" placeholder="请输入不可达原因"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否保温/保冷" prop="keepWarm">
              <el-select v-model="form.keepWarm" placeholder="请选择是/否" clearable size="small" style="width: 100%">
                <el-option
                  v-for="dict in yesOrNoOperation"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工艺温度" prop="temperature">
              <el-input v-model="form.temperature" placeholder="请输入工艺温度"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工艺压力" prop="pressure">
              <el-input v-model="form.pressure" placeholder="请输入工艺压力"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="运行时间" prop="runTime">
              <el-date-picker clearable
                              v-model="form.runTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择运行时间"
                              style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="PID图号" prop="pidNo">
              <el-input v-model="form.pidNo" placeholder="请输入PID图号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="群组照片号" prop="picNo">
              <el-input v-model="form.picNo" placeholder="请输入群组照片号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="TOC质量分数" prop="tocMark">
              <el-input v-model="form.tocMark" placeholder="请输入TOC质量分数"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="甲烷质量分数" prop="methaneMark">
              <el-input v-model="form.methaneMark" placeholder="请输入甲烷质量分数"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="描述" prop="remarks">
              <el-input v-model="form.remarks" 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>


    <!-- 用户导入对话框 -->
    <el-dialog v-dialogDrag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
          <el-link type="info" style="font-size:12px" @click="importTemplate">{{ $t('下载模板') }}</el-link>
        </div>
        <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
          <input name="type" :value="upload.type" hidden/>
        </form>
        <div class="el-upload__tip" style="color:red" slot="tip">{{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm" v-loading.fullscreen.lock="fullscreenLoading">{{
            $t('确 定')
          }}
        </el-button>
        <el-button @click="upload.open = false">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>
    <el-dialog v-dialogDrag :title="doc.title" :visible.sync="doc.open" width="400px" append-to-body>
      <el-upload
        ref="doc"
        :headers="doc.headers"
        :action="doc.url"
        :disabled="doc.isUploading"
        :on-progress="handleFileDocProgress"
        :on-success="handleFileDocSuccess"
        :auto-upload="true"
        accept=".jpg,.png"
        :limit="1"
        :on-exceed="handleExceed"
        :multiple="false"
        :file-list="fileList"
        list-type="picture"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div slot="tip" class="el-upload__tip">文件大小建议不超过5Mb</div>
      </el-upload>
    </el-dialog>
    <el-dialog v-dialogDrag :title="pic.title" :visible.sync="pic.open" width="500px" append-to-body>
      <div>
        <el-image
          style="width: 200px; height: 200px;margin:10px;border-radius: 5%"
          :key="pic.picUrl"
          :src="pic.picUrl"
          :preview-src-list="pic.picList"
          fit="cover"/>
      </div>
    </el-dialog>
    <point-detail v-if="detailVisible" ref="pointDetail"></point-detail>
  </div>
</template>

<script>
import {listPoint, getPoint, delPoint, addPoint, updatePoint, handleApprove,handleApproveAll, handleUpload} from "@/api/base/point";
import {getAllPlantName} from "@/api/base/plant";
import {getAllRegion} from "@/api/base/region";
import {getAllDeviceByRegionId} from "@/api/base/device";
import {MessageBox} from "element-ui";
import {getToken} from "@/utils/auth";
import PointDetail from "@/views/base/point/pointDetail";
import {deepClone} from "@/utils";

export default {
  name: "Point",
  components: {PointDetail},
  data() {
    return {
      pic : {
        title: '图片预览',
        picUrl: '',
        numPages: null,
        open: false,
        pageNum: 1,
        pageTotalNum: 1,
        loadedRatio: 0,
        picList:[],
      },

      detailVisible: false,
      fullscreenLoading: false,
      // 用户导入参数
      upload: {
        downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
        //下载模板类型
        type: "basePoint",
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/base/point/importData"
      },
      doc: {

        file: "",
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 报告附件上传位置编号
        ids: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/base/point/uploadFile",
      },
      plantOperation: [],
      regionOperation: [],
      deviceOperation: [],
      plantTypeOptions: [],
      leakageDegreeOperation: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      status: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      clientHeight: 300,
      // 显示搜索条件
      showSearch: false,
      yesOrNoOperation: [],
      pointOptions: [],
      mediumTypeOptions: [],
      fileList: [],
      approveStatusOperation: [],
      // 总条数
      total: 0,
      // 密封点表格数据
      pointList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      pidFlag: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        netTestValue: null,
        leakageDegree: null,
        plantId: null,
        regionId: null,
        devId: null,
        medium: null,
        mediumType: null,
        pointType: null,
        layer: null,
        groupPosition: null,
        pointPosition: null,
        groupCode: null,
        extendCode: null,
        subPointType: null,
        dia: null,
        unarrive: null,
        unarriveReason: null,
        keepWarm: null,
        temperature: null,
        pressure: null,
        runTime: null,
        pidNo: null,
        pidUrl: null,
        picNo: null,
        picUrl: null,
        tocMark: null,
        methaneMark: null,
        vocsMark: null,
        remarks: null,
        approveStatus: null,
        approveTime: null,
        deptId: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        plantId: [
          {required: true, message: this.$t('请选择') + this.$t('装置'), trigger: "blur"}
        ],
        regionId: [
          {required: true, message: this.$t('请选择') + this.$t('区域'), trigger: "blur"}
        ],
        devId: [
          {required: true, message: this.$t('请选择') + this.$t('设备'), trigger: "blur"}
        ],
        groupCode: [
          {required: true, message: this.$t('群组编码') + this.$t('不能为空'), trigger: "blur"}
        ],
        extendCode: [
          {required: true, message: this.$t('密封点扩展号编码') + this.$t('不能为空'), trigger: "blur"}
        ],
        pointType: [
          {required: true, message: this.$t('请选择') + this.$t('密封点类型'), trigger: "blur"}
        ],
        unarrive: [
          {required: true, message: this.$t('请选择') + this.$t('是否不可达点'), trigger: "blur"}
        ],
        mediumType: [
          {required: true, message: this.$t('请选择') + this.$t('介质状态'), trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getDicts("plant_type").then(response => {
      this.plantTypeOptions = response.data;
    });
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = (document.body.clientHeight - 80) * 0.8
    });
    this.getDicts("yes_no").then(response => {
      this.yesOrNoOperation = response.data;
    });
    this.getDicts("base_approve_status").then(response => {
      this.approveStatusOperation = response.data;
    });
    this.getDicts("leakage_degree").then(response => {
      this.leakageDegreeOperation = response.data;
    });
    this.getDicts("point_type").then(response => {
      this.pointOptions = response.data;
    });
    this.getDicts("medium_type").then(response => {
      this.mediumTypeOptions = response.data;
    });
    this.getList();
    getAllPlantName().then(response => {
      this.plantOperation = response.data;
    })
  },
  methods: {
    handleSee (row,flag){
      this.pic.picList = []
      this.pic.open =true
      if (flag) {
        this.pic.title = row.pidNo
        this.pic.picUrl = process.env.VUE_APP_BASE_API + row.pidUrl;
      } else {
        this.pic.title = row.picNo
        this.pic.picUrl = process.env.VUE_APP_BASE_API + row.picUrl;
      }
      this.pic.picList.push(this.pic.picUrl)
    },
    //附件上传中处理
    handleFileDocProgress(event, file, fileList) {
      this.doc.file = file;
    },
    //附件上传成功处理
    handleFileDocSuccess(response, file, fileList) {
      let data = {};
      if (this.pidFlag==1)
        data.pidUrl = response.msg;
      else
        data.picUrl = response.msg;
      data.fileName = file.name;
      data.pidFlag = this.pidFlag;
      console.log(data)
      handleUpload(data).then(() => {
        this.getList();
      })
      this.fileList=[];
      this.doc.open = false;
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    openDetail(row) {
      this.detailVisible = true;
      row.mediumTypeOptions = this.mediumTypeOptions;
      row.plantOperation = this.plantOperation;
      this.$nextTick(() => {
        this.$refs.pointDetail.init(row);
      })
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
      this.fullscreenLoading = true;
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = this.$t('用户导入');
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.$refs['downloadFileForm'].submit()
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.fullscreenLoading = false;
      console.log(response)
      if (response.data === 0) {
        this.$alert(this.$t('导入失败！') + response.msg, this.$t('导入结果'), {dangerouslyUseHTMLString: true});
      } else if (response.data[0] != null) {
        this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据') + "，" + this.$t('第') + response.data + this.$t('行数据出现错误导入失败') + "。", this.$t('导入结果'), {dangerouslyUseHTMLString: true});
      } else {
        this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据'), this.$t('导入结果'), {dangerouslyUseHTMLString: true});
      }
      this.getList();
    },
    getAllRegion(val) {
      this.form.regionId = '';
      this.queryParams.regionId = '';
      this.form.devId = '';
      this.queryParams.devId = '';
      if (val != null && val != '') {
        getAllRegion(val).then(response => {
            this.regionOperation = response.data;
          }
        )
      } else {
        this.regionOperation = [];
        this.deviceOperation = [];
      }
    },
    getAllDeviceByRegionId(val) {
      this.form.devId = '';
      this.queryParams.devId = '';
      if (val != null && val != '') {
        getAllDeviceByRegionId(val).then(response => {
            this.deviceOperation = response.data;
          }
        )
      } else {
        this.deviceOperation = [];
      }
    },
    tableCellStyle({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 1 && row.approveStatus == 2) {
        return "color:#13C2C2;";
      }
      if (columnIndex === 1 && row.approveStatus == 1) {
        return "color:#0000FF;";
      }
      if (columnIndex === 1 && row.approveStatus == 0) {
        return "color:#ff0000;";
      }
      if (columnIndex === 3 && row.leakageDegree == 1) {
        return "color:#00ff00;font-size:200%";
      }
      if (columnIndex === 3 && row.leakageDegree == 2) {
        return "color:#FFDF00;font-size:200%";
      }
      if (columnIndex === 3 && row.leakageDegree == 3) {
        return "color:#ff0000;font-size:200%";
      }
    },
    leakageFormat(row, column) {
      return row.leakageDegree ? "●" : null;
    },
    pointFormat(row, column) {
      return this.selectDictLabel(this.pointOptions, row.pointType);
    },
    mediumTypeFormat(row, column) {
      return this.selectDictLabel(this.mediumTypeOptions, row.mediumType);
    },
    unarriveFormat(row, column) {
      return this.selectDictLabel(this.yesOrNoOperation, row.unarrive);
    },
    keepWarmFormat(row, column) {
      return this.selectDictLabel(this.yesOrNoOperation, row.keepWarm);
    },
    approveStatusFormat(row, column) {
      return this.selectDictLabel(this.approveStatusOperation, row.approveStatus);
    },
    plantTypeFormat(row, column) {
      return this.selectDictLabel(this.plantTypeOptions, row.plantType);
    },
    /** 查询密封点列表 */
    getList() {
      this.loading = true;
      listPoint(this.queryParams).then(response => {
        this.pointList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cleanRegion(done) {
      this.reset();
      done(true);
    },
    // 表单重置
    reset() {
      this.form = {
        pointId: null,
        netTestValue: null,
        leakageDegree: null,
        plantId: null,
        regionId: null,
        devId: null,
        medium: null,
        mediumType: null,
        pointType: null,
        layer: null,
        groupPosition: null,
        pointPosition: null,
        groupCode: null,
        extendCode: null,
        subPointType: null,
        dia: null,
        unarrive: null,
        unarriveReason: null,
        keepWarm: null,
        temperature: null,
        pressure: null,
        runTime: null,
        pidNo: null,
        pidUrl: null,
        picNo: null,
        picUrl: null,
        tocMark: null,
        methaneMark: null,
        vocsMark: null,
        remarks: null,
        approveStatus: 0,
        approveTime: null,
        deptId: null,
        delFlag: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null
      };
      this.resetForm("form");
      this.regionOperation = [];
      this.deviceOperation = [];
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
      this.regionOperation = [];
      this.deviceOperation = [];
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pointId)
      this.status = selection.map(item => item.approveStatus)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加密封点";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const pointId = row.pointId || this.ids
      if (row.approveStatus != 0) {
        MessageBox.alert('已送审/已审核的数据不可删除！', '注意！', {
          confirmButtonText: '确定',
        })
        return
      }
      getPoint(pointId).then(response => {
        this.form = response.data;
        getAllRegion(this.form.plantId).then(response => {
            this.regionOperation = response.data;
          }
        );
        getAllDeviceByRegionId(this.form.regionId).then(response => {
            this.deviceOperation = response.data;
          }
        )
        this.open = true;
        this.title = "修改密封点";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.pointId != null) {
            updatePoint(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPoint(this.form).then(response => {
              if (response.data != 0) {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.$modal.msgWarning(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.pointId || this.ids;
      if (row.approveStatus === undefined) {
        for (let i = 0; i < this.status.length; i++) {
          if (this.status[i] != 0) {
            MessageBox.alert('已送审/已审核的数据不可删除！', '注意！', {
              confirmButtonText: '确定',
            })
            return
          }
        }
      } else if (row.approveStatus != 0) {
        MessageBox.alert('已送审/已审核的数据不可删除！', '注意！', {
          confirmButtonText: '确定',
        })
        return
      }
      this.$modal.confirm('是否确认删除数据项？').then(function () {
        return delPoint(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('base/point/export', {
        ...this.queryParams
      }, `point_${new Date().getTime()}.xlsx`)
    },
    handleToApprove() {
      let data = {}
      data.pointIds = this.ids;
      data.approveStatus = 1;
      handleApprove(data).then(() => {
        this.getList();
      });
    },
    handleApprove() {
      let data = {}
      data.pointIds = this.ids;
      data.approveStatus = 2;
      handleApprove(data).then(() => {
        this.getList();
      });
    },
    handleApproveAll(status) {
       let data = deepClone(this.queryParams);
       data.approveStatus = status
      handleApproveAll(data).then(response => {
        this.$modal.msgSuccess(response.msg);
        this.getList();
      });
    },
    habdleUpdload(title, flag) {
      this.doc.open = true;
      this.doc.title = title;
      this.pidFlag = flag;
      this.fileList=[];
    }
  }
};
</script>
