<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: 8}" :wrapper-col="{span: 16}" :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="按规定是否需要开展">
            <a-radio-group v-model:value="addObj.ifDamSafe">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <template v-if="addObj.ifDamSafe == '1'">
            <a-form-item label="是否按要求开展" v-if="addObj.ifDamSafe == '1'">
              <a-radio-group v-model:value="addObj.ifDamSafeReq">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.ifDamSafeReq =='2'" type="link" @click="addProblem('ifDamSafeReq')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
            <a-form-item label="鉴定报告内容是否合规" v-if="addObj.ifDamSafeReq == '1'" prop="ifDamSafeRul">
              <a-radio-group v-model:value="addObj.ifDamSafeRul">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.ifDamSafeRul =='2'" type="link" @click="addProblem('ifDamSafeRul')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
            <a-form-item label="鉴定单位资质是否符合规定" v-if="addObj.ifDamSafeReq == '1'" prop="ifDamSafeDepRul">
              <a-radio-group v-model:value="addObj.ifDamSafeDepRul">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.ifDamSafeDepRul =='2'" type="link" @click="addProblem('ifDamSafeDepRul')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
            <a-form-item label="安全鉴定是否被鉴定为三类坝" v-if="addObj.ifDamSafeReq == '1'" prop="ifDamSafeReq">
              <a-radio-group v-model:value="addObj.ifDamSafeThr">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
            </a-form-item>
          </template>
          <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="">
            <a-radio-group v-model:value="addObj.ifReinForce">
              <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-button v-if="addObj.ifReinForce =='4'" type="link" @click="addProblem('ifReinForce')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="最近一次除险加固情况" v-if="addObj.ifReinForce == '1'">
            <br>
            <a-form-item label="是否按批复内容实施" prop="reinForceRun">
              <a-radio-group v-model:value="addObj.reinForceRun">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.reinForceRun =='2'" type="link" @click="addProblem('reinForceRun')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
            <a-form-item label="实施后是否仍有隐患" prop="reinForceRun2">
              <a-radio-group v-model:value="addObj.reinForceRun2">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.reinForceRun2 =='2'" type="link" @click="addProblem('reinForceRun2')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
            <a-form-item label="是否蓄水验收" prop="reinForceRun3">
              <a-radio-group v-model:value="addObj.reinForceRun3">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.reinForceRun3 =='2'" type="link" @click="addProblem('reinForceRun3')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
          </a-form-item>
          <a-form-item label="正在实施水库情况" v-if="addObj.ifReinForce == '2'">
            <br>
            <a-form-item label="是否按批复内容实施" prop="ifReinImpGve">
              <a-radio-group v-model:value="addObj.ifReinImpGve">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.ifReinImpGve =='2'" type="link" @click="addProblem('ifReinImpGve')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
            <a-form-item label="施工是否按期进行" prop="ifReinImpPlan">
              <a-radio-group v-model:value="addObj.ifReinImpPlan">
                <a-radio value="1">是</a-radio>
                <a-radio value="2">否</a-radio>
              </a-radio-group>
              <a-button v-if="addObj.ifReinImpPlan =='2'" type="link" @click="addProblem('ifReinImpPlan')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-form-item>
          </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, getSecurityReinforce } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
