刘光辉
12 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<script setup lang="ts">
import { reactive, ref, toRefs } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { formValidate } from '@jnpf/utils';
 
import { Button } from 'ant-design-vue';
 
import { applySaasApi, getTenantMobileCode } from '#/api/core/auth';
import { $t } from '#/locales';
 
import { useFormValid } from './useLogin';
 
interface State {
  formData: any;
  formRules: any;
  loading: boolean;
  codeDisabled: boolean;
  codeText: string;
  codeTimer: any;
}
 
const state = reactive<State>({
  formData: {
    companyName: '',
    userName: '',
    mobile: '',
    mobileCode: '',
  },
  formRules: {
    companyName: [
      { required: true, message: '请输入企业名称' },
      { validator: formValidate('fullName'), trigger: 'blur' },
    ],
    userName: [
      { required: true, message: '请输入联系人' },
      { validator: formValidate('fullName'), trigger: 'blur' },
    ],
    mobile: [
      { required: true, message: '请输入手机号' },
      { validator: formValidate('iphone'), trigger: 'blur' },
    ],
    mobileCode: [{ required: true, message: '请输入验证码' }],
  },
  loading: false,
  codeDisabled: false,
  codeText: $t('sys.login.getCode'),
  codeTimer: null,
});
 
const { formData, formRules, loading, codeDisabled, codeText } = toRefs(state);
const { createMessage } = useMessage();
const formRef = ref();
const { validForm } = useFormValid(formRef);
const [registerModal, { closeModal }] = useModalInner(init);
 
function init() {
  state.loading = false;
  state.formData.companyName = '';
  state.formData.userName = '';
  state.formData.mobile = '';
  state.formData.mobileCode = '';
  initCodeState();
}
async function getSmsCode() {
  if (state.codeDisabled) return;
  const values = await formRef.value?.validate(['mobile']);
  if (!values) return;
  state.codeDisabled = true;
  const query = { mobile: state.formData.mobile };
  getTenantMobileCode(query)
    .then(() => {
      createMessage.success('发送成功');
      state.codeDisabled = true;
      let second = 60;
      state.codeText = `${$t('sys.login.reSend')}(${second})`;
      state.codeTimer = setInterval(execute, 1000);
      function execute() {
        second--;
        if (second) {
          state.codeText = `${$t('sys.login.reSend')}(${second})`;
        } else {
          initCodeState();
        }
      }
    })
    .catch(() => {
      state.codeDisabled = false;
    });
}
function initCodeState() {
  state.codeDisabled = false;
  state.codeText = $t('sys.login.getCode');
  clearInterval(state.codeTimer);
}
async function handleSubmit() {
  if (state.loading) return;
  const data = await validForm();
  if (!data) return;
  state.loading = true;
  applySaasApi(data)
    .then((res) => {
      createMessage.success(res.msg);
      state.loading = false;
      closeModal();
    })
    .catch(() => {
      state.loading = false;
    });
}
</script>
 
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="企业申请" :footer="null" destroy-on-close>
    <a-form :colon="false" :label-col="{ style: { width: '80px' } }" layout="vertical" :model="formData" :rules="formRules" ref="formRef">
      <a-form-item label="企业名称" name="companyName">
        <jnpf-input v-model:value="formData.companyName" :maxlength="50" placeholder="请输入企业名称" />
      </a-form-item>
      <a-form-item label="联系人" name="userName">
        <jnpf-input v-model:value="formData.userName" :maxlength="15" placeholder="请输入姓名" />
      </a-form-item>
      <a-form-item label="联系电话" name="mobile">
        <jnpf-input v-model:value="formData.mobile" placeholder="请输入手机号" />
      </a-form-item>
      <a-form-item label="" name="mobileCode">
        <a-row type="flex" justify="space-between">
          <a-col :span="16">
            <a-input v-model:value="formData.mobileCode" :placeholder="$t('sys.login.codeTip')" size="large" />
          </a-col>
          <a-col :span="7">
            <Button type="primary" size="large" block @click="getSmsCode" :disabled="codeDisabled">
              {{ codeText }}
            </Button>
          </a-col>
        </a-row>
      </a-form-item>
      <a-form-item label="" class="py-[20px]">
        <Button type="primary" size="large" block :loading="loading" @click="handleSubmit">提交申请</Button>
      </a-form-item>
    </a-form>
  </BasicModal>
</template>