<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.isSchApp">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSchApp == '2'" type="link" @click="addProblem('isSchApp')">
                <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.isPerform">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPerform == '2'" type="link" @click="addProblem('isPerform')">
                <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.isPrfWaste">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPrfWaste == '2'" type="link" @click="addProblem('isPrfWaste')">
                <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.isPrfDoba">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPrfDoba == '2'" type="link" @click="addProblem('isPrfDoba')">
                <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.isPrfDefend">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPrfDefend == '2'" type="link" @click="addProblem('isPrfDefend')">
                <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.isPrfPlant">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPrfPlant == '2'" type="link" @click="addProblem('isPrfPlant')">
                <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.isPrfSoilLoss">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isPrfSoilLoss == '2'" type="link" @click="addProblem('isPrfSoilLoss')">
                <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.isSignContract">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSignContract == '2'" type="link" @click="addProblem('isSignContract')">
                <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.isRuleRprt">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isRuleRprt == '2'" type="link" @click="addProblem('isRuleRprt')">
                <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.isSoilChk">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isSoilChk == '2'" type="link" @click="addProblem('isSoilChk')">
                <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.isNochkRun">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isNochkRun == '2'" type="link" @click="addProblem('isNochkRun')">
                <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.isCost">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isCost == '2'" type="link" @click="addProblem('isCost')">
                <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.isFileCheck">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
              <a-button v-if="formObj.isFileCheck == '2'" type="link" @click="addProblem('isFileCheck')">
                <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 { getRgstridRvlksfSlwt } 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: {
        isSchApp: '',
        isPerform: '',
        isPrfWaste: '',
        isPrfDoba: '',
        isPrfDefend: '',
        isPrfPlant: '',
        isPrfSoilLoss: '',
        isSignContract: '',
        isRuleRprt: '',
        isSoilChk: '',
        isNochkRun: '',
        isCost: '',
        isFileCheck: '',
      },
      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() {
      getRgstridRvlksfSlwt(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/slwt/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/slwt/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_SLWT',
      };
      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>
