<template>
  <div id="">
    <a-layout style="height:520px;">
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;overflow: auto;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;margin-bottom: 20px">信息填报</p>
        <a-form :model="formObj" :label-col="{ span: 10 }" :wrapper-col="{ span: 14 }">
          <a-form-item label="1、是否公示责任人">
            <a-radio-group v-model:value="formObj.isPubRespson">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPubRespson == '2'" type="link" @click="addProblem('isPubRespson')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <span class="tip_info">注：请在备注中说明未公示的责任人</span>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="2、是否编制应急预案">
            <a-radio-group v-model:value="formObj.isPrpEmp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPrpEmp == '2'" type="link" @click="addProblem('isPrpEmp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3、是否编制关键岗位口袋本">
            <a-radio-group v-model:value="formObj.isComKpp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.1 是否编制水工艺技术管理岗位口袋本" v-if="formObj.isComKpp == '2'">
            <a-radio-group v-model:value="formObj.isComPbwtmp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComPbwtmp == '2'" type="link" @click="addProblem('isComPbwtmp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.2 是否编制机电设备管理岗位口袋本" v-if="formObj.isComKpp == '2'">
            <a-radio-group v-model:value="formObj.isComPbpmeem">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComPbpmeem == '2'" type="link" @click="addProblem('isComPbpmeem')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.3 是否编制制水净化岗位口袋本" v-if="formObj.isComKpp == '2'">
            <a-radio-group v-model:value="formObj.isComPbwpp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComPbwpp == '2'" type="link" @click="addProblem('isComPbwpp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.4 是否编制制水消毒岗位口袋本" v-if="formObj.isComKpp == '2'">
            <a-radio-group v-model:value="formObj.isComPbwmdp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComPbwmdp == '2'" type="link" @click="addProblem('isComPbwmdp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.5 是否编制安全生产岗位口袋本" v-if="formObj.isComKpp == '2'">
            <a-radio-group v-model:value="formObj.isComPbspp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComPbspp == '2'" type="link" @click="addProblem('isComPbspp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.6 是否编制水质检测岗位口袋本" v-if="formObj.isComKpp == '2'">
            <a-radio-group v-model:value="formObj.isComPbwqtp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComPbwqtp == '2'" type="link" @click="addProblem('isComPbwqtp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.7 其他关键岗位口袋本是否齐全" v-if="formObj.isComKpp == '2'">
            <a-radio-group v-model:value="formObj.isComPkp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComPkp == '2'" type="link" @click="addProblem('isComPkp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <span class="tip_info">注：请在备注中说明缺少口袋本的关键岗位</span>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="4、是否编制管理手册">
            <a-radio-group v-model:value="formObj.isComMama">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="4.1 是否缺少《农村供水工程管理手册编制指南》管理手册" v-if="formObj.isComMama == '2'">
            <a-radio-group v-model:value="formObj.isComMmrwsp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComMmrwsp == '2'" type="link" @click="addProblem('isComMmrwsp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="4.2 是否缺少其他管理手册" v-if="formObj.isComMama == '2'">
            <a-radio-group v-model:value="formObj.isComOmama">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isComOmama == '2'" type="link" @click="addProblem('isComOmama')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <span class="tip_info">注：请在备注中说明缺少的管理手册名称</span>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 10, offset: 14 }">
            <a-button type="primary" @click="addHandler" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog && openType"
        :objType="63"
        :villType="63"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'农饮工程'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getRgstridrdwpjxSfo } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import { formatDateTimeD } from '../../../utils/gw_date';
import inputWith from '../../../widgets/inuptWith.vue';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  components: {
    inputWith: inputWith,
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'openType',
  ],
  data() {
    return {
      id: '',
      objtbStatu: {
        sfoState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
      type: '',
      formObj: {},
      dialogFormVisible: false,
      formLabelWidth: '380px',
      loading: true,
      operationType1: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getRgstridObj();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getRgstridObj();
    },
  },
  methods: {
    getRgstridObj() {
      getRgstridrdwpjxSfo(this.currentObjectRgstrId).then((res) => {
        if (res.data && Object.keys(res.data).length) {
          this.formObj = res.data;
          this.operationType1 = 'update';
          this.id = res.data.id;
        } else {
          this.formObj = {};
          this.operationType1 = 'add';
        }
      });
    },
    addHandler() {
      this.formObj['rgstrId'] = this.currentObjectRgstrId;
      this.formObj['recPersId'] = this.recPersId;
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;
      this.objtbStatu.id = this.currentObjectRgstrId;

      if (
        this.formObj.isPubRespson != null &&
        this.formObj.isPrpEmp != null &&
        this.formObj.isComKpp != null &&
        this.formObj.isComMama != null
      ) {
        this.formObj['state'] = '2';
        this.objtbStatu.sfoState = '2';
        this.objtbStatu.state = '1';
      } else if (
        this.formObj.isPubRespson == null &&
        this.formObj.isPrpEmp == null &&
        this.formObj.isComKpp == null &&
        this.formObj.isComMama == null
      ) {
        this.objtbStatu.sfoState = '0';
        this.formObj['state'] = '0';
      } else {
        this.objtbStatu.sfoState = '1';
        this.objtbStatu.state = '1';
        this.formObj['state'] = '1';
      }
      this.$confirm({
        title: '提示',
        content: '确认保存生态流量泄放情况信息？',
        okType: 'warning',
        onOk: () => {
          try {
            request.post('/bis/insp/rdwpjx/sfo', this.formObj).then((res) => {
              if (res.success) {
                this.$message.success('修改成功');
                request
                  .post('/bis/insp/rdwpjx/update', this.objtbStatu)
                  .then((res) => {
                    res;
                  });
                this.$emit('addShuiKuSuccess');
              }
            });
          } catch (e) {}
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_RDWPJX_SFO',
      };
      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;
 }

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

 .add-problem-icon {
   font-size: 16px;
 }

 .el-icon-camera-solid,
 .el-icon-circle-plus {
   margin-left: 20px;
   color: #00bbff;
   font-size: 18px;
   line-height: 12px;
   vertical-align: middle;
   cursor: pointer;
 }

 .el-icon-circle-plus {
   vertical-align: top;
 }

 .tip_info {
   margin-left: 20px;
   font-size: 12px;
   color: #ff0000;
 }
</style>
