<template>
  <el-dialog :title="workPermitTitle" :visible.sync="permitOpen" append-to-body :before-close="permitClose" :close-on-click-modal="false">
    <div class="permit">
      <table>
        <tr>
          <td rowspan="4" colspan="2">作业许可申请人</td>
          <td colspan="2">申请部门/单位</td>
          <td colspan="2">{{ certificateData.applyDept }}</td>
          <td colspan="2">申请人及联系方式</td>
          <td colspan="2">{{ certificateData.linkMan }} {{certificateData.linkPhone}}</td>
        </tr>
        <tr>
          <td colspan="2">作业区域范围</td>
          <td colspan="2">{{ certificateData.workBound }}</td>
          <td colspan="2">设备名称及编号</td>
          <td colspan="2">{{ certificateData.deviceName }} {{ certificateData.deviceNum }}</td>
        </tr>
        <tr>
          <td colspan="2">申请作业时间</td>
          <td colspan="6">
            {{ certificateData.applyWorkStartTime == null ? "-" :certificateData.applyWorkStartTime.split(" ")[0].split("-")[1]}}月{{certificateData.applyWorkStartTime == null ? "-" :certificateData.applyWorkStartTime.split(" ")[0].split("-")[2]}}日{{certificateData.applyWorkStartTime == null ? "-" :certificateData.applyWorkStartTime.split(" ")[1].split(":")[0]}}时{{certificateData.applyWorkStartTime == null ? "-" :certificateData.applyWorkStartTime.split(" ")[1].split(":")[1]}}分至{{certificateData.applyWorkEndTime == null ? "-" :certificateData.applyWorkEndTime.split(" ")[0].split("-")[1]}}月{{certificateData.applyWorkEndTime == null ? "-" :certificateData.applyWorkEndTime.split(" ")[0].split("-")[2]}}日{{certificateData.applyWorkEndTime == null ? "-" :certificateData.applyWorkEndTime.split(" ")[1].split(":")[0]}}时{{certificateData.applyWorkEndTime == null ? "-" :certificateData.applyWorkEndTime.split(" ")[1].split(":")[1]}}分
          </td>
        </tr>
        <tr>
          <td colspan="2">作业内容</td>
          <td colspan="6">{{ certificateData.workContent }}</td>
        </tr>
        <tr v-if="certificateData.applyStatus - 0 >= 0">
          <td colspan="2">所有相关方讨论</td>
          <td>工作安全分析</td>
          <td style="writing-mode: vertical-rl;">危害识别</td>
          <td colspan="6" style="text-align: left">
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 0" v-model="mainDangerousMark.burn">灼伤（低温/高温/化学品灼伤,电弧烧伤,火灾，易燃气/液体，蒸汽，电焊、动火、射线等）</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 0" v-model="mainDangerousMark.electricShock">电击（触电，电压，不适当的接地，电气热作业，地下/暗线等）。</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 0" v-model="mainDangerousMark.objectStrike">物体打击（爆炸，压力，能量释放，移动/坠落的物体，不正确的存放,设备）</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 0" v-model="mainDangerousMark.stifle">窒息/中毒（惰性气体，有毒气体，易挥发的液体溶剂等）</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 0" v-model="mainDangerousMark.drop">坠落（高处作业，没有防护的开口，没有固定的梯子，脚手架搭设，无防护的平台等）</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 0" v-model="mainDangerousMark.vehicleInjury">车辆伤害（速度过快,疲劳驾驶,车辆故障,缺乏防御性驾驶,能见度差,不寻常的路状，分心等）</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 0" v-model="mainDangerousMark.other">其它危害。</div>
            <div>注：如存在以上任一情况，<a style="color: #0072c6;text-decoration:underline" @click="dangerousFlag=true">请填写安全措施</a>。</div>
          </td>
        </tr>
        <tr v-if="certificateData.applyStatus - 0 >= 1">
          <td rowspan="4" colspan="2">批准人填写</td>
          <td rowspan="4" colspan="2">许可证</td>
          <td colspan="6" style="text-align: left">是否需要进一步的JSA: <input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.jsa.yes"/>否<input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.jsa.no"/>是  JSA[<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.jsa.num" style="width: 250px" placeholder="填写JSA编号"/>]</td>
        </tr>
        <tr v-if="certificateData.applyStatus - 0 >= 1">
          <td colspan="6" style="text-align: left"><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.specialLicence"/>0无需特殊工作许可</td>
        </tr>
        <tr v-if="certificateData.applyStatus - 0 >= 1">
          <td colspan="6" style="text-align: left">
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.lockListing.isChecked"/>1-1锁定挂牌记录表 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.lockListing.num" style="width: 250px" placeholder="填写编号"/>]</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.blindPlate.isChecked"/>1-2盲板抽堵作业许可 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.blindPlate.num" style="width: 250px" placeholder="填写编号"/>]</div>
          </td>
        </tr>
        <tr v-if="certificateData.applyStatus - 0 >= 1">
          <td colspan="6" style="text-align: left;">
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.flareUp.isChecked"/>2动火作业许可证 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.flareUp.num" style="width: 250px" placeholder="填写编号"/>]</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.heightWork.isChecked"/>3高处作业许可证 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.heightWork.num" style="width: 250px" placeholder="填写编号"/>]</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.breakGround.isChecked"/>4动土作业许可证 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.breakGround.num" style="width: 250px" placeholder="填写编号"/>]</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.hoisting.isChecked"/>5吊装作业许可证 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.hoisting.num" style="width: 250px" placeholder="填写编号"/>]</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.limitSpace.isChecked"/>6受限空间作业许可证 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.limitSpace.num" style="width: 250px" placeholder="填写编号"/>]</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.electricityUse.isChecked"/>7临时用电许可证 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.electricityUse.num" style="width: 250px" placeholder="填写编号"/>]</div>
            <div><input type="checkbox" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.ray.isChecked"/>8射线探伤许可证 [<input class="editInput" :disabled="(certificateData.applyStatus - 0) > 1" v-model="certificate.ray.num" style="width: 250px" placeholder="填写编号"/>]</div>
          </td>
        </tr>

        <tr v-if="certificateData.applyStatus - 0 >= 4">
          <td colspan="2">相关方填写</td>
          <td colspan="8" style="text-align: left">
            <div>本人已知晓本工作中的危害、控制措施和安全要求</div>
            <div>
              作业执行人员签字：
              <Esign :resultImg.sync="relationSign.executor"  :height="120" :width="710"/>
            </div>
            <el-row>
              <el-col :span="12">
                <div>
                  承包商负责人签字：
                  <Esign :resultImg.sync="relationSign.contractor[0].sign"  :height="60" :width="340"/>
                  负责的承包商人数：<input :disabled="(certificateData.applyStatus - 0) > 4" v-model="relationSign.contractor[0].peoples" class="editInput" style="text-align: left;width: 30%"/>
                </div>
              </el-col>
              <el-col :span="12">
                <div>承包商负责人签字：
                  <Esign :resultImg.sync="relationSign.contractor[1].sign"  :height="60" :width="340"/>
                  负责的承包商人数：<input :disabled="(certificateData.applyStatus - 0) > 4" v-model="relationSign.contractor[1].peoples" class="editInput" style="text-align: left;width: 30%"/></div>
              </el-col>
            </el-row>
          </td>
        </tr>

        <tr v-if="certificateData.applyStatus - 0 >= 4">
          <td colspan="2">生产班组确认</td>
          <td colspan="8" style="text-align: left">
            <div>本人已知晓此工作许可证的内容</div>
            <div>
              确认签字（当班班长）：
              <Esign :resultImg.sync="produceComfirm.monitor"  :height="60" :width="710"/>
              日期/时间：<input :disabled="(certificateData.applyStatus - 0) > 4" v-model="produceComfirm.date" class="editInput" style="text-align: left;width: 30%"/>
            </div>
          </td>
        </tr>

        <tr v-if="certificateData.applyStatus - 0 >= 5">
          <td rowspan="3" colspan="2">批准/移交/关闭</td>
          <td colspan="2">工作批准</td>
          <td colspan="2" style="text-align: left">
            <div>本人已知晓本工作内容及安全要求，并承诺实施</div>
            <div>
              工作负责人签字：
              <Esign v-if="-1 != certificateData.signPerson.findIndex(item => item === 'contractor') && (certificateData.applyStatus - 0) >= 5" :resultImg.sync="workDeal.workCheck.leaderInfo.leader"  :height="80" :width="170"/>
              <textarea  v-if="-1 == certificateData.signPerson.findIndex(item => item === 'contractor') && (certificateData.applyStatus - 0) == 5" disabled style="height: 96px"></textarea>
            </div>
            <div>
              日期和时间：<input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'contractor') || (certificateData.applyStatus - 0) != 5" v-model="workDeal.workCheck.leaderInfo.date" class="editInput" style="width:93px;">
            </div>
          </td>
          <td colspan="2" style="text-align: left">
            <div>
              交叉/关联作业
              <input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'contractor') || (certificateData.applyStatus - 0) != 5" v-model="workDeal.workCheck.relationInfo.yes" type="checkbox"/>否
              <input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'contractor') || (certificateData.applyStatus - 0) != 5" v-model="workDeal.workCheck.relationInfo.no" type="checkbox"/>
              是，本人已经知晓此许可证的内容
            </div>
            <div>
              关联人签字：
              <Esign v-if ="-1 != certificateData.signPerson.findIndex(item => item === 'contractor') && (certificateData.applyStatus - 0) >= 5" :resultImg.sync="workDeal.workCheck.relationInfo.relationLeader"  :height="60" :width="170"/>
              <textarea  v-if ="-1 == certificateData.signPerson.findIndex(item => item === 'contractor') && (certificateData.applyStatus - 0) == 5" disabled style="height: 85px"></textarea>
            </div>
            <div>
              日期和时间：<input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'contractor') || (certificateData.applyStatus - 0) != 5" v-model="workDeal.workCheck.relationInfo.date" class="editInput" style="width:93px;">
            </div>
          </td>
          <td colspan="2" style="text-align: left">
            <div>本人已到工作地点进行安全措施核实确认</div>
            <div>
              批准人签字：
              <Esign v-if ="-1 != certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) >= 5" :resultImg.sync="workDeal.workCheck.approvedInfo.approve"  :height="80" :width="170"/>
              <textarea v-if ="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) == 5" disabled style="height: 96px"></textarea>
            </div>
            <div>日期和时间：<input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') || (certificateData.applyStatus - 0) != 5" v-model="workDeal.workCheck.approvedInfo.date" class="editInput" style="width:93px;"></div>
          </td>
        </tr>

        <tr v-if="certificateData.applyStatus - 0 >= 5">
          <td colspan="2">批准人工作移交</td>
          <td colspan="3" style="text-align: left">
            <div>我已将工作内容完全向接收人交代清楚。</div>
            <div>
              交出人签字：
              <Esign v-if ="-1 != certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) >= 6" :resultImg.sync="workDeal.transferWork.transferInfo.transfer"  :height="80" :width="265"/>
              <textarea v-if ="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) == 6" disabled style="height: 96px"></textarea>
            </div>
            <div>日期和时间：<input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') || (certificateData.applyStatus - 0) != 6" v-model="workDeal.transferWork.transferInfo.date" style="width: 182px" class="editInput"/></div>
          </td>
          <td colspan="3" style="text-align: left">
            <div>我完全了解将要接收的工作内容。</div>
            <div>
              接受人签字：
              <Esign v-if ="-1 != certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) >= 6" :resultImg.sync="workDeal.transferWork.receiveInfo.receive"  :height="80" :width="265"/>
              <textarea v-if ="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) == 6" disabled style="height: 96px"></textarea>
            </div>
            <div>日期和时间：<input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') || (certificateData.applyStatus - 0) != 6" v-model="workDeal.transferWork.receiveInfo.date" style="width: 182px" class="editInput"/></div>
          </td>
        </tr>

        <tr v-if="certificateData.applyStatus - 0 >= 5">
          <td colspan="2">工作关闭</td>
          <td colspan="3" style="text-align: left">
            <div>本许可证工作已经执行完毕，现场处于安全、清洁的状态。</div>
            <div>
              申请人签字：
              <Esign v-if="-1 != certificateData.signPerson.findIndex(item => item === 'apply') && (certificateData.applyStatus - 0) >= 6" :resultImg.sync="workDeal.closeWork.applyInfo.apply" :height="80" :width="265"/>
              <textarea v-if ="-1 == certificateData.signPerson.findIndex(item => item === 'apply') && (certificateData.applyStatus - 0) == 6" disabled style="height: 96px"></textarea>
            </div>
            <div>日期和时间：<input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'apply') || (certificateData.applyStatus - 0) != 6" v-model="workDeal.closeWork.applyInfo.date" style="width: 182px" class="editInput"/></div>
          </td>
          <td colspan="3" style="text-align: left">
            <div>本许可证工作已经执行完毕，现场处于安全、清洁的状态。</div>
            <div>
              批准人签字：
              <Esign v-if="-1 != certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) >= 6"  :resultImg.sync="workDeal.closeWork.approvedInfo.approve" :height="80" :width="265"/>
              <textarea v-if ="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') && (certificateData.applyStatus - 0) == 6" disabled style="height: 96px"></textarea>
            </div>
            <div>日期和时间：<input :disabled="-1 == certificateData.signPerson.findIndex(item => item === 'ratifier') || (certificateData.applyStatus - 0) != 6" v-model="workDeal.closeWork.approvedInfo.date" style="width: 182px" class="editInput"/></div>
          </td>
        </tr>
      </table>
    </div>

    <!-- 上传现场照片 -->
    <div style="margin-top: 26px;" v-if="certificateData.applyStatus - 0 >= 4 && certificateData.applyStatus - 0 <= 6">
      <div style="margin-bottom: 10px;font-size: 18px">上传现场图片</div>
      <MyFileUpload
        listType="picture-card"
        @resFun="getFileInfo"
        @remove="listRemove"
        :fileArr="fileList"
      />
    </div>

    <div style="text-align: right;margin-top: 20px">
      <el-button type="primary" @click="permitSubmit">确定</el-button>
      <el-button @click="permitClose">取消</el-button>
    </div>

    <!-- 危险标识 -->
    <DangerousMark
      :dialogTableVisible.sync="dangerousFlag"
      :dangerousMarkDetial="dangerousMarkDetial"
      :applyStatus="certificateData.applyStatus"
      @submitDangerous="submitDangerous"
      @cancelDangerous="cancelDangerous"
    />
  </el-dialog>
