<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">
          <br>
          <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.diskRunInfo">
              <a-radio value="1">能正常运行</a-radio>
              <a-radio value="2">有缺陷能运行</a-radio>
              <a-radio value="3">不能运行</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.diskRunInfo =='2'" type="link" @click="addProblem('diskRunInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
            <a-button v-if="addObj.diskRunInfo =='3'" type="link" @click="addProblem('diskRunInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="泄洪建筑物运行情况">
            <a-radio-group v-model:value="addObj.mainFlInfo">
              <a-radio value="1">能正常运行</a-radio>
              <a-radio value="2">存在缺陷但能正常运行</a-radio>
              <a-radio value="3">不能正常运行</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.mainFlInfo =='2'" type="link" @click="addProblem('mainFlInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
            <a-button v-if="addObj.mainFlInfo =='3'" type="link" @click="addProblem('mainFlInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="放水建筑物运行情况">
            <a-radio-group v-model:value="addObj.pourFyInfo">
              <a-radio value="1">正常运行</a-radio>
              <a-radio value="2">存在缺陷但能正常运行</a-radio>
              <a-radio value="3">不能正常运行</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.pourFyInfo =='2'" type="link" @click="addProblem('pourFyInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
            <a-button v-if="addObj.pourFyInfo =='3'" type="link" @click="addProblem('pourFyInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="库岸运行情况">
            <a-radio-group v-model:value="addObj.rsBlInfo">
              <a-radio value="1">正常运行</a-radio>
              <a-radio value="2">存在缺陷但能正常运行</a-radio>
              <a-radio value="3">不能正常运行</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.rsBlInfo =='2'" type="link" @click="addProblem('rsBlInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
            <a-button v-if="addObj.rsBlInfo =='3'" type="link" @click="addProblem('rsBlInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </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="防汛公路是否安全畅通">
            <a-radio-group v-model:value="addObj.fcahIsSu">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.fcahIsSu =='2'" type="link" @click="addProblem('fcahIsSu')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="管理设施运行情况">
            <p>(闸站丶厂房 丶管理用房与安全监测设备等)</p>
            <a-radio-group v-model:value="addObj.mfRunInfo">
              <a-radio value="1">正常运行</a-radio>
              <a-radio value="2">存在缺陷但能正常运行</a-radio>
              <a-radio value="3">不能正常运行</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.mfRunInfo =='2'" type="link" @click="addProblem('mfRunInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
            <a-button v-if="addObj.mfRunInfo =='3'" type="link" @click="addProblem('mfRunInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="设备设施运行情况">
            <p>(闸门 拦污栅 启闭设备有供电系统)</p>
            <a-radio-group v-model:value="addObj.eafRunInfo">
              <a-radio value="1">能正常运行</a-radio>
              <a-radio value="2">有缺陷能运行</a-radio>
              <a-radio value="3">不能运行</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.eafRunInfo =='2'" type="link" @click="addProblem('eafRunInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
            <a-button v-if="addObj.eafRunInfo =='3'" type="link" @click="addProblem('eafRunInfo')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 16, offset: 8 }">
            <a-button type="primary" @click="makesure">保 存</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 { getProjectlist } from '../../../api/fujian_api';
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: {
        projectState: '',
        id: '',
      },
      dxdcMainHeight: window.innerHeight - 197,
      dialogFormVisible: false,
      formLabelWidth: '180px',
      loading: true,
      addObj: {
        diskRunInfo: '', // 挡水建筑物运行情况
        mainFlInfo: '', // 泄水建筑物运行情况
        pourFyInfo: '', // 放水建筑物运行情况
        rsBlInfo: '', // 库岸情况
        fcahIsSu: '', // 防汛公路是否安全畅通
        mfRunInfo: '', // 管理设施运行情况
        eafRunInfo: ' ', // 设备设施运行情况
      },
      operationType1: '',
      lyjg: [],
      placeholder: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getformList();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getformList();
    },
  },
  methods: {
    getformList() {
      getProjectlist(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() {
      this.addObj['rgstrId'] = this.currentObjectRgstrId;
      this.addObj['recPersId'] = this.recPersId;
      this.objtbStatu.id = this.currentObjectRgstrId;
      var params = {
        bisInspSafeExtManage: this.addObj,
      };

      if (
        this.addObj.diskRunInfo ||
        this.addObj.mainFlInfo ||
        this.addObj.pourFyInfo ||
        this.addObj.rsBlInfo ||
        this.addObj.fcahIsSu ||
        this.addObj.mfRunInfo ||
        this.addObj.eafRunInfo
      ) {
        this.objtbStatu.projectState = '1';
      }
      if (
        this.addObj.diskRunInfo &&
        this.addObj.mainFlInfo &&
        this.addObj.pourFyInfo &&
        this.addObj.rsBlInfo &&
        this.addObj.fcahIsSu &&
        this.addObj.mfRunInfo &&
        this.addObj.eafRunInfo
      ) {
        this.objtbStatu.projectState = '2';
      }
      if (
        this.addObj.diskRunInfo == undefined &&
        this.addObj.mainFlInfo == undefined &&
        this.addObj.pourFyInfo == undefined &&
        this.addObj.rsBlInfo == undefined &&
        this.addObj.fcahIsSu == undefined &&
        this.addObj.mfRunInfo == undefined &&
        this.addObj.eafRunInfo == undefined
      ) {
        this.objtbStatu.projectState = '0';
      }
      this.$confirm('确认保存水库工程实体信息吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          if (this.operationType1 == 'add') {
            request
              .post('/bis/insp/rsml/rgstr/project', this.addObj)
              .then((res) => {
                if (res.success) {
                  this.$message.success('添加成功');
                  request
                    .post('/bis/insp/rsml/rgstr', this.objtbStatu)
                    .then((res) => {
                      res;
                    });
                  this.$emit('addShuiKuSuccess');
                  this.getformList();
                }
              });
          } else {
            request
              .post('/bis/insp/rsml/rgstr/project', this.addObj)
              .then((res) => {
                if (res.success) {
                  this.$message.success('修改成功');
                  request
                    .post('/bis/insp/rsml/rgstr', this.objtbStatu)
                    .then((res) => {
                      res;
                    });
                  this.$emit('addShuiKuSuccess');
                }
              });
          }
        })
        .catch(() => {});
    },
    // 查看
    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_RSML_RGSTR_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>
#dcdxHeader {
  padding: 15px 20px;
}

#dxdcFooter {
  text-align: center;
}

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

.add-problem-icon {
  font-size: 16px;
}
</style>
