<template>
  <div class="gcsthyxglqk">
    <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: 8}" :wrapper-col="{span: 16}">
          <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.yxqk">
              <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="工况总体评价" required>
            <a-radio-group v-model:value="addObj.ztpjGk">
              <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="是否录入存在重大安全隐患水库清单" required>
            <a-radio-group v-model:value="addObj.isZdaqyh">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 16, offset: 8 }">
            <a-button type="primary" @click="makesure" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
    </a-layout>
  </div>
</template>

<script>
import { getLyjglist, getZtpjlist } 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',
    'openType',
  ],
  data() {
    return {
      objtbStatu: {
        resRunStat: '',
        rgstrId: '',
      },
      dxdcMainHeight: window.innerHeight - 197,
      dialogFormVisible: false,
      formLabelWidth: '350px',
      loading: true,
      addObj: {
        rgstrId: '',
        yxqk: '',
        recPersId: '',
        recPers2: '',
        recPersTel: '',
        status: '',
        createTime: '',
        updateTime: '',
        ztpjGk: '',
        isZdaqyh: '',
        // 注意有几个字段无法确认，需要掉接口查看
      },
      operationType1: '',
      lyjg: [],
      placeholder: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  mounted() {
    this.getLyjgList();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getformList();
    },
  },
  methods: {
    getLyjgList() {
      getLyjglist().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() {
      getZtpjlist(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.rgstrId = this.currentObjectRgstrId;
      if (this.addObj.safeComment) {
        this.objtbStatu.resRunStat = '2';
      }
      if (this.addObj.safeComment == undefined) {
        this.objtbStatu.resRunStat = '0';
      }

      this.$confirm({
        title: '提示',
        content: '确认保存总体评价情况信息吗？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            request.post('/dc/insp/xskaqZtpj', this.addObj).then((res) => {
              if (res.success) {
                this.$message.success('添加成功');
                /* request
                  .post("/dc/insp/rsvrRgstr/update", _self.objtbStatu)
                  .then(res => {
                    res;
                  }); */
                this.$emit('addShuiKuSuccess');
              }
            });
          } else {
            request
              .post('/dc/insp/xskaqZtpj/update', this.addObj)
              .then((res) => {
                if (res.success) {
                  this.$message.success('修改成功');
                  /* request
                    .post("/dc/insp/rsvrRgstr/update", _self.objtbStatu)
                    .then(res => {
                      res;
                    }); */
                  this.$emit('addShuiKuSuccess');
                }
              });
          }
        },
      });
    },
  },
};
</script>

<style lang='less' scoped>

</style>
