register.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <div class="login-box py-5">
  3. <v-card class="pa-5" :class="isMobile? 'mobileBox' : 'default-width'" :elevation="isMobile? '0' : '3'">
  4. <!-- 标题 -->
  5. <div class="mt-3" v-if="!isMobile">
  6. <v-btn v-if="pageType !== 'noLoginToRegister'" color="primary" variant="text" @click="router.push('/recruitHome')">{{ `<< 回到首页` }}</v-btn>
  7. <div v-else style="height: 30px;"></div>
  8. </div>
  9. <!-- 表单 -->
  10. <div class="CtFormClass" :style="{width: isMobile ? '' : '600px'}">
  11. <div v-if="failureReason" class="mb-8" style="color: red;">
  12. <span class="mr-5">《审核不通过》</span>
  13. <span>原因:{{ failureReason }}</span>
  14. </div>
  15. <!-- 标题 -->
  16. <div class="mb-10" :class="isMobile ? 'mt-0': 'mt-n8'" style="font-size: 22px; font-weight: bold; text-align: center;">{{ $t('enterprise.registeringNewEnterprise') }}</div>
  17. <CtForm ref="CtFormRef" :items="formItems" style="width: 100%;">
  18. <template #businessLicense>
  19. <!-- 上传照片 -->
  20. <div class="d-flex flex-column mb-6">
  21. <div style="color: var(--color-999);">
  22. <span v-if="!prepareValue" class="mr-1" style="color: var(--v-error-base);">*</span>
  23. <span>上传营业执照</span>
  24. <span>支持jpg、jpeg、png格式,图片大小不得超过10M</span>
  25. </div>
  26. <div class="file-box">
  27. <Img
  28. class="mt-3"
  29. tips="上传图片"
  30. :value="licenseUrl"
  31. :showSnackbar="false"
  32. @imgClick="showPreview = !showPreview"
  33. :showCursor="true"
  34. @success="handleUploadImg"
  35. @delete="handleDeleteImg"
  36. ></Img>
  37. </div>
  38. </div>
  39. </template>
  40. <template #contacts>
  41. <!-- 联系人 -->
  42. <v-btn class="mb-5" style="width: 100%; text-align: center;" variant="text" color="primary" prepend-icon="mdi-plus-box" @click="handleAddContact">添加联系人</v-btn>
  43. </template>
  44. </CtForm>
  45. <div class="note">
  46. <h4>注意事项:</h4>
  47. <span>企业名称为对外展示的企业名称,建议填写公司营业执照上的名称,请区分总公司和分公司</span>
  48. </div>
  49. </div>
  50. <div class="text-center">
  51. <!-- 提交 -->
  52. <v-btn
  53. :loading="loginLoading"
  54. color="primary" class="white--text my-8" min-width="350"
  55. @click="handleCommit"
  56. >
  57. {{ $t('common.complete') }}
  58. </v-btn>
  59. </div>
  60. </v-card>
  61. <PreviewImg v-if="showPreview" :current="current" :list="[licenseUrl]" @close="showPreview = !showPreview"></PreviewImg>
  62. <Loading :visible="loading"></Loading>
  63. <CtDialog :visible="showContactList" title="添加联系人" :footer="true" widthType="3" @close="showContactList = false" @submit="contactSubmit">
  64. <div style="min-height: 50vh;">
  65. <div>
  66. <div v-for="(item, index) in contactCopy" :key="index" class="contactItemCard">
  67. <div class="d-flex justify-space-between pb-2">
  68. <div class="mb-3 pl-3" style="font-size: 13px; color: 00897B; border-left: 5px solid #00897B;">{{ index ? '联系人' + index : '管理员' }}</div>
  69. <v-btn v-if="index" color="error" density="compact" variant="text" @click="delContact(index)">删除</v-btn>
  70. <div v-else style="font-size: 12px; color: #999">不可删除</div>
  71. </div>
  72. <TextUI v-model="item.contactName" :item="{...contactNameObj}"></TextUI>
  73. <TextUI v-model="item.phone" :item="{...phoneObj}"></TextUI>
  74. <TextUI v-model="item.email" :item="{...emailObj}"></TextUI>
  75. <TextUI v-model="item.password" :item="{...passwordObj}"></TextUI>
  76. <TextUI v-model="item.passwordConfirm" :item="{...passwordConfirmObj}"></TextUI>
  77. </div>
  78. </div>
  79. <v-btn class="mb-5 mt-3" style="width: 100%; text-align: center;" color="primary" prepend-icon="mdi-plus-box" @click="addMore">继续添加</v-btn>
  80. </div>
  81. </CtDialog>
  82. </div>
  83. </template>
  84. <script setup>
  85. defineOptions({name: 'enterprise-enterpriseRegister-register'})
  86. import CtForm from '@/components/CtForm'
  87. import Snackbar from '@/plugins/snackbar'
  88. import { useI18n } from '@/hooks/web/useI18n'
  89. import { useRouter } from 'vue-router'; const router = useRouter()
  90. import { enterpriseRegisterApply } from '@/api/personal/user'
  91. import { onMounted, ref, computed } from 'vue';
  92. import { checkEmail } from '@/utils/validate'
  93. import { getBusinessLicenseOCR } from '@/api/common'
  94. import Confirm from '@/plugins/confirm'
  95. import TextUI from '@/components/FormUI/TextInput'
  96. const { t } = useI18n()
  97. const CtFormRef = ref()
  98. const loginLoading = ref(false)
  99. // 图片预览
  100. const loading = ref(false)
  101. const showPreview = ref(false)
  102. const current = ref(0)
  103. const business = ref({})
  104. let licenseUrl = ref('')
  105. const email = localStorage.getItem('loginAccount') || ''
  106. // 组件挂载后添加事件监听器
  107. const isMobile = ref(false)
  108. onMounted(() => {
  109. const userAgent = navigator.userAgent
  110. isMobile.value = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i.test(userAgent)
  111. })
  112. import { useRoute } from 'vue-router'; const route = useRoute()
  113. const pageType = route?.query?.type || '' // type: noLoginToRegister:->登录页注册企业
  114. const showContactList = ref(false)
  115. const contactInfo = { contactName: '', phone: '', email: '', password: '', passwordConfirm:'' }
  116. let contactList = [{ ...contactInfo }]
  117. const contactCopy = ref([])
  118. const contactSubmit = () => {
  119. let falseValueIndex = null
  120. let falseKey = null
  121. contactCopy.value.forEach((e, index) => {
  122. if (falseValueIndex !== null) return
  123. if (e && Object.keys(e).length) {
  124. Object.keys(e).forEach(key => {
  125. if (falseValueIndex !== null) return
  126. if (!e[key]) {
  127. falseValueIndex = index
  128. falseKey = key
  129. }
  130. })
  131. }
  132. if (e.password && e.passwordConfirm && e.password !== e.passwordConfirm)
  133. falseValueIndex = index
  134. falseKey = 'compareFalse'
  135. })
  136. const textList = {
  137. contactName: '姓名',
  138. phone: '联系电话',
  139. email: '企业邮箱',
  140. password: '登录密码',
  141. passwordConfirm: '登录密码',
  142. }
  143. if (falseValueIndex || falseValueIndex === 0) {
  144. //
  145. let text = ''
  146. if (falseKey === 'compareFalse') {
  147. text = falseValueIndex ? `【联系人${falseValueIndex}】两次输入的密码不一致` : `【管理员】两次输入的密码不一致`
  148. } else {
  149. text = falseValueIndex ? `请完善联系人${falseValueIndex}的【${textList[falseKey]}】` : `请完善管理员的【${textList[falseKey]}】`
  150. }
  151. Confirm(t('common.confirmTitle'), text, { hideCancelBtn: true })
  152. return
  153. }
  154. contactList = [...contactCopy.value]
  155. showContactList.value = false
  156. saveRegisterInfo()
  157. }
  158. const handleAddContact = () => {
  159. contactCopy.value = [...contactList]
  160. showContactList.value = true
  161. }
  162. const addMore = () => {
  163. contactCopy.value.push({...contactInfo})
  164. }
  165. const delContact = (index) => {
  166. Confirm('系统提示', `是否确认删除${index ? `联系人${index}` : '管理员'}?`).then(async () => {
  167. contactCopy.value.splice(index, 1)
  168. })
  169. }
  170. // 注册信息保存
  171. const enterpriseRegisterInfo = ref(localStorage.getItem('enterpriseRegisterInfo') ? JSON.parse(localStorage.getItem('enterpriseRegisterInfo')) : {})
  172. const saveRegisterInfo = () => {
  173. const obj = {
  174. licenseUrl: licenseUrl.value,
  175. ocr: business.value
  176. }
  177. formItems.value.options.forEach(e => {
  178. if (e.key) obj[e.key] = e.value
  179. })
  180. obj.contactList = contactList
  181. localStorage.setItem('enterpriseRegisterInfo', JSON.stringify(obj))
  182. }
  183. const codeLabelTet = '企业统一社会信用代码(可从上传的营业执照自动识别)'
  184. // 是否筹建中
  185. const isPrepareChange = () => {
  186. const code = formItems.value.options.find(e => e.key === 'code')
  187. if (code) {
  188. code.label = prepareValue.value ? codeLabelTet : codeLabelTet + ' *'
  189. code.rules = prepareValue.value ? [] : [v => !!v || '请输入企业统一社会信用代码']
  190. }
  191. saveRegisterInfo()
  192. }
  193. const formItems = ref({
  194. options: [
  195. {
  196. type: 'ifRadio',
  197. key: 'prepare',
  198. value: false,
  199. label: '是否筹建中 *',
  200. width: 100,
  201. items: [
  202. { label: '是', value: true },
  203. { label: '否', value: false }
  204. ],
  205. change: isPrepareChange
  206. },
  207. {
  208. slotName: 'businessLicense'
  209. },
  210. {
  211. type: 'text',
  212. key: 'name',
  213. value: '',
  214. label: '企业名称(需要与营业执照完全一致,可从上传的营业执照自动识别)*',
  215. counter: 50,
  216. rules: [v => !!v || '请输入企业名称'],
  217. blur: saveRegisterInfo
  218. },
  219. {
  220. type: 'text',
  221. key: 'anotherName',
  222. value: '',
  223. label: '企业别称',
  224. counter: 50,
  225. blur: saveRegisterInfo
  226. },
  227. {
  228. type: 'text',
  229. key: 'code',
  230. value: '',
  231. counter: 18,
  232. label: codeLabelTet + ' *',
  233. rules: [v => !!v || '请输入企业统一社会信用代码'],
  234. blur: saveRegisterInfo
  235. },
  236. {
  237. slotName: 'contacts'
  238. },
  239. {
  240. type: 'textarea',
  241. key: 'description',
  242. value: '',
  243. clearable: true,
  244. resize: true,
  245. counter: 500,
  246. rows: 2,
  247. label: '备注/说明',
  248. blur: saveRegisterInfo
  249. },
  250. ]
  251. })
  252. // 是否筹建中
  253. const prepareValue = computed(() => {
  254. return formItems.value.options.find(e => e.key === 'prepare').value
  255. })
  256. // 识别营业执照图片
  257. const getOcr = async () => {
  258. loading.value = true
  259. try {
  260. const data = await getBusinessLicenseOCR(licenseUrl.value)
  261. if (data && Object.keys(data).length) {
  262. formItems.value.options.find(e => e.key === 'code').value = data.code
  263. formItems.value.options.find(e => e.key === 'name').value = data.name
  264. business.value = data
  265. saveRegisterInfo()
  266. } else {
  267. licenseUrl.value = ''
  268. Confirm(t('common.confirmTitle'), '营业执照图片识别失败,请重新上传清晰合法图片', { hideCancelBtn: true })
  269. }
  270. } catch (error) {
  271. licenseUrl.value = ''
  272. Confirm(t('common.confirmTitle'), error, { hideCancelBtn: true })
  273. } finally {
  274. loading.value = false
  275. }
  276. }
  277. // 上传
  278. const handleUploadImg = (url) => {
  279. licenseUrl.value = url
  280. if (licenseUrl.value) getOcr()
  281. }
  282. const handleDeleteImg = () => {
  283. licenseUrl.value = ''
  284. business.value = {}
  285. formItems.value.options.find(e => e.key === 'code').value = ''
  286. formItems.value.options.find(e => e.key === 'name').value = ''
  287. saveRegisterInfo()
  288. }
  289. // 提交 企业注册
  290. const handleCommit = async () => {
  291. const { valid } = await CtFormRef.value.formRef.validate()
  292. if (!valid) return
  293. const businessLicenseUrl = licenseUrl.value;
  294. if (!prepareValue.value && !businessLicenseUrl) return Snackbar.warning('请上传营业执照图片')
  295. if (!contactList || !contactList.length || !contactList[0].contactName) return Snackbar.warning('请添加联系人信息')
  296. const params = {
  297. businessLicenseUrl,
  298. prepare: prepareValue.value,
  299. }
  300. formItems.value.options.forEach(e => {
  301. if (e.key) params[e.key] = e.value
  302. })
  303. if (business.value && Object.keys(business.value).length) params.ocr = business.value
  304. // 联系人
  305. params.contacts = contactList
  306. params.contactName = contactList[0].contactName
  307. params.phone = contactList[0].phone
  308. params.email = contactList[0].email
  309. await enterpriseRegisterApply(params)
  310. localStorage.removeItem('loginAccount')
  311. localStorage.removeItem('enterpriseRegisterInfo')
  312. Snackbar.success(t('common.submittedSuccessfully'))
  313. router.push({ path: '/recruit/entRegister/inReview' })
  314. }
  315. // 不通过的企业注册申请 重新发起
  316. const failureReason = ref('')
  317. const info = JSON.parse(localStorage.getItem('userApplyInfo'))
  318. console.log(1, '23456', info)
  319. // 审核不通过的数据回显
  320. if (info && Object.keys(info).length && info.status === '2') {
  321. failureReason.value = info?.reason || ''
  322. licenseUrl.value = info?.businessLicenseUrl
  323. contactList = info?.contacts.map(e => {
  324. e.passwordConfirm = e.password
  325. return e
  326. }) || [{ ...contactInfo }]
  327. // prepareValue.value = info?.prepare || false
  328. formItems.value.options.forEach(e => {
  329. // if (e.key === 'passwordConfirm') e.value = info.password
  330. // else e.value = info[e.key]
  331. e.value = info[e.key]
  332. })
  333. isPrepareChange()
  334. } else {
  335. // 表单信息保存
  336. if (enterpriseRegisterInfo.value && Object.keys(enterpriseRegisterInfo.value).length) {
  337. licenseUrl.value = enterpriseRegisterInfo.value.licenseUrl
  338. business.value = enterpriseRegisterInfo.value?.ocr
  339. contactList = enterpriseRegisterInfo.value?.contactList || []
  340. formItems.value.options.forEach(e => {
  341. if (e.key === 'passwordConfirm') e.value = enterpriseRegisterInfo.value.password
  342. else e.value = enterpriseRegisterInfo.value[e.key]
  343. })
  344. isPrepareChange()
  345. }
  346. }
  347. const contactNameObj = {
  348. type: 'text',
  349. key: 'contactName',
  350. value: '',
  351. label: '联系人姓名 *',
  352. rules: [v => !!v || '请输入联系人姓名'],
  353. }
  354. const phoneObj = {
  355. type: 'phoneNumber',
  356. key: 'phone',
  357. value: '',
  358. label: '联系电话 *',
  359. rules: [v => !!v || '请输入联系电话'],
  360. }
  361. const emailObj = {
  362. type: 'text',
  363. key: 'email',
  364. value: email ? email : '',
  365. label: '企业邮箱 *(此邮箱将用于日后“登录邮箱”)',
  366. // label: '企业邮箱 * (此邮箱将作为企业登录的账号)',
  367. rules: [
  368. value => {
  369. if (value) return true
  370. return '请输入企业邮箱'
  371. },
  372. value => {
  373. if (checkEmail(value)) return true
  374. return '请输入正确的企业邮箱'
  375. }
  376. ],
  377. }
  378. const passwordObj = {
  379. type: 'password',
  380. key: 'password',
  381. value: '',
  382. password: true,
  383. appendInnerIcon: 'mdi-eye-off-outline',
  384. label: '账户登录密码 *',
  385. placeholder: '请输入账户登录密码',
  386. // appendInnerClick: handlePassword,
  387. rules: [
  388. value => {
  389. if (value) return true
  390. return '请输入账户登录密码'
  391. },
  392. value => {
  393. if (/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{8,16}$/.test(value)) return true
  394. return '请输入8-16位数由数字、大小写字母组成的密码'
  395. }
  396. ],
  397. }
  398. const passwordConfirmObj = {
  399. type: 'password',
  400. key: 'passwordConfirm',
  401. value: '',
  402. password: true,
  403. appendInnerIcon: 'mdi-eye-off-outline',
  404. label: '请再次输入账户登录密码 *',
  405. placeholder: '请再次输入账户登录密码',
  406. // appendInnerClick: handleSecondConfirm,
  407. rules: [
  408. value => {
  409. if (value) return true
  410. return '请再次输入密码'
  411. },
  412. ],
  413. }
  414. </script>
  415. <style lang="scss" scoped>
  416. .CtFormClass {
  417. margin: 0 auto;
  418. }
  419. .note {
  420. color: var(--color-666);
  421. font-size: 14px;
  422. line-height: 32px;
  423. }
  424. .login-box {
  425. position: relative;
  426. width: 100%;
  427. height: 100%;
  428. background-image: url('https://www.mendunerhr.com/images/userfiles/92d7e4a755e2428b94aab3636d5047f3/images/recruitment/adImages/2018/11/1920x940.jpg');
  429. background-size: cover;
  430. }
  431. .file-box {
  432. display: flex;
  433. flex-wrap: wrap; /* 允许换行 */
  434. width: 100%; /* 设置容器宽度 */
  435. .file-item {
  436. height: 80px;
  437. width: 100px;
  438. border-radius: 5px;
  439. margin-right: 8px;
  440. margin-top: 12px;
  441. // border: 1px solid rgb(188, 188, 188);
  442. border: 1px solid rgba(188, 188, 188, 0.5);
  443. }
  444. .file-input-box {
  445. position: relative;
  446. border: 1px solid rgb(188, 188, 188);
  447. cursor: pointer;
  448. .icon {
  449. position: absolute;
  450. top: 45%;
  451. left: 50%;
  452. transform: translate(-50%, -50%);
  453. color: var(--color-999);
  454. }
  455. }
  456. // 验证是否为空
  457. .verifyAct {
  458. color: var(--v-error-base);
  459. border: 1px solid var(--v-error-base);
  460. .icon { color: var(--v-error-base); }
  461. }
  462. }
  463. .PrepareBox {
  464. margin-top: 74px;
  465. margin-left: 32px;
  466. }
  467. .mobileBox {
  468. width: calc(100vw - 16px);
  469. margin: 0 auto;
  470. .resume-header {
  471. margin-bottom: 12px;
  472. }
  473. }
  474. .contactItemCard {
  475. background-color: var(--default-bgc);
  476. border-radius: 8px;
  477. padding: 16px 24px;
  478. margin-bottom: 20px;
  479. }
  480. </style>