PersonalInfoTab.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. <template>
  2. <view class="personal-info-tab">
  3. <view class="user-form">
  4. <uni-row class="demo-uni-row">
  5. <uni-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
  6. <view class="avatar-section">
  7. <cwg-input v-model:value="formData.idBackUrl" type="upload" fkey="idBackUrl"
  8. rulesKey="idBackUrl" :is-upload-d="true" accept="image/png, image/jpeg, image/jpg"
  9. :readonly="isReadonly" :disabled="isReadonly" @change="handleChange">
  10. <view class="cwg-upload">
  11. </view>
  12. </cwg-input>
  13. <view class="text name">{{ formData.firstName }} {{ formData.lastName }}</view>
  14. <view class="text cid">CID:{{ formData.cId }}</view>
  15. <view class="btn-primary" @click="handleEditProfile">
  16. <cwg-icon name="crm-photo-film" :size="16" color="#fff" />
  17. 上传头像
  18. </view>
  19. </view>
  20. </uni-col>
  21. <uni-col :xs="24" :sm="24" :md="24" :lg="18" :xl="18">
  22. <uni-forms ref="baseForm" :model="formData" labelWidth="200" label-position="top" :rules="rules"
  23. class="base-info-form">
  24. <uni-row class="demo-uni-row uni-row1">
  25. <!-- 客户类型 -->
  26. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  27. <uni-forms-item :label="t('ImproveImmediately.Label.CustomerType')">
  28. <cwg-combox :clearable="false" v-model:value="formData.customType"
  29. :options="customTypeOptions" :placeholder="t('placeholder.choose')" />
  30. </uni-forms-item>
  31. </uni-col>
  32. <!-- 公司名称 -->
  33. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8" v-if="formData.companyName">
  34. <uni-forms-item :label="t('ImproveImmediately.Label.CompanyName')">
  35. <uni-easyinput :clearable="false" v-model="formData.companyName"
  36. :placeholder="t('placeholder.input')" />
  37. </uni-forms-item>
  38. </uni-col>
  39. <!-- 姓 -->
  40. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  41. <uni-forms-item :label="formData.customType == 2
  42. ? t('ImproveImmediately.Label.CorporationLastName')
  43. : t('ImproveImmediately.Label.LastName')">
  44. <uni-easyinput :clearable="false" v-model="formData.lastName"
  45. :placeholder="t('placeholder.input')" />
  46. </uni-forms-item>
  47. </uni-col>
  48. <!-- 名 -->
  49. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  50. <uni-forms-item :label="formData.customType == 2
  51. ? t('ImproveImmediately.Label.CorporationName')
  52. : t('ImproveImmediately.Label.Name')">
  53. <uni-easyinput :clearable="false" v-model="formData.firstName"
  54. :placeholder="t('placeholder.input')" />
  55. </uni-forms-item>
  56. </uni-col>
  57. <!-- 法人中间名 -->
  58. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8" v-if="locale == 'en'">
  59. <uni-forms-item :label="formData.customType == 2
  60. ? t('ImproveImmediately.Label.CorporationMName')
  61. : t('placeholder.middle')">
  62. <uni-easyinput :clearable="false" v-model="formData.middle"
  63. :placeholder="t('placeholder.input')" />
  64. </uni-forms-item>
  65. </uni-col>
  66. <!-- 国家 -->
  67. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8" v-if="countryOptions.length">
  68. <uni-forms-item :label="t('ImproveImmediately.Label.Nationality')">
  69. <cwg-combox :clearable="false" :filterable="true"
  70. v-model:value="formData.nationality" :options="countryOptions"
  71. :placeholder="t('placeholder.choose')" @change="changeCountry" />
  72. </uni-forms-item>
  73. </uni-col>
  74. <!-- 证件类型 -->
  75. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  76. <uni-forms-item :label="t('ImproveImmediately.Label.CardType')">
  77. <cwg-combox :clearable="false" v-model:value="formData.customType"
  78. :options="idTypeOptions" :placeholder="t('placeholder.choose')" />
  79. </uni-forms-item>
  80. </uni-col>
  81. <!-- 证件号 -->
  82. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  83. <uni-forms-item :label="t('ImproveImmediately.Label.IdentityID')">
  84. <uni-easyinput :clearable="false" v-model="formData.identity"
  85. :placeholder="t('placeholder.input')" />
  86. </uni-forms-item>
  87. </uni-col>
  88. <!-- 拼音 -->
  89. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8" v-if="isZh">
  90. <uni-forms-item :label="t('ImproveImmediately.Label.NamePinYin')">
  91. <uni-easyinput :clearable="false" v-model="formData.nameEn"
  92. :placeholder="t('placeholder.input')" />
  93. </uni-forms-item>
  94. </uni-col>
  95. <!-- 性别 -->
  96. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  97. <uni-forms-item :label="t('ImproveImmediately.Label.Gender')">
  98. <cwg-combox :clearable="false" v-model:value="formData.gender" :options="sexOptions"
  99. :placeholder="t('placeholder.choose')" />
  100. </uni-forms-item>
  101. </uni-col>
  102. <!-- 生日 -->
  103. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  104. <uni-forms-item :label="t('ImproveImmediately.Label.Birthday')">
  105. <uni-datetime-picker :clear-icon="false" type="datetime" return-type="timestamp"
  106. v-model="formData.birth" :placeholder="t('placeholder.choose')" />
  107. </uni-forms-item>
  108. </uni-col>
  109. <!-- 国家/地区 -->
  110. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8" v-if="countryOptions.length">
  111. <uni-forms-item :label="t('ImproveImmediately.Label.CountryRegionOfResidence')">
  112. <cwg-combox :clearable="false" :filterable="true" v-model:value="formData.country"
  113. :options="countryOptions" :placeholder="t('placeholder.choose')" />
  114. </uni-forms-item>
  115. </uni-col>
  116. <!-- 省份/州 -->
  117. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8"
  118. v-if="stateOptions.length && isCountryCN">
  119. <uni-forms-item :label="t('ImproveImmediately.Label.ProvinceRegion')">
  120. <cwg-combox :clearable="false" :filterable="true" v-model:value="formData.state"
  121. :options="stateOptions" :placeholder="t('placeholder.choose')"
  122. @change="onStateChange" />
  123. </uni-forms-item>
  124. </uni-col>
  125. <!-- 国外省份/州 -->
  126. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8" v-if="!isCountryCN">
  127. <uni-forms-item :label="t('ImproveImmediately.Label.ProvinceRegion')">
  128. <uni-easyinput :clearable="false" v-model="formData.state"
  129. :placeholder="t('placeholder.input')" />
  130. </uni-forms-item>
  131. </uni-col>
  132. <!-- 城市 -->
  133. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8"
  134. v-if="cityOptions.length && isCountryCN">
  135. <uni-forms-item :label="t('ImproveImmediately.Label.City')">
  136. <cwg-combox :clearable="false" :filterable="true" v-model:value="formData.city"
  137. :options="cityOptions" :placeholder="t('placeholder.choose')" />
  138. </uni-forms-item>
  139. </uni-col>
  140. <!-- 国外城市 -->
  141. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8" v-if="!isCountryCN">
  142. <uni-forms-item :label="t('ImproveImmediately.Label.City')">
  143. <uni-easyinput :clearable="false" v-model="formData.city"
  144. :placeholder="t('placeholder.input')" />
  145. </uni-forms-item>
  146. </uni-col>
  147. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  148. <uni-forms-item :label="t('ImproveImmediately.Label.DetailedAddress')">
  149. <uni-easyinput :clearable="false" v-model="formData.addressLines1"
  150. :placeholder="t('placeholder.input')" />
  151. </uni-forms-item>
  152. </uni-col>
  153. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  154. <uni-forms-item :label="t('ImproveImmediately.Label.ZipCode')">
  155. <uni-easyinput :clearable="false" v-model="formData.zipCode"
  156. :placeholder="t('placeholder.input')" />
  157. </uni-forms-item>
  158. </uni-col>
  159. <uni-col :xs="24" :sm="24" :md="12" :lg="8" :xl="8">
  160. <uni-forms-item :label="t('ImproveImmediately.Label.DetailedAddressStandby')">
  161. <uni-easyinput :clearable="false" v-model="formData.addressLines2"
  162. :placeholder="t('placeholder.input')" />
  163. </uni-forms-item>
  164. </uni-col>
  165. </uni-row>
  166. </uni-forms>
  167. </uni-col>
  168. </uni-row>
  169. </view>
  170. <view class="btns">
  171. <view class="btn-primary" @click="handleCancel">{{ t('Btn.Cancel') }}</view>
  172. <view class="btn-primary" @click="handleNext">{{ t('Btn.Next') }}</view>
  173. </view>
  174. </view>
  175. </template>
  176. <script setup lang="ts">
  177. import { ref, computed, onMounted } from 'vue';
  178. import { useI18n } from 'vue-i18n';
  179. import { personalApi } from '@/service/personal';
  180. import { Patterns, Validators } from '@/utils/validators';
  181. const { t, locale } = useI18n();
  182. interface PersonalInfo {
  183. merchantOrderNo?: string;
  184. cardTypeId?: string;
  185. areaCode?: string;
  186. mobile?: string;
  187. email?: string;
  188. firstName?: string;
  189. lastName?: string;
  190. middle?: string;
  191. birthday?: string;
  192. nationality?: string;
  193. country?: string;
  194. state?: string;
  195. city?: string;
  196. town?: string;
  197. address?: string;
  198. postCode?: string;
  199. gender?: number;
  200. occupation?: string;
  201. annualSalary?: string;
  202. accountPurpose?: string;
  203. expectedMonthlyVolume?: string;
  204. idType?: number;
  205. idNumber?: string;
  206. identity?: string;
  207. ssn?: string;
  208. issueDate?: string;
  209. idNoExpiryDate?: string;
  210. idFrontUrl?: string;
  211. idBackUrl?: string;
  212. idHoldUrl?: string;
  213. ipAddress?: string;
  214. cId?: string;
  215. customId?: string;
  216. customType?: number;
  217. companyName?: string;
  218. nameEn?: string;
  219. birth?: string;
  220. addressLines1?: string;
  221. addressLines2?: string;
  222. zipCode?: string;
  223. photoStatus?: string;
  224. kycStatus?: string;
  225. }
  226. const props = defineProps<{
  227. modelValue: PersonalInfo;
  228. isReadonly?: boolean;
  229. }>();
  230. const emit = defineEmits<{
  231. 'update:modelValue': [value: PersonalInfo];
  232. 'cancel': [];
  233. 'next': [];
  234. }>();
  235. const formData = computed({
  236. get: () => props.modelValue,
  237. set: (val) => emit('update:modelValue', val)
  238. });
  239. const baseForm = ref<any>(null);
  240. const sexOptions = ref([
  241. { text: t('PersonalManagement.Label.Men'), value: 1 },
  242. { text: t('PersonalManagement.Label.Women'), value: 2 }
  243. ]);
  244. const customTypeOptions = ref([
  245. { text: t('ImproveImmediately.Label.CustomerType1'), value: 1 },
  246. { text: t('ImproveImmediately.Label.CustomerType2'), value: 2 }
  247. ]);
  248. const idTypeOptions = ref([
  249. { text: t('ImproveImmediately.Label.IDCard'), value: 2 },
  250. { text: t('ImproveImmediately.Label.Passport'), value: 3 }
  251. ]);
  252. // 验证函数
  253. function validateName(a: any, b?: any, c?: any) {
  254. const reg = /^[A-Z\s]+$/i;
  255. if (typeof c === 'function') {
  256. const value = b;
  257. const callback = c;
  258. const val = String(value ?? '').trim();
  259. if (!val) return callback(new Error(t('card.vaildate.v4')));
  260. if (!reg.test(val)) return callback(new Error(t('card.vaildate.v38')));
  261. if (val.length < 2 || val.length > 23) return callback(new Error(t('card.vaildate.v39')));
  262. const firstName = String(formData.value?.firstName ?? '').trim();
  263. const lastName = String(formData.value?.lastName ?? '').trim();
  264. if (`${firstName} ${lastName}`.length > 23) return callback(new Error(t('card.vaildate.v40')));
  265. return callback();
  266. }
  267. const val = String(a ?? '').trim();
  268. if (!val) return t('card.vaildate.v4');
  269. if (!reg.test(val)) return t('card.vaildate.v38');
  270. if (val.length < 2 || val.length > 23) return t('card.vaildate.v39');
  271. const firstName = String(formData.value?.firstName ?? '').trim();
  272. const lastName = String(formData.value?.lastName ?? '').trim();
  273. if (`${firstName} ${lastName}`.length > 23) return t('card.vaildate.v40');
  274. return true;
  275. }
  276. function validateBirthday(a: any, b?: any, c?: any) {
  277. if (typeof c === 'function') {
  278. const value = b;
  279. const callback = c;
  280. const val = value;
  281. if (!val) return callback(new Error(t('card.vaildate.v5')));
  282. const today = new Date();
  283. const birthDate = new Date(val);
  284. let age = today.getFullYear() - birthDate.getFullYear();
  285. const month = today.getMonth() - birthDate.getMonth();
  286. if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) age--;
  287. if (age < 18) return callback(new Error(t('card.New.n3')));
  288. return callback();
  289. }
  290. const val = a;
  291. if (!val) return t('card.vaildate.v5');
  292. const today = new Date();
  293. const birthDate = new Date(val);
  294. let age = today.getFullYear() - birthDate.getFullYear();
  295. const month = today.getMonth() - birthDate.getMonth();
  296. if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) age--;
  297. return age < 18 ? t('card.New.n3') : true;
  298. }
  299. function validateAddress(a: any, b?: any, c?: any) {
  300. if (typeof c === 'function') {
  301. const value = b;
  302. const callback = c;
  303. const val = String(value ?? '').trim();
  304. if (!val) return callback(new Error(t('card.vaildate.v27')));
  305. if (val.length < 2 || val.length > 40) return callback(new Error(t('card.New.n1')));
  306. if (!Patterns.address.test(val)) return callback(new Error(t('card.New.n1')));
  307. return callback();
  308. }
  309. const val = String(a ?? '').trim();
  310. if (!val) return t('card.vaildate.v27');
  311. if (val.length < 2 || val.length > 40) return t('card.New.n1');
  312. return Patterns.address.test(val) ? true : t('card.New.n1');
  313. }
  314. const rules = {
  315. areaCode: [Validators.required(t('card.vaildate.v1'))],
  316. mobile: [
  317. Validators.required(t('card.vaildate.v2')),
  318. Validators.pattern(Patterns.mobile, t('card.vaildate.v44'))
  319. ],
  320. email: [
  321. Validators.required(t('card.vaildate.v28')),
  322. Validators.pattern(Patterns.email, t('card.vaildate.v28'))
  323. ],
  324. firstName: [Validators.required(t('card.vaildate.v3')), Validators.custom(validateName)],
  325. lastName: [Validators.required(t('card.vaildate.v4')), Validators.custom(validateName)],
  326. birthday: [
  327. Validators.required(t('card.vaildate.v5'), 'change'),
  328. Validators.custom(validateBirthday, 'change')
  329. ],
  330. nationality: [Validators.required(t('card.vaildate.v6'), 'change')],
  331. town: [Validators.required(t('card.vaildate.v7'), 'change')],
  332. address: [Validators.required(t('card.vaildate.v27')), Validators.custom(validateAddress)],
  333. gender: [Validators.required(t('card.vaildate.v9'), 'change')],
  334. postCode: [
  335. Validators.required(t('card.vaildate.v8')),
  336. Validators.pattern(Patterns.postcode, t('card.New.n2'))
  337. ]
  338. };
  339. // 国家省份城市数据
  340. const countryList = ref<Array<any>>([]);
  341. const stateList = ref<Array<any>>([]);
  342. const cityList = ref<Array<any>>([]);
  343. const phoneCodes = ref<Array<{ text: string; value: string }>>([]);
  344. const isZh = computed(() => ['cn', 'zh', 'zhHant'].includes(locale.value));
  345. const isCountryCN = computed(() => ['CN', 'CNX', 'CNA', 'CNT'].includes(formData.value.country || ''));
  346. const getLangName = (item: any) => (isZh.value ? item.name : item.enName);
  347. const createOptions = (list: any[], valueKey = 'code') => {
  348. return list.map((item) => ({
  349. text: getLangName(item),
  350. value: valueKey === 'name' ? getLangName(item) : item[valueKey],
  351. id: item.id
  352. }));
  353. };
  354. const countryOptions = computed(() => createOptions(countryList.value, 'code'));
  355. const stateOptions = computed(() => createOptions(stateList.value, 'name'));
  356. const cityOptions = computed(() => createOptions(cityList.value, 'name'));
  357. const getCountry = async () => {
  358. const res = await personalApi.Country({});
  359. if (res.code === 200) {
  360. countryList.value = res.data;
  361. phoneCodes.value = res.data.map((item: any) => ({
  362. text: `+ ${item.callingCode}`,
  363. value: item.callingCode
  364. }));
  365. if (formData.value.country) {
  366. const country = countryList.value.find((i) => i.code === formData.value.country);
  367. if (country) {
  368. await getState(country.id);
  369. }
  370. }
  371. }
  372. };
  373. const fetchRegion = async (pid?: number) => {
  374. const res = await personalApi.Country({ pid });
  375. if (res.code !== 200) {
  376. return [];
  377. }
  378. return res.data || [];
  379. };
  380. const getState = async (pid: number) => {
  381. stateList.value = await fetchRegion(pid);
  382. if (formData.value.state) {
  383. const item = stateList.value.find(
  384. (i) => i.enName === formData.value.state || i.name === formData.value.state
  385. );
  386. if (item) {
  387. await getCity(item.id);
  388. }
  389. }
  390. };
  391. const getCity = async (pid: number) => {
  392. cityList.value = await fetchRegion(pid);
  393. };
  394. const changeCountry = async (val: any) => {
  395. formData.value.state = '';
  396. formData.value.city = '';
  397. const item = countryOptions.value.find((i: any) => i.value === val);
  398. if (item) {
  399. await getState(item.id);
  400. }
  401. };
  402. const onStateChange = async (val: any) => {
  403. formData.value.city = '';
  404. const item = stateOptions.value.find((i: any) => i.value === val);
  405. if (item) {
  406. await getCity(item.id);
  407. }
  408. };
  409. function handleChange(value: any) {
  410. emit('update:modelValue', { ...formData.value, [value.key]: value.value });
  411. }
  412. const handleEditProfile = () => {
  413. // 头像上传逻辑
  414. };
  415. const handleCancel = () => {
  416. emit('cancel');
  417. };
  418. const handleNext = () => {
  419. emit('next');
  420. };
  421. onMounted(() => {
  422. getCountry();
  423. });
  424. </script>
  425. <style scoped lang="scss">
  426. @import "@/uni.scss";
  427. .personal-info-tab {
  428. .user-form {
  429. margin-top: px2rpx(30);
  430. .demo-uni-row {
  431. margin-bottom: px2rpx(16);
  432. :deep(.form-label) {
  433. margin: 0 !important;
  434. }
  435. :deep(.form-input) {
  436. border: none !important;
  437. }
  438. .avatar-section {
  439. display: flex;
  440. flex-direction: column;
  441. align-items: center;
  442. gap: px2rpx(12);
  443. padding: px2rpx(16);
  444. .cwg-upload {
  445. width: px2rpx(120);
  446. height: px2rpx(120);
  447. border-radius: 50%;
  448. margin: 0 auto;
  449. }
  450. .text {
  451. font-size: px2rpx(20);
  452. font-weight: 700;
  453. color: var(--color-navy-900);
  454. }
  455. .btn-primary {
  456. min-width: px2rpx(120);
  457. background-color: var(--color-navy-900);
  458. color: white;
  459. padding: px2rpx(12);
  460. border: none;
  461. font-size: px2rpx(14);
  462. text-align: center;
  463. cursor: pointer;
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. gap: px2rpx(8);
  468. &:active {
  469. background-color: var(--color-navy-700);
  470. }
  471. }
  472. .cid {
  473. color: var(--color-error);
  474. font-size: px2rpx(12);
  475. margin-top: px2rpx(4);
  476. }
  477. }
  478. }
  479. }
  480. .btns {
  481. display: flex;
  482. justify-content: flex-end;
  483. gap: 30px;
  484. margin-top: 30px;
  485. .btn-primary {
  486. min-width: px2rpx(120);
  487. background-color: var(--color-navy-900);
  488. color: white;
  489. padding: 12px;
  490. border-radius: 8px;
  491. border: none;
  492. font-size: 14px;
  493. text-align: center;
  494. cursor: pointer;
  495. display: flex;
  496. align-items: center;
  497. justify-content: center;
  498. gap: 8px;
  499. &:active {
  500. background-color: var(--color-navy-700);
  501. }
  502. }
  503. }
  504. }
  505. :deep(.uni-row1) {
  506. .uni-col {
  507. padding: 0 10px !important;
  508. }
  509. .base-info-form>span {
  510. display: contents;
  511. }
  512. .uni-forms-item {
  513. min-height: px2rpx(79);
  514. margin-bottom: px2rpx(10);
  515. }
  516. .uni-select,
  517. .uni-combox,
  518. .uni-easyinput__content,
  519. .uni-date-editor--x {
  520. border: none !important;
  521. background-color: var(--color-zinc-100) !important;
  522. }
  523. .uni-date-x {
  524. border: none !important;
  525. background-color: rgba(195, 195, 195, 0) !important;
  526. }
  527. }
  528. </style>