index.vue
3.73 KB
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
141
142
143
144
145
146
147
<template>
<div class="nationality_container">
<NafmHeader :title="$t('title.nationality')" navClass="nafmii-head-bg3">
<template #bottom>
<SearchInput v-model="keyword" :placeholder="$t('person.country')" @search="handleSearch" />
</template>
</NafmHeader>
<div class="search_content" ref="searchContent" v-show="keyword">
<ul>
<li class="search_item" v-for="(item,index) of list" :key="index" @click="handleCountryClick(item.cityName)">{{item.cityName}}</li>
<li class="search_item" v-show="hasNoData">没有搜索到匹配内容</li>
</ul>
</div>
<div class="city-area" ref="cityarea">
<van-index-bar :sticky="false" @select="handleSelect">
<div class="city-area-list" v-for="(item,key) in countryList" :key="key">
<van-index-anchor :index="key">{{key}}</van-index-anchor>
<van-cell v-for="(innerItem,Index) in item " :key="Index" :title="innerItem.cityName" @click="handleCountryClick(innerItem.cityName)"></van-cell>
</div>
</van-index-bar>
</div>
</div>
</template>
<script>
import BScroll from 'better-scroll'
import SearchInput from '@/components/SearchInput.vue'
import data from './city.json'
export default {
name: 'Nationality',
components: {
SearchInput
},
data() {
return {
keyword: '',
list: [],
countryList: {},
}
},
computed: {
hasNoData() {
return !this.list.length
}
},
watch: {
keyword() {
// console.log('keyword', this.keyword)
if (!this.keyword) {
this.list = []
return false
}
const result = []
for (const i in this.countryList) {
this.countryList[i].forEach(value => {
if (value.cityName.indexOf(this.keyword) > -1 || value.cityPinyin.indexOf(this.keyword) > -1) {
result.push(value)
}
})
}
this.list = result
},
countryList() {
setTimeout(() => {
this.$refs.cityarea.style.height = document.documentElement.clientHeight - this.$refs.cityarea.getBoundingClientRect().top - 10 + "px";
this.InsertElementBuildIos();
}, 1000)
}
},
mounted() {
this.scroll = new BScroll(this.$refs.searchContent, {
click: true
})
this.countryList = data.list[0]
},
methods: {
//修改a-z列表在ios中fixed未脱离文档流bug
InsertElementBuildIos() {
let li = document.querySelector(".nationality_container");
let el = document.querySelector(".van-index-bar__sidebar");
li.insertBefore(el, li.firstChild);
},
jumpPage() {
},
// 字母选择
handleSelect(value) {
let cityDom = document.querySelector(".city-area");
cityDom.scrollTop += 5;
},
//
handleCountryClick(value) {
console.log('value', value)
// 接口请求 返回上页
this.$router.back()
},
handleSearch(v){
console.log('handleSeach',v)
}
}
}
</script>
<style lang="less" scoped>
@import "~@/assets/css/search.less";
.nationality_container {
height: 100vh;
}
.search_content {
overflow: hidden;
position: absolute;
top: 94px;
left: 0;
right: 0;
bottom: 0;
background: #f7f7f7;
z-index: 9;
.search_item {
line-height: 35px;
padding-left: 35px;
border-bottom: 1px solid #efefef;
background: #fff;
color: #666;
}
}
.city-area {
overflow: hidden;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
/deep/ .van-index-bar__sidebar {
top: 55%;
right: 10px;
}
/deep/ .van-index-bar__index {
font-size: 10px;
width: 15px;
height: 15px;
text-align: center;
margin-bottom: 2px;
padding: 0;
}
/deep/ .van-index-bar__index--active {
color: #fff;
background: #5594e5;
padding: 2px;
border-radius: 50%;
}
</style>