claim.ts 4.7 KB

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