<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="formObj" :label-col="{ span: 10 }" :wrapper-col="{ span: 14 }" :rules="rules">
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">乱堆乱占</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="是否清理乱堆的物料、渣土垃圾等" required>
            <a-radio-group v-model:value="formObj.isClrWst">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isClrWst == '2'" type="link" @click="addProblem('isClrWst')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否清除河道管理范围种植的植物" required>
            <a-radio-group v-model:value="formObj.isClrPlnt">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isClrPlnt == '2'" type="link" @click="addProblem('isClrPlnt')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否平整恢复河道滩地" required>
            <a-radio-group v-model:value="formObj.isRenew">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isRenew == '2'" type="link" @click="addProblem('isRenew')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">涉水违规建设</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="是否停止违规建设行为" required>
            <a-radio-group v-model:value="formObj.isStopBuild">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isStopBuild == '2'" type="link" @click="addProblem('isStopBuild')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否补办涉水建设项目审批手续" required>
            <a-radio-group v-model:value="formObj.isRssApp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isRssApp == '2'" type="link" @click="addProblem('isRssApp')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否拆除违规建筑" required>
            <a-radio-group v-model:value="formObj.isDstBuild">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isDstBuild == '2'" type="link" @click="addProblem('isDstBuild')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否立案查处" required>
            <a-radio-group v-model:value="formObj.isFlchk">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isFlchk == '2'" type="link" @click="addProblem('isFlchk')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">损坏水利工程设施</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="是否停止损害水利工程设施行为" required>
            <a-radio-group v-model:value="formObj.isStopDst">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isStopDst == '2'" type="link" @click="addProblem('isStopDst')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否立案查处" required>
            <a-radio-group v-model:value="formObj.isFlchkDst">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isFlchkDst == '2'" type="link" @click="addProblem('isFlchkDst')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否采取措施恢复水利工程设施" required>
            <a-radio-group v-model:value="formObj.isRenewMsu">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isRenewMsu == '2'" type="link" @click="addProblem('isRenewMsu')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">围湖围汊</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="是否拆除清理矮圩围汊" required>
            <a-radio-group v-model:value="formObj.isDstTrnlk">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isDstTrnlk == '2'" type="link" @click="addProblem('isDstTrnlk')">
                <a-icon type="plus-circle" theme="filled" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否立案查处" required>
            <a-radio-group v-model:value="formObj.isFlchkTrnlk">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isFlchkTrnlk == '2'" type="link" @click="addProblem('isFlchkTrnlk')">
                <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="50"
        :villType="50"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'河湖卫士'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getRgstridRvlksfWtpjsf } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import { formatDateTimeD } from '../../../utils/gw_date.js';
import inputWith from '../../../widgets/inuptWith.vue';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  components: {
    inputWith: inputWith,
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'openType',
  ],
  data() {
    var checkTel = (rule, value, callback) => {
      var isPhone = /^([0-9]{3,4}-)?[0-9]{7,8}$/; // 座机
      var isMob = /^[1][3,4,5,7,8][0-9]{9}$/; // 座机格式
      if (value && !isMob.test(value) && !isPhone.test(value)) {
        callback(new Error('请输入合理电话'));
      } else if (value && (isMob.test(value) || isPhone.test(value))) {
        callback();
      }
      // setTimeout(() => {

      // }, 1000);
    };
    return {
      objtbStatu: {
        state: '',
        rgstrId: '',
        id: '',
      },
      rules: {
        wiunWaoLegPersTel: [{ validator: checkTel, trigger: 'blur' }],
        techPersTel: [{ validator: checkTel, trigger: 'blur' }],
        patrolPersTel: [{ validator: checkTel, trigger: 'blur' }],
      },
      jqmmDialogShow: false,
      type: '',
      formObj: {
        isClrWst: '',
        isClrPlnt: '',
        isRenew: '',
        isStopBuild: '',
        isRssApp: '',
        isDstBuild: '',
        isFlchk: '',
        isStopDst: '',
        isFlchkDst: '',
        isRenewMsu: '',
        isDstTrnlk: '',
        isFlchkTrnlk: '',
      },
      dialogFormVisible: false,
      formLabelWidth: '180px',
      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: {
    jqmmDialogClose() {
      this.jqmmDialogShow = false;
    },
    showPic(type) {
      this.type = type;
      this.jqmmDialogShow = true;
    },
    getRgstridObj() {
      getRgstridRvlksfWtpjsf(this.currentObjectRgstrId).then((res) => {
        //  res.data.dutyId去掉dutyId解决dutyId为空时不显示三个责任人
        if (res.data && Object.keys(res.data).length) {
          this.formObj = res.data;
          this.operationType1 = 'update';
        } 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;
      this.objtbStatu.state = '1';
      this.$confirm({
        title: '提示',
        content: '确认保存现场督察情况信息？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            try {
              request
                .post('/bis/insp/rvlksf/wtpjsf/add', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('添加成功');
                    request
                      .post('/bis/insp/rvlksf/update', this.objtbStatu)
                      .then((res) => {
                        res;
                      });
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          } else if (this.operationType1 == 'update') {
            try {
              request
                .post('/bis/insp/rvlksf/wtpjsf/update', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('修改成功');
                    request
                      .post('/bis/insp/rvlksf/update', this.objtbStatu)
                      .then((res) => {
                        res;
                      });
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          }
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_RVLKSF_WTPJSF',
      };
      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;
    },
    formatRadio(val) {
      if (val == '1') {
        return '是';
      } else if (val == '2') {
        return '否';
      } else {
        return val;
      }
    },
    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>
