claim.ts 4.3 KB

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