<template>
  <div id="">
    <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: 10 }" :wrapper-col="{ span: 14 }" :rules="rules" ref="addObj">
          <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.isMsrCost">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isMsrCost == '2'" type="link" @click="addProblem('isMsrCost', addObj.isMsrCost)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="查看关责任人落实文件，行政、管理、技术、巡查等责任人是否落实">
            <a-radio-group v-model:value="addObj.isInCost">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="行政责任人是否落实文件" v-if="addObj.isInCost === '2'">
            <a-radio-group v-model:value="addObj.isUsrCost">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isUsrCost == '2'" type="link" @click="addProblem('isUsrCost', addObj.isUsrCost)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="管理责任人是否落实文件" v-if="addObj.isInCost === '2'">
            <a-radio-group v-model:value="addObj.isDisCost">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isDisCost == '2'" type="link" @click="addProblem('isDisCost', addObj.isDisCost)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="技术责任人是否落实文件" v-if="addObj.isInCost === '2'">
            <a-radio-group v-model:value="addObj.isTelDuty">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isTelDuty == '2'" type="link" @click="addProblem('isTelDuty', addObj.isTelDuty)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="巡查责任人是否落实文件" v-if="addObj.isInCost === '2'">
            <a-radio-group v-model:value="addObj.isTourDuty">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isTourDuty == '2'" type="link" @click="addProblem('isTourDuty', addObj.isTourDuty)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否编制应急预案">
            <a-radio-group v-model:value="addObj.isMakPlan">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isMakPlan == '2'" type="link" @click="addProblem('isMakPlan', addObj.isMakPlan)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="查看检查记录，是否开展险工险段安全检查">
            <a-radio-group v-model:value="addObj.isChk">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isChk == '2'" type="link" @click="addProblem('isChk', addObj.isChk)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 10, offset: 14 }">
            <a-button type="primary" @click="makesure('addObj')" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog"
        :objType="58"
        :villType="58"
        :objId="rowData.objId"
        :objName="rowData.nm"
        :problemMiddleType="'堤防'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :rgstrId="rowData.rgstrId"
        :szRuls="[]">
      </problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import request from '../../../utils/gw_ajax_request';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  props: {
    rowData: {
      type: Object,
      default: {},
    },
    openType: {
      type: Boolean,
      default: true,
    },
  },
  components: {
    problemDialog,
  },
  data() {
    return {
      formLabelWidth: '600px',
      addObj: {
        isChkTime: '',
        isUpKeep: '',
        isChkRcord: '',
      },
      rules: {},
      showAddProblemDialog: false,
      probId: '',
      operationType1: '',
      id: '',
      objtbStatu: {
        jxqState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
    };
  },
  computed: {
    // 监听属性 类似于data概念
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    if (this.rowData.rgstrId) {
      this.getInfoData();
    }
  },
  methods: {
    makesure(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addObj['rgstrId'] = this.rowData.rgstrId;
          this.addObj['recPersId'] = this.recPersId;
          this.objtbStatu.rgstrId = this.rowData.rgstrId;
          this.objtbStatu.id = this.rowData.rgstrId;
          if (
            this.addObj.isMsrCost != null &&
            this.addObj.isInCost != null &&
            this.addObj.isMakPlan != null &&
            this.addObj.isChk != null
          ) {
            this.addObj['state'] = '2';
            this.objtbStatu.riskState = '2';
            this.objtbStatu.state = '1';
          } else if (
            this.addObj.isMsrCost != null &&
            this.addObj.isInCost != null &&
            this.addObj.isMakPlan != null &&
            this.addObj.isChk != null
          ) {
            this.objtbStatu.riskState = '0';
            this.addObj['state'] = '0';
          } else {
            this.objtbStatu.riskState = '1';
            this.objtbStatu.state = '1';
            this.addObj['state'] = '1';
          }
          this.$confirm({
            title: '提示',
            content: '确认保存运行管理情况信息吗？',
            okType: 'warning',
            onOk: () => {
              request.post('/bis/insp/dikejx/risk', this.addObj).then((res) => {
                if (res.success) {
                  this.$message.success('添加成功');
                  request
                    .post('/bis/insp/dikejx/update', this.objtbStatu)
                    .then((res) => {
                      res;
                    });
                  this.$emit('addDiFangSuccess');
                }
              });
            },
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 如果已经填报  则查询
    getInfoData() {
      request
        .get('/bis/insp/dikejx/risk/' + this.rowData.rgstrId, {})
        .then((res) => {
          if (res.success) {
            this.addObj = res.data;
          }
        });
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_DIKEJX_RISK',
      };
      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;
    },
  },
};
</script>

<style lang='less' scoped>

</style>
