<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;margin-bottom: 20px">信息填报</p>
        <a-form :model="formObj" :label-col="{ span: 10 }" :wrapper-col="{ span: 14 }">
          <a-form-item label="1、大坝是否无明显渗漏、裂缝、塌陷、隆起、动物洞穴、蚁害等病险隐患。">
            <a-radio-group v-model:value="formObj.isNml">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="1.1 大坝是否存在明显渗漏病险隐患" v-if="formObj.isNml == '2'">
            <a-radio-group v-model:value="formObj.isLkg">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isLkg == '1'" type="link" @click="addProblem('isLkg')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="1.2 大坝是否存在明显裂缝病险隐患" v-if="formObj.isNml == '2'">
            <a-radio-group v-model:value="formObj.isFissure">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isFissure == '1'" type="link" @click="addProblem('isFissure')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="1.3 大坝是否存在明显塌陷病险隐患" v-if="formObj.isNml == '2'">
            <a-radio-group v-model:value="formObj.isSub">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSub == '1'" type="link" @click="addProblem('isSub')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="1.4 大坝是否存在明显隆起病险隐患" v-if="formObj.isNml == '2'">
            <a-radio-group v-model:value="formObj.isRise">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isRise == '1'" type="link" @click="addProblem('isRise')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="1.5 大坝是否存在明显动物洞穴或蚁害病险隐患" v-if="formObj.isNml == '2'">
            <a-radio-group v-model:value="formObj.isCave">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isCave == '1'" type="link" @click="addProblem('isCave')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="1.6 大坝是否无明显其他病险隐患。" v-if="formObj.isNml == '2'">
            <a-radio-group v-model:value="formObj.isOthr">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isOthr == '1'" type="link" @click="addProblem('isOthr')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <span class="tip_info">注：如选“是”请在备注中说明具体隐患</span>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 10, offset: 14 }">
            <a-button type="primary" @click="addHandler" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog && openType"
        :objType="59"
        :villType="59"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'长江经济带小水电清理'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getRgstridHystjxSaf } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import { formatDateTimeD } from '../../../utils/gw_date';
import inputWith from '../../../widgets/inuptWith.vue';
import problemDialog from '../../duChaWenTi/problemDialog.vue';

export default {
  components: {
    inputWith: inputWith,
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'openType',
  ],
  data() {
    return {
      id: '',
      objtbStatu: {
        safState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
      type: '',
      formObj: {},
      dialogFormVisible: false,
      formLabelWidth: '320px',
      loading: true,
      operationType1: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getRgstridObj();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getRgstridObj();
    },
  },
  methods: {
    getRgstridObj() {
      getRgstridHystjxSaf(this.currentObjectRgstrId).then((res) => {
        if (res.data && Object.keys(res.data).length) {
          this.formObj = res.data;
          this.operationType1 = 'update';
          this.id = res.data.id;
        } else {
          this.formObj = {};
          this.operationType1 = 'add';
        }
      });
    },
    addHandler() {
      this.formObj['rgstrId'] = this.currentObjectRgstrId;
      this.formObj['recPersId'] = this.recPersId;
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;
      this.objtbStatu.id = this.currentObjectRgstrId;

      if (this.formObj.isNml != null) {
        this.formObj['state'] = '2';
        this.objtbStatu.safState = '2';
        this.objtbStatu.state = '1';
      } else if (this.formObj.isNml == null) {
        this.objtbStatu.safState = '0';
        this.formObj['state'] = '0';
      } else {
        this.objtbStatu.safState = '1';
        this.objtbStatu.state = '1';
        this.formObj['state'] = '1';
      }
      this.$confirm({
        title: '提示',
        content: '确认保存大坝安全情况信息？',
        okType: 'warning',
        onOk: () => {
          request.post('/bis/insp/hystjx/saf', this.formObj).then((res) => {
            if (res.success) {
              this.$message.success('修改成功');
              request
                .post('/bis/insp/hystjx/update', this.objtbStatu)
                .then((res) => {
                  res;
                });
              this.$emit('addShuiKuSuccess');
            }
          });
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_HYST_SAF',
      };
      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>
#dcdxHeader {
   padding: 15px 20px;
 }

#dxdcFooter {
   text-align: center;
 }

 #dxdcAside {
   border: 1px solid #d5d5ff;
 }

 .el-dialog__wrapper .el-treeWhite {
   /* max-height: 260px !important; */
 }

 .add-problem-icon {
   font-size: 16px;
 }

 .el-icon-camera-solid,
 .el-icon-circle-plus {
   margin-left: 20px;
   color: #00bbff;
   font-size: 18px;
   line-height: 12px;
   vertical-align: middle;
   cursor: pointer;
 }

 .el-icon-circle-plus {
   vertical-align: top;
 }

 .tip_info {
   margin-left: 20px;
   font-size: 12px;
   color: #ff0000;
 }
</style>
