<template>
  <div id="">
    <a-layout>
      <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="addObj"
          :label-col="{ span: 10 }"
          :wrapper-col="{ span: 14 }"
          :rules="diRongYangMaoRules"
          ref="addObj">
          <a-form-item label="是否安装取用水计量设施">
            <a-radio-group v-model:value="addObj.isBuldMsu">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isBuldMsu == '2'" type="link" @click="addProblem('isBuldMsu',addObj.isBuldMsu)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <a-popover title="" trigger="click" placement="bottom">
                <span slot="content">对于除水电站以外的取用水户，查看其从河湖直接取水的取水管道或渠道上是否安装了水表等计量设施。</span>
                <a-icon type="question-circle" style="margin-left: 20px; color: #ff0000; cursor: pointer" />
              </a-popover>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="计量设施是否具备计量部门出具的检定或核准证明">
            <a-radio-group v-model:value="addObj.isMsuProve">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isMsuProve == '2'" type="link" @click="addProblem('isMsuProve', addObj.isMsuProve)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <a-popover title="" trigger="click" placement="bottom">
                <span slot="content">对于除水电站以外的取用水户，查看其计量设施是否有计量部门出具的检定报告或核准报告等证明材料，且检定或核准结果是否为合格。</span>
                <a-icon type="question-circle" style="margin-left: 20px; color: #ff0000; cursor: pointer" />
              </a-popover>
              <span class="tip_info">注：未安装取用水计量设施默认为“是”，不产生问题</span>
            </a-radio-group>
          </a-form-item>

          <a-form-item label="取水计量设施是否运行正常">
            <a-radio-group v-model:value="addObj.isMsuNml">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isMsuNml == '2'" type="link" @click="addProblem('isMsuNml',addObj.isMsuNml)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <a-popover title="" trigger="click" placement="bottom">
                <span slot="content">对于除水电站以外的取用水户，现场检查其计量设施是否运行正常。</span>
                <a-icon type="question-circle" style="margin-left: 20px; color: #ff0000; cursor: pointer" />
              </a-popover>
              <span class="tip_info">注：未安装取用水计量设施默认为“是”，不产生问题</span>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否建立了取用水计量台账，并每月向水利部门报送用水（发电）统计报表">
            <a-radio-group v-model:value="addObj.isBuldSend">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isBuldSend == '2'" type="link" @click="addProblem('isBuldSend', addObj.isBuldSend)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <a-popover title="" trigger="click" placement="bottom" width="200px">
                <a
                  slot="content">查看取用水户的取水计量台账，并查看其每月向水利部门报送用水量或发电量的报表。</a>
                <a-icon type="question-circle" style="margin-left: 20px; color: #ff0000; cursor: pointer" />
              </a-popover>
              <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="makesure('addObj')" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog"
        :objType="60"
        :villType="60"
        :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 {
  components: {
    problemDialog,
  },
  props: {
    rowData: {
      type: Object,
      default: {},
    },
    openType: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      formLabelWidth: '530px',
      diRongYangMaoRules: {},
      probId: '',
      operationType1: '',
      id: '',
      rsvrRules: null,
      showAddProblemDialog: false,
      addObj: {
        isBuldMsu: '',
        isMsuProve: '',
        isMsuNml: '',
        isBuldSend: '',
      },
      objtbStatu: {
        jxqState: '',
        rgstrId: '',
        id: '',
        state: '',
      },
    };
  },
  computed: {
    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.isBuldMsu != null &&
            this.addObj.isMsuProve != null &&
            this.addObj.isMsuNml != null &&
            this.addObj.isBuldSend != null
          ) {
            this.addObj['state'] = '2';
            this.objtbStatu.sttState = '2';
            this.objtbStatu.state = '1';
          } else if (
            this.addObj.isBuldMsu == null &&
            this.addObj.isMsuProve == null &&
            this.addObj.isMsuNml == null &&
            this.addObj.isBuldSend == null
          ) {
            this.objtbStatu.sttState = '0';
            this.addObj['state'] = '0';
          } else {
            this.objtbStatu.sttState = '1';
            this.objtbStatu.state = '1';
            this.addObj['state'] = '1';
          }
          this.$confirm({
            title: '提示',
            content: '确认保存取水许可情况信息吗？',
            okType: 'warning',
            onOk: () => {
              request.post('/bis/insp/winjx/stat', this.addObj).then((res) => {
                if (res.success) {
                  this.$message.success('添加成功');
                  request
                    .post('/bis/insp/winjx/update', this.objtbStatu)
                    .then((res) => {
                      res;
                    });
                  this.$emit('addDiFangSuccess');
                }
              });
            },
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 如果已经填报  则查询
    getInfoData() {
      request
        .get('/bis/insp/winjx/stat/' + this.rowData.rgstrId, {})
        .then((res) => {
          if (res.success) {
            this.addObj = res.data;
          }
          if (res.data && Object.keys(res.data).length) {
            this.addObj = res.data;
            this.operationType1 = 'update';
            this.id = res.data.id;
          } else {
            this.addObj = {};
            this.operationType1 = 'add';
          }
        });
    },
    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;
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_WINJX_STAT',
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
  },
};
</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;
}

:deep(.ant-popover-placement-bottom) {
  width: 200px;
}
</style>
