<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: 8}" :wrapper-col="{span: 16}" :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="是否有行政责任人" required>
            <a-radio-group v-model:value="formObj.hasWiunWaoLegPers">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.hasWiunWaoLegPers =='2'" type="link" @click="addProblem('hasWiunWaoLegPers')"><a-icon type="plus-circle" theme="filled" /></a-button>
          </a-form-item>
          <a-form-item label="责任人姓名" v-if="formObj.hasWiunWaoLegPers == '1'">
            <a-input v-model:value="formObj.wiunWaoLegPers" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="责任人电话" prop="wiunWaoLegPersTel" v-if="formObj.hasWiunWaoLegPers == '1'">
            <a-input v-model:value="formObj.wiunWaoLegPersTel" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="责任人职务" v-if="formObj.hasWiunWaoLegPers == '1'">
            <a-input v-model:value="formObj.wiunWaoLegPersDuty" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="是否接受过岗位培训" required v-if="formObj.hasWiunWaoLegPers == '1'">
            <a-radio-group v-model:value="formObj.wiunWaoLegPersTrain">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.wiunWaoLegPersTrain =='2'" type="link" @click="addProblem('wiunWaoLegPersTrain')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="履职情况" :required="this.formObj.hasWiunWaoLegPers === '1' ? true:false" v-if="formObj.hasWiunWaoLegPers == '1'">
            <a-radio-group v-model:value="formObj.wiunWaoLegPersResu">
              <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.wiunWaoLegPersResu =='3'" type="link" @click="addProblem('wiunWaoLegPersResu')">
              <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="是否有技术责任人" required>
            <a-radio-group v-model:value="formObj.hasTechPers">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.hasTechPers =='2'" type="link" @click="addProblem('hasTechPers')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="责任人姓名" v-if="formObj.hasTechPers == '1'">
            <a-input v-model:value="formObj.techPers" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="责任人电话" prop="techPersTel" v-if="formObj.hasTechPers == '1'">
            <a-input v-model:value="formObj.techPersTel" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="责任人职务" v-if="formObj.hasTechPers == '1'">
            <a-input v-model:value="formObj.techPersDuty" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="是否接受过岗位培训" required v-if="formObj.hasTechPers == '1'">
            <a-radio-group v-model:value="formObj.techPersTrain">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.techPersTrain =='2'" type="link" @click="addProblem('techPersTrain')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="履职情况" v-if="formObj.hasTechPers == '1'">
            <a-radio-group v-model:value="formObj.techPersResu">
              <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.techPersResu =='3'" type="link" @click="addProblem('techPersResu')">
              <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="是否有巡查责任人" required>
            <a-radio-group v-model:value="formObj.hasPatrolPers">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.hasPatrolPers =='2'" type="link" @click="addProblem('hasPatrolPers')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="责任人姓名" v-if="formObj.hasPatrolPers == '1'">
            <a-input v-model:value="formObj.patrolPers" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="责任人电话" prop="patrolPersTel" v-if="formObj.hasPatrolPers == '1'">
            <a-input v-model:value="formObj.patrolPersTel" autocomplete="off" style="width:70%;"></a-input>
          </a-form-item>
          <a-form-item label="是否接受过岗位培训" required v-if="formObj.hasPatrolPers == '1'">
            <a-radio-group v-model:value="formObj.patrolPersTrain">
              <a-radio value="1">是</a-radio>
              <a-radio value="2">否</a-radio>
            </a-radio-group>
            <a-button v-if="formObj.patrolPersTrain =='2'" type="link" @click="addProblem('patrolPersTrain')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item label="履职情况" v-if="formObj.hasPatrolPers == '1'">
            <a-radio-group v-model:value="formObj.patrolPersResu">
              <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.patrolPersResu =='3'" type="link" @click="addProblem('patrolPersResu')">
              <a-icon type="plus-circle" theme="filled" />
            </a-button>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 16, offset: 8 }">
            <a-button type="primary" @click="addHandler">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
      <problem-dialog
        v-if="showAddProblemDialog"
        :objType="1"
        :villType="0"
        :objId="currentObjectId"
        :objName="currentObjectName"
        :problemMiddleType="'小水库'"
        :problData="probId"
        @closeDialog="closePlDialog"
        :currentObjectRgstrId="currentObjectRgstrId"></problem-dialog>
    </a-layout>
  </div>
</template>

