<template>
<view>
<cu-custom bgColor="bg-gradual-white" :isBack="true">
<block slot="backText">我的收藏</block>
</cu-custom>
<view class="top">
<view>
加油站
</view>
<view class="editing-container" :class="{ 'editing': !isEditing, 'completed': isEditing }"
@click="toggleEditing">
<view v-if="!isEditing">
<u-icon name="edit-pen" color="#FD893F" size="24"></u-icon>
<text class="editing-text">编辑</text>
</view>
<view v-else>
<text class="completed-text">完成</text>
</view>
</view>
</view>
<view style="padding-bottom: 150rpx;">
<view class="middle">
<view v-if="list.length > 0" class="card-content" v-for="(item, index) in list" :key="item.id">
<view class="content-left" style="">
<checkbox-group @change="updateAllSelected(item)">
<checkbox v-if="isEditing" :checked="item.isCollect"
style="margin-right: 20rpx; transform:scale(1.3)"></checkbox>
</checkbox-group>
<view>
<view class="title">
<view class="left">
<image class="img" src="https://static.taidoukeji.cn/wxchat/yww/oilIcon.png"
mode=""></image>
<view class="name">
{{item.shopName||'-'}}
<!-- <span>({{item.map}})</span> -->
</view>
</view>
</view>
<view class="address">
{{item.address||'-'}}
</view>
</view>
</view>
</view>
</view>
</view>
<view v-if="list.length == 0" class="nodata">
<image src="https://static.youwangs.com/imges/yww_user/null.png" class="nodataImg"></image>
<view class="f14 c333 f_Regular">暂无数据</view>
</view>
<view class="bottom" v-if="isEditing">
<view>
<checkbox-group @change="selectAll">
<checkbox style=" transform:scale(1.3)" :checked="allSelected"></checkbox>
</checkbox-group>
<view class="allcheck">
全选
</view>
</view>
<view class="btn" @click="cancelCollection">取消收藏</view>
</view>
</view>
</template>
<script>
import {
collectList,
cancelFavoriteBatchIds
} from '@/api/oilApi.js'
export default {
data() {
return {
allSelected: false, // 用于跟踪是否所有项都被选中
list: [],
pageNo: 1,
pageSize: 10,
total: 0,
isEditing: false, // 控制编辑模式的新变量
noData: false,
};
},
onLoad() {
this.getCollectList()
},
onReachBottom() {
if (this.list.length < this.total) {
this.getCollectList(); // 加载下一页
}
},
methods: {
// 编辑
toggleEditing() {
this.isEditing = !this.isEditing;
},
// 收藏列表
getCollectList() {
let that = this;
let params = {
customId: getApp().globalData.customId,
pageNo: this.pageNo,
pageSize: this.pageSize,
}
collectList(params).then(res => {
this.total = res.data.data.total
this.pageNo = this.pageNo + 1; // 更新页数
this.list = this.list.concat(res.data.data.list);
})
},
// 单选
updateAllSelected(item) {
this.list.forEach(i => {
if (i.id === item.id) {
i.isCollect = !i.isCollect
}
})
if (this.list.every(i => i.isCollect === true)) {
this.allSelected = true
} else {
this.allSelected = false
}
},
// 全选
selectAll(e) {
this.allSelected = !this.allSelected
this.list.forEach(i => i.isCollect = this.allSelected)
},
// 取消收藏
cancelCollection() {
let shopIds = this.list.filter(item => item.isCollect).map(item => item.shopId);
if (shopIds.length === 0) return;
cancelFavoriteBatchIds({
shopIds: shopIds.join(',')
}).then(res => {
this.pageNo = 1; // 重置页码
this.list = []; // 清空列表
this.allSelected = false; // 重置全选状态
this.getCollectList(); // 重新加载数据
})
}
}
}
</script>
<style lang="scss">
/deep/ radio::before,
checkbox::before {
right: 1rpx;
font-size: 26rpx;
line-height: 20rpx;
}
.bottom {
padding: 25rpx 30rpx 25rpx 67rpx;
width: 100%;
position: fixed;
bottom: var(--window-bottom);
height: 154rpx;
background: #FFFFFF;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: border-box;
box-shadow: #999999;
& view:nth-child(1) {
display: flex;
.allcheck {
margin-left: 30rpx;
}
}
.btn {
text-align: center;
line-height: 80rpx;
color: #fff;
width: 258rpx;
height: 80rpx;
font-size: 32rpx;
background: #FD893F;
border-radius: 200rpx 200rpx 200rpx 200rpx;
}
}
.top {
padding: 20rpx 34rpx 14rpx 34rpx;
display: flex;
justify-content: space-between;
align-items: center;
& view:nth-child(1) {
font-family: PingFang SC, PingFang SC;
font-weight: 800;
font-size: 32rpx;
color: #1A1D1F;
}
.editing-container {
background: rgba(253, 137, 63, 0.3);
border-radius: 200rpx;
width: 160rpx;
height: 62rpx;
line-height: 62rpx;
& view:nth-child(1) {
display: flex;
justify-content: center;
text-align: center;
font-size: 28rpx;
color: #FD893F;
}
}
.completed {
background-color: #FD893F;
justify-content: center;
}
.editing-text {
font-size: 28rpx;
color: #FD893F;
}
.completed-text {
font-size: 28rpx;
color: #ffffff;
}
}
.middle {
padding: 10rpx 34rpx 10rpx 34rpx;
.card-content {
width: 100%;
padding: 20rpx 34rpx 20rpx 34rpx;
background: #FFFFFF;
border-radius: 16rpx 16rpx 16rpx 16rpx;
margin-bottom: 28rpx;
display: flex;
align-items: center;
.content-left {
display: flex;
flex: 1;
align-items: center;
.title {
display: flex;
justify-content: space-between;
// flex: 1, 1, 2;
margin-bottom: 28rpx;
align-items: center;
.left {
display: flex;
.img {
width: 48rpx;
height: 44rpx;
margin-right: 10rpx;
}
.name {
font-family: PingFang SC, PingFang SC;
font-weight: bold;
font-size: 28rpx;
color: #000000;
& span {
margin-left: 10rpx;
}
}
}
}
}
.address {
font-family: PingFang SC, PingFang SC;
font-weight: 500;
font-size: 24rpx;
color: #999999;
}
}
}
.nodata {
padding-top: 240rpx;
padding-bottom: 10rpx;
text-align: center;
.nodataImg {
width: 348rpx;
height: 348rpx;
}
}
</style>