|
|
@@ -0,0 +1,121 @@
|
|
|
+<template>
|
|
|
+ <CommonTopBanner title="创建村庄">
|
|
|
+ <FlexCol padding="padding.md" gap="gap.md">
|
|
|
+ <template v-if="step === 'selectArea'">
|
|
|
+ <FlexRow center>
|
|
|
+ <Text>请选择您的家乡位置</Text>
|
|
|
+ </FlexRow>
|
|
|
+ <Cascader
|
|
|
+ v-model="selectedValue"
|
|
|
+ :data="provinceList"
|
|
|
+ textKey="text"
|
|
|
+ valueKey="value"
|
|
|
+ :asyncLoadData="asyncLoadData"
|
|
|
+ :maxSelectLevel="5"
|
|
|
+ @pickEnd="handlePickEnd"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ <template v-else-if="step === 'inputInfo'">
|
|
|
+ <FlexRow center gap="gap.md">
|
|
|
+ <Text>请输入家乡名称,然后选择地图位置定位哦</Text>
|
|
|
+ </FlexRow>
|
|
|
+ <Field v-model="currentVillageName" placeholder="请输入家乡名称,例如:大庆村" />
|
|
|
+ <map
|
|
|
+ id="prevMap"
|
|
|
+ map-id="prevMap"
|
|
|
+ :longitude="currentLonLat.longitude"
|
|
|
+ :latitude="currentLonLat.latitude"
|
|
|
+ :zoom="15"
|
|
|
+ :enable-satellite="enableSatellite"
|
|
|
+ :style="{
|
|
|
+ width: '100%',
|
|
|
+ height: '500px',
|
|
|
+ }"
|
|
|
+ @regionchange="handleRegionchange"
|
|
|
+ >
|
|
|
+ </map>
|
|
|
+ <FlexRow justify="flex-end">
|
|
|
+ <Button :text="'切换' + (enableSatellite ? '地图' : '卫星')" @click="enableSatellite = !enableSatellite" />
|
|
|
+ </FlexRow>
|
|
|
+ <FlexCol gap="gap.md">
|
|
|
+ <Button text="返回上一步" @click="step = 'selectArea'" />
|
|
|
+ <Button text="立即建村" type="primary" @click="handleConfirm" />
|
|
|
+ </FlexCol>
|
|
|
+ </template>
|
|
|
+ </FlexCol>
|
|
|
+ </CommonTopBanner>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { ref, onMounted } from 'vue';
|
|
|
+import FlexCol from '@/components/layout/FlexCol.vue';
|
|
|
+import FlexRow from '@/components/layout/FlexRow.vue';
|
|
|
+import Cascader, { type CascaderItem } from '@/components/form/Cascader.vue';
|
|
|
+import CommonTopBanner from '@/common/components/CommonTopBanner.vue';
|
|
|
+import RegionApi, { type RegionItem } from '@/api/map/RegionApi';
|
|
|
+import Text from '@/components/basic/Text.vue';
|
|
|
+import Button from '@/components/basic/Button.vue';
|
|
|
+import Field from '@/components/form/Field.vue';
|
|
|
+import { showError } from '@/common/composeabe/ErrorDisplay';
|
|
|
+import { toast } from '@/components/dialog/CommonRoot';
|
|
|
+
|
|
|
+const mapCtx = uni.createMapContext('prevMap');
|
|
|
+
|
|
|
+const step = ref<'selectArea'|'inputInfo'>('selectArea');
|
|
|
+const selectedRegion = ref<RegionItem>();
|
|
|
+const currentLonLat = ref({ longitude: 0, latitude: 0 });
|
|
|
+const currentVillageName = ref('')
|
|
|
+
|
|
|
+const enableSatellite = ref(false);
|
|
|
+const selectedValue = ref<(string | number)[]>([]);
|
|
|
+const provinceList = ref<CascaderItem[]>([]);
|
|
|
+
|
|
|
+async function asyncLoadData(item: CascaderItem) {
|
|
|
+ const list = await RegionApi.getChildList(Number(item.value));
|
|
|
+ return list.map(region => ({
|
|
|
+ text: region.name,
|
|
|
+ value: String(region.areaCode),
|
|
|
+ data: region,
|
|
|
+ }));
|
|
|
+}
|
|
|
+function handlePickEnd(values: CascaderItem[]) {
|
|
|
+ if (values.length > 0) {
|
|
|
+ selectedRegion.value = values[values.length - 1].data;
|
|
|
+ currentLonLat.value = {
|
|
|
+ longitude: Number(selectedRegion.value!.longitude),
|
|
|
+ latitude: Number(selectedRegion.value!.latitude),
|
|
|
+ };
|
|
|
+ mapCtx.moveToLocation({
|
|
|
+ longitude: Number(currentLonLat.value.longitude),
|
|
|
+ latitude: Number(currentLonLat.value.latitude),
|
|
|
+ });
|
|
|
+ console.log('currentLonLat.value', currentLonLat.value);
|
|
|
+ step.value = 'inputInfo';
|
|
|
+ }
|
|
|
+}
|
|
|
+function handleRegionchange(e: any) {
|
|
|
+ if (e.type === 'end') {
|
|
|
+ currentLonLat.value = {
|
|
|
+ longitude: Number(e.detail.centerLocation.longitude),
|
|
|
+ latitude: Number(e.detail.centerLocation.latitude),
|
|
|
+ };
|
|
|
+ }
|
|
|
+}
|
|
|
+function handleConfirm() {
|
|
|
+ if (!currentVillageName.value) {
|
|
|
+ toast('请输入家乡名称');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ showError('暂无接口');
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(async () => {
|
|
|
+ const list = await RegionApi.getChildList(0);
|
|
|
+ provinceList.value = list.map(region => ({
|
|
|
+ text: region.name,
|
|
|
+ value: String(region.areaCode),
|
|
|
+ data: region,
|
|
|
+ }));
|
|
|
+});
|
|
|
+
|
|
|
+</script>
|