brandDetail.js
2.7 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
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: '',
showEnterShop: true,
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 showEnterShop = that.data.showEnterShop;
let shopId = that.data.shopId;
let link = brandInfo.link;
if (link.indexOf("shop_id") != -1) {
shopId = link.split('=').pop() || '';
that.fetchProductList(shopId);
if (shopId.length == 0 || parseInt(shopId) == 0) {
showEnterShop = false;
}
} else {
showEnterShop = false;
}
that.setData({
brandInfo,
showEnterShop,
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 || '';
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.
}
})