ClamVolunteerDialog.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <CommonDialog v-model:show="show" title="成为志愿者" :showDivider="false" :showCloseButton="false">
  3. <FlexCol gap="gap.lg" padding="padding.md" width="600rpx">
  4. <template v-if="step === 'form'">
  5. <Text textAlign="center" text="请完善身份信息,解锁更多村社专属功能" fontConfig="contentSpeicalText" />
  6. <Height :height="10" />
  7. <ProvideVar :vars="{
  8. FieldBackgroundColor: 'transparent',
  9. }">
  10. <BoxMid>
  11. <DynamicForm
  12. ref="addFormRef"
  13. :model="addFormModel"
  14. :options="addFormDefine"
  15. />
  16. </BoxMid>
  17. </ProvideVar>
  18. <Height :height="20" />
  19. <FlexRow justify="space-around" gap="gap.md">
  20. <FrameButton text="返回" @click="show = false" width="220rpx" />
  21. <FrameButton primary text="提交" @click="addSubmit" :loading="addFormLoading" width="220rpx" />
  22. </FlexRow>
  23. </template>
  24. <template v-else-if="step === 'finished'">
  25. <Result
  26. status="success"
  27. title="提交成功"
  28. description="等待系统审核,您可稍后再回来,您可以先逛逛社区看看其他村社吧"
  29. />
  30. <FlexRow justify="space-around" gap="gap.md">
  31. <FrameButton primary text="完成" @click="show = false; emit('finish')" width="220rpx" />
  32. </FlexRow>
  33. </template>
  34. </FlexCol>
  35. </CommonDialog>
  36. </template>
  37. <script setup lang="ts">
  38. import { ref } from 'vue';
  39. import { toast } from '@/components/dialog/CommonRoot';
  40. import { showError } from '@/common/composeabe/ErrorDisplay';
  41. import { useVillageStore } from '@/store/village';
  42. import VillageApi, { VillageClaimInfo } from '@/api/inhert/VillageApi';
  43. import CommonDialog from '@/common/components/CommonDialog.vue';
  44. import FrameButton from '@/common/components/FrameButton.vue';
  45. import Text from '@/components/basic/Text.vue';
  46. import DynamicForm from '@/components/dynamic/DynamicForm.vue';
  47. import FlexCol from '@/components/layout/FlexCol.vue';
  48. import FlexRow from '@/components/layout/FlexRow.vue';
  49. import Height from '@/components/layout/space/Height.vue';
  50. import Result from '@/components/feedback/Result.vue';
  51. import ProvideVar from '@/components/theme/ProvideVar.vue';
  52. import BoxMid from '@/common/components/box/BoxMid.vue';
  53. import type { RadioValueProps } from '@/components/dynamic/wrappers/RadioValue';
  54. import type { IDynamicFormOptions, IDynamicFormRef } from '@/components/dynamic';
  55. import type { FieldProps } from '@/components/form/Field.vue';
  56. import type { RuleItem } from 'async-validator';
  57. import { getClaimVillageForm } from '../../light/form/claim';
  58. const show = ref(false);
  59. const props = defineProps<{
  60. villageId: number;
  61. }>();
  62. const emit = defineEmits(['finish']);
  63. const villageStore = useVillageStore();
  64. const step = ref('form');
  65. const addFormLoading = ref(false);
  66. const addFormRef = ref<IDynamicFormRef>();
  67. const addFormModel = ref<VillageClaimInfo>(new VillageClaimInfo());
  68. const addFormDefine = ref<IDynamicFormOptions>();
  69. async function addSubmit() {
  70. if (!addFormRef.value || !addFormModel.value)
  71. return;
  72. try {
  73. await addFormRef.value.validate();
  74. } catch (e) {
  75. toast({ content: '有必填项未填写,请检查' });
  76. return;
  77. }
  78. try {
  79. addFormLoading.value = true;
  80. addFormModel.value.villageId = props.villageId;
  81. await VillageApi.claimVallage(addFormModel.value as VillageClaimInfo);
  82. toast({ content: '提交成功' });
  83. step.value = 'finished';
  84. villageStore.loadMyJoinedVillages();
  85. setTimeout(() => {
  86. villageStore.reloadVillageInfo();
  87. }, 500);
  88. } catch (e) {
  89. showError(e);
  90. } finally {
  91. addFormLoading.value = false;
  92. }
  93. }
  94. defineExpose({
  95. show: () => {
  96. show.value = true;
  97. step.value = 'form';
  98. addFormModel.value = new VillageClaimInfo();
  99. addFormModel.value.type = 'volunteer';
  100. addFormModel.value.villageId = props.villageId;
  101. addFormDefine.value = getClaimVillageForm({
  102. formRef: addFormRef,
  103. });
  104. },
  105. });
  106. </script>