<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="formObj" :label-col="{span: 10}" :wrapper-col="{span: 14}" :rules="rules" :disabled="ifView">
          <p style="margin-top:10px;margin-bottom: 10px">
            <i class="left-vertical"></i>
            <!--<span class="hrs"></span>-->
          </p>
          <a-form-item label="初查年度">
            <a-input v-model:value="formObj.inspYear" autocomplete="off" style="width:70%;" readonly />
          </a-form-item>
          <a-form-item label="原工况评价">
            <a-input v-model:value="formObj.wcEvltOld" autocomplete="off" style="width:70%;" readonly />
          </a-form-item>
          <a-form-item label="工况总体评价" prop="wcEvltNow">
            <a-radio-group v-model:value="formObj.wcEvltNow">
              <a-radio value="1" :disabled="rowData.isSaf == 1">重大安全隐患</a-radio>
              <a-radio value="2" :disabled="rowData.isSaf == 1">一般安全隐患</a-radio>
              <a-radio value="3" :disabled="rowData.isSaf == 1">正常安全运行</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="重大安全隐患主要表现" v-if="formObj.wcEvltNow == '1'">
            <a-select v-model:value="formObj.mshTmp" placeholder="请选择" allow-clear>
              <a-select-option v-for="item in zdaqyhOption" :key="item.value" :value="item.value">{{ item.label }}</a-select-option>
            </a-select>
            <br />
            <el-textarea
              :rows="4"
              v-model="formObj.chkDesc"
              autocomplete="off"
              v-if="formObj.mshTmp == 5"
              style="width:70%;" />
          </a-form-item>
          <a-form-item label="水库类型">
            <a-radio-group v-model:value="formObj.chkType">
              <a-radio value="1">重大安全隐患排查</a-radio>
              <a-radio value="2">整改情况复查</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否到现场">
            <a-radio-group v-model:value="formObj.isSite">
              <a-radio value="1" :disabled="rowData.inspType == 1">是</a-radio>
              <a-radio value="2" :disabled="rowData.inspType == 1">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否已实施除险加固" v-if="formObj.chkType == 1">
            <a-radio-group v-model:value="formObj.isTrhbco">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <div v-if="formObj.isTrhbco == 1">
            <a-form-item label="类型">
              <a-radio-group v-model:value="formObj.trhbcoInfo">
                <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="已实施除险加固开工时间">
              <a-date-picker v-model:value="formObj.trhbcoSttm" placeholder="请选择"></a-date-picker>
            </a-form-item>
            <a-form-item label="已实施除险加固完工时间">
              <a-date-picker v-model:value="formObj.trhbcoEntm" placeholder="请选择"></a-date-picker>
            </a-form-item>
          </div>
          <a-form-item :wrapper-col="{ span: 12, offset: 10 }">
            <a-button type="primary" @click="addHandler" :loading="saveLoading">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog"
        :objType="1"
        :villType="0"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'小水库'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getRsvrRgstrChkInfo } from '../../../../api/duChaTianBao';
