<template>
  <div id="">
    <a-layout style="height:520px;">
      <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: 10}" :wrapper-col="{span: 14}" :rules="rules">
          <a-form-item label="是否明确防汛“三个责任人”" required>
            <a-radio-group v-model:value="formObj.isClearPers">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.isClearPers =='2'" type="link" @click="addProblem('isClearPers')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </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="姓名" v-if="formObj.isClearPers == '1'">
            <a-input v-model:value="formObj.wiunWaoLegPers" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="电话" v-if="formObj.isClearPers == '1'" prop="wiunWaoLegPersTel">
            <a-input v-model:value="formObj.wiunWaoLegPersTel" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="职务" v-if="formObj.isClearPers == '1'">
            <a-input v-model:value="formObj.wiunWaoLegPersDuty" autocomplete="off" style="width:70%;"></a-input>
          </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="姓名" v-if="formObj.isClearPers == '1'">
            <a-input v-model:value="formObj.techPers" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="电话" v-if="formObj.isClearPers == '1'" prop="techPersTel">
            <a-input v-model:value="formObj.techPersTel" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="职务" v-if="formObj.isClearPers == '1'">
            <a-input v-model:value="formObj.techPersDuty" autocomplete="off" style="width:70%;"></a-input>
          </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="姓名" v-if="formObj.isClearPers == '1'">
            <a-input v-model:value="formObj.patrolPers" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="电话" v-if="formObj.isClearPers == '1'" prop="patrolPersTel">
            <a-input v-model:value="formObj.patrolPersTel" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="职务" v-if="formObj.isClearPers == '1'">
            <a-input v-model:value="formObj.techPersDuty" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="是否设立标识牌" v-if="formObj.isClearPers == '1'" required>
            <a-radio-group v-model:value="formObj.isSetCard">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.isSetCard =='2'" type="link" @click="addProblem('isSetCard')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="“三个责任人”履职情况" v-if="formObj.isClearPers == '1'" required>
            <a-radio-group v-model:value="formObj.persResu">
              <a-radio value="1">好</a-radio>
              <a-radio value="2">基本到位</a-radio>
              <a-radio value="3">差</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.persResu =='2' || formObj.persResu =='3'" type="link" @click="addProblem('persResu')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 14, offset: 10 }">
            <a-button type="primary" @click="addHandler">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog"
        :objType="pType"
        :villType="0"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'大中型水库'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { getRgstrid } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import { formatDateTimeD } from '../../../utils/gw_date.js';
import inputWith from '../../../widgets/inuptWith';
import problemDialog from '../../duChaWenTi/problemDialog.vue';
export default {
  components: {
    inputWith: inputWith,
    problemDialog,
  },
  props: [
    'currentObjectId',
    'currentObjectName',
    'currentObjectRgstrId',
    'pType',
  ],
  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: '',
        id: '',
      },
      rules: {
        wiunWaoLegPersTel: [{ validator: checkTel, trigger: 'blur' }],
        techPersTel: [{ validator: checkTel, trigger: 'blur' }],
        patrolPersTel: [{ validator: checkTel, trigger: 'blur' }],
      },
      formObj: {
        dutyId: '',
        isClearPers: '', // 是否明确防汛"三个责任人"
        isSetCard: '', // 是否有标识牌
        persResu: '', // 三个责任人履职情况 0  1  2
      },
      dialogFormVisible: false,
      formLabelWidth: '210px',
      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: {
    getRgstridObj() {
      getRgstrid(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.id = this.currentObjectRgstrId;
      // 选择否的时候
      if (this.formObj.isClearPers == '2') {
        this.objtbStatu.presStat = '2';
      }
      // 当选择是 或者 不选择
      else {
        if (this.formObj.isClearPers) {
          this.objtbStatu.presStat = '1';
        }
        if (
          this.formObj.isClearPers == undefined &&
          this.formObj.persResu == undefined && // 履职情况
          this.formObj.isSetCard == undefined
        ) {
          this.objtbStatu.presStat = '0';
        }
        if (this.formObj.isClearPers == '1') {
          if (
            this.formObj.isSetCard && // 是否有标识牌
            this.formObj.persResu // 巡查责任人履职情况 0  1  2
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
      }

      this.$confirm('确认保存责任人落实情况信息？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          if (this.operationType1 == 'add') {
            try {
              request
                .post('/bis/insp/rsml/rgstr/pres', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('添加成功');
                    request
                      .post('/bis/insp/rsml/rgstr', this.objtbStatu)
                      .then((res) => {
                        res;
                      });
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          } else if (this.operationType1 == 'update') {
            try {
              request
                .post('/bis/insp/rsml/rgstr/pres', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('修改成功');
                    request
                      .post('/bis/insp/rsml/rgstr', this.objtbStatu)
                      .then((res) => {
                        res;
                      });
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          }
        })
        .catch(() => {});
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_RSML_RGSTR_PRES', // 三个责任人 表名
        type: this.pType,
      };
      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>

</style>
