<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.isInValid">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <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="取用水户取得取水许可证" v-if="addObj.isInValid ==='2'">
            <a-radio-group v-model:value="addObj.isGetIcp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isGetIcp == '2'" type="link" @click="addProblem('isGetIcp', addObj.isGetIcp)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="取水许可证在有效期内" v-if="addObj.isInValid ==='2'">
            <a-radio-group v-model:value="addObj.isInIcp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isInIcp == '2'" type="link" @click="addProblem('isInIcp',addObj.isInIcp)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <span class="tip_info">注：无取水许可证默认为“是”，不产生问题</span>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否按照要求编制水资源论证报告书或水资源论证报告表">
            <a-radio-group v-model:value="addObj.isBuldRpt">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isBuldRpt == '2'" type="link" @click="addProblem('isBuldRpt',addObj.isBuldRpt)">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
              <a-popover title="" trigger="click" placement="bottom" width="200px">
                <span slot="content">对于有取水许可证的用水户，查看其是否编制了水资源论证报告书（需附专家审查意见）或水资源论证表。需要编制报告书的项目为（一）日取地表水五千立方米以上的；（二）日取地下水（含排水）三百立方米以上的；（三）蓄水工程总库容十万立方米以上的；（四）水力发电总装机一千千瓦以上的；（五）洗矿、造纸、电镀、印染、规模养殖、规模种植等污染较大的；（六）大中型农业灌区。其它工程均应编制水资源论证表。（注：2002年5月1日前已建成、且未改扩建的建设项目可不编制水资源论证报告或水资源论证表）</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.isGetIdea">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isGetIdea == '2'" type="link" @click="addProblem('isGetIdea',addObj.isGetIdea)">
                <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.isGetRange">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="addObj.isGetRange == '2'" type="link" @click="addProblem('isGetRange',addObj.isGetRange)">
                <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 :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: {
        isInValid: '',
        isGetIcp: '',
        isInIcp: '',
        isBuldRpt: '',
        isGetIdea: '',
        isGetRange: '',
      },
      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.isInValid != null &&
            this.addObj.isBuldRpt != null &&
            this.addObj.isGetIdea != null &&
            this.addObj.isGetRange != null
          ) {
            this.addObj['state'] = '2';
            this.objtbStatu.gtwtlState = '2';
            this.objtbStatu.state = '1';
          } else if (
            this.addObj.isInValid == null &&
            this.addObj.isBuldRpt == null &&
            this.addObj.isGetIdea == null &&
            this.addObj.isGetRange == null
          ) {
            this.objtbStatu.gtwtlState = '0';
            this.addObj['state'] = '0';
          } else {
            this.objtbStatu.gtwtlState = '1';
            this.objtbStatu.state = '1';
            this.addObj['state'] = '1';
          }

          this.$confirm({
            title: '提示',
            content: '确认保存取水许可情况信息吗？',
            okType: 'warning',
            onOk: () => {
              request.post('/bis/insp/winjx/gtwtl', 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/gtwtl/' + 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_GTWTL',
      };
      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>
