records.vue
10.1 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<template>
<div>
<div v-if="hasdata">
<!--<div class='title-wrap'>浏览记录<span class='clear' v-touch:tap="clearAllRecords">清空</span></div>-->
<div class='nav'>
<div class="fixed">
<span :class="{focus2:cate.focus}" v-for="cate in category" :key="cate.category_id"
v-touch:tap="focusCate(cate.category_id,$index, $event)">{{cate.category_name}}</span>
</div>
</div>
<swiper-list :list="list" :showbutton="showbutton" :hidebutton="hidebutton"
:deleteSkn="deleteskn"></swiper-list>
</div>
<div v-if="nodata">
<!--<div class='title-wrap'>浏览记录</div>-->
<div class="nodata">
<i></i>
<div class="tip1">暂无浏览记录</div>
<div class="tip2">You have no recently viewed items</div>
<a class="go" href="/product/new">随便逛逛</a>
</div>
</div>
</div>
</template>
<script>
import yoho from 'yoho';
import $ from 'jquery';
import swiperList from 'component/me/swiperList.vue';
import modal from 'common/modal';
import interceptClick from 'common/intercept-click';
let originList, originCategory, categoryLen;
export default {
data() {
return {
list: [],
category: [],
hasdata: 0,
nodata: 0
};
},
components: {
swiperList
},
methods: {
imgerror() {
// 图片报错时,给个默认透明图片
this.headIco = 'data:image/png;base64,R0lGODlhFAAUAIAAAP///wAAACH5BAEAAAAALAAAAAAUABQAAAIRhI+py+0Po5y02ouz3rz7rxUAOw==';
},
reload() {
if (yoho.isLogin()) {
$.ajax({
url: '/me/recordDataNew'
}).then(result => {
if (result.data && result.data.total) {
originList = result.data.product_list;
let list = originList;
for (let i = 0; i < list.length; i++) {
list[i].image = list[i].image.replace(/(\{width\}x\{\height})/g, '150x203');
list[i].isshowbtn = false;
list[i].show = true;
}
this.list = list;
originCategory = result.data.category_list;
originCategory.forEach(function(item) {
item.focus = false;
});
originCategory.splice(0, 0, {
category_name: '全部',
focus: true,
category_id: 0
});
categoryLen = originCategory.length;
this.category = originCategory;
this.hasdata = 1;
this.nodata = 0;
// 绑定清空事件
yoho.addNativeMethod('clearRecords', this.clearAllRecords);
} else {
this.nodata = 1;
this.hasdata = 0;
}
});
}
},
showbutton(i) {
event.preventDefault();
this.list[i].isshowbtn = true;
},
hidebutton(i) {
event.preventDefault();
this.list[i].isshowbtn = false;
},
deleteskn(i) {
event.preventDefault();
let id = this.list[i].category_id;
let skn = this.list[i].product_skn;
this.list.splice(i, 1);
for (let j in originList) {
if (originList[j].product_skn === skn) {
originList.splice(j, 1);
}
}
if (!originList.length) {
this.nodata = 1;
this.hasdata = 0;
this.updateNavBar();
} else {
let deleteId = true;
for (let k in this.list) {
if (this.list[k].category_id === id) {
deleteId = false;
}
}
if (deleteId) {
for (let w = 0; w < categoryLen; w++) {
if (this.category[w].category_id === id) {
this.category.splice(w, 1);
categoryLen--;
// 更新页面
this.refreshRecords();
break;
}
}
}
}
$.ajax({
url: '/me/deleteRecordData',
data: {
skn: skn
}
}).then(() => {});
},
clearAllRecords() {
let that = this;
let name, id, index;
// 寻找类别
for (let i = 0; i < categoryLen; i++) {
if (this.category[i].focus === true) {
name = this.category[i].category_name;
id = this.category[i].category_id;
index = i;
break;
}
}
// 弹出框
modal.confirm('确定清空"' + name + '"下的浏览记录', '确定清空?', function() {
let skn = [];
for (let i in that.list) {
skn.push(that.list[i].product_skn);
}
// 删除商品
function deepDelete() {
for (let i in originList) {
if (originList[i].category_id === id) {
originList.splice(i, 1);
deepDelete();
}
}
}
deepDelete();
// 删除标签
that.category.splice(index, 1);
categoryLen--;
// 是否没有数据了
if (!index || !originList.length) {
that.nodata = 1;
that.hasdata = 0;
that.updateNavBar();
} else {
// 更新页面
that.refreshRecords();
}
$.ajax({
url: '/me/deleteRecordData',
data: {
skn: skn
}
}).then(() => {
});
this.hide();
return false;
});
},
focusCate(id, index, event) {
if (event) {
let el = event.target;
event.preventDefault();
// 标签移动
if (el.getBoundingClientRect().right > window.innerWidth) {
el.parentNode.scrollLeft += el.getBoundingClientRect().right - window.innerWidth + 10;
}
}
let list = Object.assign([], originList);
let newList;
if (id) {
newList = list.filter(function(item) {
return item.category_id === id;
});
} else {
newList = list;
}
this.list = newList;
for (let i = 0; i < categoryLen; i++) {
this.category[i].focus = false;
}
this.category[index].focus = true;
},
refreshRecords() {
this.list = originList;
this.focusCate(0, 0);
},
updateNavBar() {
const header = Object.assign({}, interceptClick.defaultTitleMap[3]);
header.right.des = '';
yoho.updateNavigationBar({
header: header
});
}
},
ready() {
this.reload();
$('#setting').on('click', function() {
yoho.goSetting();
return false;
});
document.addEventListener('visibilitychange', () => {
if (!document.hidden) {
this.reload();
}
});
}
};
</script>
<style>
.title-wrap {
height: 94px;
font-size: 40px;
color: #000;
text-align: center;
line-height: 94px;
.clear {
position: absolute;
right: 0;
color: #b0b0b0;
margin: 30px 30px 0 0;
font-size: 30px;
line-height: 1;
}
}
.nav {
position: relative;
height: 88px;
.fixed {
position: fixed;
height: 88px;
width: 100%;
border-bottom: 1px solid #eee;
border-top: 1px solid #eee;
line-height: 88px;
overflow-x: auto;
white-space: nowrap;
z-index: 10;
background: #fff;
}
span {
padding: 8px 20px;
color: #b0b0b0;
border: 2px solid #b0b0b0;
border-radius: 20px;
font-size: 22px;
line-height: 22px;
margin-left: 30px;
}
.focus2 {
border-color: #000;
color: #000;
}
}
.nodata {
color: #b0b0b0;
i {
width: 207px;
height: 183px;
background: resolve("me/norecords.png") no-repeat;
display: block;
background-size: 100% 100%;
margin: 300px auto 56px;
}
.tip1 {
font-size: 34px;
text-align: center;
}
.tip2 {
font-size: 20px;
margin-top: 32px;
text-align: center;
margin-bottom: 60px;
}
.go {
width: 414px;
height: 94px;
background: #000;
color: #fff;
line-height: 94px;
margin: auto;
text-align: center;
font-size: 28px;
display: block;
}
}
</style>