<template>
  <div id="">
    <a-layout>
      <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="diRongYangMaoRules" ref="addObj">
          <a-form-item label="督察对象是否包含险工险段">
            <a-radio-group v-model:value="addObj.isCtinDike">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否设置工程简介牌" v-if="addObj.isCtinDike === '1'">
            <a-radio-group v-model:value="addObj.isDspMes">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isDspMes == '2'" type="link" @click="addProblem('isDspMes', addObj.isDspMes)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否储备必要的抢险物资" v-if="addObj.isCtinDike === '1'">
            <a-radio-group v-model:value="addObj.isStoreGoods">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isStoreGoods == '2'" type="link" @click="addProblem('isStoreGoods', addObj.isStoreGoods)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 10, offset: 14 }">
            <a-button type="primary" @click="makesure('addObj')" v-if="openType">保 存</a-button>
          </a-form-item>
          <div class="tip_info">
            <p>符合以下条件之一的，即可判定为险工险段。 </p>
            <p>1. 老口门堤段：历史上出现决口但未彻底治理，背水侧仍存在坑塘或高水位期间出现集中渗水的堤段。</p>
            <p>2. 管涌堤段：曾出现过管涌、流土等渗透破坏但未彻底治理，高水位期间背水侧仍有明显渗水现象的堤段。</p>
            <p>3. 崩岸堤段：水流淘刷易造成崩岸、坍塌而危及堤防安全的堤段，包括因河势变化引起的洪（潮）水顶冲堤段。 </p>
            <p>4. 卡口堤段：堤距较小，过水断面严重不足，或河道弯曲狭窄，易造成卡阻洪水或冰凌的堤段。 </p>
            <p>5. 病险穿堤建筑物堤段：穿堤建筑物自身存在严重安全隐患，或与堤防接合部出现过渗水问题且未彻底治理，危及堤防安全的堤段。 </p>
            <p>6. 严重缺陷堤段：堤身堤基土质不好，施工质量差，存在较多隐患或堤身断面不满足设计规范要求，极易发生险情的薄弱堤段。 </p>
            <p>7. 其他堤段：其他严重影响堤防安全运行的堤段。 </p>
          </div>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog"
        :objType="58"
        :villType="58"
        :objId="rowData.objId"
        :objName="rowData.nm"
        :problemMiddleType="'堤防'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :rgstrId="rowData.rgstrId"
        :szRuls="[]">
      </problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import request from '../../../utils/gw_ajax_request';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  props: {
    rowData: {
      type: Object,
      default: {},
    },
    openType: {
      type: Boolean,
      default: true,
    },
  },
  components: {
    problemDialog,
  },
  data() {
    return {
      formLabelWidth: '530px',
      diRongYangMaoRules: {},
      probId: '',
      operationType1: '',
      id: '',
      objtbStatu: {
        jxqState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
      rsvrRules: null,
      showAddProblemDialog: false,
      addObj: {
        isCtinDike: '',
        isDspMes: '',
        isStoreGoods: '',
      },
    };
  },
  computed: {
    // 监听属性 类似于data概念
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    if (this.rowData.rgstrId) {
      this.getInfoData();
    }
  },
  methods: {
    makesure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addObj['rgstrId'] = this.rowData.rgstrId;
          this.addObj['recPersId'] = this.recPersId;
          this.objtbStatu.rgstrId = this.rowData.rgstrId;
          this.objtbStatu.id = this.rowData.rgstrId;
          if (
            this.addObj.isCtinDike != null &&
            this.addObj.isDspMes != null &&
            this.addObj.isStoreGoods != null
          ) {
            this.addObj['state'] = '2';
            this.objtbStatu.safeState = '2';
            this.objtbStatu.state = '1';
          } else if (
            this.addObj.isCtinDike != null &&
            this.addObj.isDspMes != null &&
            this.addObj.isStoreGoods != null
          ) {
            this.objtbStatu.safeState = '0';
            this.addObj['state'] = '0';
          } else {
            this.objtbStatu.safeState = '1';
            this.objtbStatu.state = '1';
            this.addObj['state'] = '1';
          }
          this.$confirm({
            title: '提示',
            content: '确认保存运行管理情况信息吗？',
            okType: 'warning',
            onOk: () => {
              request.post('/bis/insp/dikejx/safe', this.addObj).then((res) => {
                if (res.success) {
                  this.$message.success('添加成功');
                  request
                    .post('/bis/insp/dikejx/update', this.objtbStatu)
                    .then((res) => {
                      res;
                    });

                  this.$emit('addDiFangSuccess');
                }
              });
            },
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 如果已经填报  则查询
    getInfoData() {
      request
        .get('/bis/insp/dikejx/safe/' + this.rowData.rgstrId, {})
        .then((res) => {
          if (res.success) {
            this.addObj = res.data;
          }
        });
    },
    addProblem(item, iValue) {
      const rest = this.rsvrRules.filter((e) => {
        return e.iValue === iValue && e.eName === item;
      });
      if (rest[0]) {
        this.probId = rest[0].id;
      }
      this.showAddProblemDialog = true;
    },
    closePlDialog(val) {
      this.showAddProblemDialog = false;
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_DIKEJX_SAFE',
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
  },
};
</script>

<style lang='less' scoped>
.tip_info {
  width: 50%;
  margin: 20px auto;
  font-size: 12px;
  color: #ff0000;
}
</style>
