goodsList.js
4.6 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
import category from '@/api/category'
import goods from '@/api/goods'
import store from '@/store'
import {
Card,
Cell,
CellGroup,
Col,
Divider,
Icon,
Lazyload,
List,
Row,
Swipe,
SwipeItem,
Tab,
Tabbar,
TabbarItem,
Tabs,
Toast
} from 'vant';
const baseApi = process.env.VUE_APP_BASE_API
export default {
components: {
[Row.name]: Row,
[Col.name]: Col,
[Icon.name]: Icon,
[Cell.name]: Cell,
[CellGroup.name]: CellGroup,
[Tabbar.name]: Tabbar,
[TabbarItem.name]: TabbarItem,
[Swipe.name]: Swipe,
[SwipeItem.name]: SwipeItem,
[Tab.name]: Tab,
[Tabs.name]: Tabs,
[Card.name]: Card,
[Toast.name]: Toast,
[Divider.name]: Divider,
[List.name]: List,
Lazyload
},
data() {
return {
loading: false,
finished: false,
navList: [],
banners: [],
goodsList: [],
activeFooter: 0,
activeNav: undefined,
total: 0,
listQuery: {
page: 1,
limit: 50,
idCategory: undefined
},
count: 0,
isLoading: false
}
},
mounted() {
this.init()
},
methods: {
init() {
this.activeNav = parseInt(this.$route.query.itemId)
let categoryData = store.state.app.category
if (!categoryData || categoryData.length == 0) {
let platform = navigator.platform
store.dispatch('app/toggleDevice', platform)
category.getAllCategories().then(response => {
let navList = response.data
navList.splice(0, 0, {name: '推荐', id: '0'})
this.navList = navList
store.dispatch('app/toggleCategory', navList)
this.getBanners(this.activeNav)
}).catch((err) => {
console.log('err', err)
Toast.fail(err);
})
} else {
this.navList = categoryData
this.getBanners(this.activeNav)
}
this.getGoods(this.activeNav)
},
getBanners(categoryIndex) {
let bannerList = null
for (const i in this.navList) {
if (this.navList[i].id == categoryIndex) {
bannerList = this.navList[i].bannerList
}
}
let imgList = new Array()
for (let i = 0; i < bannerList.length; i++) {
let url = ''
let page = bannerList[i].page
if (page != '') {
if (page.indexOf('http') === 0) {
url = page
} else {
url = '#/' + bannerList[i].page
}
}
if (bannerList[i].param != '') {
const param = JSON.parse(bannerList[i].param)
for (const key in param) {
url += '/' + param[key]
}
}
imgList.push({
url: url,
path: baseApi + '/file/getImgStream?idFile=' + bannerList[i].idFile
})
}
this.banners = imgList
},
getGoods(idCategory) {
this.listQuery['idCategory'] = idCategory
goods.queryGoods(this.listQuery).then(response => {
let list = response.data.records
this.total = response.data.total
for (var index in list) {
const item = list[index]
item.img = baseApi + '/file/getImgStream?idFile=' + item.pic
}
this.goodsList = list
}).catch((err) => {
Toast(err)
})
},
loadMore() {
this.loading = false
this.finished = true
},
onClickNav(index, title) {
if (index === '0') {
this.$router.push({path: '/index'})
return
}
this.activeNav = index;
this.getBanners(index)
this.getGoods(index)
},
clickSwipe(index, p2) {
console.log(index)
console.log(p2)
},
viewGoodsDetail(id) {
this.$router.push({path: '/goods/' + id})
},
formatPrice(price) {
return (price / 100).toFixed(2)
}
}
};