conversionLeft.vue
6.32 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
<template>
<div class='conversion-left'>
<view-sub-title :title='diffsTitle[copyBussinessType]' />
<div class='component' v-if='boxList'>
<div class='titles'>
<span>订单月份</span>
<span>{{ copyBussinessType == 'expandedGold' ? '活动名称' : '商品名称' }}</span>
<span>订单数</span>
</div>
<div
ref='forwardScrollBox'
class='list_dv'
@mouseenter='mouseenter'
@mouseleave='mouseleave'
>
<div ref='forwardContent' class='scroll_dv'>
<div v-for='(item, index) in boxList' :key='index' class='list_item dfac'>
<!-- @click='selectData(item)'-->
<div
class='dataList'
:class="currentIndex === index? 'selectMerchant' : ''"
@mouseleave="currentIndex = ''"
@mouseenter='mouseenterList(item,index)'>
<div>{{ item.statMonth }}</div>
<div>{{ item[diffsGoodsName[copyBussinessType]] }}</div>
<div>{{ item[diffsNum[copyBussinessType]] }}</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'ConversionLeft',
data() {
return {
diffsTitle: {
'transWork': '各月各商品订单量排名',
'expandedGold': '各月各活动订单量排名',
'crowdFunding': '各月各商品订单量排名',
'noWorries': '各月各商品订单量排名'
},
diffsGoodsName: {
'transWork': 'goodsName',
'expandedGold': 'activityName',
'crowdFunding': 'goodsName',
'noWorries': 'goodsName'
},
diffsNum:{
'transWork': 'orderNum',
'expandedGold': 'totalNum',
'crowdFunding': 'totalNum',
'noWorries': 'totalNum'
},
totalCount: 10000, // 总数
scrollContentHeight: 0, // 滚动内容的高度
scrollBoxHeight: 0, // 滚动父级盒子的高度
scrollableHeight: 0, // 可以滚动的高度
scrollTop: 0, // 元素已经滚动的高度
timer2: null, // 定时器
boxList: [],
currentIndex: '',
copyBussinessType: ''
}
},
async mounted() {
await this.getGoodsOrderinfoMonthly()
this.$bus.$on('orderinfoMonthly', data => {
this.copyBussinessType = data.bussinessType
this.getGoodsOrderinfoMonthly(data.bussinessType)
})
this.$bus.$on('changeMonths', data => {
this.getGoodsOrderinfoMonthly(this.copyBussinessType, data.month)
})
this.$bus.$on('changeBussiness', data => {
clearInterval(this.timer2)
})
},
destroyed() {
// 离开时销毁定时器
clearInterval(this.timer2)
},
methods: {
getGoodsOrderinfoMonthly(val = 'transWork', month = '') {
this.copyBussinessType = val
// let getmonth = month
// if (!getmonth) {
// const date = new Date() // 获取时间
// const year = date.getFullYear() // 获取年
// const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1// 获取月
// getmonth = year + '-' + month
// }
const params = month ? {
month
} : ''
this.api[val].getGoodsOrderinfoMonthly(params).then(res => {
if (res.code == 0) {
this.boxList = res.data.dataList
this.$nextTick(() => {
this.regainHeight()
})
}
})
},
mouseenterList(item, index) {
this.currentIndex = index
},
// 页面第一次进入或者窗口大小变化时,获取滚动相关元素的高度
regainHeight() {
// 获取需要滚动元素的真实高度
this.scrollContentHeight = this.$refs.forwardContent ? this.$refs.forwardContent.getBoundingClientRect().height : ''
// 获取限制高度滚动容器的真实高度
this.scrollBoxHeight = this.$refs.forwardContent ? this.$refs.forwardScrollBox.getBoundingClientRect().height : ''
// 可以滚动的高度
this.scrollableHeight = this.scrollContentHeight - this.scrollBoxHeight
this.autoScroll()
},
// 自动滚动
autoScroll() {
clearInterval(this.timer2)
this.timer2 = setInterval(() => {
if (this.scrollableHeight >= this.scrollTop) {
// 当为滚动到结尾时滚动
this.scrollTop = this.$refs.forwardScrollBox ? this.$refs.forwardScrollBox.scrollTop += 1 : ''
} else {
// 滚动结束,清除当前定时器,scrollTop重置为0,继续滚动
this.scrollTop = this.$refs.forwardScrollBox ? this.$refs.forwardScrollBox.scrollTop = 0 : ''
clearInterval(this.timer2)
this.autoScroll()
}
}, 100)
},
// 鼠标移入时停止滚动
mouseenter() {
clearInterval(this.timer2)
},
// 鼠标移开继续滚动
mouseleave() {
this.autoScroll()
},
// 滚动元素滚动时的方法
handleScroll(e) {
console.log(e.target.scrollTop)
}
}
}
</script>
<style scoped lang='scss'>
.conversion-left {
background-image: url('./../../../assets/images/bg-1.png');
background-repeat: no-repeat;
background-size: 100% 100%;
//background: forestgreen;
padding: 0 1.2vw;
width: 35vw;
height: 85vh;
.component {
//padding: 0.5vw 0;
//font-family: Source Han Sans CN, Source Han Sans CN-Regular;
letter-spacing: 0.1vw;
.titles {
//display: flex;
//justify-content: space-between;
display: grid;
grid-template-columns:28% 54% 18%;
font-size: 0.9vw;
}
.list_dv::-webkit-scrollbar {
display: none;
}
.list_dv {
width: 100%;
height: 77vh;
overflow-y: auto;
font-size: 0.6vw;
color: #d4eaf6;
.list_item {
width: 100%;
height: 3.5vh;
line-height: 3.5vh;
//height: 26px;
//margin-bottom: 1vw;
.dataList {
display: grid;
grid-template-columns: 28% 54% 18%;
cursor: pointer;
div{
width: 100%;
&:nth-child(2){
width: 93%;
overflow: hidden; //超出隐藏
white-space: nowrap; //不折行
text-overflow: ellipsis; //溢出显示省略号
}
}
}
.selectMerchant {
background: #6578FF;
}
}
}
}
}
</style>