fav-product-list.vue
3.99 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="fav-type show" v-infinite-scroll="loadMore()" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
<ul class="fav-product-list">
<li v-for="item in productData" track-by="fav_id">
<div class="fav-del {{editmodel ? 'show': ''}}">
<button @click="delProduct($index, item.fav_id)">删除</button>
</div>
<a :href="item.link">
<div class="fav-img-box">
<img :src="item.imgUrl" alt=""/>
</div>
<div class="fav-info-list">
<span class="title">{{item.title}}</span>
<br/>
<div class="fav-price">
<span class="new-price" v-if="item.discountPrice">{{item.discountPrice}}</span>
<span class="fav-price {{ item.discountPrice ? 'price-underline' : ''}}">{{item.price}}</span>
</div>
<br/>
<div class="save-price">
<span class="sell-out" v-if="item.sellOut || item.invalidGoods">{{item.sellOut ? '已售罄' : '已下架'}}</span>
</div>
</div>
</a>
</li>
</ul>
<div class="fav-null-box {{ nullbox }}">
<span class="fav-null">您暂无收藏任何商品}}</span>
<a slot="go-shopping" class="go-shopping" :href="productUrl">随便逛逛</a>
</div>
</div>
</template>
<script>
const $ = require('yoho-jquery');
const tip = require('common/tip');
const Loading = require('common/loading');
const modal = require('common/modal');
const loading = new Loading();
module.exports = {
props: ['productUrl'],
data() {
return {
nullbox : 'hide',
busy: false,
editmodel: false,
page: 0,
productData: []
};
},
methods: {
loadMore: function() {
loading.show();
let _this = this;
this.busy = true;
$.ajax({
url: '/home/favorite/favpaging',
data: {
page : ++_this.page
}
}).then(result => {
if (result.length) {
result.forEach(function(o){
_this.productData.push(o);
});
_this.busy = false;
} else {
_this.busy = true;
}
_this.nullbox = _this.productData.length ? "hide" : "";
loading.hide();
}).fail(() => {
tip('网络错误');
});
},
editProduct(action) {
this.editmodel = action;
},
delProduct(index, id) {
let _this = this;
$.modal.confirm('', '确定刪除该收藏吗?', function() {
this.hide();
$.ajax({
method: 'post',
url: '/home/favorite/favdel',
data: {
id: id
}
}).then(function(data) {
if (data.code === 200) {
_this.productData.splice(index, 1);
} else if (data.code === 400) {
$.modal.alert(data.message, '出错了!');
} else {
$.modal.alert('', '取消收藏失败');
}
}).fail(function() {
$.modal.alert('', '网络错误');
});
});
}
}
};
</script>