JoinDialog.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <CommonDialog v-model:show="show" title="加入村社" :showDivider="false">
  3. <FlexCol gap="gap.lg" padding="padding.md" width="600rpx">
  4. <template v-if="step === 'chooseType'">
  5. <FlexCol gap="gap.md">
  6. <Text text="加入村社后,您即可为村社做贡献。请完善身份信息,解锁更多村社专属功能" fontConfig="contentSpeicalText" />
  7. <Height :height="10" />
  8. <BackgroundBox
  9. v-for="(item, k) in typeChoices"
  10. :key="k"
  11. backgroundImage="https://xy.wenlvti.net/app_static/images/village/BoxMid.png"
  12. :backgroundCutBorder="32"
  13. :backgroundCutBorderSize="36"
  14. :padding="24"
  15. direction="row"
  16. >
  17. <Touchable direction="row" gap="gap.md"center @click="handleChooseType(item.value)">
  18. <Image :src="item.image" :radius="20" width="100" height="100" mode="aspectFill" />
  19. <Width :width="20" />
  20. <Text text="我是" fontConfig="lightImportantTitle" />
  21. <Text :text="item.label" fontConfig="lightGoldTitle" />
  22. </Touchable>
  23. </BackgroundBox>
  24. </FlexCol>
  25. </template>
  26. <template v-else-if="step === 'chooseIdentity'">
  27. <FlexCol gap="gap.md">
  28. <Text textAlign="center" text="请选择你的村民身份" fontConfig="contentSpeicalText" />
  29. <Height :height="10" />
  30. <BackgroundBox
  31. v-for="(item, k) in identityChoices"
  32. :key="k"
  33. backgroundImage="https://xy.wenlvti.net/app_static/images/village/BoxMid.png"
  34. :backgroundCutBorder="32"
  35. :backgroundCutBorderSize="36"
  36. :padding="24"
  37. direction="row"
  38. >
  39. <Touchable direction="row" gap="gap.md"center @click="handleChooseIdentity(item.value)">
  40. <Image :src="item.image" :radius="20" width="100" height="100" mode="aspectFill" />
  41. <Width :width="20" />
  42. <Text :text="item.label" fontConfig="lightGoldTitle" />
  43. </Touchable>
  44. </BackgroundBox>
  45. </FlexCol>
  46. </template>
  47. <template v-else-if="step === 'form'">
  48. <Text textAlign="center" text="请完善身份信息,解锁更多村社专属功能" fontConfig="contentSpeicalText" />
  49. <Height :height="10" />
  50. <ProvideVar :vars="{
  51. FieldBackgroundColor: 'transparent',
  52. }">
  53. <BackgroundBox
  54. backgroundImage="https://xy.wenlvti.net/app_static/images/village/BoxMid.png"
  55. :backgroundCutBorder="32"
  56. :backgroundCutBorderSize="36"
  57. :padding="24"
  58. >
  59. <DynamicForm
  60. ref="addFormRef"
  61. :model="addFormModel"
  62. :options="addFormDefine"
  63. />
  64. </BackgroundBox>
  65. </ProvideVar>
  66. <Height :height="20" />
  67. <FlexRow justify="space-around" gap="gap.md">
  68. <FrameButton text="返回" @click="step = 'chooseType'" width="220rpx" />
  69. <FrameButton primary text="提交" @click="addSubmit" :loading="addFormLoading" width="220rpx" />
  70. </FlexRow>
  71. </template>
  72. <template v-else-if="step === 'finished'">
  73. <Result
  74. status="success"
  75. title="提交成功"
  76. description="等待管理员审核,通过后即可为村社做贡献,您可以先逛逛学习吧"
  77. />
  78. <FlexRow justify="space-around" gap="gap.md">
  79. <FrameButton primary text="完成" @click="show = false" width="220rpx" />
  80. </FlexRow>
  81. </template>
  82. </FlexCol>
  83. </CommonDialog>
  84. </template>
  85. <script setup lang="ts">
  86. import { ref } from 'vue';
  87. import { toast } from '@/components/dialog/CommonRoot';
  88. import { showError } from '@/common/composeabe/ErrorDisplay';
  89. import VillageApi, { VillageClaimInfo } from '@/api/inhert/VillageApi';
  90. import CommonDialog from '@/common/components/CommonDialog.vue';
  91. import FrameButton from '@/common/components/FrameButton.vue';
  92. import Image from '@/components/basic/Image.vue';
  93. import Text from '@/components/basic/Text.vue';
  94. import DynamicForm from '@/components/dynamic/DynamicForm.vue';
  95. import FlexCol from '@/components/layout/FlexCol.vue';
  96. import FlexRow from '@/components/layout/FlexRow.vue';
  97. import Height from '@/components/layout/space/Height.vue';
  98. import BackgroundBox from '@/components/display/block/BackgroundBox.vue';
  99. import Touchable from '@/components/feedback/Touchable.vue';
  100. import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
  101. import type { RuleItem } from 'async-validator';
  102. import type { FieldProps } from '@/components/form/Field.vue';
  103. import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
  104. import Result from '@/components/feedback/Result.vue';
  105. import Width from '@/components/layout/space/Width.vue';
  106. import ProvideVar from '@/components/theme/ProvideVar.vue';
  107. const show = ref(false);
  108. const props = defineProps<{
  109. villageId: number;
  110. }>();
  111. const emit = defineEmits(['apply']);
  112. const step = ref('chooseType');
  113. const typeChoices = ref([
  114. {
  115. label: '志愿者',
  116. value: 'volunteer',
  117. image: 'https://xy.wenlvti.net/app_static/images/home/volunteer/IconTypeExternal.png',
  118. },
  119. {
  120. label: '管理人员',
  121. value: 'staff',
  122. image: 'https://xy.wenlvti.net/app_static/images/home/volunteer/IconTypeLocal.png',
  123. },
  124. {
  125. label: '村民',
  126. value: 'villager',
  127. image: 'https://xy.wenlvti.net/app_static/images/home/volunteer/IconTypeWork.png',
  128. },
  129. ]);
  130. function handleChooseType(type: string) {
  131. step.value = 'chooseIdentity';
  132. addFormModel.value.type = type;
  133. }
  134. const identityChoices = ref([
  135. {
  136. label: '在村劳作',
  137. value: 1,
  138. image: 'https://xy.wenlvti.net/app_static/images/home/volunteer/IconTypeWork.png',
  139. },
  140. {
  141. label: '社区居民',
  142. value: 2,
  143. image: 'https://xy.wenlvti.net/app_static/images/home/volunteer/IconTypeLocal.png',
  144. },
  145. {
  146. label: '在外游子',
  147. value: 3,
  148. image: 'https://xy.wenlvti.net/app_static/images/home/volunteer/IconTypeOut.png',
  149. },
  150. {
  151. label: '退休人员',
  152. value: 4,
  153. image: 'https://xy.wenlvti.net/app_static/images/home/volunteer/IconTypeOld.png',
  154. },
  155. ]);
  156. function handleChooseIdentity(identity: number) {
  157. step.value = 'form';
  158. addFormModel.value.identity = identity;
  159. }
  160. const addFormLoading = ref(false);
  161. const addFormRef = ref<IDynamicFormRef>();
  162. const addFormModel = ref<VillageClaimInfo>(new VillageClaimInfo());
  163. const addFormDefine : IDynamicFormOptions = {
  164. formAdditionaProps: {},
  165. formItems: [
  166. {
  167. label: '真实姓名',
  168. name: 'name',
  169. type: 'text',
  170. additionalProps: { placeholder: '请输入真实姓名' },
  171. rules: [{ required: true, message: '请输入真实姓名' }],
  172. },
  173. {
  174. label: '联系方式',
  175. name: 'mobile',
  176. type: 'text',
  177. additionalProps: { placeholder: '请输入手机号' },
  178. rules: [{ required: true, message: '请输入联系方式' }],
  179. },
  180. {
  181. label: '性别',
  182. name: 'sex',
  183. type: 'radio-value',
  184. defaultValue: 3,
  185. additionalProps: {
  186. options: [
  187. { text: '男', value: 1 },
  188. { text: '女', value: 2 },
  189. { text: '未知', value: 3 },
  190. ],
  191. } as RadioValueProps,
  192. },
  193. {
  194. label: '居住地址',
  195. name: 'address',
  196. type: 'text',
  197. additionalProps: { placeholder: '请输入居住地址(选填)' },
  198. },
  199. {
  200. label: '工作单位',
  201. name: 'unit',
  202. type: 'text',
  203. additionalProps: { placeholder: '请输入工作单位(选填)' },
  204. show: { callback: () => addFormModel.value.type === 'staff' },
  205. rules: [{
  206. required: true,
  207. message: '请输入工作单位',
  208. }] as RuleItem[],
  209. },
  210. {
  211. label: '职位',
  212. name: 'job',
  213. type: 'text',
  214. additionalProps: { placeholder: '请输入职位' },
  215. show: { callback: () => addFormModel.value.type === 'staff' },
  216. rules: [{
  217. required: true,
  218. message: '请输入职位',
  219. }] as RuleItem[],
  220. },
  221. {
  222. label: '申请理由',
  223. name: 'claimReason',
  224. type: 'textarea',
  225. additionalProps: {
  226. placeholder: '请说明认领该村社的原因(选填),可以加快管理员审核速度',
  227. showWordLimit: true,
  228. maxLength: 200,
  229. } as FieldProps,
  230. },
  231. ]
  232. }
  233. async function addSubmit() {
  234. if (!addFormRef.value || !addFormModel.value)
  235. return;
  236. try {
  237. await addFormRef.value.validate();
  238. } catch (e) {
  239. toast({ content: '有必填项未填写,请检查' });
  240. return;
  241. }
  242. try {
  243. addFormLoading.value = true;
  244. addFormModel.value.villageId = props.villageId;
  245. await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo);
  246. toast({ content: '提交成功' });
  247. show.value = false;
  248. } catch (e) {
  249. showError(e);
  250. } finally {
  251. addFormLoading.value = false;
  252. }
  253. }
  254. defineExpose({
  255. show: () => {
  256. show.value = true;
  257. step.value = 'chooseType';
  258. addFormModel.value = new VillageClaimInfo();
  259. addFormModel.value.type = 'villager';
  260. addFormModel.value.villageId = props.villageId;
  261. },
  262. });
  263. </script>