volunteer.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import CommonContent from "@/api/CommonContent";
  2. import VillageApi from "@/api/inhert/VillageApi";
  3. import { useAliOssUploadCo } from "@/common/components/upload/AliOssUploadCo";
  4. import type { IDynamicFormItemCallbackAdditionalProps, IDynamicFormOptions, IDynamicFormRef } from "@/components/dynamic";
  5. import type { CheckBoxTreeListProps } from "@/components/dynamic/wrappers/CheckBoxTreeList.vue";
  6. import type { PickerIdFieldProps } from "@/components/dynamic/wrappers/PickerIdField";
  7. import type { RadioValueProps } from "@/components/dynamic/wrappers/RadioValue";
  8. import type { FieldProps } from "@/components/form/Field.vue";
  9. import type { FormProps } from "@/components/form/Form.vue";
  10. import type { UploaderFieldProps } from "@/components/form/UploaderField.vue";
  11. import type { RuleItem } from "async-validator";
  12. import type { Ref } from "vue";
  13. export function getVolunteerForm(options: {
  14. canSetCatalog: boolean,
  15. villageId: number,
  16. onlyPassword?: boolean,
  17. noPassword?: boolean,
  18. isNew: Ref<boolean>,
  19. formRef: Ref<IDynamicFormRef|undefined>,
  20. }) : IDynamicFormOptions {
  21. return {
  22. formItems: [
  23. {
  24. name: 'groupBase',
  25. type: 'flat-simple',
  26. show: { callback: () => !options.noPassword },
  27. children: [
  28. {
  29. label: '登录账号', name: 'username', type: 'text',
  30. additionalProps: {
  31. placeholder: '请输入登录账号',
  32. },
  33. rules: [{ required: true, message: '请输入登录账号' }],
  34. show: { callback: () => options.isNew.value },
  35. },
  36. {
  37. label: '密码',
  38. name: 'password',
  39. type: 'text',
  40. additionalProps: {
  41. placeholder: '请输入密码',
  42. type: 'password',
  43. } as FieldProps,
  44. rules: [{ required: true, message: '请输入密码' }],
  45. show: { callback: () => options.isNew.value || options.onlyPassword === true },
  46. },
  47. {
  48. label: '确认密码',
  49. name: 'passwordRepeat',
  50. type: 'text',
  51. additionalProps: {
  52. placeholder: '请再输入一次密码',
  53. type: 'password',
  54. } as FieldProps,
  55. rules: [
  56. { required: true, message: '请再输入一次密码' },
  57. {
  58. async validator(rule, value) {
  59. if (value != options.formRef.value?.getValueByPath('password'))
  60. throw '两次输入密码不一致,请检查';
  61. },
  62. }
  63. ] as RuleItem[],
  64. show: { callback: () => options.isNew.value || options.onlyPassword === true },
  65. },
  66. ]
  67. },
  68. {
  69. name: 'groupExtra',
  70. type: 'flat-simple',
  71. show: { callback: () => options.onlyPassword !== true },
  72. childrenColProps: {
  73. span: 24,
  74. },
  75. children: [
  76. {
  77. label: '真实名称', name: 'name', type: 'text',
  78. additionalProps: { placeholder: '请输入真实名称' },
  79. rules: [{ required: true, message: '请输入真实名称' }],
  80. },
  81. {
  82. label: '手机号', name: 'mobile', type: 'text',
  83. additionalProps: { placeholder: '请输入手机号' },
  84. rules: [{ required: true, message: '请输入手机号' }],
  85. },
  86. {
  87. label: '区域', name: 'regionId', type: 'select-id',
  88. additionalProps: {
  89. placeholder: '请选择区域',
  90. disabled: { callback: () => !options.isNew.value },
  91. loadData: async () => (await CommonContent.getCategoryList(1)).map(p => ({ text: p.title, value: p.id, raw: p }))
  92. } as IDynamicFormItemCallbackAdditionalProps<PickerIdFieldProps>,
  93. rules: [{ required: true, message: '请选择区域' }],
  94. },
  95. {
  96. label: '性别', name: 'sex', type: 'radio-value',
  97. additionalProps: {
  98. options: [
  99. { text: '男', value: 1 },
  100. { text: '女', value: 2 }
  101. ]
  102. } as RadioValueProps,
  103. },
  104. {
  105. label: '头像', name: 'image', type: 'uploader',
  106. additionalProps: {
  107. single: true,
  108. maxFileSize: 1024 * 1024 * 10,
  109. upload: useAliOssUploadCo('xiangyuan/volunteer/images')
  110. } as UploaderFieldProps,
  111. },
  112. {
  113. label: '类型', name: 'type', type: 'radio-value',
  114. additionalProps: {
  115. options: [
  116. { text: '志愿者', value: 'volunteer' },
  117. { text: '社区工作者', value: 'staff' }
  118. ]
  119. } as RadioValueProps,
  120. rules: [{ required: true, message: '请选择类型' }],
  121. },
  122. {
  123. label: '工作单位', name: 'unit', type: 'text', additionalProps: { placeholder: '请输入手机号' } ,
  124. rules: [{ required: true, message: '请输入手机号' }],
  125. show: { callback: () => options.formRef.value?.getValueByPath('type') === 'staff' },
  126. },
  127. {
  128. label: '职位', name: 'job', type: 'text', additionalProps: { placeholder: '请输入手机号' } ,
  129. rules: [{ required: true, message: '请输入手机号' }],
  130. show: { callback: () => options.formRef.value?.getValueByPath('type') === 'staff' },
  131. },
  132. {
  133. label: '手机号', name: 'mobile', type: 'text', additionalProps: { placeholder: '请输入手机号' } ,
  134. rules: [{ required: true, message: '请输入手机号' }],
  135. },
  136. { label: '现居地址', name: 'address', type: 'text', additionalProps: { placeholder: '请输入现居地址' } },
  137. {
  138. label: '个人介绍',
  139. name: 'intro',
  140. type: 'textarea',
  141. additionalProps: {
  142. placeholder: '请输入个人介绍',
  143. showWordLimit: true,
  144. maxLength: 500,
  145. } as FieldProps,
  146. },
  147. ...(options.canSetCatalog ? [{
  148. label: '采集版块', name: 'catalogIds', type: 'check-box-tree',
  149. additionalProps: {
  150. placeholder: '请选择采集版块',
  151. vertical: true,
  152. multiple: true,
  153. loadData: async (pid) => (await VillageApi.getCatalogList(options.villageId, undefined, pid)).map((p) => ({
  154. text: p.title,
  155. value: p.id,
  156. hasChildren: p.haschild,
  157. })),
  158. } as CheckBoxTreeListProps,
  159. }]: []),
  160. {
  161. label: '村社认领说明', name: 'claimReason', type: 'text',
  162. additionalProps: { placeholder: '请输入村社认领说明' } ,
  163. show: { callback: () => options.isNew.value },
  164. },
  165. ]
  166. },
  167. ],
  168. formAdditionaProps: {
  169. labelWidth: '160rpx',
  170. labelAlign: 'right',
  171. innerStyle: {
  172. radius: '10rpx',
  173. },
  174. } as Omit<FormProps, 'model'>,
  175. }
  176. }