tabBox.vue
8.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
<template>
<div class="tabBox">
<!-- 主内容区域 -->
<van-tabs @change="onChange" swipeable v-model="active" ellipsis swipe-threshold="3">
<van-tab v-for="(item,index) in tabbar" :key="index" :title="item.title">
</van-tab>
<div class="tabBox_main" ref="tabsSwiperBox">
<div class="tabbar" v-for="(item, index) in tabbaromponents&&tabbaromponents.ads" :key="index">
<!-- 关爱屋简介 -->
<div :style="{backgroundColor:(tabbar&&tabbar[0].color) || tabbarBackgroud}" class="skeleton brief" ref="brief">
<html-box
v-if="item.style === '14'"
:htmls="item.content">
</html-box>
</div>
<!-- 精品推荐 -->
<div :style="{backgroundColor:(tabbar&&tabbar[0].color) || tabbarBackgroud}" class="skeleton boutique" ref="boutique">
<img-list-box
v-if="item.style === '12'"
@detail="toDetail"
:imgLists="item.img">
</img-list-box>
<!--优惠专区-->
<discountZone v-if="item.style == '1'" @more="toDetail" @toDetail="toDetail"
:discountZoneInfo="item">
</discountZone>
<!--天天特惠-->
<preferential v-if="item.style == '2'" @more="toDetail" @toDetail="toDetail"
:preferentialInfo="item">
</preferential>
<!--视听专区-->
<videoArea v-if="item.style == '13'" @more="toDetail" @toDetail="toDetail"
:videoAreaInfo="item">
</videoArea>
<!-- style_7组件 -->
<style-7 v-if="item.style == '7'" @more="toDetail" @bannerJump="toDetail" @jump=$parent.jump @addCart=$parent.addCart
:styles="item">
</style-7>
</div>
<!-- 商品推荐 -->
<div :style="{backgroundColor:(tabbar&&tabbar[0].color) || tabbarBackgroud}" class="skeleton commodity" ref="commodity">
<!--infinite-scroll-immediate-check="true"可避免上拉多次调用接口问题-->
<!-- 渐变过度 -->
<div class="column-commodity-excessive"></div>
<div class="column-commodity-list" infinite-scroll-immediate-check="true" v-infinite-scroll="loadCommodity" infinite-scroll-disabled="paging.commodity.loading" :infinite-scroll-distance="paging.distance">
<column-commodity-list-box
v-if="item.style === '15'"
@detail="toCommodityDetail"
:columnLists="commoditys">
</column-commodity-list-box>
</div>
</div>
</div>
</div>
</van-tabs>
</div>
</template>
<script>
import { Toast, Indicator } from "mint-ui";
import htmlBox from "@/components/htmlBox/htmlBox";
import imgListBox from "@/components/imgListBox/imgListBox";
import columnCommodityListBox from "@/components/columnCommodityListBox/columnCommodityListBox";
import discountZone from "@/components/discountZone/discountZone";
import preferential from "@/components/preferential/preferential";
import videoArea from "@/components/videoArea/videoArea";
import style7 from "@/components/style_7/style_7";
export default {
name: 'name',
data () {
return {
active: 0,
tabbaromponents: null, // 组件库
commoditys: { // 全部推荐
list: []
},
paging: { // 分页
commodity: {
loading: true,
page: 1
},
distance: 50
}
}
},
props:["tabbar","tabbarBackgroud"],
components: {
htmlBox,
imgListBox,
columnCommodityListBox,
discountZone,
preferential,
videoArea,
style7,
},
created(){
// 初始化的时选中关爱屋
if(this.tabbar&&this.tabbar[0]&&this.tabbar[0].ads){
this.tabbaromponents = this.tabbar[0]
}
// 获取爱心屋全部商品数据
this.shopRecommendGoods(this.paging.commodity.page)
},
methods: {
onChange(name, title) {
// 切换tab时判断展示哪个组件
this.tabbaromponents = this.tabbar.find((item)=>{
return item.title === title
});
},
/**
* 调用通用跳转
* @param {object} item [通用跳转对象]
*/
toDetail(item) {
// 判断是否有通用跳转函数
if (typeof this.$parent.toDetail === "function") {
// 调用通用跳转
this.$parent.toDetail(item);
}
},
/**
* 特定跳转商品详情
* @param {object} item [跳转对象]
*/
toCommodityDetail(item) {
// 设置跳转参数
Object.assign(item, {
type: "2",
to: item.id
});
// 调用通用跳转
this.toDetail(item);
},
/**
* 爱心屋项目全部商品
* @param {int} page [页码]
*/
shopRecommendGoods(page) {
for (let i = 0; i < this.tabbar.length; i++) {
// 判断必要参数
if (this.tabbar[i].ads[0].style==15) {
// 加载中
this.$set(this.paging.commodity, "loading", true);
// 加载中提示
Indicator.open('加载中...');
// 请求接口
this.http("/Api/" + (this.getApiVersion().index) + "/shopGoodsList", {
shopId: this.tabbar[i].shop_id,
page: page
}, this.shopRecommendGoodsCallback, {
method: "POST"
});
}
}
},
/**
* 爱心屋项目全部商品回调
* @param {object} res [服务器返回数据]
* @param {object} ext [扩展参数]
*/
shopRecommendGoodsCallback(res, ext) {
// 加载完成
Indicator.close();
// 返回处理
if (res.code == 200) {
// 解构数据
let {data: datas} = res;
/* 设置商品推荐数据 开始 */
// 判断是否有数据
if (datas && datas.length) {
// 追加列表
this.$set(this.commoditys, "list", [...this.commoditys.list, ...datas]);
// 设置还有需要加载的内容
this.$set(this.paging.commodity, "loading", false);
} else {
// 没有需要加载的内容,停止上拉加载
this.$set(this.paging.commodity, "loading", true);
}
/* 设置商品推荐数据 结束 */
} else if (res.code == 400) {
// 获取商品推荐失败
Toast(res.message);
} else {
// 获取商品推荐失败
Toast("获取商品推荐失败");
}
},
/**
* 上拉加载“爱心屋项目全部商品”
*/
loadCommodity() {
// 判断是“精品推荐”页才加载
if (this.tabbaromponents.title === '全部商品' && this.tabbaromponents.shop_id) {
// 设置“精品推荐”页码
this.$set(this.paging.commodity, "page", ++this.paging.commodity.page);
// 调用接口
this.shopRecommendGoods(this.paging.commodity.page);
}
},
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less">
@import './tabBox';
</style>