</template>

<script>
  import { updatePermit } from "@/api/workPermit/permit";
  import DangerousMark from '@/components/DangerousMark/DangerousMark';
  import Esign from "@/components/SaftyWork/Esign";
  import MyFileUpload from '@/components/MyFileUpload';
  import FileUpload from '@/components/FileUpload';
  export default {
    name: "work-permit",
    props:{
      certificateData:{
        type: Object
      },
      permitOpen:{
        type: Boolean,
        default: false
      },
      workPermitTitle:{
        type: String
      }
    },
    components:{
      DangerousMark,
      Esign,
      MyFileUpload
    },
    watch:{
      certificateData(newValue){
        if(newValue){
          if(null != this.certificateData.mainDangerousMark){
            this.mainDangerousMark = JSON.parse(this.certificateData.mainDangerousMark);
          }
          if(null != this.certificateData.dangerousMarkDetial){
            this.dangerousMarkDetial = JSON.parse(this.certificateData.dangerousMarkDetial);
          }
          if(null != this.certificateData.licenceInfo){
            this.certificate = JSON.parse(this.certificateData.licenceInfo);
          }
          if(null != this.certificateData.relationSign){
            this.relationSign = JSON.parse(this.certificateData.relationSign);
          }
          if(null != this.certificateData.workDeal){
            this.workDeal = JSON.parse(this.certificateData.workDeal);
          }
        }
      }
    },
    data(){
      return{
        //安全措施
        dangerousFlag:false,
        //危险标识
        mainDangerousMark: {
          burn:false,
          electricShock:false,
          objectStrike:false,
          stifle:false,
          drop:false,
          vehicleInjury:false,
          other:false
        },
        //安全措施
        dangerousMarkDetial: {
          noxiousGas:{
            isChecked:false,
            processPurging:false,
            ventilate:false,
            mechanicalVentilation:false,
            naturalVentilation:false,
            gasComposition:false,
            guardian:{
              isChecked:false,
              person: ""
            }
          },
          heightWork:{
            isChecked:false,
            ladderCheck:false,
            ladderStable:{
              isChecked:false,
              top:false,
              bottom:false
            },
            scaffolding:false,
            designatedErea:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            tools:false
          },
          fireAndExplosionProof:{
            isChecked:false,
            moveCombustibles:false,
            container:false,
            sprayWater:false,
            barrier:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            other:{
              isChecked:false,
              detail:""
            },
            firePreventionTools:false,
            fireproofBlanket:false,
            fireHose:false,
            fireExtinguisher:{
              isChecked:false,
              carbonDioxide:false,
              abc:false,
              other:{
                isChecked:false,
                detail:""
              },
              specifications:"",
              quantity:""
            }
          },
          electricShockProtection:{
            isChecked:false,
            powerSupply:false,
            checkCircuit:false,
            checkSocket:false,
            insulatingLadder:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            safeDistance:false,
            insulatingGloves:false,
            insulatingShoe:false,
            insulatingClothing:false,
            insulatingMat:false,
            groundingProtector:false,
            removeFuse:false,
            disconnectGate:false,
            isolateWorkArea:false,
            other:{
              isChecked:false,
              detail:""
            }
          },
          lockoutTagout:{
            isChecked:false,
            safetyEnergyRing:{
              isChecked:false,
              hydraulicPressure:false,
              pressure:false,
              mechanicalEnergy:false,
              steam:false,
              electrical:false,
              other:false
            },
            energyTest:false,
            personalLock:false,
            lockBox:false,
            contractorGroup:false,
            values:{
              isChecked:false,
              blindPlate:false,
              vent:false,
              pipingSplit:false,
              deviceVent:false,
              cutOffInstrumentGas:false,
              switchLocked:false
            }
          },
          hoisting:{
            isChecked:false,
            hoistingCheck:false,
            cantileverSupport:false,
            hoistingLevel:false,
            wireSpacing:false,
            settingAreaIsolation:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            liftingPlan:false,
            hoistingToolsCheck:false
          },
          groundBreaking:{
            isChecked:false,
            groundDevice:false,
            eleticGrounding:false,
            brace:false,
            topDistance:false,
            warningMark:false,
            emergencyAccess:false,
            lighting:false,
            moveMaterial:false
          },

          protectArticles:{
            isChecked:false,
            headProtect:{
              isChecked:false,
              hat:false,
              allFaceShield:false,
              halfFaceShield:false
            },
            protectGlass:{
              isChecked:false,
              attack:false,
              eletic:false,
              spatter:false,
              dust:false,
              faceShield:false
            },
            hearing:{
              isChecked:false,
              earplugs:false,
              doubleProtection:false,
              timeControl:false
            },
            breathing:{
              isChecked:false,
              dustFiltration:false,
              gasFiltration:false,
              dustAndGas:false,
              scba:false,
              respirator:false
            },
            head:{
              isChecked:false,
              canvas:false,
              chemicalResistantGloves:false,
              weldingGloves:false,
              lowTemperatureGloves:false,
              heightTemperatureGloves:false,
              cutResistantGloves:false,
              prohibitGloves:false
            },
            body:{
              isChecked:false,
              weldingSuit:false,
              antistatic:false,
              weldingSuitA:false,
              weldingSuitB:false,
              weldingSuitC:false,
              weldingSuitD:false
            },
            foot:{
              isChecked:false,
              antiPiercingShoe:false,
              insulationShoe:false,
              antiChemicalShoe:false,
              antistaticShoe:false
            },
            specialLabor:{
              isChecked:false,
              safetyBelt:false,
              safetyNet:false,
              gasMonitor:false,
              communicationEquipment:false
            },
            other:{
              isChecked:false,
              detail:""
            }

          },

          otherWork:{
            isChecked:false,
            detail:""
          },
          checkResult:[
            {
              checkPoint:"",
              checkTime:"",
              oxygenContent:"",
              flammableGasContent:"",
              toxicGasContent:""
            },
            {
              checkPoint:"",
              checkTime:"",
              oxygenContent:"",
              flammableGasContent:"",
              toxicGasContent:""
            },
            {
              checkPoint:"",
              checkTime:"",
              oxygenContent:"",
              flammableGasContent:"",
              toxicGasContent:""
            }
          ]
        },
        //作业许可证
        certificate:{
          jsa:{
            yes:false,
            no:false,
            num:""
          },
          specialLicence:false,
          lockListing:{
            isChecked:false,
            num:""
          },
          blindPlate:{
            isChecked:false,
            // 0待审核 1审核通过 2驳回
            status:"",
            num:""
          },
          flareUp:{
            isChecked:false,
            // 0待审核 1审核通过 2驳回
            status:"",
            num:""
          },
          heightWork:{
            isChecked:false,
            // 0待审核 1审核通过 2驳回
            status:"",
            num:""
          },
          breakGround:{
            isChecked:false,
            // 0待审核 1审核通过 2驳回
            status:"",
            num:""
          },
          hoisting:{
            isChecked:false,
            // 0待审核 1审核通过 2驳回
            status:"",
            num:""
          },
          limitSpace:{
            isChecked:false,
            // 0待审核 1审核通过 2驳回
            status:"",
            num:""
          },
          electricityUse:{
            isChecked:false,
            // 0待审核 1审核通过 2驳回
            status:"",
            num:""
          },
          ray:{
            isChecked:false,
            num:""
          }
        },
        //相关方签字
        relationSign:{
          executor:"",
          contractor:[
            {
              sign:"",
              peoples:""
            },
            {
              sign:"",
              peoples:""
            }
          ],
          picUrl:""
        },
        //生产组签字
        produceComfirm:{
          monitor:"",
          date:""
        },
        //工作处理
        workDeal:{
          workCheck:{
            leaderInfo:{
              leader:"",
                date:"",
                picUrl:""
            },
            relationInfo:{
                yes:false,
                no:false,
                relationLeader:"",
                date:"",
                picUrl:""
            },
            approvedInfo:{
              approve:"",
                date:"",
                picUrl:""
            }
          },
          monitor:{
            monitor:"",
              date:"",
              picUrl:""
          },
          transferWork:{
            transferInfo:{
              transfer:"",
                date:""
            },
            receiveInfo:{
              receive:"",
                date:""
            }
          },
          closeWork:{
            applyInfo:{
              apply:"",
                date:"",
                picUrl:""
            },
            approvedInfo:{
              approve:"",
                date:"",
                picUrl:""
            }
          }
        },
        fileList:[]
      }
    },
    methods:{
      permitClose(){
        this.$emit("update:permitOpen", false);
        //安全分析
        if(this.certificateData.applyStatus == '0'){
          this.resetMainDangerousMark();
        }
        //审批人审批
        if(this.certificateData.applyStatus == '1'){
          this.resetCertificate();
        }
        //事前检查
        if(this.certificateData.applyStatus == '4'){
          this.resetRelationSign();
          this.resetProduceComfirm();
        }
        if(this.certificateData.applyStatus == '5' || this.certificateData.applyStatus == '6'){
          this.restWorkDeal();
        }
      },
      //确认安全数据
      submitDangerous(dangerousData){
        this.dangerousMarkDetial = dangerousData;
        this.dangerousFlag = false;
      },
      //取消安全数据
      cancelDangerous(){
        if(this.certificateData.applyStatus == '0'){
          this.resetDangerousMarkDetial();
        }
        this.dangerousFlag = false;

      },
      //重置危险标识
      resetMainDangerousMark(){
        this.mainDangerousMark = {
          burn:false,
          electricShock:false,
          objectStrike:false,
          stifle:false,
          drop:false,
          vehicleInjury:false,
          other:false
        };
      },
      //重置安全措施
      resetDangerousMarkDetial(){
        this.dangerousMarkDetial = {
          noxiousGas:{
            isChecked:false,
            processPurging:false,
            ventilate:false,
            mechanicalVentilation:false,
            naturalVentilation:false,
            gasComposition:false,
            guardian:{
              isChecked:false,
              person: ""
            }
          },
          heightWork:{
            isChecked:false,
            ladderCheck:false,
            ladderStable:{
              isChecked:false,
              top:false,
              bottom:false
            },
            scaffolding:false,
            designatedErea:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            tools:false
          },
          fireAndExplosionProof:{
            isChecked:false,
            moveCombustibles:false,
            container:false,
            sprayWater:false,
            barrier:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            other:{
              isChecked:false,
              detail:""
            },
            firePreventionTools:false,
            fireproofBlanket:false,
            fireHose:false,
            fireExtinguisher:{
              isChecked:false,
              carbonDioxide:false,
              abc:false,
              other:{
                isChecked:false,
                detail:""
              },
              specifications:"",
              quantity:""
            }
          },
          electricShockProtection:{
            isChecked:false,
            powerSupply:false,
            checkCircuit:false,
            checkSocket:false,
            insulatingLadder:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            safeDistance:false,
            insulatingGloves:false,
            insulatingShoe:false,
            insulatingClothing:false,
            insulatingMat:false,
            groundingProtector:false,
            removeFuse:false,
            disconnectGate:false,
            isolateWorkArea:false,
            other:{
              isChecked:false,
              detail:""
            }
          },
          lockoutTagout:{
            isChecked:false,
            safetyEnergyRing:{
              isChecked:false,
              hydraulicPressure:false,
              pressure:false,
              mechanicalEnergy:false,
              steam:false,
              electrical:false,
              other:false
            },
            energyTest:false,
            personalLock:false,
            lockBox:false,
            contractorGroup:false,
            values:{
              isChecked:false,
              blindPlate:false,
              vent:false,
              pipingSplit:false,
              deviceVent:false,
              cutOffInstrumentGas:false,
              switchLocked:false
            }
          },
          hoisting:{
            isChecked:false,
            hoistingCheck:false,
            cantileverSupport:false,
            hoistingLevel:false,
            wireSpacing:false,
            settingAreaIsolation:false,
            guardian:{
              isChecked:false,
              person: ""
            },
            liftingPlan:false,
            hoistingToolsCheck:false
          },
          groundBreaking:{
            isChecked:false,
            groundDevice:false,
            eleticGrounding:false,
            brace:false,
            topDistance:false,
            warningMark:false,
            emergencyAccess:false,
            lighting:false,
            moveMaterial:false
          },

          protectArticles:{
            isChecked:false,
            headProtect:{
              isChecked:false,
              hat:false,
              allFaceShield:false,
              halfFaceShield:false
            },
            protectGlass:{
              isChecked:false,
              attack:false,
              eletic:false,
              spatter:false,
              dust:false,
              faceShield:false
            },
            hearing:{
              isChecked:false,
              earplugs:false,
              doubleProtection:false,
              timeControl:false
            },
            breathing:{
              isChecked:false,
              dustFiltration:false,
              gasFiltration:false,
              dustAndGas:false,
              scba:false,
              respirator:false
            },
            head:{
              isChecked:false,
              canvas:false,
              chemicalResistantGloves:false,
              weldingGloves:false,
              lowTemperatureGloves:false,
              heightTemperatureGloves:false,
              cutResistantGloves:false,
              prohibitGloves:false
            },
            body:{
              isChecked:false,
              weldingSuit:false,
              antistatic:false,
              weldingSuitA:false,
              weldingSuitB:false,
              weldingSuitC:false,
              weldingSuitD:false
            },
            foot:{
              isChecked:false,
              antiPiercingShoe:false,
              insulationShoe:false,
              antiChemicalShoe:false,
              antistaticShoe:false
            },
            specialLabor:{
              isChecked:false,
              safetyBelt:false,
              safetyNet:false,
              gasMonitor:false,
              communicationEquipment:false
            },
            other:{
              isChecked:false,
              detail:""
            }

          },

          otherWork:{
            isChecked:false,
            detail:""
          },
          checkResult:[
            {
              checkPoint:"",
              checkTime:"",
              oxygenContent:"",
              flammableGasContent:"",
              toxicGasContent:""
            },
            {
              checkPoint:"",
              checkTime:"",
              oxygenContent:"",
              flammableGasContent:"",
              toxicGasContent:""
            },
            {
              checkPoint:"",
              checkTime:"",
              oxygenContent:"",
              flammableGasContent:"",
              toxicGasContent:""
            }
          ]
        };
      },
      //重置许可证信息
      resetCertificate(){
        this.certificate = {
          jsa:{
            yes:false,
              no:false,
              num:""
          },
          specialLicence:false,
            lockListing:{
            isChecked:false,
              num:""
          },
          blindPlate:{
            isChecked:false,
              num:""
          },
          flareUp:{
            isChecked:false,
              num:""
          },
          heightWork:{
            isChecked:false,
              num:""
          },
          breakGround:{
            isChecked:false,
              num:""
          },
          hoisting:{
            isChecked:false,
              num:""
          },
          limitSpace:{
            isChecked:false,
              num:""
          },
          electricityUse:{
            isChecked:false,
              num:""
          },
          ray:{
            isChecked:false,
              num:""
          }
        }
      },
      resetRelationSign(){
        this.relationSign ={
          executor:"",
          contractor:[
            {
              sign:"",
              peoples:""
            },
            {
              sign:"",
              peoples:""
            }
          ],
          picUrl:""
        }
      },
      resetProduceComfirm(){
        this.produceComfirm = {
          monitor:"",
          date:""
        }
      },
      restWorkDeal(){
        this.WorkDeal = {
          workCheck:{
            leaderInfo:{
              leader:"",
              date:"",
              picUrl:""
            },
            relationInfo:{
              yes:false,
              no:false,
              relationLeader:"",
              date:"",
              picUrl:""
            },
            approvedInfo:{
              approve:"",
              date:"",
              picUrl:""
            }
          },
          monitor:{
            monitor:"",
            date:"",
            picUrl:""
          },
          transferWork:{
            transferInfo:{
              transfer:"",
              date:""
            },
            receiveInfo:{
              receive:"",
              date:""
            }
          },
          closeWork:{
            applyInfo:{
              apply:"",
              date:"",
              picUrl:""
            },
            approvedInfo:{
              approve:"",
              date:"",
              picUrl:""
            }
          }
        }
      },
      //提交许可单
      permitSubmit(){
        var param = {};
        param.workPermitId =  this.certificateData.workPermitId;
        //安全分析
        if(this.certificateData.applyStatus == '0'){
          //校验
          if(!this.validateAnalyseData()){
            return;
          };
          param.dangerousMarkDetial =  JSON.stringify(this.dangerousMarkDetial);
          param.mainDangerousMark =  JSON.stringify(this.mainDangerousMark);
          param.applyStatus = '1';
        }
        //审批人审批
        if(this.certificateData.applyStatus == '1'){
          //校验
          if(!this.validateCertificate()){
            return;
          };
          param.licenceInfo = JSON.stringify(this.certificate);
          if(this.certificate.specialLicence){
            param.applyStatus = '4';
          }else{
            param.applyStatus = '2';
          }
        }
        //作业前检查
        if(this.certificateData.applyStatus == '4'){
          if(this.validateRelationSign()){
            return;
          }
          param.relationSign = JSON.stringify(this.relationSign);
          param.produceComfirm = JSON.stringify(this.produceComfirm);
          param.applyStatus = '5';
        }
        //作业中
        if(this.certificateData.applyStatus == '5'){
          if(this.validateWorkDeal()){
            return
          }
          if(this.workDeal.workCheck.leaderInfo.leader != '' && this.workDeal.workCheck.approvedInfo.approve != ''){
            param.applyStatus = '6';
          }
          param.workDeal = JSON.stringify(this.workDeal);
        }
        //关闭作业单
        if(this.certificateData.applyStatus == '6'){
          if(this.workDeal.closeWork.applyInfo.apply != '' && this.workDeal.closeWork.approvedInfo.approve != ''){
            param.applyStatus = '7';
          }
          param.workDeal = JSON.stringify(this.workDeal);
        }

        updatePermit(param).then(response => {
          this.msgSuccess("信息填写成功");
          this.$emit("update:permitOpen", false);
          this.$emit("getList");
        });
      },
      //校验安全分析数据
      validateAnalyseData(){
        for(var key in this.mainDangerousMark){
          var value = this.mainDangerousMark[key];
          if(value){
            if(JSON.stringify(this.dangerousMarkDetial) === "{}"){
              this.msgError("请填写安全措施");
              return false;
            }
          }
        }
        return true;
      },
      //校验许可证信息
      validateCertificate(){
        var flag = true;
        for(var key in this.certificate){
          var check = false;
          if("specialLicence" == key){
            check = this.certificate[key];
          }else{
            check = this.certificate[key].isChecked;
          }
          if(check){
            flag = false;
          }
        }
        if(flag){
          this.msgError("请填写许可证信息");
          return false;
        }
        return true;
      },
      //相关方校验
      validateRelationSign(){
        if(!this.relationSign.executor){
          this.msgError("作业执行人员请签字！")
          return true;
        }
        if(this.relationSign.contractor[0].sign == '' || this.relationSign.contractor[1].sign == ''){
          this.msgError("承包商请签字！")
          return true;
        }
        if(!this.produceComfirm.monitor){
          this.msgError("当班班长请签字！");
          return true;
        }
        if(this.produceComfirm)
        if(!this.relationSign.picUrl){
          this.msgError("请上传现场照片！");
          return true;
        }
        return false;
      },
      //校验工作中
      validateWorkDeal(){
        if(this.certificateData.signPerson == "contractor"){
          if(this.workDeal.workCheck.leaderInfo.leader == ""){
            this.msgError("作业执行人请签字！");
            return true;
          }
        }
        if(this.certificateData.signPerson == "ratifier"){
          if(this.workDeal.workCheck.approvedInfo.approve == ''){
            this.msgError("批准人请签字！");
            return true;
          }
        }
        return false;
      },
      getFileInfo(res){
        if(this.certificateData.applyStatus == '4'){
          this.relationSign.picUrl = res.url;
        }
        if(this.certificateData.applyStatus == '5'){
          if(this.workDeal.workCheck.leaderInfo.leader != ""){
            this.workDeal.workCheck.leaderInfo.picUrl = res.url;
          }
          if(this.workDeal.workCheck.approvedInfo.approve != ""){
            this.workDeal.workCheck.approvedInfo.picUrl = res.url;
          }
        }

        if(this.certificateData.applyStatus == '6'){
          if(this.workDeal.closeWork.applyInfo !=""){
            this.workDeal.closeWork.applyInfo.picUrl = res.url;
          }
          if(this.workDeal.closeWork.approvedInfo.approve != ""){
            this.workDeal.closeWork.approvedInfo.picUrl = res.url;
          }
        }
        //this.form.certificateUrl = res.url;
      },
      listRemove(e) {
        if(this.certificateData.applyStatus == '4'){
          this.relationSign.picUrl = '';
        }
        if(this.certificateData.applyStatus == '5'){
          if(this.workDeal.workCheck.leaderInfo.leader != ""){
            this.workDeal.workCheck.leaderInfo.picUrl = '';
          }
          if(this.workDeal.workCheck.approvedInfo.approve != ""){
            this.workDeal.workCheck.approvedInfo.picUrl = '';
          }
        }
        if(this.certificateData.applyStatus == '6'){
          if(this.workDeal.closeWork.applyInfo !=""){
            this.workDeal.closeWork.applyInfo.picUrl = '';
          }
          if(this.workDeal.closeWork.approvedInfo.approve != ""){
            this.workDeal.closeWork.approvedInfo.picUrl = '';
          }
        }
        //this.form.certificateUrl = "";
        this.fileList = [];
      },
    },
  }
</script>

<style scoped lang="scss">
  table{
    border-collapse: collapse;
    table-layout: fixed;
    text-align: center;
    width: 100%;
  }
  table td, table th{
    border: 1px solid;
    height: 30px;
  }

  .editInput{
    border: none;
    width: 100%;
    height: 100%;
    text-align: center;
  }

  .editInput:focus{
    outline: none;
  }

  .editLine{
    border-bottom: 1px solid;
    border-top: none;
    border-left: none;
    border-right: none;
    text-align: center;
  }

  .editLine:focus{
    outline: none;
  }


  textarea{
    height: 100%;
    width: 100%;
    border: none;
    resize:none;
  }

  textarea:focus{
    outline: none;
  }

  .permit{
    height: 400px;;
    overflow-y: scroll;
    &::-webkit-scrollbar {
      width:5px;
    }
    &::-webkit-scrollbar-track {
      -webkit-box-shadow:inset006pxrgba(0,0,0,0.3);
      border-radius:10px;
    }
    &::-webkit-scrollbar-thumb {
      border-radius:5px;
      background:rgba(0,0,0,0.1);
      -webkit-box-shadow:inset006pxrgba(0,0,0,0.5);
    }
  }


</style>
