shop-box.vue
9.29 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<template>
<div class="shop-box" :class="{'no-header': noheader}">
<top-bar :share-data="shareData" :show-top-bar="showTopBar"></top-bar>
<div :class='{"shop-goods-top": true}' class="list-items">
<product-list :report-page-name="pageName" :report-page-param="pageParam" :data="productList"
:state="listState"></product-list>
</div>
<filter-box :val="order" :filter="filterConfig" v-if="enableOrder" ref="filter"></filter-box>
<shopping-bag :cart-count="cartCount" v-if="isApp"></shopping-bag>
</div>
</template>
<style>
html,
body {
height: 100%;
background-color: #fff;
}
.shop-box.no-header {
.top-filter {
top: 0;
}
}
#shop {
.empty-tip {
margin-top: 40px;
}
.list-items {
padding-top: 105px;
background-color: #fff;
}
}
</style>
<script>
import $ from 'jquery';
import _ from 'lodash';
import yoho from 'yoho';
import qs from 'yoho-qs/parse';
import bus from 'common/vue-bus';
import tip from 'common/tip';
import cookie from 'yoho-cookie';
import topBar from 'product/shop/top-bar.vue'; // 顶部栏,包括返回、收藏店铺、分享,打开筛选页面
import shopTop from 'product/shop/shop-top.vue'; // 店铺头部信息
import ProductList from 'component/product/list.vue';
import FilterBox from 'component/product/filter/index.vue';
import ShoppingBag from 'component/product/shopping-bag.vue';
const $shop = $('#shop');
const channelTrans = {
men: {
key: 'MEN男士',
code: '1,3'
},
women: {
key: 'WOMEN女士',
code: '2,3'
},
lifestyle: {
key: 'LIFESTYLE生活',
code: '1,2,3'
}
};
const shareSubTitle = '我在BLK发现了一个不错的品牌,赶快来看看吧!';
let locationQuery = qs(decodeURIComponent(location.search.replace(/^\?/, '')));
export default {
data() {
return {
isApp: yoho.isApp,
noheader: false,
shareData: {}, // 分享相关数据
shopInfo: {}, // 店铺介绍相关数据
sortConfig: {},
filterConfig: null,
showTopBar: true,
// query
url: '/product/shop/goods.json',
filter: {
domain: $shop.data('domain')
},
page: 0, // page= 0 未搜索, 1 并且productList.length =0 没有数据, page = page_total 全部加载完
totalPage: null,
// 产品列表
productList: [],
inSearching: false,
enableOrder: false,
order: 's_t_desc',
cartCount: 0,
// for yas report
pageName: 'FP_BLK_Brand_h5',
pageParam: locationQuery.brandId || ''
};
},
computed: {
empty: function() {
return this.page !== 0 && !this.productList.length;
},
listState: function() {
let state = 1; // 0: 全部加载完 1: 正在加载
if (!this.page) {
return;
}
if (!this.productList.length) {
return -1;
} else if (this.page === this.totalPage) {
return 0;
} else if (this.inSearching) {
return 1;
}
return state;
}
},
watch: {
/* order 和 filter 改变 都会触发 重新搜索 (想象成清空所有分页) */
order: function() {
this.research();
},
filter: function() {
this.research();
}
},
methods: {
/* 获取店铺简介相关数据 */
getShopInfo() {
$.get({
// async: false,
url: '/product/shop/info.json',
data: {
domain: $shop.data('domain'),
shopId: $shop.data('shopid') // 店铺 ID
}
}).done(result => {
if (result) {
this.shopInfo = result;
this.shopInfo.showBrandInfo = true;
// 处理富文本
this.shopInfo.shopIntro && (this.shopInfo.shopIntro = this.shopInfo.shopIntro.replace(/<\/?[^>]*>/g, ''));
let shareUrl = locationQuery.id ?
location.origin + '/product/shop/favorite/share?id=' + locationQuery.id :
location.origin + '/product/shop/' + $shop.data('domain') + '/share';
this.shareData = {
des: shareSubTitle,
url: shareUrl,
img: result.shopLogo ? result.shopLogo.split('?')[0] +
'?imageMogr2/thumbnail/300x300/format/jpg/quality/90' : '',
isBlkShop: result.isBlkShop,
domain: locationQuery.domain,
brandName: result.brandName,
brandId: result.brandId, // 不是分享的参数,收藏店铺使用
shopId: result.shopId, // 不是分享的参数,收藏店铺使用
isFav: result.isFav // 不是分享的参数,收藏店铺使用
};
} else {
this.shopInfo.showBrandInfo = false;
}
this.showTopBar = true;
}).fail(() => {
tip('网络出错~');
});
},
search: function() {
const nextPage = this.page + 1;
if (this.inSearching) {
return;
}
// page = 0, 始终执行搜索
if (this.page && nextPage > this.totalPage) {
return;
}
this.inSearching = true;
let channel = cookie.get('_Channel') || 'men';
let gender = channelTrans[channel].code || '1,3';
return $.get(this.url, Object.assign({
gender,
channel,
order: this.order,
page: nextPage
}, locationQuery, this.filter)).done(result => {
if (result.code === 200) {
this.page = result.data.page;
this.totalPage = result.data.pageTotal;
// yas report param injection
_.each(result.data.productList, item => {
item.from_page_name = this.pageName;
item.from_page_param = this.pageParam;
});
this.productList = this.productList.concat(result.data.productList);
if (!this.filterConfig) {
this.filterConfig = result.data.filter;
}
}
}).fail(() => {
tip('网络出错~');
}).always(() => {
this.inSearching = false;
});
},
research: function() {
this.page = 0;
this.productList = [];
this.search();
},
refreshCart: function() {
$.get('/product/cart-count.json').then(result=> {
if (result.code === 200) {
this.cartCount = result.data.cart_goods_count;
}
});
}
},
components: {
topBar,
shopTop,
ProductList,
FilterBox,
ShoppingBag
},
created() {
const self = this;
// this.noheader = yoho.isYohoBuy;
this.getShopInfo();
this.search()
.then(()=>{
if (self.productList.length) {
self.enableOrder = true;
}
});
bus.$on('list.paging', () => {
this.search();
});
bus.$on('order.change', ({
val
}) => {
this.order = val;
});
/**
* 筛选组件 筛选值变更,触发 filter.change事件
* 1. 重新搜索
* 2. 关闭 filter 组件
*/
bus.$on('filter.change', function({val}) {
Object.assign(val, { domain: $shop.data('domain') });
self.filter = val;
self.$refs.filter.isVisible = false;
});
// 读取购物车数量
if (this.isApp) {
this.refreshCart();
bus.$on('app.shoppingcart.refresh', this.refreshCart);
}
}
};
</script>