edit.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <CommonTopBanner title="编辑村庄简介">
  3. <FlexCol padding="padding.md" gap="gap.md">
  4. <Field v-model="currentVillageName" placeholder="请输入家乡名称,例如:大庆村" />
  5. <Field
  6. v-model="currentVillageDesc"
  7. placeholder="输入家乡的介绍,可以让大家了解更多"
  8. multiline
  9. showWordLimit
  10. :maxLength="300"
  11. :inputStyle="{ height: '100px' }"
  12. />
  13. <FlexCol
  14. position="relative"
  15. borderColor="border.default"
  16. borderWidth="1px"
  17. borderStyle="solid"
  18. backgroundColor="background.primary"
  19. radius="radius.md"
  20. overflow="hidden"
  21. >
  22. <template v-if="currentVillageImage">
  23. <Image
  24. v-if="currentVillageImage"
  25. :src="currentVillageImage"
  26. width="100%"
  27. height="300px"
  28. mode="aspectFill"
  29. />
  30. <Touchable position="absolute" :inset="0" direction="column" center gap="gap.sm" @click="handleChooseImage">
  31. <FlexCol radius="radius.md" padding="padding.md" backgroundColor="mask.default">
  32. <Text text="点击修改村社封面" fontConfig="lightTitle" color="white" />
  33. </FlexCol>
  34. </Touchable>
  35. </template>
  36. <Touchable v-else
  37. center
  38. :padding="[100, 50]"
  39. @click="handleChooseImage"
  40. >
  41. <Text text="暂无村社封面,点击设置封面" fontConfig="lightTitle" />
  42. </Touchable>
  43. </FlexCol>
  44. <FlexCol gap="gap.md">
  45. <Button text="返回上一步" @click="back" />
  46. <Button text="保存修改" type="primary" @click="handleConfirm()" />
  47. </FlexCol>
  48. </FlexCol>
  49. </CommonTopBanner>
  50. </template>
  51. <script setup lang="ts">
  52. import { ref } from 'vue';
  53. import { showError } from '@/common/composeabe/ErrorDisplay';
  54. import { toast, alert } from '@/components/dialog/CommonRoot';
  55. import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
  56. import { back, backAndCallOnPageBack, navTo } from '@/components/utils/PageAction';
  57. import FlexCol from '@/components/layout/FlexCol.vue';
  58. import CommonTopBanner from '@/common/components/CommonTopBanner.vue';
  59. import Button from '@/components/basic/Button.vue';
  60. import Field from '@/components/form/Field.vue';
  61. import LightVillageApi from '@/api/light/LightVillageApi';
  62. import Image from '@/components/basic/Image.vue';
  63. import Text from '@/components/basic/Text.vue';
  64. import Touchable from '@/components/feedback/Touchable.vue';
  65. const { querys } = useLoadQuerys({
  66. villageId: 0,
  67. areaCode: 0,
  68. longitude: 0,
  69. latitude: 0,
  70. }, async (query) => {
  71. const res = await LightVillageApi.getVillageDetails(query.villageId);
  72. currentVillageName.value = res.name;
  73. currentVillageDesc.value = res.desc;
  74. currentVillageImage.value = res.image;
  75. });
  76. const currentVillageName = ref('')
  77. const currentVillageDesc = ref('')
  78. const currentVillageImage = ref('')
  79. async function handleConfirm() {
  80. if (!currentVillageName.value) {
  81. toast('请输入家乡名称');
  82. return;
  83. }
  84. uni.showLoading();
  85. try {
  86. await LightVillageApi.updateVillageInfo(
  87. querys.value.villageId,
  88. currentVillageDesc.value,
  89. currentVillageImage.value
  90. );
  91. await alert({
  92. title: '提示',
  93. content: '修改村社简介成功!',
  94. });
  95. backAndCallOnPageBack('goVillage', {
  96. id: querys.value.villageId,
  97. });
  98. } catch (e) {
  99. showError(e);
  100. } finally {
  101. uni.hideLoading();
  102. }
  103. }
  104. function handleChooseImage() {
  105. navTo('/pages/home/village/gallery/choose', {
  106. villageId: querys.value.villageId,
  107. });
  108. }
  109. defineExpose({
  110. onPageBack: (name: string, data: Record<string, unknown>) => {
  111. if (name === 'choosedImage') {
  112. currentVillageImage.value = data.url as string;
  113. }
  114. },
  115. });
  116. </script>