<template>
|
<PageLayout title="选择城市" class="citySelect-page-wrapper" :need-auth="false">
|
<ContentView class="citySelect-content-wrapper">
|
<!-- <div class="current-city">当前城市:{{ locationCity }}</div> -->
|
<div class="home-searchbar-wrapper">
|
<div class="city-btn-wrapper">
|
<div class="city-btn">
|
<img :src="IconLocaltion" class="city-btn-icon" />
|
<div class="city-btn-text">当前定位:{{ locationCity }}</div>
|
</div>
|
</div>
|
<div class="reset-localtion" @click="resetLocation">重新定位</div>
|
</div>
|
<Elevator :index-list="elevatorData" :height="'100%'" @click-item="clickItem" />
|
</ContentView>
|
</PageLayout>
|
</template>
|
|
<script setup lang="ts">
|
import { PageLayout, LoadingLayout, ContentScrollView, ContentView } from '@/components';
|
import { useUser } from '@/hooks';
|
import { useArea } from '@12333/hooks';
|
import { AreaType } from '@12333/constants';
|
import { groupBy, sortBy } from 'lodash';
|
import { useUserStore } from '@/stores/modules/user';
|
import { Elevator } from '@12333/components';
|
import IconLocaltion from '@/assets/task/icon-localtion.png';
|
import { setLocationCity } from '@/utils';
|
|
defineOptions({
|
name: 'citySelect',
|
});
|
|
const { completeAreaList, getAreaByAreaCode } = useArea();
|
const { locationCity } = useUser();
|
const userStore = useUserStore();
|
|
const cityList = computed(() => {
|
if (completeAreaList.value?.length > 0) {
|
return [...completeAreaList.value].filter((x) => x.layer === AreaType.City);
|
}
|
return [];
|
});
|
|
const elevatorData = computed(() => {
|
let cityGroups = groupBy(
|
sortBy(cityList.value, (c) => c.quickQuery.charAt(0)),
|
(city) => city.quickQuery.charAt(0)
|
);
|
const _elevatorData = [];
|
for (let key in cityGroups) {
|
_elevatorData.push({
|
title: key,
|
list: cityGroups[key].map((x) => ({
|
name: x.areaName,
|
id: x.areaCode,
|
parentId: x.parentId,
|
})),
|
});
|
}
|
return _elevatorData;
|
});
|
|
console.log('elevatorData: ', elevatorData);
|
|
const clickItem = (key: string, item: any) => {
|
console.log('item: ', item, getAreaByAreaCode(item.parentId).areaName);
|
userStore.setLocationCity(item.name, getAreaByAreaCode(item.parentId).areaName);
|
};
|
|
async function resetLocation() {
|
try {
|
await setLocationCity();
|
} catch (error) {}
|
}
|
</script>
|
|
<style lang="scss">
|
@import '@/styles/common.scss';
|
|
.citySelect-page-wrapper {
|
.home-searchbar-wrapper {
|
padding: 32px 0 28px;
|
display: flex;
|
align-items: center;
|
|
.city-btn-wrapper {
|
flex: 1;
|
min-width: 0;
|
|
.city-btn {
|
display: flex;
|
align-items: center;
|
padding-right: 36px;
|
color: boleGetCssVar('text-color', 'primary');
|
|
.city-btn-icon {
|
width: 40px;
|
height: 40px;
|
}
|
|
.city-btn-text {
|
@include ellipsis;
|
margin-left: 12px;
|
font-size: 30px;
|
}
|
}
|
}
|
|
.reset-localtion {
|
font-weight: 400;
|
font-size: 24px;
|
color: boleGetCssVar('color', 'primary');
|
line-height: 28px;
|
}
|
}
|
|
.current-city {
|
padding: 20px 0;
|
color: boleGetCssVar('text-color', 'primary');
|
font-size: 28px;
|
}
|
|
.citySelect-content-wrapper {
|
display: flex;
|
flex-direction: column;
|
height: 100%;
|
}
|
|
.nut-elevator {
|
flex: 1;
|
min-height: 0;
|
|
.nut-elevator__list__item__name,
|
.nut-elevator__list__item__code {
|
padding: 0;
|
}
|
}
|
}
|
</style>
|