337 lines
7.6 KiB
Vue
337 lines
7.6 KiB
Vue
<template>
|
||
<view class="card-wallet">
|
||
<!-- 搜索区 -->
|
||
<view class="search-bar">
|
||
<view class="search-input-wrap">
|
||
<input class="search-input" confirm-type="search" :value="keyword"
|
||
placeholder="搜索姓名 / 手机 / 公司" @confirm="onSearch" @input="onKeywordInput" />
|
||
<text v-if="keyword" class="search-clear" @tap="clearKeyword">✕</text>
|
||
<text class="iconfont icon-sousuo3" @tap="onSearch"></text>
|
||
</view>
|
||
<view class="claim-btn create-btn" @tap="goCreate">新建</view>
|
||
<view class="claim-btn apply-btn" v-if="!isLoading && list.length === 0" @tap="goApply">申请</view>
|
||
<view class="claim-btn" @tap="onClaimTap">认领</view>
|
||
</view>
|
||
|
||
<!-- 列表 -->
|
||
<view class="card-list">
|
||
<view v-for="(item, index) in list" :key="item.id || index" class="card-item"
|
||
@tap="goDetail(item)">
|
||
<view class="card-avatar">
|
||
<text>{{ avatarText(item.name) }}</text>
|
||
</view>
|
||
<view class="card-info">
|
||
<view class="card-name line1">{{ item.name || '未命名名片' }}</view>
|
||
<view class="card-sub line1" v-if="item.job_title || item.company">
|
||
{{ [item.job_title, item.company].filter(Boolean).join(' · ') }}
|
||
</view>
|
||
<view class="card-mobile" v-if="item.mobile">📱 {{ item.mobile }}</view>
|
||
</view>
|
||
<view class="card-arrow">›</view>
|
||
</view>
|
||
|
||
<!-- 加载状态 -->
|
||
<view class="load-more" v-if="list.length > 0">
|
||
<text v-if="isLoading">加载中…</text>
|
||
<text v-else-if="page < pageCount">上拉加载更多</text>
|
||
<text v-else class="load-end">— 没有更多了 —</text>
|
||
</view>
|
||
|
||
<!-- 空态 -->
|
||
<ns-empty v-if="!isLoading && list.length === 0" :isIndex="false"
|
||
:text="emptyText"></ns-empty>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
data() {
|
||
return {
|
||
list: [],
|
||
page: 1,
|
||
pageSize: 20,
|
||
pageCount: 1,
|
||
count: 0,
|
||
keyword: '',
|
||
isLoading: false,
|
||
emptyText: '暂无名片,可「新建」「申请」或「认领」添加'
|
||
};
|
||
},
|
||
onLoad() {
|
||
this.refresh();
|
||
},
|
||
onPullDownRefresh() {
|
||
this.refresh(() => uni.stopPullDownRefresh());
|
||
},
|
||
onReachBottom() {
|
||
if (this.isLoading) return;
|
||
if (this.page >= this.pageCount) return;
|
||
this.loadPage(this.page + 1);
|
||
},
|
||
methods: {
|
||
avatarText(name) {
|
||
return (name || '?').trim().charAt(0).toUpperCase();
|
||
},
|
||
onKeywordInput(e) {
|
||
this.keyword = e.detail.value;
|
||
},
|
||
onSearch() {
|
||
this.refresh();
|
||
},
|
||
clearKeyword() {
|
||
this.keyword = '';
|
||
this.refresh();
|
||
},
|
||
refresh(done) {
|
||
this.page = 1;
|
||
this.loadPage(1, done);
|
||
},
|
||
loadPage(pageNo, done) {
|
||
this.isLoading = true;
|
||
this.$api.sendRequest({
|
||
url: '/card/api/card/lists',
|
||
data: {
|
||
page: pageNo,
|
||
page_size: this.pageSize,
|
||
keyword: this.keyword.trim()
|
||
},
|
||
success: res => {
|
||
if (res.code == 0) {
|
||
const data = res.data || {};
|
||
const rows = data.list || [];
|
||
this.pageCount = data.page_count || 1;
|
||
this.count = data.count || 0;
|
||
this.page = pageNo;
|
||
this.list = pageNo === 1 ? rows : this.list.concat(rows);
|
||
this.emptyText = this.keyword.trim()
|
||
? '未找到匹配的名片'
|
||
: '暂无名片,可「新建」「申请」或「认领」添加';
|
||
} else {
|
||
this.handleApiError(res);
|
||
}
|
||
this.isLoading = false;
|
||
typeof done === 'function' && done();
|
||
},
|
||
fail: () => {
|
||
this.isLoading = false;
|
||
uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
|
||
typeof done === 'function' && done();
|
||
}
|
||
});
|
||
},
|
||
goDetail(item) {
|
||
if (!item.card_id) return;
|
||
uni.navigateTo({
|
||
url: '/pages_tool/card/detail?card_id=' + encodeURIComponent(item.card_id)
|
||
});
|
||
},
|
||
goCreate() {
|
||
uni.navigateTo({
|
||
url: '/pages_tool/card/edit'
|
||
});
|
||
},
|
||
// 员工已注册但没有名片时, 向商家提交建卡申请(商家后台审批后自动归属)
|
||
goApply() {
|
||
uni.navigateTo({
|
||
url: '/pages_tool/card/apply'
|
||
});
|
||
},
|
||
onClaimTap() {
|
||
uni.showModal({
|
||
title: '认领名片',
|
||
editable: true,
|
||
placeholderText: '粘贴领取码或名片编号(card_id)',
|
||
success: res => {
|
||
if (!res.confirm) return;
|
||
const cardId = (res.content || '').trim();
|
||
if (!cardId) {
|
||
uni.showToast({ title: '请输入名片编号', icon: 'none' });
|
||
return;
|
||
}
|
||
this.doClaim(cardId);
|
||
}
|
||
});
|
||
},
|
||
doClaim(codeOrCardId) {
|
||
uni.showLoading({ title: '认领中…' });
|
||
this.$api.sendRequest({
|
||
url: '/card/api/card/claim',
|
||
// 同值双传: 后端按领取码优先解析, 未命中回落 card_id
|
||
data: { claim_code: codeOrCardId, card_id: codeOrCardId },
|
||
success: res => {
|
||
uni.hideLoading();
|
||
if (res.code == 0) {
|
||
const claimed = res.data && res.data.claimed === false;
|
||
uni.showToast({
|
||
title: claimed ? '该名片已在您的名片夹中' : '认领成功',
|
||
icon: 'success'
|
||
});
|
||
this.refresh();
|
||
} else {
|
||
this.handleApiError(res);
|
||
}
|
||
},
|
||
fail: () => {
|
||
uni.hideLoading();
|
||
uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
|
||
}
|
||
});
|
||
},
|
||
handleApiError(res) {
|
||
const msg = (res && res.message) || '操作失败';
|
||
// 未登录/凭证失效时引导登录(与全站约定一致:code < 0)
|
||
if (res && res.code < 0) {
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
return;
|
||
}
|
||
uni.showToast({ title: msg, icon: 'none' });
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.card-wallet {
|
||
min-height: 100vh;
|
||
background-color: #f6f7f9;
|
||
padding: 20rpx 24rpx 40rpx;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.search-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
margin-bottom: 20rpx;
|
||
|
||
.search-input-wrap {
|
||
flex: 1;
|
||
display: flex;
|
||
align-items: center;
|
||
background-color: #ffffff;
|
||
border-radius: 36rpx;
|
||
padding: 0 24rpx;
|
||
height: 72rpx;
|
||
|
||
.search-input {
|
||
flex: 1;
|
||
height: 72rpx;
|
||
font-size: 28rpx;
|
||
color: #333;
|
||
}
|
||
|
||
.search-clear {
|
||
padding: 0 12rpx;
|
||
color: #bbb;
|
||
font-size: 28rpx;
|
||
}
|
||
|
||
.iconfont {
|
||
color: #999;
|
||
font-size: 32rpx;
|
||
padding-left: 12rpx;
|
||
}
|
||
}
|
||
|
||
.claim-btn {
|
||
margin-left: 20rpx;
|
||
height: 72rpx;
|
||
line-height: 72rpx;
|
||
padding: 0 30rpx;
|
||
background-color: var(--main-color, #0054a5);
|
||
color: #ffffff;
|
||
font-size: 28rpx;
|
||
border-radius: 36rpx;
|
||
|
||
/* 「新建」次级按钮: 主按钮同构, 淡底弱化一档 */
|
||
&.create-btn {
|
||
background-color: var(--main-color-shallow, #e8f1fb);
|
||
color: var(--main-color, #0054a5);
|
||
}
|
||
|
||
/* 「申请」: 仅空态出现的第三入口, 边框幽灵式再弱一档 */
|
||
&.apply-btn {
|
||
background-color: #ffffff;
|
||
color: #666666;
|
||
border: 1rpx solid #dcdfe6;
|
||
}
|
||
}
|
||
}
|
||
|
||
.card-list {
|
||
.card-item {
|
||
display: flex;
|
||
align-items: center;
|
||
background-color: #ffffff;
|
||
border-radius: 16rpx;
|
||
padding: 28rpx 24rpx;
|
||
margin-bottom: 20rpx;
|
||
|
||
&:active {
|
||
background-color: #f0f2f5;
|
||
}
|
||
|
||
.card-avatar {
|
||
width: 88rpx;
|
||
height: 88rpx;
|
||
border-radius: 50%;
|
||
background-color: var(--main-color-shallow, #e8f1fb);
|
||
color: var(--main-color, #0054a5);
|
||
font-size: 36rpx;
|
||
font-weight: 600;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
flex-shrink: 0;
|
||
margin-right: 24rpx;
|
||
}
|
||
|
||
.card-info {
|
||
flex: 1;
|
||
min-width: 0;
|
||
|
||
.card-name {
|
||
font-size: 32rpx;
|
||
font-weight: 600;
|
||
color: #333;
|
||
}
|
||
|
||
.card-sub {
|
||
font-size: 26rpx;
|
||
color: #666;
|
||
margin-top: 8rpx;
|
||
}
|
||
|
||
.card-mobile {
|
||
font-size: 26rpx;
|
||
color: #999;
|
||
margin-top: 8rpx;
|
||
}
|
||
}
|
||
|
||
.card-arrow {
|
||
color: #ccc;
|
||
font-size: 40rpx;
|
||
margin-left: 16rpx;
|
||
}
|
||
}
|
||
}
|
||
|
||
.load-more {
|
||
text-align: center;
|
||
color: #999;
|
||
font-size: 24rpx;
|
||
padding: 24rpx 0;
|
||
|
||
.load-end {
|
||
color: #ccc;
|
||
}
|
||
}
|
||
|
||
.line1 {
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
</style>
|