index.vue
3.28 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
<template>
<div class="resources">
<template v-for="floor in resources">
<focus v-if="floor.focus && floor.focusType === '1'" v-bind:floor="floor.data" v-bind:style="{height: '9.1rem'}">
<!-- 轮播图,通栏 -->
</focus>
<focus-left-right v-if="floor.focus && floor.focusType === '2'" v-bind:floor="floor.data">
<!-- 轮播图,左右滑动 -->
</focus-left-right>
<title-image v-if="floor.titleImage" v-bind:floor="floor.data">
<!-- 标题图片 -->
</title-image>
<title-floor v-if="floor.titleFloor" v-bind:title="floor.data.title">
<!-- 楼层标题 -->
</title-floor>
<recommend-content-five v-if="floor.recommendContentFive" v-bind:floor="floor.data.list">
<!-- 带标题的12个小图推荐 -->
</recommend-content-five>
<goods v-if="floor.goods" v-bind:floor="floor.data">
<!-- 商品 -->
</goods>
</template>
</div>
</template>
<script>
const $ = require('yoho-jquery');
const tip = require('common/tip');
const bus = require('common/vue-bus');
const contentCode = require('content-code');
const focus = require('./focus.vue');
const focusLeftRight = require('./focus-left-right.vue');
const titleImage = require('./title-image.vue');
const titleFloor = require('./title-floor.vue');
const recommendContentFive = require('./recommend-content-five.vue');
const goods = require('./goods.vue');
const dataCache = {};
module.exports = {
props: {
contentCode: {
type: String,
default: contentCode.channel.men
}
},
data() {
return {
resources: []
};
},
components: {
focus,
focusLeftRight,
titleImage,
titleFloor,
recommendContentFive,
goods
},
watch: {
contentCode() {
this.getResourcesData();
bus.$emit('contentCode.change', this.contentCode);
}
},
methods: {
getResourcesData() {
let data = {};
if (this.contentCode) {
data.contentCode = this.contentCode;
}
let param = $.param(data);
if (dataCache[param]) {
this.resources = dataCache[param];
return;
}
return $.ajax({
url: '/resources',
data: data
}).then(result => {
this.resources = result;
if (result.length) {
dataCache[param] = result;
}
}).fail(() => {
tip('网络错误');
});
}
},
created() {
this.getResourcesData();
bus.$on('channel.change', (page, channel) => {
this.contentCode = contentCode[page][channel];
});
}
};
</script>
<style>
.resources {
background: #f6f6f6;
}
</style>