<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="调压箱名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入调压箱名称" clearable size="small" @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="管理所" prop="administrativeOffice">
        <el-select v-model="queryParams.administrativeOffice" placeholder="请选择管理所" clearable size="small"
                   @keyup.enter.native="handleQuery">
          <el-option
            v-for="dict in dict.type.administrative_office"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="编号" prop="number">
        <el-input
          v-model="queryParams.number"
          placeholder="请输入编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="队伍" prop="ranks">
        <el-select v-model="queryParams.ranks" clearable placeholder="请选择队伍" @change="getUsers" :disabled="postName.indexOf('xx') > -1&&postName!='xxallrank'">
          <el-option
            v-for="item in postOptions"
            :key="item.postId"
            :label="item.postName"
            :value="item.postId"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="上传人" prop="createBy">
        <el-select v-model="queryParams.createBy" filterable placeholder="请选择上传人" clearable size="small">
          <el-option v-for="item in workerListSelect"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态">
        <el-select v-model="queryParams.processStatus" placeholder="请选择审核状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.process_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="时间范围" prop="createTimes">
        <el-date-picker
          v-model="queryParams.createTimes"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right">
        </el-date-picker>
      </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="['gas:regulatorBox: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="['gas:regulatorBox: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="['gas:regulatorBox:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-search"
          size="mini"
          :disabled="multiple"
          @click="process(null,true)"
          v-hasPermi="['gas:regulatingBoxMaintenance:remove']"
        >批量审核
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-s-claim"
          size="mini"
          :disabled="multiple"
          @click="chushiBatch"
          v-if="['deputyDirector','director','admin'].includes(this.$store.state.user.postName)"
        >一键审核通过
        </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="['gas:regulatorBox:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="regulatorBoxList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="id" v-if="false"/>
      <el-table-column label="序号" width="70">
        <template slot-scope="scope">
          {{(queryParams.pageNum-1)*queryParams.pageSize+scope.$index+1}}
        </template>
      </el-table-column>
      <el-table-column label="调压箱名称" align="center" prop="name"/>
      <!--      <el-table-column label="所属楼宇" align="center" prop="buildingName"/>-->
      <!--      <el-table-column label="所属单元" align="center" prop="unitName"/>-->
      <el-table-column label="管理所" align="center" prop="administrativeOffice">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.administrative_office" :value="scope.row.administrativeOffice"/>
        </template>
      </el-table-column>
      <el-table-column label="编号" align="center" prop="number"/>
      <el-table-column label="上传人" align="center" prop="createByName"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="审核状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.process_status" :value="scope.row.processStatus"
                    v-if="scope.row.processStatus != null"/>
          <span v-else>未审核</span>
        </template>
      </el-table-column>
      <el-table-column label="照片" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.photoList[0]"
            :preview-src-list="scope.row.photoList">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" show-overflow-tooltip/>
      <el-table-column label="操作" width="180" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row,true)"
            v-hasPermi="['gas:regulatorBox:query']"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row,false)"
            v-hasPermi="['gas:regulatorBox:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="process(scope.row)"
            v-if="btnShow(scope.row)"
            v-hasPermi="['gas:regulatingBoxMaintenance:edit']"
          >审核
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="reviewListOpen(scope.row)"
          >审核记录
          </el-button>
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-delete"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            v-hasPermi="['gas:regulatorBox: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="审核记录" :visible.sync="reviewListShow" width="800px" append-to-body>
      <el-table
        :data="reviewList"
        style="width: 100%"
        border
        :header-cell-style="{'text-align':'center'}"
        height="500">
        <el-table-column label="历史审核记录">
          <el-table-column
            prop="createName"
            label="审核人"
            width="80">
          </el-table-column>
          <el-table-column
            prop="userPost"
            label="岗位"
            width="65">
            <template slot-scope="scope">
              <span v-if="scope.row.userPost == 'admin'">管理员</span>
              <span v-if="scope.row.userPost == 'deputyDirector'">副处长</span>
              <span v-if="scope.row.userPost == 'director'">处长</span>
              <span v-if="scope.row.userPost.indexOf('xx')>-1">队长</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="processStatus"
            label="审核状态"
            width="75">
            <template slot-scope="scope">
              {{ scope.row.processStatus == '0' ? '通过' : '拒绝' }}
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="审核时间"
            width="155">
          </el-table-column>
          <el-table-column
            prop="processComments"
            label="审核意见"
            width="384">
          </el-table-column>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="reviewListShow = false">关 闭</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="审核"
      :visible.sync="dialogVisible"
      width="30%">
      <el-form ref="shFrom" :model="shFrom" label-width="80px">
        <el-form-item label="审核状态" prop="processStatus">
          <el-select v-model="shFrom.processStatus" placeholder="请选择审核状态" clearable size="small" @change="$forceUpdate">
            <el-option
              v-for="dict in dictList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" v-model="shFrom.processComments"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="upprocess">确 定</el-button>
  </span>
    </el-dialog>
    <!-- 添加或修改调压箱管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px" :disabled="disabled">
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="调压箱名称" prop="areaId">
              <el-input v-model="form.name" placeholder="请输入调压箱名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="管理所" prop="administrativeOffice">
              <el-select v-model="form.administrativeOffice" placeholder="请输入管理所" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.administrative_office"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="编号" prop="number">
              <el-input v-model="form.number" placeholder="请输入编号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10">
          <el-col :span="8">
            <el-form-item label="商服" prop="businessService">
              <el-radio-group v-model="form.businessService">
                <el-radio
                  v-for="dict in dict.type.business_service"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="外观" prop="appearance">
              <el-select v-model="form.appearance" placeholder="请选择外观" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.appearance"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="方砖" prop="squareBrick">
              <el-select v-model="form.squareBrick" placeholder="请选择方砖" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.square_brick"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="护栏" prop="guardrail">
              <el-select v-model="form.guardrail" placeholder="请选择护栏" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.guardrail"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="基础" prop="foundation">
              <el-select v-model="form.foundation" placeholder="请选择基础" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.foundation"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="压力表" prop="pressureGage">
              <el-select v-model="form.pressureGage" placeholder="请选择压力表" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.pressure_gage"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="阀门" prop="valve">
              <el-select v-model="form.valve" placeholder="请选择阀门" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.valve"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否泄露" prop="isThereALeak">
              <el-radio-group v-model="form.isThereALeak">
                <el-radio
                  v-for="dict in dict.type.yes_and_no"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="调压器" prop="voltageRegulator">
              <el-select v-model="form.voltageRegulator" placeholder="请选择调压器" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.voltage_regulator"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入口压力" prop="inletPressure">
              <el-input type="text" @input="(v)=>(form.inletPressure=v.replace(/[^\d.]/g,''))"
                        v-model="form.inletPressure" placeholder="请输入入口压力">
                <template slot="append">MPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出口压力(主路)" prop="exportPressureMain">
              <el-input type="text" @input="(v)=>(form.exportPressureMain=v.replace(/[^\d.]/g,''))"
                        v-model="form.exportPressureMain" placeholder="请输入出口压力(主路)">
                <template slot="append">KPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出口压力(副路)" prop="exportPressureAccessory">
              <el-input type="text" @input="(v)=>(form.exportPressureAccessory=v.replace(/[^\d.]/g,''))"
                        v-model="form.exportPressureAccessory" placeholder="请输入出口压力(副路)">
                <template slot="append">KPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="关闭压力(主路)" prop="closingPressureMain">
              <el-input type="text" @input="(v)=>(form.closingPressureMain=v.replace(/[^\d.]/g,''))"
                        v-model="form.closingPressureMain" placeholder="请输入关闭压力(主路)">
                <template slot="append">KPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="关闭压力(副路)" prop="closingPressureAccessory">
              <el-input type="text" @input="(v)=>(form.closingPressureAccessory=v.replace(/[^\d.]/g,''))"
                        v-model="form.closingPressureAccessory" placeholder="请输入关闭压力(副路)">
                <template slot="append">KPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="主副路交替" prop="manOfAccessoryAlternating">
              <el-radio-group v-model="form.manOfAccessoryAlternating">
                <el-radio
                  v-for="dict in dict.type.secondary_roads"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="过滤器" prop="filter">
              <el-select v-model="form.filter" placeholder="请选择过滤器" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.filter"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当前主路" prop="mainRoad" v-show="form.manOfAccessoryAlternating == '1'">
              <el-input v-model="form.mainRoad" placeholder="请输入当前主路"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否开启伴热带" prop="isNotXtv">
                <el-radio-group v-model="form.isNotXtv">
                  <el-radio
                    v-for="dict in dict.type.on_off"
                    :key="dict.value"
                    :label="dict.value"
                  >{{dict.label}}</el-radio>
                </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="伴热带" prop="xtv">
              <el-radio-group v-model="form.xtv">
                <el-radio
                  v-for="dict in dict.type.xtv"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="有无控温器" prop="thermostat">
              <el-radio-group v-model="form.thermostat">
                <el-radio
                  v-for="dict in dict.type.yes_or_no"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="有无防爆开关" prop="explosionProofSwitch">
              <el-radio-group v-model="form.explosionProofSwitch">
                <el-radio
                  v-for="dict in dict.type.yes_or_no"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="切断器测试" prop="cutterTested">
              <el-radio-group v-model="form.cutterTested">
                <el-radio
                  v-for="dict in dict.type.cutoff_test_certification"
                  :key="dict.value"
                  :label="dict.value"
                >{{dict.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="切断器(放散阀)测试情况" prop="disconnectorTestStatus" v-show="form.cutterTested == '1'">
              <el-select v-model="form.disconnectorTestStatus" placeholder="请选择切断器(放散阀)测试情况"
                         style="width: 100%">
                <el-option
                  v-for="dict in dict.type.disconnector_test_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="切断压力(主路)" prop="cutOffPressureMain" v-show="form.cutterTested == '1'">
              <el-input type="text" @input="(v)=>(form.cutOffPressureMain=v.replace(/[^\d.]/g,''))"
                        v-model="form.cutOffPressureMain" placeholder="请输入切断压力(主路)">
                <template slot="append">KPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="切断压力(副路)" prop="cutOffPressureAccessory" v-show="form.cutterTested == '1'">
              <el-input type="text" @input="(v)=>(form.cutOffPressureAccessory=v.replace(/[^\d.]/g,''))"
                        v-model="form.cutOffPressureAccessory" placeholder="请输入切断压力(副路)">
                <template slot="append">KPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="放散压力" prop="releasePressure" v-show="form.cutterTested == '1'">
              <el-input type="text" @input="(v)=>(form.releasePressure=v.replace(/[^\d.]/g,''))"
                        v-model="form.releasePressure" placeholder="请输入放散压力">
                <template slot="append">KPa</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="调压设施特例" prop="specialCaseOfPressureRegulatingFacilities">
              <el-select v-model="form.specialCaseOfPressureRegulatingFacilities" placeholder="请选择调压设施特例"
                         style="width: 100%">
                <el-option
                  v-for="dict in dict.type.special_case_of_pressure_regulating_facilities"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="超期巡检天数" prop="overdueInspectionDays">
              <el-select v-model="form.overdueInspectionDays" placeholder="请选择超期巡检天数" style="width: 100%">
                <el-option
                  v-for="dict in dict.type.overdue_inspection_days"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="超期巡检原因" prop="reasonForOverdueInspection">
              <el-select v-model="form.reasonForOverdueInspection" clearable placeholder="请选择超期巡检原因"
                         style="width: 100%">
                <el-option
                  v-for="dict in dict.type.reason_for_overdue_inspection"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
<!--          <el-col :span="8">-->
<!--            <el-form-item label="阀井测试" prop="valveWellTesting">-->
<!--              <el-switch-->
<!--                v-model="form.valveWellTesting"-->
<!--                active-text="是"-->
<!--                inactive-text="否">-->
<!--              </el-switch>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="阀井情况" prop="valveWellCondition">-->
<!--              <el-select v-model="form.valveWellCondition" placeholder="请选择阀井情况" style="width: 100%">-->
<!--                <el-option-->
<!--                  v-for="dict in dict.type.valve_well_condition"-->
<!--                  :key="dict.value"-->
<!--                  :label="dict.label"-->
<!--                  :value="dict.value"-->
<!--                ></el-option>-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
          <el-col :span="24">
            <el-form-item label="照片" prop="photoList">
              <imageUpload v-model="form.photoList" :disabled="disabled"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="审核状态" v-if="isDisabled && form.processStatus!=null">
              <el-select v-model="form.processStatus" placeholder="请选择审核状态" clearable size="small" @change="$forceUpdate">
                <el-option
                  v-for="dict in dict.type.process_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="审核备注" v-if="isDisabled && form.processStatus!=null">
              <el-input type="textarea" v-model="form.processComments" placeholder=""/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" v-if="!disabled" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">{{ disabled ? "关 闭" : "取 消" }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRegulatorBox,
  getRegulatorBox,
  delRegulatorBox,
  addRegulatorBox,
  updateRegulatorBox, batchReview
} from "@/api/gas/regulatorBox";
import {getAreaList} from "@/api/gas/area";
import {getBuildingList} from "@/api/gas/building";
import {getUnitList} from "@/api/gas/unit";
import {getWorker} from "@/api/gas/user";
import Cookies from "js-cookie";
import {listPostAll} from "@/api/system/post";
import {getReviewList} from "@/api/gas/regulatorBox.js";

export default {
  name: "RegulatorBox",
  dicts: ['appearance', 'administrative_office', 'square_brick', 'business_service',
    'yes_and_no','on_off','yes_or_no','cutoff_test_certification','secondary_roads',
    'guardrail', 'foundation', 'pressure_gage', 'valve', 'voltage_regulator', 'xtv',
    'disconnector_test_status', 'filter','process_status', 'special_case_of_pressure_regulating_facilities',
    'overdue_inspection_days', 'reason_for_overdue_inspection', 'valve_well_condition'],
  data() {
    return {
      buildingList: [], // 楼宇集合
      areaList: [], // 小区集合
      unitList: [], // 单元集合
      // 按钮loading
      buttonLoading: false,
      disabled: false,
      isDisabled: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调压箱管理表格数据
      regulatorBoxList: [],
      workerList: [],
      //审核记录
      reviewListShow: false,
      reviewList: [],
      dialogVisible: false,
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      dictList:[{label:'通过',value:'0'},{label:'不通过',value:'1'}],
      shFrom:{
        id: '',
        uids: [],
        processStatus:'',
        processComments: "",
        postNameArias:null,
      },
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        administrativeOffice: undefined,
        number: undefined,
        createTimes:[],
        createBy:undefined,
        processStatus: '',
        postNameArias:this.$store.state.user.postName,
        ranks:(Cookies.get("postName").indexOf('xx') > -1 ? parseInt(Cookies.get("postId")) : undefined),
      },
      // 岗位选项
      postOptions: [],
      postName:Cookies.get("postName"),
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // areaId: [
        //   {required: true, message: "所属小区不能为空", trigger: "blur"}
        // ],
        // buildingId: [
        //   {required: true, message: "所属楼宇不能为空", trigger: "blur"}
        // ],
        // unitId: [
        //   {required: true, message: "单元id不能为空", trigger: "change"}
        // ],
        administrativeOffice: [
          {required: true, message: "管理所不能为空", trigger: "blur"}
        ],
        number: [
          {required: true, message: "编号不能为空", trigger: "blur"}
        ],
        businessService: [
          {required: true, message: "商服不能为空", trigger: "blur"}
        ],
        appearance: [
          {required: true, message: "外观不能为空", trigger: "change"}
        ],
        squareBrick: [
          {required: true, message: "方砖不能为空", trigger: "change"}
        ],
        guardrail: [
          {required: true, message: "护栏不能为空", trigger: "change"}
        ],
        foundation: [
          {required: true, message: "基础不能为空", trigger: "change"}
        ],
        pressureGage: [
          {required: true, message: "压力表不能为空", trigger: "change"}
        ],
        valve: [
          {required: true, message: "阀门不能为空", trigger: "change"}
        ],
        isThereALeak: [
          {required: true, message: "是否泄露不能为空", trigger: "blur"}
        ],
        voltageRegulator: [
          {required: true, message: "调压器不能为空", trigger: "change"}
        ],
        inletPressure: [
          {required: true, message: "入口压力不能为空", trigger: "blur"}
        ],
        exportPressureMain: [
          {required: true, message: "出口压力(主路)不能为空", trigger: "blur"}
        ],
        exportPressureAccessory: [
          {required: true, message: "出口压力(副路)不能为空", trigger: "blur"}
        ],
        closingPressureMain: [
          {required: true, message: "关闭压力(主路)不能为空", trigger: "blur"}
        ],
        closingPressureAccessory: [
          {required: true, message: "关闭压力(副路)不能为空", trigger: "blur"}
        ],
        isNotXtv: [
          {required: true, message: "是否开启伴热带不能为空", trigger: "change"}
        ],
        xtv: [
          {required: true, message: "伴热带不能为空", trigger: "change"}
        ],
        thermostat: [
          {required: true, message: "有无控温器不能为空", trigger: "blur"}
        ],
        explosionProofSwitch: [
          {required: true, message: "有无防爆开关不能为空", trigger: "blur"}
        ],
        cutterTested: [
          {required: true, message: "切断器测试不能为空", trigger: "blur"}
        ],
        manOfAccessoryAlternating: [
          {required: true, message: "主副路交替不能为空", trigger: "blur"}
        ],
        filter: [
          {required: true, message: "过滤器不能为空", trigger: "change"}
        ],
        // specialCaseOfPressureRegulatingFacilities: [
        //   {required: true, message: "调压设施特例不能为空", trigger: "change"}
        // ],
        // overdueInspectionDays: [
        //   {required: true, message: "超期巡检天数不能为空", trigger: "change"}
        // ],
        // valveWellTesting: [
        //   {required: true, message: "阀井测试不能为空", trigger: "blur"}
        // ],
        // valveWellCondition: [
        //   {required: true, message: "阀井情况不能为空", trigger: "change"}
        // ]
      },
      workerListSelect:[]
    };
  },
  created() {
    this.getPostList();
    this.getAreaList();
    // this.getWorkerList();
    this.getList();
  },
  mounted() {
    setTimeout(
      this.getUsers(parseInt(Cookies.get("postId")))
      ,1000)
  },
  methods: {
    btnShow(row){
      let b = false;
      if (row.flag==true){
        b = true;
      }
      return b;
    },
    reviewListOpen(row){
      this.reviewList = [];
      this.reviewListShow=true;
      getReviewList({emrId: row.id}).then(res=>this.reviewList = res.rows);
    },
    getUsers(value){
      if (!value) return;
      getWorker({ranks:value}).then(response => {
        this.workerListSelect = response.data;
      });
    },
    upprocess(){
      const postNameArias = this.$store.state.user.postName;
      this.shFrom.postNameArias = postNameArias
      if (this.shFrom.processStatus == undefined || this.shFrom.processStatus == ''){
        this.$message.warning("请选择审核状态")
      } if (this.shFrom.uids.length == 0){
      updateRegulatorBox(this.shFrom).then(response => {
        this.$modal.msgSuccess("审核成功");
        this.getList();
      }).finally(() => {
        this.dialogVisible = false;
      });}else {
        batchReview(this.shFrom).then(response => {
          this.$modal.msgSuccess("审核成功");
          this.getList();
        }).finally(() => {
          this.dialogVisible = false;
        });
      }
    },
    chushiBatch(){
      if (this.ids.length > 0) {
        let chushiForm = {uids:[],processStatus:null,processComments:null,postNameArias:null}
        chushiForm.processStatus = '0';
        chushiForm.processComments = '一键审核通过';
        chushiForm.uids = this.ids;
        chushiForm.postNameArias = this.$store.state.user.postName;
        console.log(chushiForm)
        batchReview(chushiForm).then(response => {
          if (response.code===200) {
            this.$modal.msgSuccess("审核成功");
          }
          this.getList();
        })
      }
    },
    getPostList(){
      listPostAll({remark:'ranks'}).then(response => {
        this.postOptions = response.data;
      });
    },
    getWorkerList(ranks) {
      let data = null
      if(ranks){
        data = {
          ranks:ranks
        }
      }
      getWorker(data).then(req => {
        this.workerList = req.data
      })
    },
    // 小区下拉
    getAreaList() {
      getAreaList().then(req => this.areaList = req.data)
    },
    // 楼宇下拉
    getBuildingList() {
      this.form.buildingId = undefined
      this.queryParams.buildingId = undefined
      let areaId = this.form.areaId || this.queryParams.areaId
      getBuildingList(areaId).then(req => this.buildingList = req.data)
    },
    getUnitList() {
      this.form.unitId = undefined
      this.queryParams.unitId = undefined
      let buildingId = this.form.buildingId || this.queryParams.buildingId
      getUnitList(buildingId).then(req => this.unitList = req.data)
    },
    /** 查询调压箱管理列表 */
    getList() {
      this.loading = true;
      listRegulatorBox(this.queryParams).then(response => {
        this.regulatorBoxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        unitId: undefined,
        administrativeOffice: undefined,
        number: undefined,
        businessService: false,
        appearance: undefined,
        squareBrick: undefined,
        guardrail: undefined,
        foundation: undefined,
        pressureGage: undefined,
        valve: undefined,
        isThereALeak: false,
        voltageRegulator: undefined,
        mainRoad: undefined,
        inletPressure: undefined,
        exportPressureMain: undefined,
        exportPressureAccessory: undefined,
        closingPressureMain: undefined,
        closingPressureAccessory: undefined,
        isNotXtv: undefined,
        xtv: undefined,
        thermostat: false,
        explosionProofSwitch: false,
        cutterTested: false,
        disconnectorTestStatus: undefined,
        cutOffPressureMain: undefined,
        cutOffPressureAccessory: undefined,
        releasePressure: undefined,
        manOfAccessoryAlternating: false,
        filter: undefined,
        specialCaseOfPressureRegulatingFacilities: undefined,
        overdueInspectionDays: undefined,
        reasonForOverdueInspection: undefined,
        // valveWellTesting: false,
        valveWellCondition: undefined,
        photoList: "",
        processComments: undefined,
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.createTimes=[]
      this.workerListSelect=[]
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.disabled = false;
      this.open = true;
      this.title = "添加调压箱管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row,disabled) {
      this.loading = true;
      this.disabled = disabled;
      this.isDisabled = disabled;
      this.reset();
      const id = row.id || this.ids
      getRegulatorBox(id).then(response => {
        this.loading = false;
        this.form = response.data;
        let buildingId = this.form.buildingId
        let unitId = this.form.unitId
        this.getBuildingList(this.form.areaId)
        this.form.buildingId = buildingId
        this.getUnitList(this.form.buildingId)
        this.form.unitId = unitId
        this.open = true;
        this.title = "查看调压箱管理";
      });
    },
    process(data, isBatch) {
      this.shFrom.id = undefined
      this.shFrom.uids = []
      if (isBatch)
        this.shFrom.uids = this.ids
      else
        this.shFrom.uids = [data.id];
      this.shFrom.processStatus = '';
      this.shFrom.processComments = '';
      this.dialogVisible = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            if (typeof this.form.photoList === 'string') {
              this.form.photoList = this.form.photoList.split(',')
            }
            updateRegulatorBox(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            this.form.photoList = this.form.photoList.split(',')
            addRegulatorBox(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除调压箱管理编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delRegulatorBox(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.$download.excel('/gas/regulatorBox/export', this.queryParams);
    }
  }
};
</script>