// import ElTableWithPagination from "@widget/elTableWithPagination";
export default {
  components: {
    // ElTableWithPagination,
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'pType',
  ],
  data() {
    return {
      objtbStatu: {
        reverStat: '',
        rgstrId: '',
      },
      dxdcMainHeight: window.innerHeight - 197,
      dialogFormVisible: false,
      formLabelWidth: '180px',
      loading: true,
      addObj: {
        reverOrg: '',
        rgstrId: '',
        recPersId: '',
        // 注意有几个字段无法确认，需要掉接口查看
        ifReinForce: '',
        ifDamSafe: '', // 是否按规定需要开展
        ifDamSafeReq: '', // 是否按要求开展
        ifDamSafeRul: '', // 鉴定报告内容是否合规
        ifDamSafeDepRul: '', // 鉴定单位资质是否符合规定
        ifDamSafeThr: '', // 安全鉴定是否被鉴定为三类坝
        ifReinImpGve: '', // 正在实施水库情况是否按批复内容实施
        ifReinImpPlan: '', // 正在实施水库情况施工是否按期进行
        reinForceRun: '', // 最近一次除险加固情况是否按批复内容实施
        reinForceRun2: '', // 最近一次除险加固情况实施后是否仍有隐患
        reinForceRun3: '', // 最近一次除险加固情况是否蓄水验收
        status: '', // 填报状态
      },
      operationType1: '',
      lyjg: [],
      placeholder: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
      rules: {
        ifDamSafeRul: [
          {
            required: true,
            message: '请选择鉴定报告内容是否合规',
            trigger: 'change',
          },
        ],
        ifDamSafeDepRul: [
          {
            required: true,
            message: '请选择鉴定单位资质是否符合规定',
            trigger: 'change',
          },
        ],
        ifDamSafeReq: [
          {
            required: true,
            message: '请选择安全鉴定是否被鉴定为三类坝',
            trigger: 'change',
          },
        ],
        reinForceRun: [
          {
            required: true,
            message: '请选择是否按批复内容实施',
            trigger: 'change',
          },
        ],
        reinForceRun2: [
          {
            required: true,
            message: '请选择实施后是否仍有隐患',
            trigger: 'change',
          },
        ],
        reinForceRun3: [
          { required: true, message: '请选择是否蓄水验收', trigger: 'change' },
        ],
        ifReinImpGve: [
          {
            required: true,
            message: '请选择是否按批复内容实施',
            trigger: 'change',
          },
        ],
        ifReinImpPlan: [
          {
            required: true,
            message: '请选择施工是否按期进行',
            trigger: 'change',
          },
        ],
      },
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getLyList();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getformList();
    },
  },
  methods: {
    // 获取流域信息
    getLyList() {
      request.get(`/dc/insp/base/getInspByPid?pid=''`).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() {
      getSecurityReinforce(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 {
          this.$message.warning(res.message);
        }
      });
    },
    // 保存
    makesure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addObj['rgstrId'] = this.currentObjectRgstrId;
          this.addObj['recPersId'] = this.recPersId;
          if (this.addObj.ifDamSafe == '2') {
            this.addObj.ifDamSafeReq = '';
            this.addObj.ifDamSafeRul = '';
            this.addObj.ifDamSafeDepRul = '';
            this.addObj.ifDamSafeThr = '';
          }
          if (this.addObj.ifDamSafeReq == '2') {
            this.addObj.ifDamSafeRul = '';
            this.addObj.ifDamSafeDepRul = '';
            this.addObj.ifDamSafeThr = '';
          }
          if (
            (this.addObj.ifDamSafe == '2' &&
              Number(this.addObj.ifReinForce) > 2) ||
            (this.addObj.ifDamSafe && this.addObj.ifReinForce)
          ) {
            this.addObj.status = '2';
          } else {
            this.addObj.status = '1';
          }
          if (Number(this.addObj.ifReinForce) > 2) {
            this.addObj.reinForceRun = '';
            this.addObj.reinForceRun2 = '';
            this.addObj.reinForceRun3 = '';
            this.addObj.ifReinImpGve = '';
            this.addObj.ifReinImpPlan = '';
          }
          if (
            this.addObj.ifDamSafe == undefined &&
            this.addObj.ifReinForce == undefined
          ) {
            this.addObj.status = '0';
          }
          this.$confirm({
            title: '提示',
            content: '确认保存安全鉴定及除险加固信息吗？',
            okType: 'warning',
            onOk: () => {
              if (this.operationType1 == 'add') {
                request
                  .post('/dc/rever/project/insert', this.addObj)
                  .then((res) => {
                    if (res.success) {
                      this.$message.success('添加成功');
                      this.$emit('addShuiKuSuccess');
                      this.getformList();
                    }
                  });
              } else {
                request
                  .post('/dc/rever/project/insert', this.addObj)
                  .then((res) => {
                    if (res.success) {
                      this.$message.success('修改成功');
                      this.$emit('addShuiKuSuccess');
                      this.getformList();
                    }
                  });
              }
            },
          });
        }
      });
    },
    // 查看
    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_RSVR_PROJECT',
        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>
