zhengyiming
2025-02-19 c8724a3d88607516fe95ffb91e4b52c99405d063
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<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>