forked from apache/incubator-weex-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.vue
177 lines (167 loc) · 4.64 KB
/
index.vue
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!-- CopyRight (C) 2017-2022 Alibaba Group Holding Limited. -->
<!-- Created by Tw93 on 17/12/27. -->
<!--A City -->
<template>
<div class="wxc-city" ref="city">
<wxc-searchbar ref="wxc-searchbar"
v-bind="mergeInputConfig"
@wxcSearchbarInputOnInput="onInput"
@wxcSearchbarInputReturned="onSubmit"
@wxcSearchbarCancelClicked="onCancel"></wxc-searchbar>
<wxc-tab ref="wxc-tab"
v-if="showTab"
@wxcTabSwitch="onTabSwitch"></wxc-tab>
<wxc-indexlist :normal-list="normalList"
:hot-list-config="hotListConfig"
:nav-style="{ top: '24px'}"
:height="listHeight"
:show-index="showIndex"
:only-show-list="onlyShowList"
:city-location-config="cityLocationConfig"
@wxcIndexlistItemClicked="onItemClick"></wxc-indexlist>
<wxc-result type="noGoods"
:wrap-style="{top:'84px'}"
:show="true"
:customSet="result"
v-if="showError"></wxc-result>
</div>
</template>
<script>
const animation = weex.requireModule('animation');
import Utils from '../utils';
import wxcTab from './tab.vue';
import WxcSearchbar from '../wxc-searchbar'
import WxcResult from '../wxc-result';
import WxcIndexlist from '../wxc-indexlist';
export default {
components: { wxcTab, WxcSearchbar, WxcResult, WxcIndexlist },
props: {
inputConfig: {
type: Object,
default: () => ({})
},
normalList: {
type: Array,
default: () => ([])
},
cityHeight: {
type: Number,
default: 0
},
showTab: {
type: Boolean,
default: false
},
hotListConfig: {
type: Object,
default: () => ({})
},
cityLocationConfig: {
type: Object,
default: () => ({})
},
onlyShowList: {
type: Boolean,
default: false
},
showIndex: {
type: Boolean,
default: true
}
},
data: () => ({
tId: null,
result: {
noGoods: {
pic: 'https://img.alicdn.com/tfs/TB1SpPHkf2H8KJjy0FcXXaDlFXa-200-200.png',
button: '',
content: '搜索无结果'
}
}
}),
computed: {
showError () {
const { normalList, hotListConfig } = this;
return (normalList && normalList.length < 1) && (hotListConfig && hotListConfig.list && hotListConfig.list.length < 1)
},
listHeight () {
// 兼容去头逻辑
let pageHeight = Utils.env.getPageHeight();
const { cityHeight } = this;
if (cityHeight && !isNaN(cityHeight) && cityHeight > 0) {
pageHeight = cityHeight;
}
// searchInput 84
const tabHeight = this.showTab ? 90 : 0;
return pageHeight - 84 - tabHeight;
},
mergeInputConfig () {
return {
autofocus: false,
alwaysShowCancel: true,
placeholder: '中文/拼音/首字母',
...this.inputConfig
}
}
},
methods: {
onTabSwitch (e) {
this.$emit('wxcTabSwitch', e);
},
switchTab (i = 0) {
setTimeout(() => {
this.$refs['wxc-tab'].switchTab(i)
}, 100);
},
onItemClick (e) {
this.$refs['wxc-searchbar'].autoBlur();
this.show(false);
this.$emit('wxcCityItemSelected', { item: e.item });
},
onInput (e) {
clearTimeout(this.tId);
this.tId = setTimeout(() => {
this.$emit('wxcCityOnInput', {
value: e.value
});
}, 300);
},
onCancel () {
this.autoBlur();
this.show(false);
this.$emit('wxcCityCanceled', {});
},
onSubmit (e) {
this.autoBlur();
this.$emit('wxcCityOnKeyUpEnter', { value: e.value });
},
autoBlur () {
const inputRef = this.$refs['wxc-searchbar'];
inputRef && inputRef.autoBlur();
},
show (status = true, callback = null) {
animation.transition(this.$refs.city, {
styles: {
transform: `translateX(${status ? -750 : 750}px)`
},
duration: status ? 250 : 300, // ms
timingFunction: status ? 'ease-in' : 'ease-out',
delay: 0 // ms
}, function () {
callback && callback();
});
}
}
};
</script>
<style scoped>
.wxc-city {
position: fixed;
width: 750px;
top: 0;
left: 750px;
right: 0;
bottom: 0;
background-color: #F2F3F4;
}
</style>