<template>
  <div id="">
    <a-layout style="height:520px;">
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;">信息填报</p>
        <a-form :model="addObj" :label-col="{span: 10}" :wrapper-col="{span: 14}" :rules="rules">
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">综合管理</span><span class="hrs"></span>
          </p>
          <a-form-item label="组织机构与制度建设是否健全合理" required>
            <a-radio-group v-model:value="addObj.osascIsNasaa">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.osascIsNasaa =='2'" type="link" @click="addProblem('osascIsNasaa')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="人员管理是否满足工作要求" required>
            <a-radio-group v-model:value="addObj.pmIsMjr">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.pmIsMjr =='2'" type="link" @click="addProblem('pmIsMjr')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="信息档案管理工作是否落实到位" required>
            <a-radio-group v-model:value="addObj.iamIsPip">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.iamIsPip =='2'" type="link" @click="addProblem('iamIsPip')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">运行管理与调度</span><span class="hrs"></span>
          </p>
          <a-form-item label="工程运行管理与调度工作是否落实到位" required>
            <a-radio-group v-model:value="addObj.pomasIsPip">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.iamIsPip =='2'" type="link" @click="addProblem('pomasIsPip')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="工程巡查工作是否落实到位（含实体工程、设施设备等）" required>
            <a-radio-group v-model:value="addObj.eiIsPip">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.eiIsPip =='2'" type="link" @click="addProblem('eiIsPip')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="是否制定值班制度或值班计划" required>
            <a-radio-group v-model:value="addObj.isFmltWsOdp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.isFmltWsOdp =='2'" type="link" @click="addProblem('isFmltWsOdp')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">应急管理</span><span class="hrs"></span>
          </p>
          <a-form-item label="应急准备工作是否落实到位" required>
            <a-radio-group v-model:value="addObj.epIsPip">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.epIsPip =='2'" type="link" @click="addProblem('epIsPip')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="突发事件是否按规定报告，且及时采取应急处理措施" required>
            <a-radio-group v-model:value="addObj.emgcIsRarTem">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.emgcIsRarTem =='2'" type="link" @click="addProblem('emgcIsRarTem')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">防汛度汛</span><span class="hrs"></span>
          </p>
          <a-form-item label="度汛准备工作是否落实到位" required>
            <a-radio-group v-model:value="addObj.pffsIsPip">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.pffsIsPip =='2'" type="link" @click="addProblem('pffsIsPip')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="是否按规定或巡查方案进行度汛、防汛检查（查看检查记录）" required>
            <a-radio-group v-model:value="addObj.isAtroipIffcafc">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.isAtroipIffcafc =='2'" type="link" @click="addProblem('isAtroipIffcafc')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">设备设施丶软硬件系统</span><span class="hrs"></span>
          </p>
          <a-form-item label="是否按规定对设施设备进行试运行、功能性测试或调试" required>
            <a-radio-group v-model:value="addObj.isAttrotfaeCftod">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.isAttrotfaeCftod =='2'" type="link" @click="addProblem('isAttrotfaeCftod')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">供电系统(主要检查备用电源情况)</span><span class="hrs"></span>
          </p>
          <a-form-item label="高低压系统是否正常运行" required>
            <a-radio-group v-model:value="addObj.halpsIsGdrun">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.halpsIsGdrun =='2'" type="link" @click="addProblem('halpsIsGdrun')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="汽柴油发电机是否正常运行" required>
            <a-radio-group v-model:value="addObj.sdgIsGdrun">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.sdgIsGdrun =='2'" type="link" @click="addProblem('sdgIsGdrun')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">维修养护</span><span
              class="hrs"></span>
          </p>
          <a-form-item label="工程缺陷是否按规定及时处理（工程缺陷是否处理或上报维养计划）" required>
            <a-radio-group v-model:value="addObj.edIsThatr">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.edIsThatr =='2'" type="link" @click="addProblem('edIsThatr')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">安全管理</span><span class="hrs"></span>
          </p>
          <a-form-item label="是否建立健全安全生产责任制" required>
            <a-radio-group v-model:value="addObj.isBldWwitrsfps">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.isBldWwitrsfps =='2'" type="link" @click="addProblem('isBldWwitrsfps')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="安全生产相关工作是否符合要求" required>
            <a-radio-group v-model:value="addObj.wrtpsIsPm">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.wrtpsIsPm =='2'" type="link" @click="addProblem('wrtpsIsPm')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="是否及时发现安全隐患且按规定报告" required>
            <a-radio-group v-model:value="addObj.isTfsharar">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.isTfsharar =='2'" type="link" @click="addProblem('isTfsharar')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" /><span style="width:120px;padding-left: 10px">工程监测</span><span class="hrs"></span>
          </p>
          <a-form-item label="是否开展监测工作或对委托单位的监测工作进行检查" required>
            <a-radio-group v-model:value="addObj.isTcomwTitmwoteu">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.isTcomwTitmwoteu =='2'" type="link" @click="addProblem('isTcomwTitmwoteu')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 14, offset: 10 }">
            <a-button type="primary" @click="makesure">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog"
        :objType="pType"
        :villType="0"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'大中型水库'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getLyjglist } from '../../../api/duChaTianBao';
