2020-06-08 15:23:23 +08:00
|
|
|
|
<template>
|
|
|
|
|
<view class="collection-item">
|
2020-06-24 16:39:31 +08:00
|
|
|
|
<u-empty mode="list" v-if="!list.length" color="#000" img-width="200" font-size="30" margin-top="300"></u-empty>
|
2020-06-08 15:23:23 +08:00
|
|
|
|
<u-swipe-action
|
|
|
|
|
v-for="(item, index) in list" :key="index"
|
2020-08-07 11:59:08 +08:00
|
|
|
|
:index='index'
|
2020-06-08 15:23:23 +08:00
|
|
|
|
:show="item.show"
|
|
|
|
|
:options="options"
|
2020-07-01 17:32:36 +08:00
|
|
|
|
@click="removeFavorite"
|
2020-06-08 15:23:23 +08:00
|
|
|
|
@open="open"
|
|
|
|
|
>
|
2020-08-07 17:34:59 +08:00
|
|
|
|
<view class="item u-border-bottom" @click="viewGoodsDetails(item)">
|
2020-08-03 20:59:24 +08:00
|
|
|
|
<image :src="item.goods_image"></image>
|
2020-06-08 15:23:23 +08:00
|
|
|
|
<!-- 此层wrap在此为必写的,否则可能会出现标题定位错误 -->
|
|
|
|
|
<view class="title-wrap">
|
2020-08-03 20:59:24 +08:00
|
|
|
|
<view class="item-top u-line-2">{{ item.goods_name }}</view>
|
2020-06-08 15:23:23 +08:00
|
|
|
|
<view class="item-bottom">
|
2020-08-03 20:59:24 +08:00
|
|
|
|
<view class="item-price">¥{{ item.favlog_price }}</view>
|
2020-06-08 15:23:23 +08:00
|
|
|
|
<view class="item-date">
|
|
|
|
|
<image src="@/pageE/static/mine/26.png"></image>
|
2020-08-07 11:59:08 +08:00
|
|
|
|
<view>{{ item.fav_time | date }}</view>
|
2020-06-08 15:23:23 +08:00
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</u-swipe-action>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
export default {
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2020-08-03 20:59:24 +08:00
|
|
|
|
list: [],
|
2020-06-08 15:23:23 +08:00
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
text: '删除',
|
|
|
|
|
style: {
|
|
|
|
|
backgroundColor: '#FF3131'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-06-24 16:39:31 +08:00
|
|
|
|
mounted() {
|
|
|
|
|
this.getGoodsFavoritesList();
|
|
|
|
|
},
|
2020-06-08 15:23:23 +08:00
|
|
|
|
methods: {
|
2020-08-07 17:34:59 +08:00
|
|
|
|
viewGoodsDetails(item) {
|
|
|
|
|
const list = this.list.filter(item => {
|
|
|
|
|
return item.show;
|
|
|
|
|
})
|
|
|
|
|
if(list.length) return false;
|
|
|
|
|
this.$u.route({
|
|
|
|
|
url: 'pageB/sdetails/index',
|
|
|
|
|
params: {
|
|
|
|
|
id: item.fav_id,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2020-06-24 16:39:31 +08:00
|
|
|
|
getGoodsFavoritesList() {
|
2020-07-01 17:32:36 +08:00
|
|
|
|
this.$u.api.getFavoritesList().then(res => {
|
2020-08-03 20:59:24 +08:00
|
|
|
|
if(res.errCode == 0) {
|
|
|
|
|
this.list = res.data;
|
2020-08-07 11:59:08 +08:00
|
|
|
|
this.list.forEach(item => {
|
|
|
|
|
Object.assign(item, { show: false });
|
|
|
|
|
})
|
2020-08-03 20:59:24 +08:00
|
|
|
|
}
|
2020-07-01 17:32:36 +08:00
|
|
|
|
})
|
|
|
|
|
},
|
2020-08-07 11:59:08 +08:00
|
|
|
|
removeFavorite(index) {
|
|
|
|
|
const id = this.list[index].fav_id;
|
2020-07-01 17:32:36 +08:00
|
|
|
|
this.$u.api.removeFavorite({
|
2020-08-07 11:59:08 +08:00
|
|
|
|
fid: id,
|
|
|
|
|
type: 'goods'
|
2020-07-01 17:32:36 +08:00
|
|
|
|
}).then(res => {
|
2020-06-24 16:39:31 +08:00
|
|
|
|
if(res.errCode == 0) {
|
2020-07-01 17:32:36 +08:00
|
|
|
|
this.getGoodsFavoritesList();
|
2020-08-07 11:59:08 +08:00
|
|
|
|
} else {
|
|
|
|
|
this.$u.toast(res.message);
|
2020-06-24 16:39:31 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
2020-06-08 15:23:23 +08:00
|
|
|
|
open(index) {
|
|
|
|
|
// 先将正在被操作的swipeAction标记为打开状态,否则由于props的特性限制,
|
|
|
|
|
// 原本为'false',再次设置为'false'会无效
|
|
|
|
|
this.list[index].show = true;
|
|
|
|
|
this.list.map((val, idx) => {
|
|
|
|
|
if(index != idx) this.list[idx].show = false;
|
|
|
|
|
})
|
2020-08-07 17:34:59 +08:00
|
|
|
|
this.$forceUpdate();
|
2020-06-08 15:23:23 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.collection-item {
|
|
|
|
|
.item {
|
|
|
|
|
padding: 30rpx;
|
|
|
|
|
display: flex;
|
|
|
|
|
> image {
|
|
|
|
|
width: 180rpx;
|
|
|
|
|
height: 160rpx;
|
|
|
|
|
border-radius: 10rpx;
|
|
|
|
|
margin-right: 30rpx;
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
}
|
|
|
|
|
.title-wrap {
|
2020-08-08 12:07:50 +08:00
|
|
|
|
flex: 1;
|
2020-06-08 15:23:23 +08:00
|
|
|
|
.item-top {
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
color: rgba(51,51,51,1);
|
|
|
|
|
line-height: 44rpx;
|
|
|
|
|
margin-bottom: 54rpx;
|
|
|
|
|
}
|
|
|
|
|
.item-bottom {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
.item-price {
|
|
|
|
|
font-size: 30rpx;
|
|
|
|
|
color: rgba(51,51,51,1);
|
|
|
|
|
}
|
|
|
|
|
.item-date {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
> image {
|
|
|
|
|
margin-right: 25rpx;
|
|
|
|
|
width: 24rpx;
|
|
|
|
|
height: 24rpx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|