chore:名片删人脉解锁重新申请+收藏

This commit is contained in:
2026-10-15 11:11:09 +08:00
parent 5a009130e6
commit f41057a9ad

View File

@@ -12,6 +12,14 @@
<view class="claim-btn" @tap="onClaimTap">认领</view> <view class="claim-btn" @tap="onClaimTap">认领</view>
</view> </view>
<!-- 筛选条: 仅看收藏 -->
<view class="filter-row">
<view class="fav-filter" :class="{ active: onlyFav }" @tap="toggleFavFilter">
<text class="fav-filter-icon">{{ onlyFav ? '★' : '☆' }}</text>
<text>{{ onlyFav ? '仅看收藏' : '全部名片' }}</text>
</view>
</view>
<!-- 列表 --> <!-- 列表 -->
<view class="card-list"> <view class="card-list">
<view v-for="(item, index) in list" :key="item.id || index" class="card-item" <view v-for="(item, index) in list" :key="item.id || index" class="card-item"
@@ -26,6 +34,9 @@
</view> </view>
<view class="card-mobile" v-if="item.mobile">📱 {{ item.mobile }}</view> <view class="card-mobile" v-if="item.mobile">📱 {{ item.mobile }}</view>
</view> </view>
<!-- 收藏星标: 实心=已收藏, 空心=未收藏; 单独点击不进详情 -->
<text class="card-fav" :class="{ 'is-fav': item.is_favorite == 1 }"
@tap.stop="toggleFavorite(item)">{{ item.is_favorite == 1 ? '★' : '☆' }}</text>
<view class="card-arrow">›</view> <view class="card-arrow">›</view>
</view> </view>
@@ -53,6 +64,7 @@ export default {
pageCount: 1, pageCount: 1,
count: 0, count: 0,
keyword: '', keyword: '',
onlyFav: false,
isLoading: false, isLoading: false,
emptyText: '暂无名片,可点击右上角「新建」或「认领」添加' emptyText: '暂无名片,可点击右上角「新建」或「认领」添加'
}; };
@@ -82,18 +94,65 @@ export default {
this.keyword = ''; this.keyword = '';
this.refresh(); this.refresh();
}, },
// 仅看收藏筛选开关(列表筛选, favorite=1; 可与 keyword 叠加)
toggleFavFilter() {
this.onlyFav = !this.onlyFav;
this.refresh();
},
/**
* 切换收藏(双向 toggle): 直接调, 用返回的 is_favorite 回填。
* 乐观更新 + 失败回滚; 仅看收藏模式下取消收藏则从列表移除该行。
*/
toggleFavorite(item) {
if (!item) return;
const cardId = this.cardIdOf(item);
if (!cardId) {
uni.showToast({ title: '该名片缺少编号,无法收藏', icon: 'none' });
return;
}
const prev = item.is_favorite == 1 ? 1 : 0;
// 乐观翻转
this.$set(item, 'is_favorite', prev ? 0 : 1);
this.$cardApi.cardToggleFavorite({
data: { card_id: cardId },
success: res => {
if (res.code == 0) {
const d = res.data || {};
const next = d.is_favorite == 1 ? 1 : 0;
this.$set(item, 'is_favorite', next);
// 仅看收藏模式下取消收藏 → 从列表移除
if (this.onlyFav && next === 0) {
const idx = this.list.indexOf(item);
if (idx >= 0) this.list.splice(idx, 1);
}
} else {
// 「名片不存在」/「非自己名下卡」等拒绝场景: 回滚 + 直接 toast message
this.$set(item, 'is_favorite', prev);
if (res.message) uni.showToast({ title: res.message, icon: 'none' });
}
},
fail: () => {
this.$set(item, 'is_favorite', prev);
uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
}
});
},
refresh(done) { refresh(done) {
this.page = 1; this.page = 1;
this.loadPage(1, done); this.loadPage(1, done);
}, },
loadPage(pageNo, done) { loadPage(pageNo, done) {
this.isLoading = true; this.isLoading = true;
// 列表筛选: favorite=1 只返回星标卡(后端 2.9.12); 不传/非1 返回全部。
// 与现有 page/keyword 一并放 body(TP6 param() 合并 query+body, 等效 ?favorite=1)。
const reqData = {
page: pageNo,
page_size: this.pageSize,
keyword: this.keyword.trim()
};
if (this.onlyFav) reqData.favorite = 1;
this.$cardApi.cardLists({ this.$cardApi.cardLists({
data: { data: reqData,
page: pageNo,
page_size: this.pageSize,
keyword: this.keyword.trim()
},
success: res => { success: res => {
if (res.code == 0) { if (res.code == 0) {
const data = res.data || {}; const data = res.data || {};
@@ -259,6 +318,40 @@ export default {
} }
} }
/* 筛选条: 仅看收藏 */
.filter-row {
display: flex;
margin-bottom: 20rpx;
}
.fav-filter {
display: inline-flex;
align-items: center;
height: 60rpx;
padding: 0 28rpx;
border-radius: 30rpx;
background-color: #ffffff;
color: #666;
font-size: 26rpx;
border: 1rpx solid #e5e5e5;
.fav-filter-icon {
margin-right: 8rpx;
font-size: 30rpx;
color: #ccc;
}
&.active {
background-color: #fff6e0;
border-color: #f5b301;
color: #c8860a;
.fav-filter-icon {
color: #f5b301;
}
}
}
.card-list { .card-list {
.card-item { .card-item {
display: flex; display: flex;
@@ -315,6 +408,20 @@ export default {
font-size: 40rpx; font-size: 40rpx;
margin-left: 16rpx; margin-left: 16rpx;
} }
/* 收藏星标: 空心=未收藏(灰), 实心=已收藏(金) */
.card-fav {
flex-shrink: 0;
font-size: 44rpx;
line-height: 1;
color: #ccc;
margin-left: 16rpx;
padding: 4rpx;
&.is-fav {
color: #f5b301;
}
}
} }
} }