setup.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { getCardTypeEnumList } from '@/common/constants/enumsList';
  2. import { validateCommon } from '@/common/setup/validate';
  3. import { QueryAddUserInfoApply } from '@/services/go/ermcp/customInfo';
  4. import { AddUserInfoApplyReq } from '@/services/go/ermcp/customInfo/interface';
  5. import { message } from 'ant-design-vue';
  6. import { RuleObject } from 'ant-design-vue/lib/form/interface';
  7. import { reactive, ref, UnwrapRef } from 'vue';
  8. import { FormState } from './interface';
  9. /**
  10. * 获取证件类型
  11. * @returns
  12. */
  13. export function getCardType() {
  14. const arr = [2, 4, 18, 21];
  15. return getCardTypeEnumList().filter(e => arr.includes(e.enumitemname))
  16. }
  17. export function handleForm() {
  18. const formRef = ref();
  19. const formState: UnwrapRef<FormState> = reactive(initFormState());
  20. // 验证仓库类型
  21. async function v_cardtype(rule: RuleObject, value: number) {
  22. return validateCommon(value, '请选择证件类型')
  23. }
  24. const rules = {
  25. userinfotype: [{ required: true, message: '请选择客户类型', trigger: 'change' }],
  26. customername: [{ required: true, message: '请输入企业名称', trigger: 'blur' }],
  27. nickname: [{ required: true, message: '请输入企业简称', trigger: 'blur' }],
  28. cardtype: [{ required: true, validator: v_cardtype, trigger: 'change' }],
  29. };
  30. return { formRef, formState, rules }
  31. }
  32. /**
  33. * 初始化表单数据
  34. * @returns
  35. */
  36. export function initFormState(): FormState {
  37. return {
  38. userinfotype: '2',
  39. customername: '',
  40. nickname: '',
  41. cardtype: undefined,
  42. cardnum: '',
  43. legalpersonname: '',
  44. taxpayernum: '',
  45. attachment1: '',
  46. attachment2: '',
  47. attachment3: '',
  48. attachment4: '',
  49. attachment5: '',
  50. contactname: '',
  51. mobilephone: '',
  52. telphone: '',
  53. provinceid: undefined,
  54. cityid: undefined,
  55. districtid: undefined,
  56. cardaddress: '',
  57. remark: '',
  58. username: '',
  59. cardbackphotourl: '',
  60. cardfrontphotourl: '',
  61. email: '',
  62. }
  63. }
  64. export function handleApply() {
  65. const loading = ref<boolean>(false);
  66. function applyAction(param: AddUserInfoApplyReq) {
  67. loading.value = true;
  68. QueryAddUserInfoApply(param).then(res => {
  69. console.log('res', res);
  70. }).catch(err => {
  71. message.error(err)
  72. }).finally(() => loading.value = false)
  73. }
  74. return { loading, applyAction }
  75. }