<template>
  <div class="gcsthyxglqk">
    <a-layout>
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;">信息填报</p>
        <a-form :model="formObj" :label-col="{span: 12}" :wrapper-col="{span: 12}" :rules="rules">
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">巡查（巡检）</span>
            <span class="hrs"> </span>
          </p>
          <a-form-item label="巡查（巡检）通道是否满足巡查（巡检）需要">
            <a-radio-group v-model:value="formObj.xcTdmzxc">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('xcTdmzxc',formObj.xcTdmzxc)" type="link" v-if="formObj.xcTdmzxc =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否对大坝进行安全监测、采集监测数据（检查重点：是否有水位、渗流量巡查记录）">
            <a-radio-group v-model:value="formObj.xcDbjc">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button
                @click="addProblem('xcDbjc',formObj.xcDbjc)"
                type="link"
                v-if="formObj.xcDbjc =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否及时整理分析监测资料，掌握大坝运行状况（检查重点：是否有大坝运行情况巡查记录）">
            <a-radio-group v-model:value="formObj.xcZljczl">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('xcZljczl',formObj.xcZljczl)" type="link" v-if="formObj.xcZljczl =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">工程维护</span>
            <span class="hrs"> </span>
          </p>
          <a-form-item label="是否按要求进行日常维护（检查重点：大坝、溢洪道等工程管理范围内是否杂草丛生，影响运行观测及巡查检查）">
            <a-radio-group v-model:value="formObj.xcRcwh">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('xcRcwh',formObj.xcRcwh)" type="link" v-if="formObj.xcRcwh =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否及时处理影响大坝安全的白蚁危害等安全隐患">
            <a-radio-group v-model:value="formObj.xcClby">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('xcClby',formObj.xcClby)" type="link" v-if="formObj.xcClby =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="工程实体是否存在其他问题未及时处理">
            <a-radio-group v-model:value="formObj.xcCzwt">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="工程实体类型" v-if="formObj.xcCzwt == '1'">
            <a-radio-group v-model:value="formObj.xcGcstlx">
              <a-radio value="1">一般小型水库</a-radio>
              <a-radio value="2">重要小型水库</a-radio>
              <a-radio value="3">影响运行安全</a-radio>
              <a-button @click="addProblem('xcGcstlx',formObj.xcGcstlx)" type="link" v-if="ormObj.xcGcstlx =='2' || formObj.xcGcstlx =='3' || formObj.xcGcstlx =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <p style="margin-top:10px;margin-bottom: 10px">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">安全监测设备、设施维护</span>
            <span class="hrs"> </span>
          </p>
          <a-form-item label="安全监测设备、设施保护是否到位">
            <a-radio-group v-model:value="formObj.jcSbbh">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('jcSbbh',formObj.jcSbbh)" type="link" v-if="formObj.jcSbbh =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="设备设施、软硬件系统报警是否及时处理">
            <a-radio-group v-model:value="formObj.jcSbbjcl">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button @click="addProblem('jcSbbjcl',formObj.jcSbbjcl)" type="link" v-if="formObj.jcSbbjcl =='0'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="是否及时发现安全监测设备、设施维护存在的问题">
            <a-radio-group v-model:value="formObj.jcSbwh">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="发现问题后是否按规定报告或处理" v-if="formObj.jcSbwh == '1'">
            <a-radio-group v-model:value="formObj.jcWtbg">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
            </a-radio-group>
          </a-form-item>
          <a-form-item label="问题是否影响运行安全" v-if="formObj.jcSbwh == '0' || formObj.jcWtbg == '0'">
            <a-radio-group v-model:value="formObj.jcWtyxaqyx">
              <a-radio value="1">是</a-radio>
              <a-radio value="0">否</a-radio>
              <a-button
                @click="addProblem('jcWtyxaqyx',formObj.jcWtyxaqyx)"
                type="link"
                v-if="formObj.jcWtyxaqyx =='0' || formObj.jcWtyxaqyx =='1'">
                <a-icon type="plus-circle" theme="filled" class="add-problem-icon" />
              </a-button>
            </a-radio-group>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 12, offset: 12 }">
            <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 && openType"
        :objType="pType"
        :villType="0"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'小水库'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"> </problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getLyjglist, getZhgllist } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import inputWith from '../../../widgets/inuptWith.vue';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  components: {
    inputWith,
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'pType',
    '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: {
        presStat: '',
        rgstrId: '',
      },
      rules: {
        wiunWaoLegPersTel: [{ validator: checkTel, trigger: 'blur' }],
        techPersTel: [{ validator: checkTel, trigger: 'blur' }],
        patrolPersTel: [{ validator: checkTel, trigger: 'blur' }],
      },
      formObj: {
        rgstrId: '',
        xcTdmzxc: '', // 是否有巡查责任人
        xcDbjc: '', // 是否有技术责任人
        xcZlJzl: '', // 是否有行政责任人
        xcRcwh: '', // 是否有主管责任人
        xcClby: '', // 是否有管理责任人
        xcCzwt: '', // 巡查责任人姓名
        xcGcstlx: '', // 巡查责任人是否接受岗位培训
        jcSbbh: '', // 巡查责任人规范性履职标准
        jcSbbjcl: '', // 巡查责任人履职情况 0  1  2
        jcSbwh: '', // 巡查责任人电话
        jcWtbg: '', // 水库督查登记ID
        jcWtyxaqyx: '', // 技术责任人姓名
        recPersId: '', // 技术责任人职务
        recPers2: '', // 技术责任人履职情况
        recPersTel: '', // 技术责任人电话
        createTime: '', // 技术责任人是否接受岗位培训
        updateTime: '', // 技术责任人规范性履职标准
        status: '',
      },
      dialogFormVisible: false,
      formLabelWidth: '350px',
      loading: true,
      operationType1: '',
      rsvrRules: null,
      probId: '',
      showAddProblemDialog: false,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '1098101939614724096';
    },
  },
  created() {
    this.findItemByType();
  },
  mounted() {
    this.getRgstridObj();
  },
  watch: {
    currentObjectRgstrId(n, o) {
      this.getRgstridObj();
    },
  },
  methods: {
    getRgstridObj() {
      getRcxclist(this.currentObjectRgstrId).then((res) => {
        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;
      console.log(this.formObj);
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;

      if (
        this.formObj.hasWiunWaoLegPers == '2' &&
        this.formObj.hasTechPers == '2' &&
        this.formObj.hasPatrolPers == '2' &&
        this.formObj.hasSuperPers == '2' &&
        this.formObj.hasManagePers == '2'
      ) {
        this.objtbStatu.presStat = '2';
      } else {
        if (
          this.formObj.hasWiunWaoLegPers ||
          this.formObj.hasTechPers ||
          this.formObj.hasPatrolPers ||
          this.formObj.hasSuperPers ||
          this.formObj.hasManagePers
        ) {
          this.objtbStatu.presStat = '1';
        }
        if (
          this.formObj.hasWiunWaoLegPers == undefined &&
          this.formObj.hasSuperPers == undefined &&
          this.formObj.hasTechPers == undefined &&
          this.formObj.hasManagePers == undefined &&
          this.formObj.hasPatrolPers == undefined
        ) {
          this.objtbStatu.presStat = '0';
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.wiunWaoLegPersCnps &&
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.techPersTrain &&
            this.formObj.techPersCnps &&
            this.formObj.techPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '1' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersCnps &&
            this.formObj.patrolPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '1' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.superPersTrain &&
            this.formObj.superPersCnps &&
            this.formObj.superPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '1'
        ) {
          if (
            this.formObj.managePersTrain &&
            this.formObj.managePersCnps &&
            this.formObj.managePersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '1' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.techPersTrain &&
            this.formObj.techPersCnps &&
            this.formObj.techPersResu &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersCnps &&
            this.formObj.patrolPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '1' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.wiunWaoLegPersCnps &&
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersCnps &&
            this.formObj.patrolPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.wiunWaoLegPersCnps &&
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.techPersTrain &&
            this.formObj.techPersCnps &&
            this.formObj.techPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '1' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.wiunWaoLegPersCnps &&
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.superPersTrain &&
            this.formObj.superPersCnps &&
            this.formObj.superPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '1'
        ) {
          if (
            this.formObj.wiunWaoLegPersCnps &&
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.managePersTrain &&
            this.formObj.managePersCnps &&
            this.formObj.managePersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '1' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.techPersCnps &&
            this.formObj.techPersTrain &&
            this.formObj.techPersResu &&
            this.formObj.superPersTrain &&
            this.formObj.superPersCnps &&
            this.formObj.superPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '2' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '1'
        ) {
          if (
            this.formObj.techPersCnps &&
            this.formObj.techPersTrain &&
            this.formObj.techPersResu &&
            this.formObj.managePersTrain &&
            this.formObj.managePersCnps &&
            this.formObj.managePersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '1' &&
          this.formObj.hasSuperPers == '1' &&
          this.formObj.hasManagePers == '2'
        ) {
          if (
            this.formObj.patrolPersCnps &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersResu &&
            this.formObj.superPersTrain &&
            this.formObj.superPersCnps &&
            this.formObj.superPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '1' &&
          this.formObj.hasSuperPers == '2' &&
          this.formObj.hasManagePers == '1'
        ) {
          if (
            this.formObj.patrolPersCnps &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersResu &&
            this.formObj.managePersTrain &&
            this.formObj.managePersCnps &&
            this.formObj.managePersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '1' &&
          this.formObj.hasSuperPers == '1' &&
          this.formObj.hasManagePers == '1'
        ) {
          if (
            this.formObj.techPersTrain &&
            this.formObj.techPersCnps &&
            this.formObj.techPersResu &&
            this.formObj.wiunWaoLegPersCnps &&
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersCnps &&
            this.formObj.patrolPersResu &&
            this.formObj.superPersTrain &&
            this.formObj.superPersCnps &&
            this.formObj.superPersResu &&
            this.formObj.managePersTrain &&
            this.formObj.managePersCnps &&
            this.formObj.managePersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
      }

      this.$confirm({
        title: '提示',
        content: '此操作将督查对象从列表中删除，确认删除该水库吗？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            try {
              request.post('/dc/insp/xskaqRcxc', this.formObj).then((res) => {
                if (res.success) {
                  this.$message.success('添加成功');
                  /* request.post("/dc/insp/rsvrRgstr/update", _self.objtbStatu).then((res) => {
                    res;
                  }) */
                  this.$emit('addShuiKuSuccess');
                }
              });
            } catch (e) {}
          } else if (this.operationType1 == 'update') {
            try {
              request
                .post('/dc/insp/xskaqRcxc/update', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('修改成功');
                    /* request.post("/dc/insp/rsvrRgstr/update", _self.objtbStatu).then((res) => {
                    res;
                  }) */
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          }
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_XSKAQ_RCXC',
        type: this.pType,
      };
      request
        .post('/bis/insp/item/ques/info/findItemByType', obj)
        .then((res) => {
          this.rsvrRules = res.data;
        });
    },
    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;
    },
    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;
}
</style>
