<template>
  <div id="">
    <a-layout>
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;overflow: auto;">
        <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.isBuldWtr">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isBuldWtr == '2'" type="link" @click="addProblem('isBuldWtr')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="2、是否建立巡查制度以及巡查记录是否完整">
            <a-radio-group v-model:value="formObj.isBuldWtr">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="2.1 是否建立巡查制度" v-if="formObj.isBuldMg == '2'">
            <a-radio-group v-model:value="formObj.isBuldPtr">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isBuldPtr == '2'" type="link" @click="addProblem('isBuldPtr')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="2.2 巡查记录是否完整" v-if="formObj.isBuldMg == '2'">
            <a-radio-group v-model:value="formObj.isPrtAll">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPrtAll == '2'" type="link" @click="addProblem('isPrtAll')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3、是否建立信息监控系统">
            <a-radio-group v-model:value="formObj.isMonSys">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isMonSys == '2'" type="link" @click="addProblem('isMonSys')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="4、是否制定应急预案及开展应急演练">
            <a-radio-group v-model:value="formObj.isBuldDry">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="4.1 是否制定应急预案" v-if="formObj.isBuldDry == '2'">
            <a-radio-group v-model:value="formObj.isBuldPlan">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isBuldPlan == '2'" type="link" @click="addProblem('isBuldPlan')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="4.2 是否开展应急演练" v-if="formObj.isBuldDry == '2'">
            <a-radio-group v-model:value="formObj.isBuldDrill">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isBuldDrill == '2'" type="link" @click="addProblem('isBuldDrill')">
                <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="61"
        :villType="61"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'水源地达标'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getRgstridSwhsjxStn } 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: {
        stnState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
      type: '',
      formObj: {},
      dialogFormVisible: false,
      formLabelWidth: '300px',
      loading: true,
      operationType1: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getRgstridObj();
  },
  methods: {
    getRgstridObj() {
      getRgstridSwhsjxStn(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.isBuldWtr != null &&
        this.formObj.isBuldMg != null &&
        this.formObj.isMonSys != null &&
        this.formObj.isBuldDry != null
      ) {
        this.formObj['state'] = '2';
        this.objtbStatu.stnState = '2';
        this.objtbStatu.state = '1';
      } else if (
        this.formObj.isBuldWtr == null &&
        this.formObj.isBuldMg == null &&
        this.formObj.isMonSys == null &&
        this.formObj.isBuldDry == null
      ) {
        this.objtbStatu.stnState = '0';
        this.formObj['state'] = '0';
      } else {
        this.objtbStatu.stnState = '1';
        this.objtbStatu.state = '1';
        this.formObj['state'] = '1';
      }
      this.$confirm({
        title: '提示',
        content: '确认保存生态流量泄放情况信息？',
        okType: 'warning',
        onOk: () => {
          try {
            request.post('/bis/insp/swhsjx/stn', this.formObj).then((res) => {
              if (res.success) {
                this.$message.success('修改成功');
                request
                  .post('/bis/insp/swhsjx/update', this.objtbStatu)
                  .then((res) => {
                    res;
                  });
                this.$emit('addShuiKuSuccess');
              }
            });
          } catch (e) {}
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_SWHSJX_STN',
      };
      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>