import { getManagelist } from '../../../api/fujian_api';
import request from '../../../utils/gw_ajax_request';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  components: {
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'pType',
  ],
  data() {
    return {
      objtbStatu: {
        runManageState: '',
        id: '',
      },
      dxdcMainHeight: window.innerHeight - 197,
      dialogFormVisible: false,
      formLabelWidth: '300px',
      loading: true,
      addObj: {
        osascIsNasaa: '', // 组织机构与制度建设是否健全合理
        pmIsMjr: '', // 组织机构与制度建设是否健全合理
        iamIsPip: '', // 信息档案管理工作是否落实到位
        pomasIsPip: '', // 工程运行管理与调度工作是否落实到位
        eiIsPip: '', // 工程巡查工作是否落实到位（含实体工程、设施设备等）
        isFmltWsOdp: '', // 是否制定值班制度或值班计划
        epIsPip: '', // 应急准备工作是否落实到位
        emgcIsRarTem: '', // 突发事件是否按规定报告，且及时采取应急处理措施
        pffsIsPip: '', // 度汛准备工作是否落实到位
        isAtroipIffcafc: '', // 是否按规定或巡查方案进行度汛、防汛检查（查看检查记录）
        isAttrotfaeCftod: '', // 是否按规定或巡查方案进行度汛、防汛检查（查看检查记录）
        halpsIsGdrun: '', // 高低压系统是否正常运行
        sdgIsGdrun: '', // 汽柴油发电机是否正常运行
        edIsThatr: '', // 工程缺陷是否按规定及时处理（工程缺陷是否处理或上报维养计划）
        isBldWwitrsfps: '', // 是否建立健全安全生产责任制
        wrtpsIsPm: '', // 安全生产相关工作是否符合要求
        isTfsharar: '', // 是否及时发现安全隐患且按规定报告
        isTcomwTitmwoteu: '', // 是否开展监测工作或对委托单位的监测工作进行检查
        mngrnId: '',
        rgstrId: '',
        status: '',
      },
      operationType1: '',
      lyjg: [],
      placeholder: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
      ifPdtj1: '',
      ifPdtj2: '',
      ifPdtj3: '',
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getLyjgList();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getformList();
    },
  },
  methods: {
    // 格式化判断条件
    getStrParams(obj) {
      let str = '';
      for (const key of Object.keys(obj)) {
        str += `${obj}.${key}||`;
      }
      str = str.slice(0, str.length - 2);
      return str;
    },
    getLyjgList() {
      getLyjglist().then((res) => {
        if (res.success) {
          this.lyjg = res.data;
          this.placeholder = this.lyjg[0].pnm;
          this.addObj.reverOrg = this.lyjg[0].id;
          this.getformList();
        } else {
          this.getformList();
        }
      });
    },
    getformList() {
      getManagelist(this.currentObjectRgstrId).then((res) => {
        if (res.success) {
          if (res.data && Object.keys(res.data).length) {
            this.addObj = res.data;
            this.operationType1 = 'update';
          } else {
            this.addObj = {};
            this.operationType1 = 'add';
          }
        } else {
        }
      });
    },
    // 保存
    makesure() {
      if (
        this.addObj.osascIsNasaa ||
        this.addObj.pmIsMjr ||
        this.addObj.iamIsPip ||
        this.addObj.pomasIsPip ||
        this.addObj.eiIsPip ||
        this.addObj.isFmltWsOdp ||
        this.addObj.epIsPip ||
        this.addObj.emgcIsRarTem ||
        this.addObj.pffsIsPip ||
        this.addObj.isAtroipIffcafc ||
        this.addObj.isAttrotfaeCftod ||
        this.addObj.halpsIsGdrun ||
        this.addObj.sdgIsGdrun ||
        this.addObj.edIsThatr ||
        this.addObj.isBldWwitrsfps ||
        this.addObj.wrtpsIsPm ||
        this.addObj.isTfsharar ||
        this.addObj.isTcomwTitmwoteu
      ) {
        this.addObj['status'] = '1';
      }
      if (
        this.addObj.osascIsNasaa &&
        this.addObj.pmIsMjr &&
        this.addObj.iamIsPip &&
        this.addObj.pomasIsPip &&
        this.addObj.eiIsPip &&
        this.addObj.isFmltWsOdp &&
        this.addObj.epIsPip &&
        this.addObj.emgcIsRarTem &&
        this.addObj.pffsIsPip &&
        this.addObj.isAtroipIffcafc &&
        this.addObj.isAttrotfaeCftod &&
        this.addObj.halpsIsGdrun &&
        this.addObj.sdgIsGdrun &&
        this.addObj.edIsThatr &&
        this.addObj.isBldWwitrsfps &&
        this.addObj.wrtpsIsPm &&
        this.addObj.isTfsharar &&
        this.addObj.isTcomwTitmwoteu
      ) {
        this.addObj['status'] = '2';
      }
      if (
        this.addObj.osascIsNasaa == undefined &&
        this.addObj.pmIsMjr == undefined &&
        this.addObj.iamIsPip == undefined &&
        this.addObj.pomasIsPip == undefined &&
        this.addObj.eiIsPip == undefined &&
        this.addObj.isFmltWsOdp == undefined &&
        this.addObj.epIsPip == undefined &&
        this.addObj.emgcIsRarTem == undefined &&
        this.addObj.pffsIsPip == undefined &&
        this.addObj.isAtroipIffcafc == undefined &&
        this.addObj.isAttrotfaeCftod == undefined &&
        this.addObj.halpsIsGdrun == undefined &&
        this.addObj.sdgIsGdrun == undefined &&
        this.addObj.edIsThatr == undefined &&
        this.addObj.isBldWwitrsfps == undefined &&
        this.addObj.wrtpsIsPm == undefined &&
        this.addObj.isTfsharar == undefined &&
        this.addObj.isTcomwTitmwoteu == undefined
      ) {
        this.addObj['status'] = '0';
      }

      this.$confirm({
        title: '提示',
        content: '确认保存运行管理情况信息吗？',
        okType: 'warning',
        onOk: () => {
          this.addObj['rgstrId'] = this.currentObjectRgstrId;
          this.addObj['recPersId'] = this.recPersId;
          if (this.operationType1 == 'add') {
            request
              .post('/bis/insp/rsml/rgstr/run/manage', this.addObj)
              .then((res) => {
                if (res.success) {
                  this.$message.success('添加成功');
                  this.$emit('addShuiKuSuccess');
                }
              });
          } else {
            request
              .post('/bis/insp/rsml/rgstr/run/manage', this.addObj)
              .then((res) => {
                if (res.success) {
                  this.$message.success('修改成功');
                  this.$emit('addShuiKuSuccess');
                }
              });
          }
        },
      });
    },
    // 查看
    makeshow(type, row) {
      this.dialogFormVisible = true;
    },
    formatRadio(val) {
      if (val == '1') {
        return '是';
      } else if (val == '0') {
        return '否';
      } else {
        return val;
      }
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_RSML_RGSTR_RUN_MANAGE',
        type: this.pType,
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
    addProblem(item) {
      const rest = this.rsvrRules.filter((e) => {
        return e.eName === item;
      });
      this.probId = rest[0].id;
      this.showAddProblemDialog = true;
    },
    closePlDialog(val) {
      this.showAddProblemDialog = false;
    },
  },
};
</script>

<style lang='less' scoped>

</style>