import request from '../../../../utils/gw_ajax_request';
import { dateFormat } from '../../../../utils/gw_date.js';
import inputWith from '../../../../widgets/inuptWith.vue';
import problemDialog from '../../../duChaWenTi/problemDialog.vue';
export default {
  components: {
    inputWith: inputWith,
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'rowData',
    'ifView',
  ],
  data() {
    return {
      objtbStatu: {
        presStat: '',
        rgstrId: '',
      },
      rules: {
        wcEvltNow: [{ required: true }],
      },
      formObj: {
        inspYear: '', // 初查年度 ,
        wcEvltOld: '', // 原工况评价 ,
        wcEvltNow: '', // 工况总体评价(1:重大安全隐患;2:一般安全隐患;3:正常安全运行;) ,
        mshTmp: '', // 重大安全隐患主要表现 ,
        chkType: '', // 水库检查类型(1:重大安全隐患排查;2:整改情况复查;3:其他) ,
        isTrhbco: '', // 是否已实施除险加固(1:是;2:否;) ,
        trhbcoInfo: '', // 已实施除险加固情况(1:遗留问题;2:灾后薄弱;3:遗留问题及灾后薄弱;) ,
        trhbcoSttm: '', // 已实施除险加固开工时间 ,
        trhbcoEntm: '', // 已实施除险加固完工时间 ,
        mngUnit: '', // 管理单位 ,
        dutyUnit: '', // 责任单位 ,
        isSite: '', // 是否到现场
        chkDesc: '',
      },
      zdaqyhOption: [
        {
          label: '挡水建筑物存在危险',
          value: '1',
        },
        {
          label: '挡水建筑物异常渗漏、流土',
          value: '2',
        },
        {
          label: '泄洪建筑物存在危险',
          value: '3',
        },
        {
          label: '放水建筑物存在危险',
          value: '4',
        },
        {
          label: '其他',
          value: '5',
        },
      ],
      dialogFormVisible: false,
      formLabelWidth: '200px',
      loading: true,
      operationType1: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
      saveLoading: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    // this.findItemByType()
  },
  mounted() {
    this.$nextTick(() => {
      console.log(this.rowData.inspType);
      this.getRgstridObj();
    });
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getRgstridObj();
    },
  },
  methods: {
    getRgstridObj() {
      getRsvrRgstrChkInfo(this.currentObjectRgstrId).then((res) => {
        if (Object.keys(res.data).length) {
          this.formObj = res.data;
          this.formObj.trhbcoEntm = res.data.trhbcoEntm
            ? dateFormat(res.data.trhbcoEntm, 'yyyy-MM-dd')
            : '';
          this.formObj.trhbcoSttm = res.data.trhbcoSttm
            ? dateFormat(res.data.trhbcoSttm, 'yyyy-MM-dd')
            : '';
          this.operationType1 = 'update';
          if (this.rowData.inspType == 1) {
            this.formObj.isSite = '1';
          }
          if (this.rowData.isSaf == 1) {
            this.formObj.wcEvltNow = '1';
          }
        } else {
          this.formObj = {};
          this.operationType1 = 'add';
        }
      });
    },
    addHandler() {
      if (!this.formObj.wcEvltNow) {
        this.$message.warning('请选择工况总体评价');
        return;
      }
      this.formObj['rgstrId'] = this.currentObjectRgstrId;
      this.formObj['recPersId'] = this.recPersId;
      console.log(this.formObj);
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;
      if (
        this.formObj.wcEvltNow &&
        this.formObj.chkType &&
        this.formObj.isSite
      ) {
        this.formObj.status = '2';
      } else {
        this.formObj.status = '1';
      }
      if (
        this.formObj.wcEvltNow === undefined &&
        this.formObj.chkType === undefined &&
        this.formObj.isSite === undefined
      ) {
        this.formObj.status = '0';
      }
      this.$confirm({
        title: '提示',
        content: '确认保存水库检查情况信息？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            try {
              if (!this.saveLoading) {
                this.saveLoading = true;
                request
                  .post('/bis/insp/rsvr/rgstr/chk/info', this.formObj)
                  .then((res) => {
                    if (res.success) {
                      this.$message.success('添加成功');
                      this.getRgstridObj();
                      this.$emit('addShuiKuSuccess');
                    }
                    this.saveLoading = false;
                  })
                  .catch((err) => {
                    this.saveLoading = false;
                  });
              }
            } catch (e) {}
          } else if (this.operationType1 == 'update') {
            try {
              if (!this.saveLoading) {
                this.saveLoading = true;
                request
                  .post('/bis/insp/rsvr/rgstr/chk/info', this.formObj)
                  .then((res) => {
                    if (res.success) {
                      this.$message.success('修改成功');
                      this.getRgstridObj();
                      this.$emit('addShuiKuSuccess');
                    }
                    this.saveLoading = false;
                  })
                  .catch((err) => {
                    this.saveLoading = false;
                  });
              }
            } catch (e) {}
          }
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_BASE_PRES_EXT',
      };
      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;
    },
    formatRadio(val) {
      if (val == '1') {
        return '是';
      } else if (val == '2') {
        return '否';
      } else {
        return val;
      }
    },
    closePlDialog(val) {
      this.showAddProblemDialog = false;
    },
  },
};
</script>

<style lang='less' scoped>
#dcdxHeader {
  padding: 15px 20px;
}

#dxdcFooter {
  text-align: center;
}

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

.left-vertical {
  width: 8px;
  height: 24px;
  background: #00b0f0;
  display: inline-block;
  vertical-align: bottom;
}

.hrs {
  display: inline-block;
  width: calc(100% - 40px);
  margin-left: 10px;
  height: 1px;
  vertical-align: middle;
  background-color: #ddd;
}

.el-dialog__wrapper .el-treeWhite {
  /* max-height: 260px !important; */
}

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