zhengyiming
2025-02-14 ddfa27c45cc80f575f414bac49201ac60f20888a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<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">重新定位</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/home/icon-localtion.png';
 
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);
};
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.citySelect-page-wrapper {
  .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>