<template>
  <div style="width: 100%;margin: auto">
    <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: 10}" :wrapper-col="{span: 14}" :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.nlJbybnl">
              <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.nlJbybnl =='2' || addObj.nlJbybnl =='3'" type="link" @click="addProblem('nlJbybnl', addObj.nlJbybnl)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="设置的水位尺、水位标识是否满足观测需要" v-if="addObj.nlJbybnl == '1'">
            <a-radio-group v-model:value="addObj.nlSwcmzgc">
              <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.nlSwcmzgc =='2' || addObj.nlSwcmzgc =='3'"
              type="link"
              @click="addProblem('nlSwcmzgc', addObj.nlSwcmzgc)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="通信（报警）手段能否满足汛期水雨情报送和紧急情况下报送预警信息的要求">
            <a-radio-group v-model:value="addObj.nlTxsd">
              <a-radio value="1">满足</a-radio>
              <a-radio value="0">不满足</a-radio>
            </a-radio-group>
            <a-button
              v-if="addObj.nlTxsd =='0'"
              type="link"
              @click="addProblem('nlTxsd', addObj.nlTxsd)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="发现大坝险情时能否立即报告水库主管部门（或业主）、地方人民政府，及时发出警报">
            <a-radio-group v-model:value="addObj.nlBgzg">
              <a-radio value="1">能</a-radio>
              <a-radio value="0">不能</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.nlBgzg =='0'" type="link" @click="addProblem('nlBgzg', addObj.nlBgzg)">
              <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="是否有水库调度运用方案" required>
            <a-radio-group v-model:value="addObj.faDdyw">
              <a-radio value="1">有</a-radio>
              <a-radio value="0">无</a-radio>
            </a-radio-group>
            <a-button
              v-if="addObj.faDdyw =='0'"
              type="link"
              @click="addProblem('faDdyw', addObj.faDdyw)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="水库调度运用方案是否获得批复或备案" v-if="addObj.faDdyw == '1'">
            <a-radio-group v-model:value="addObj.faDdfapf">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.faDdfapf =='0'" type="link" @click="addProblem('faDdfapf', addObj.faDdfapf)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="水库调度运用方案可操作性" required v-if="addObj.faDdyw == '1'">
            <a-radio-group v-model:value="addObj.faDdfacz">
              <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.faDdfacz =='3'" type="link" @click="addProblem('faDdfacz', addObj.faDdfacz)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="是否按要求对水库调度运用方案进行演练" v-if="addObj.faDdyw == '1'">
            <a-radio-group v-model:value="addObj.faDdfayl">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否(一般小水库)</a-radio>
              <a-radio value="3">否(小I型、重要小Ⅱ型)</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.faDdfayl !='1'" type="link" @click="addProblem('faDdfayl', addObj.faDdfayl)">
              <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.yaYjya">
              <a-radio value="1">有</a-radio>
              <a-radio value="0">无</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.yaYjya =='0'" type="link" @click="addProblem('yaYjya', addObj.yaYjya)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="安全管理（防汛）应急预案是否获得批复未备案" v-if="addObj.yaYjya == '1'">
            <a-radio-group v-model:value="addObj.yaYjyapf">
              <a-radio value="1">有</a-radio>
              <a-radio value="0">无</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.yaYjyapf =='0'" type="link" @click="addProblem('yaYjyapf', addObj.yaYjyapf)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="安全管理（防汛）应急预案可操作性" v-if="addObj.yaYjya == '1'">
            <a-radio-group v-model:value="addObj.yaYjyacz">
              <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.yaYjyacz =='3'" type="link" @click="addProblem('yaYjyacz', addObj.yaYjyacz)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="是否按要求对安全管理（防汛）应急预案进行演练" required v-if="addObj.yaYjya == '1'">
            <a-radio-group v-model:value="addObj.yaYjyayl">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
            </a-radio-group>
            <a-button v-if="addObj.yaYjyayl =='0'" type="link" @click="addProblem('yaYjyayl', addObj.yaYjyayl)">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 14, offset: 10 }">
            <a-button type="primary" @click="makesure">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog && openType"
        :objType="pType"
        :villType="0"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'小水库'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getSgzdlist } from '../../api/duChaTianBao.js';
