<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;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.isNeorFaeq">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isNeorFaeq == '2'" type="link" @click="addProblem('isNeorFaeq')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="2、办公环境是否整洁">
            <a-radio-group v-model:value="formObj.isCntdOffenv">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isCntdOffenv == '2'" type="link" @click="addProblem('isCntdOffenv')">
                <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.isComSign">
              <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.isComSign == '2'">
            <a-radio-group v-model:value="formObj.isSetSignancs">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSetSignancs == '2'" type="link" @click="addProblem('isSetSignancs')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.2 是否设置名称类标识牌" v-if="formObj.isComSign == '2'">
            <a-radio-group v-model:value="formObj.isSetNamecsident">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSetNamecsident == '2'" type="link" @click="addProblem('isSetNamecsident')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.3 是否设置警示类标识牌" v-if="formObj.isComSign == '2'">
            <a-radio-group v-model:value="formObj.isSetWarncssign">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSetWarncssign == '2'" type="link" @click="addProblem('isSetWarncssign')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="3.4 是否设置指引类标识牌" v-if="formObj.isComSign == '2'">
            <a-radio-group v-model:value="formObj.isSetGuidecsident">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSetGuidecsident == '2'" type="link" @click="addProblem('isSetGuidecsident')">
                <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="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 { getRgstridHystjxWwe } 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: {
        wweState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
      type: '',
      formObj: {},
      dialogFormVisible: false,
      formLabelWidth: '300px',
      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() {
      getRgstridHystjxWwe(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.isNeorFaeq != null &&
        this.formObj.isCntdOffenv != null &&
        this.formObj.isComSign != null
      ) {
        this.formObj['state'] = '2';
        this.objtbStatu.wweState = '2';
        this.objtbStatu.state = '1';
      } else if (
        this.formObj.isNeorFaeq == null &&
        this.formObj.isCntdOffenv == null &&
        this.formObj.isComSign == null
      ) {
        this.objtbStatu.wweState = '0';
        this.formObj['state'] = '0';
      } else {
        this.objtbStatu.wweState = '1';
        this.objtbStatu.state = '1';
        this.formObj['state'] = '1';
      }
      this.$confirm({
        title: '提示',
        content: '确认保存水厂环境管理信息？',
        okType: 'warning',
        onOk: () => {
          try {
            request.post('/bis/insp/rdwpjx/wwe', 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_WWE',
      };
      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>
