rk
2025-09-28 2304d7b140c5c5b4bf3a83f9ced8bff37d20c42e
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
<template>
    <view class="t-index-address">
        <scroll-view class="t-index-address__scroll-view" :scroll-into-view="scrollview" :scroll-y="true"
            :enable-flex="true">
            <view :id="group.initial" v-for="group in cityList" :key="group.initial">
                <view class="t-index-address__anchor" style="background-color: #ffffff;">
                    <text>{{ group.initial }}</text>
                </view>
                <view class="t-index-address__list">
                    <view class="t-index-address__cell" v-for="(city, index) in group.list" :key="index"
                        @click="$emit('select', city)">
                        <text>{{ city.name }}</text>
                    </view>
                </view>
            </view>
        </scroll-view>
        <view class="t-index-address__sidebar">
            <view class="t-index-address__index" :style="{ color: activeIndex === group.initial ? '#00BC12' : '' }" v-for="group in cityList" :key="group.initial"
                @touchstart.stop.prevent="onTouchMove(group.initial)" @touchend.stop.prevent="onTouchStop"
                @touchcancel.stop.prevent="onTouchStop">
                <span>{{ group.initial }}</span>
            </view>
        </view>
        <view class="t-index-address__alert" v-if="touchmove">
            <text>{{ activeIndex }}</text>
        </view>
    </view>
</template>
 
<script>
    import cityList from "./cities.json";
 
    export default {
        data() {
            return {
                scrollview: "A",
                cityList: [],
                activeIndex: "A",
                touchmove: false,
            };
        },
        watch: {
            activeIndex(value) {
                this.scrollview = value;
            },
        },
        methods: {
            search(val) {
                let arr = JSON.parse(JSON.stringify(cityList))
                arr.forEach(item => {
                    item.list = item.list.filter((child) => child.name.indexOf(val) !== -1)
                })
                this.cityList = arr.filter(item => item.list.length > 0);
            },
            initCityList() {
                this.cityList = cityList;
            },
            onTouchMove(index) {
                this.activeIndex = index;
                this.touchmove = true;
            },
            onTouchStop() {
                this.touchmove = false;
            },
        },
        mounted() {
            this.initCityList();
        },
    };
</script>
 
<style lang="scss" scoped>
    .t-index-address {
        height: 100%;
 
        &__scroll-view {
            width: 100%;
            height: 100%;
            max-height: 100vh;
        }
 
        &__anchor {
            padding: 15rpx 30rpx;
            width: 100%;
            font-size: 28rpx;
            font-weight: 500;
            color: #606266;
            background-color: rgb(245, 245, 245);
        }
 
        &__list {
            padding: 0 70rpx 0 30rpx;
        }
 
        &__cell {
            height: 100rpx;
            line-height: 100rpx;
            border-bottom: 1rpx solid #f2f2f2;
 
            &:last-child {
                border: none;
            }
        }
 
        &__sidebar {
            position: fixed;
            top: 50%;
            right: 0;
            transform: translateY(-50%);
            z-index: 99;
        }
 
        &__index {
            padding: 10rpx 20rpx;
            font-size: 22rpx;
            font-weight: 500;
            line-height: 1;
        }
 
        &__alert {
            position: fixed;
            top: 50%;
            right: 90rpx;
            z-index: 99;
            margin-top: -60rpx;
            width: 120rpx;
            height: 120rpx;
            font-size: 50rpx;
            color: #fff;
            border-radius: 24rpx;
            background-color: rgba(0, 0, 0, 0.5);
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }
</style>