import request from '../../utils/gw_ajax_request.js';
import problemDialog from '../duChaWenTi/problemDialog.vue';
export default {
  props: [
    'currentObjectRgstrId',
    'currentObjectName',
    'currentObjectId',
    'pType',
    'openType',
  ],
  data() {
    return {
      objtbStatu: {
        baseStat: '',
        rgstrId: '',
      },
      addObj: {
        rgstrId: '',
        nlJbybnl: '',
        nlSwcmzgc: '',
        nlTxsd: '', // 是否有水库调度运用方案
        nlBgzg: '', // 水库是否获得批复
        faDdyw: '', // 水库演练
        faDdfapf: '', // 水库可操作性
        faDdfacz: '', // 是否有应急预案
        faDdfayl: '', // 应急是否批复
        yaYjya: '', // 应急是否演练
        yaYjyapf: '', // 应急可操作性
        yaYjyacz: '',
        yaYjyayl: '',
        recPersId: '',
        recPers2: '',
        recPersTel: '',
        createTime: '',
        updateTime: '',
        status: '',
      },
      curOperate: '',
      formLabelWidth: '350px',
      loading: true,
      operationType1: '',
      dialogShow: false,
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  components: {
    problemDialog,
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  created() {
    this.findItemByType();
    this.getRgstridObj();
  },
  mounted() {
    this.getRgstridObj();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getRgstridObj();
    },
  },
  methods: {
    appearDialog(type) {
      this.dialogShow = true;
      this.problemSmallType = type;
    },
    closeDialog() {
      this.dialogShow = false;
    },
    getRgstridObj() {
      getSgzdlist(this.currentObjectRgstrId).then((res) => {
        if (res.data && Object.keys(res.data).length) {
          this.addObj = res.data;
          this.operationType1 = 'update';
          console.log(this.addObj);
        } else {
          this.addObj = {};
          this.operationType1 = 'add';
        }
      });
    },
    addMember() {
      this.addObj['rgstrId'] = this.currentObjectRgstrId;
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;
      this.addObj['recPersId'] = this.recPersId;
      /* let gllsObj = {
        rgstrId: this.currentObjectRgstrId,
        recPersId: this.recPersId,
        rainForc: this.addObj.rainForc,
        rainForcNote: this.addObj.rainForcNote,
        schPlanSameExta: this.addObj.schPlanSameExta,
        schPlanSameAppr: this.addObj.schPlanSameAppr,
        schPlanSameEme: this.addObj.schPlanSameEme,
        schPlanSameSpeed: this.addObj.schPlanSameSpeed,
        // emerPlanSameExta: this.addObj.emerPlanSameExta,
        // emerPlanSameAppr: this.addObj.emerPlanSameAppr,
        // emerPlanSameEme: this.addObj.emerPlanSameEme,
        // emerPlanSameSpeed: this.addObj.emerPlanSameSpeed,
        thrqId: this.addObj.thrqId
      };
      let addObj = {};
      Object.assign(addObj, gllsObj); */
      // if(!addObj.rainForc){
      //   this.$message.warning('请选择是否能自主预测预报水雨情')
      //   return
      // }
      // if(addObj.rainForc == '2' && !addObj.rainForcNote){
      //   this.$message.warning('请选择是否有其他方法及时了解水雨情')
      //   return
      // }
      // if(addObj.rainForc == '1'){
      //     addObj.rainForcNote = ''
      // }
      // if(!addObj.schPlanSameExta){
      //   this.$message.warning('请选择是否有水库调度运用方案')
      //   return
      // }
      // if(addObj.schPlanSameExta == '1' && (!addObj.schPlanSameAppr || !addObj.schPlanSameEme || !addObj.schPlanSameSpeed)){
      //   this.$message.warning('请完善水库调度运行方案信息')
      //   return
      // }
      // if(addObj.schPlanSameExta == '2'){
      //     addObj.schPlanSameAppr = ''
      //     addObj.schPlanSameEme = ''
      //     addObj.schPlanSameSpeed = ''
      // }
      // if(!addObj.emerPlanSameExta){
      //   this.$message.warning('请选择是否有安全管理（防汛）应急方案')
      //   return
      // }
      // if(addObj.emerPlanSameExta == '1' && (!addObj.emerPlanSameAppr || !addObj.emerPlanSameEme || !addObj.emerPlanSameSpeed)){
      //   this.$message.warning('请完善安全管理（防汛）应急方案信息')
      //   return
      // }
      // if(addObj.emerPlanSameExta == '2'){
      //     addObj.emerPlanSameAppr = ''
      //     addObj.emerPlanSameEme = ''
      //     addObj.emerPlanSameSpeed = ''
      // }

      this.$confirm({
        title: '提示',
        content: '确认保存重点环节落实情况信息？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            request
              .post('/dc/insp/xskaqSgzd', this.addObj)
              .then((res) => {
                if (res.success) {
                  /* request.post("/dc/insp/rsvrRgstr/update", _self.objtbStatu).then((res) => {
                    res;
                  }) */
                  this.$message.success('添加成功!');

                  this.$emit('addShuiKuSuccess');
                } else {
                  this.$message.error(res.message);
                }
              })
              .catch((err) => {
                this.$message.error(err.message);
              });
          } else {
            request
              .post('/dc/insp/xskaqSgzd/update', this.addObj)
              .then((res) => {
                if (res.success) {
                  /* request.post("/dc/insp/rsvrRgstr/update", _self.objtbStatu).then((res) => {
                    res;
                  }) */
                  this.$message.success('修改成功!');

                  this.$emit('addShuiKuSuccess');
                } else {
                  this.$message.error(res.message);
                }
              })
              .catch((err) => {
                this.$message.error(err.message);
              });
          }
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_XSKAQ_SGZD',
        type: this.pType,
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
    addProblem(item, iValue) {
      const rest = this.rsvrRules.filter((e) => {
        return e.iValue === iValue && e.eName === item;
      });
      if (rest[0]) {
        this.probId = rest[0].id;
      }
      this.showAddProblemDialog = true;
    },
    closePlDialog(val) {
      this.showAddProblemDialog = false;
    },
    // deleteMember(row){
    //   this.$confirm('确定删除吗?', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(() => {
    //     request.post(`/dc/insp/baseExt/delete/${row.thrqId}`).then((res)=>{
    //       console.log(res);
    //       if(res.success){
    //         this.$message.success('删除成功!');
    //         this.dialogFormVisible = false;
    //       }else{
    //         this.$message.error(res.message);
    //       }
    //     })
    //   }).catch(() => {
    //     this.$message.info('已取消删除');
    //   });
    // },
  },
};
</script>

<style lang='less' scoped>

</style>
