<template>
  <div class="gcsthyxglqk">
    <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: 8}" :wrapper-col="{span: 16}" :rules="rules" ref="addObj">
          <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.requiredRule">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-radio value="3">鉴定为三类坝</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="按规定需要开展" v-if="addObj.requiredRule == '1'">
            <a-radio-group v-model:value="addObj.demandRule">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item v-if="addObj.demandRule == '1'">
            <a-radio-group v-model:value="addObj.appraiseResult">
              <a-radio value="1">鉴定报告内容合规</a-radio>
              <a-radio value="2">鉴定报告内容不规范</a-radio>
              <a-radio value="3">鉴定单位资质符合规定</a-radio>
              <a-radio value="4">鉴定单位资质不符</a-radio>
            </a-radio-group>
          </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.isReinforce">
              <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.isReinforce == '1'">
            <a-radio-group v-model:value="addObj.statusOfLatest">
              <a-radio value="1">已按批复内容实施</a-radio>
              <a-radio value="2">未按批复内容实施</a-radio>
              <a-radio value="3">实施后仍有隐患</a-radio>
              <a-radio value="4">已蓄水验收</a-radio>
              <a-radio value="5">未蓄水验收</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="正在实施水库情况" v-if="addObj.isReinforce == '1'">
            <a-radio-group v-model:value="addObj.statusOfLatest">
              <a-radio value="1">正按批复内容实施</a-radio>
              <a-radio value="2">未按批复内容实施</a-radio>
              <a-radio value="3">施工按期进行</a-radio>
              <a-radio value="4">施工时间超批复工期</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="鉴定为三类坝应实施未实施" required>
            <a-radio-group v-model:value="addObj.statusOfLatest">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 16, offset: 8 }">
            <a-button type="primary" @click="makesure('addObj')">保 存</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, getManagelist } from '../../../api/duChaTianBao';
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: {
        resRunStat: '',
        rgstrId: '',
      },
      dxdcMainHeight: window.innerHeight - 197,
      dialogFormVisible: false,
      formLabelWidth: '200px',
      loading: true,
      addObj: {
        isReinforce: '', // 是否已实施除险加固 add by xqyi
        thirdAndUnenforced: '', // 三类坝应实施未实施  add by xqyi
        ifManageReg: '',
        appraiseResult: '', // 鉴定结果 add by xqyi
        statusOfOperating: '', // 正在实施除险加固的水库的情况  add by xqyi

        requiredRule: '', // 是否按规定需要开展  add by xqyi
        demandRule: '', // 是否按要求开展  add by xqyi

        statusOfLatest: '', // 最近一次除险加固情况   add by xqyi
      },
      rules: {},
      operationType1: '',
      lyjg: [],
      placeholder: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getLyjgList();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getformList();
    },
  },
  methods: {
    getformList() {
      console.log('currentObjectRgstrId on getformList method.');
      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(formName) {
      console.log(
        'currentObjectRgstrId on makesure method.' + this.currentObjectRgstrId,
      );
      this.$refs[formName].validate((valid) => {
        if (valid) {
          const _self = this;
          this.addObj['rgstrId'] = this.currentObjectRgstrId;
          this.addObj['recPersId'] = this.recPersId;
          this.objtbStatu.rgstrId = this.currentObjectRgstrId;
          if (this.addObj.requiredRule == '2') {
            this.addObj.demandRule = '';
          }
          if (this.addObj.isReinforce == '1') {
            this.addObj.statusOfLatest = '';
          }

          this.$confirm({
            title: '提示',
            content: '确认保存安全鉴定及除险加固情况信息吗？',
            okType: 'warning',
            onOk: () => {
              console.log(
                'confirmed to post request to server ' + _self.operationType1,
              );
              if (_self.operationType1 == 'add') {
                request
                  .post('/dc/insp/SecurityIdentity', _self.addObj)
                  .then((res) => {
                    if (res.success) {
                      _self.$message.success('添加成功');
                      request
                        .post('/dc/insp/rsvrRgstr/update', _self.objtbStatu)
                        .then((res) => {
                          res;
                        });
                      _self.$emit('addShuiKuSuccess');
                    }
                  });
              } else {
                console.log('update to db ' + _self.addObj);
                request
                  .post('/dc/insp/SecurityIdentity/update', _self.addObj)
                  .then((res) => {
                    if (res.success) {
                      _self.$message.success('修改成功');
                      request
                        .post('/dc/insp/rsvrRgstr/update', _self.objtbStatu)
                        .then((res) => {
                          res;
                        });
                      _self.$emit('addShuiKuSuccess');
                    }
                  });
              }
            },
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 查看
    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_SAFE_EXT_MANAGE',
        type: this.pType,
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
    addProblem(item) {
      let rest = null;
      if (item == 'statusOfLatest') {
        rest = this.rsvrRules.filter((e) => {
          return e.iValue === this.addObj.statusOfLatest && e.eName === item;
        });
      } else {
        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;
}
</style>
