claim.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
  2. import type { CheckBoxListProps } from '@/components/dynamic/wrappers/CheckBoxList.vue';
  3. import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
  4. import type { FieldProps } from '@/components/form/Field.vue';
  5. import type { FormProps } from '@/components/form/Form.vue';
  6. import type { RuleItem } from 'async-validator';
  7. import type { Ref } from 'vue';
  8. import type { VolunteerInfo } from '@/api/inhert/VillageApi';
  9. import { VillageClaimInfo } from '@/api/inhert/VillageApi';
  10. import { waitTimeOut } from '@imengyu/imengyu-utils';
  11. function hasClaimType(formRef: Ref<IDynamicFormRef | undefined>, value: string) {
  12. const type = formRef.value?.getValueByPath('type');
  13. if (Array.isArray(type))
  14. return type.includes(value);
  15. return type === value;
  16. }
  17. export function fillClaimFromVolunteer(model: VillageClaimInfo, volunteer: VolunteerInfo) {
  18. model.name = volunteer.name || '';
  19. model.mobile = volunteer.mobile || '';
  20. model.address = volunteer.address || '';
  21. model.sex = volunteer.sex || 3;
  22. model.job = (volunteer as VolunteerInfo & { job?: string }).job || '';
  23. model.unit = (volunteer as VolunteerInfo & { unit?: string }).unit || '';
  24. model.claimReason = (volunteer as VolunteerInfo & { claimReason?: string }).claimReason || '';
  25. if (volunteer.type) {
  26. model.type = volunteer.type.includes(',')
  27. ? volunteer.type.split(',').map((s) => s.trim()).filter(Boolean)
  28. : [volunteer.type];
  29. }
  30. }
  31. export function getClaimVillageForm(options: {
  32. formRef: Ref<IDynamicFormRef | undefined>,
  33. }): IDynamicFormOptions {
  34. return {
  35. formItems: [
  36. {
  37. name: 'groupClaim',
  38. type: 'flat-simple',
  39. childrenColProps: { span: 24 },
  40. children: [
  41. {
  42. label: '真实姓名',
  43. name: 'name',
  44. type: 'text',
  45. additionalProps: { placeholder: '请输入真实姓名' },
  46. rules: [{ required: true, message: '请输入真实姓名' }],
  47. },
  48. {
  49. label: '认领类型',
  50. name: 'type',
  51. type: 'radio-value',
  52. defaultValue: ['villager'],
  53. additionalProps: {
  54. options: [
  55. { text: '村民', value: 'villager' },
  56. { text: '志愿者', value: 'volunteer' },
  57. { text: '管理人员', value: 'staff' },
  58. ]
  59. } as RadioValueProps,
  60. rules: [{ required: true, message: '请选择认领类型' }],
  61. },
  62. {
  63. label: '性别',
  64. name: 'sex',
  65. type: 'radio-value',
  66. defaultValue: 3,
  67. additionalProps: {
  68. options: [
  69. { text: '男', value: 1 },
  70. { text: '女', value: 2 },
  71. { text: '未知', value: 3 },
  72. ],
  73. } as RadioValueProps,
  74. },
  75. {
  76. label: '联系方式',
  77. name: 'mobile',
  78. type: 'text',
  79. additionalProps: { placeholder: '请输入手机号' },
  80. rules: [{ required: true, message: '请输入联系方式' }],
  81. },
  82. {
  83. label: '居住地址',
  84. name: 'address',
  85. type: 'text',
  86. additionalProps: { placeholder: '请输入居住地址' },
  87. },
  88. {
  89. label: '工作单位',
  90. name: 'unit',
  91. type: 'text',
  92. additionalProps: { placeholder: '请输入工作单位' },
  93. show: { callback: () => hasClaimType(options.formRef, 'staff') },
  94. rules: [{
  95. required: true,
  96. message: '请输入工作单位',
  97. }] as RuleItem[],
  98. },
  99. {
  100. label: '职位',
  101. name: 'job',
  102. type: 'text',
  103. additionalProps: { placeholder: '请输入职位' },
  104. show: { callback: () => hasClaimType(options.formRef, 'staff') },
  105. rules: [{
  106. required: true,
  107. message: '请输入职位',
  108. }] as RuleItem[],
  109. },
  110. {
  111. label: '申请理由',
  112. name: 'claimReason',
  113. type: 'textarea',
  114. additionalProps: {
  115. placeholder: '请说明认领该村落的原因',
  116. showWordLimit: true,
  117. maxLength: 5000,
  118. } as FieldProps,
  119. },
  120. ],
  121. },
  122. ],
  123. formAdditionaProps: {
  124. labelPosition: 'top',
  125. innerStyle: {
  126. radius: '10rpx',
  127. },
  128. } as Omit<FormProps, 'model'>,
  129. };
  130. }