brandDetail.js
2.42 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
import { ACTIVITY_HOST, YOHOOD_HOST, API_HOST } from '../../libs/config';
import { GET, POST } from '../../libs/request';
import { parseBrandListData } from '../../utils/productList';
import jumpToMiniapp from '../../router/jump-to-miniapp';
Page({
data: {
shopId: '',
brandInfo: {},
productList: {
page: 0,
page_total: 0,
total: 0,
list: [],
},
},
onLoad: function(options) {
//Do some initialize when page load.
let brandId = options.brandId;
let brandName = options.brandName;
wx.setNavigationBarTitle({title: brandName || '品牌详情'});
this.fetchDetail(brandId);
},
onReady: function() {
//Do some when page ready.
},
onShow: function() {
//Do some when page show.
},
fetchDetail(brandId) {
let that = this;
let param = {
id: brandId
}
GET(YOHOOD_HOST + '/brand/getBrandById', param)
.then(data => {
let brandInfo = data.data;
wx.setNavigationBarTitle({title: brandInfo.name || '品牌详情'});
let link = brandInfo.link;
let shopId = link.split('=').pop();
that.fetchProductList(shopId);
that.setData({
brandInfo,
shopId
})
})
.catch(error => {
});
},
fetchProductList(brandId) {
let that = this;
let productList = this.data.productList;
let param = {
id: brandId
}
GET(ACTIVITY_HOST + '/api/yohood/getShopProduct', param)
.then(data => {
if (data && data.code==200 && data.data) {
let product_list = data.data.product_list;
product_list = parseBrandListData(product_list);
productList.list = product_list;
productList.total = data.data.total;
productList.page_total = data.data.page_total;
productList.page = data.data.page;
that.setData({
productList
})
}
})
.catch(error => {
});
},
enterShop(event) {
let shopId = this.data.shopId;
// page_name=brands&is_red_shop=1&shop_id=2192&shop_name=TEEBACCO&shop_template_type=1
let data = {
shop_id: shopId,
};
jumpToMiniapp({ app: 'yohobuy', page: 'shopDetail', data: data })
},
onHide: function() {
//Do some when page hide.
},
onUnload: function() {
//Do some when page unload.
},
onPullDownRefresh: function() {
//Do some when page pull down.
}
})