<script>
import { addBasePres, 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'],
  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: {
        dutyId: '',
        hasPatrolPers: '', // 是否有巡查责任人
        hasTechPers: '', // 是否有技术责任人
        hasWiunWaoLegPers: '', // 是否有行政责任人
        patrolPers: '', // 巡查责任人姓名
        patrolPersTrain: '', // 巡查责任人是否接受岗位培训
        // "patrolPersCnps": "",//巡查责任人规范性履职标准
        patrolPersResu: '', // 巡查责任人履职情况 0  1  2
        patrolPersTel: '', // 巡查责任人电话
        rgstrId: '', // 水库督查登记ID
        techPers: '', // 技术责任人姓名
        techPersDuty: '', // 技术责任人职务
        techPersResu: '', // 技术责任人履职情况
        techPersTel: '', // 技术责任人电话
        techPersTrain: '', // 技术责任人是否接受岗位培训
        // "techPersCnps": "",//技术责任人规范性履职标准
        wiunWaoLegPers: '', // 行政责任人姓名
        wiunWaoLegPersDuty: '', // 行政责任人职务
        wiunWaoLegPersResu: '', // 行政责任人履职情况
        wiunWaoLegPersTel: '', // 行政责任人电话
        wiunWaoLegPersTrain: '', // 行政责任人是否接受岗位培训
        // "wiunWaoLegPersCnps": "",//行政责任人规范性履职标准
      },
      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: {
    getRgstridObj() {
      getRgstrid(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;
      console.log(this.formObj);
      this.objtbStatu.rgstrId = this.currentObjectRgstrId;

      if (
        this.formObj.hasWiunWaoLegPers == '2' &&
        this.formObj.hasTechPers == '2' &&
        this.formObj.hasPatrolPers == '2'
      ) {
        this.objtbStatu.presStat = '2';
      } else {
        if (
          this.formObj.hasWiunWaoLegPers ||
          this.formObj.hasTechPers ||
          this.formObj.hasPatrolPers
        ) {
          this.objtbStatu.presStat = '1';
        }
        if (
          this.formObj.hasWiunWaoLegPers == undefined &&
          this.formObj.wiunWaoLegPersResu == undefined &&
          this.formObj.hasTechPers == undefined &&
          this.formObj.techPersResu == undefined &&
          this.formObj.hasPatrolPers == undefined
        ) {
          this.objtbStatu.presStat = '0';
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '2'
        ) {
          if (
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '2'
        ) {
          if (this.formObj.techPersTrain && this.formObj.techPersResu) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '1'
        ) {
          if (this.formObj.patrolPersTrain && this.formObj.patrolPersResu) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '2' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '1'
        ) {
          if (
            this.formObj.techPersTrain &&
            this.formObj.techPersResu &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '1'
        ) {
          if (
            this.formObj.techPersTrain &&
            this.formObj.techPersResu &&
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '2' &&
          this.formObj.hasPatrolPers == '1'
        ) {
          if (
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.patrolPersTrain &&
            this.formObj.patrolPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
        if (
          this.formObj.hasWiunWaoLegPers == '1' &&
          this.formObj.hasTechPers == '1' &&
          this.formObj.hasPatrolPers == '2'
        ) {
          if (
            this.formObj.wiunWaoLegPersTrain &&
            this.formObj.wiunWaoLegPersResu &&
            this.formObj.techPersTrain &&
            this.formObj.techPersResu
          ) {
            this.objtbStatu.presStat = '2';
          }
        }
      }

      this.$confirm({
        title: '提示',
        content: '确认保存责任人落实情况信息？',
        okType: 'warning',
        onOk: () => {
          if (this.operationType1 == 'add') {
            try {
              request.post('/dc/insp/basePres', this.formObj).then((res) => {
                if (res.success) {
                  this.$message.success('添加成功');
                  request
                    .post('/dc/insp/rsvrRgstr/update', this.objtbStatu)
                    .then((res) => {
                      res;
                    });
                  this.$emit('addShuiKuSuccess');
                }
              });
            } catch (e) {}
          } else if (this.operationType1 == 'update') {
            try {
              request
                .post('/dc/insp/basePres/update', this.formObj)
                .then((res) => {
                  if (res.success) {
                    this.$message.success('修改成功');
                    request
                      .post('/dc/insp/rsvrRgstr/update', this.objtbStatu)
                      .then((res) => {
                        res;
                      });
                    this.$emit('addShuiKuSuccess');
                  }
                });
            } catch (e) {}
          }
        },
      });
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    findItemByType() {
      const obj = {
        tname: 'BIS_INSP_BASE_PRES_EXT',
      };
      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>
