linyongLynn 1 year ago
parent 2779b72dce
commit 595cc408ed

@ -1,12 +1,27 @@
<template>
<view class="library-container">
<view class="search-bar">
<u-search placeholder="书名/作者" v-model="keyword" :show-action="false" bg-color="#f5f5f5"
border-color="#e0e0e0" @search="searchBooks"></u-search>
<u-search
placeholder="书名/作者"
v-model="keyword"
:show-action="true"
action-text="搜索"
bg-color="#f5f5f5"
border-color="#e0e0e0"
@search="searchBooks"
@clear="clearSearch">
</u-search>
</view>
<view class="tabs-container">
<u-tabs :list="tabsList" :is-scroll="true" :current="currentTab" @change="tabChange" active-color="#73685c"></u-tabs>
<u-tabs
:list="tabsList"
:is-scroll="true"
:current="currentTab"
@change="tabChange"
active-color="#73685c"
:loading="tabsList.length <= 1">
</u-tabs>
</view>
<view class="book-list">
@ -68,7 +83,9 @@
totalPages: 1,
hasMore: true,
tabsList: [{
name: '全部'
name: '全部',
value: 'all',
id: 'all'
}],
bookList: []
}
@ -85,28 +102,37 @@
// 加载分类数据
loadCategories() {
this.$u.api.bookOther().then(res => {
console.log('分类接口返回数据:', res);
if (res && res.category) {
// 构建分类列表,第一个是"全部"
const categories = [{
name: '全部'
name: '全部',
value: 'all',
id: 'all'
}];
// 添加从接口获取的分类
if (Array.isArray(res.category)) {
res.category.forEach(categoryName => {
// 处理返回的分类数据(对象格式:{id: name})
if (typeof res.category === 'object' && !Array.isArray(res.category)) {
Object.keys(res.category).forEach(categoryId => {
const categoryName = res.category[categoryId];
categories.push({
name: categoryName
name: categoryName,
value: categoryName,
id: categoryId
});
});
}
this.tabsList = categories;
console.log('设置分类列表:', this.tabsList);
}
}).catch(err => {
console.error('获取分类失败:', err);
// 如果获取分类失败,使用默认分类
this.tabsList = [{
name: '全部'
name: '全部',
value: 'all',
id: 'all'
}];
}).finally(() => {
// 分类加载完成后,加载图书列表
@ -129,10 +155,12 @@
}
// 添加分类筛选
if (this.currentTab > 0) {
params.category = this.currentTab;
if (this.currentTab > 0 && this.tabsList[this.currentTab]) {
params.category = this.tabsList[this.currentTab].id;
console.log('使用分类筛选:', this.tabsList[this.currentTab]);
}
console.log('请求参数:', params);
this.$u.api.bookIndex(params).then(res => {
// 处理返回的数据结构
const bookData = res || {};
@ -181,13 +209,26 @@
// 搜索图书
searchBooks() {
console.log('搜索关键词:', this.keyword);
this.currentPage = 1;
// 搜索时重置分类选择
this.currentTab = 0;
this.loadBookList();
},
// 清空搜索
clearSearch() {
console.log('清空搜索');
this.keyword = '';
this.currentPage = 1;
this.currentTab = 0;
this.loadBookList();
},
// 分类切换
tabChange(index) {
this.currentTab = index;
console.log('切换到分类:', index, this.tabsList[index]);
this.currentTab = index;
this.currentPage = 1;
this.loadBookList();
},
@ -220,10 +261,12 @@
.search-bar {
padding: 20rpx 30rpx;
background-color: #fff;
border-bottom: 1rpx solid #f0f0f0;
}
.tabs-container {
border-top: 1rpx solid #eee;
background-color: #fff;
border-bottom: 1rpx solid #f0f0f0;
}
.book-list {

@ -61,14 +61,14 @@
<u-icon name="chat-fill" color="#07c160" size="24"></u-icon>
<text class="label-text">微信</text>
</view>
<text class="contact-value">{{ detail.wechat }}</text>
<text class="contact-value wechat-clickable" @click="openWechat(detail.wechat)">{{ detail.wechat }}</text>
</view>
<view class="contact-item" v-if="detail.mobile">
<view class="contact-label">
<u-icon name="phone-fill" color="#007aff" size="24"></u-icon>
<text class="label-text">电话</text>
</view>
<text class="contact-value">{{ detail.mobile }}</text>
<text class="contact-value phone-clickable" @click="makePhoneCall(detail.mobile)">{{ detail.mobile }}</text>
</view>
<view class="contact-item" v-if="detail.email">
<view class="contact-label">
@ -210,6 +210,142 @@
current: file.url,
index: index
});
},
// 新增方法:拨打电话
makePhoneCall(phoneNumber) {
uni.showModal({
title: '拨打电话',
content: `是否拨打 ${phoneNumber}?`,
success: (res) => {
if (res.confirm) {
uni.makePhoneCall({
phoneNumber: phoneNumber,
success: () => {
console.log('拨号成功');
},
fail: (err) => {
console.error('拨号失败:', err);
this.$u.toast('拨号失败,请重试');
}
});
}
}
});
},
// 新增方法:打开微信
openWechat(wechatId) {
console.log('点击微信,微信号:', wechatId);
// 尝试使用微信的URL Scheme打开微信
const wechatUrl = `weixin://`;
// 检查是否在APP环境中且有plus对象
if (typeof window !== 'undefined' && window.plus && plus.runtime) {
console.log('检测到plus环境,尝试打开微信');
plus.runtime.openURL(wechatUrl, (err) => {
if (err) {
console.error('打开微信失败:', err);
this.showWechatCopyDialog(wechatId);
} else {
console.log('微信打开成功');
this.$u.toast('请在微信中搜索并添加好友');
}
});
} else {
console.log('非APP环境或plus不可用,直接显示复制对话框');
// 非APP环境直接显示复制对话框
this.showWechatCopyDialog(wechatId);
}
},
// 显示微信复制对话框
showWechatCopyDialog(wechatId) {
console.log('准备显示微信复制对话框,微信号:', wechatId);
// 在小程序中使用showModal
uni.showModal({
title: '添加微信好友',
content: `微信号:${wechatId}\n请复制微信号到微信中搜索添加`,
confirmText: '复制',
cancelText: '取消',
showCancel: true,
success: (res) => {
console.log('showModal success callback:', res);
if (res.confirm) {
console.log('用户点击确认,准备复制微信号');
// 尝试复制微信号到剪贴板
this.tryCopyToClipboard(wechatId);
}
},
fail: (err) => {
console.error('showModal fail callback:', err);
// 如果showModal失败,尝试使用toast提示
uni.showToast({
title: `微信号:${wechatId}`,
icon: 'none',
duration: 3000
});
}
});
},
// 尝试复制到剪贴板的方法(适配隐私保护指引)
tryCopyToClipboard(text) {
// 检查小程序隐私协议是否已同意
if (typeof wx !== 'undefined' && wx.requirePrivacyAuthorize) {
// 需要用户同意隐私协议
wx.requirePrivacyAuthorize({
success: () => {
// 用户同意后,执行复制操作
this.executeCopyToClipboard(text);
},
fail: () => {
// 用户拒绝,显示手动复制提示
this.showManualCopyTip(text);
}
});
} else {
// 直接尝试复制
this.executeCopyToClipboard(text);
}
},
// 执行复制到剪贴板
executeCopyToClipboard(text) {
uni.setClipboardData({
data: text,
success: () => {
console.log('复制成功');
uni.showToast({
title: '微信号已复制到剪贴板',
icon: 'success',
duration: 2000
});
},
fail: (err) => {
console.error('复制失败:', err);
// 如果复制失败,显示手动复制的提示
this.showManualCopyTip(text);
}
});
},
// 显示手动复制提示
showManualCopyTip(text) {
uni.showModal({
title: '复制失败',
content: `微信号:${text}\n\n由于权限限制,请手动复制微信号到微信中搜索添加`,
confirmText: '知道了',
showCancel: false,
success: () => {
// 可以尝试使用其他方式提示用户
uni.showToast({
title: '请手动复制微信号',
icon: 'none',
duration: 3000
});
}
});
}
}
}
@ -473,6 +609,28 @@
font-weight: 500;
}
.phone-clickable {
color: #007aff;
text-decoration: underline;
cursor: pointer;
transition: color 0.3s ease;
}
.phone-clickable:active {
color: #0056b3;
}
.wechat-clickable {
color: #07c160;
text-decoration: underline;
cursor: pointer;
transition: color 0.3s ease;
}
.wechat-clickable:active {
color: #06ad56;
}
.contact-placeholder {
display: flex;
flex-direction: column;

@ -71,11 +71,9 @@
currentStatusTab: 0, // 当前选中的状态标签
statusTabs: [
{ name: '全部' },
{ name: '待审核' },
{ name: '审核通过' },
{ name: '已拒绝' },
{ name: '已发布' },
{ name: '退回修改' },
{ name: '永久隐藏' }
{ name: '已拒绝' }
]
}
},
@ -100,19 +98,17 @@
};
// 根据状态标签索引映射到实际状态值
// 现在有4个状态标签:全部、已发布、退回修改、已拒绝
if (this.currentStatusTab === 0) {
// 全部状态,传递null
params.status = '-1'
// 全部状态,传递-1表示不筛选状态
params.status = '-1';
} else {
// 根据状态标签索引映射到实际状态值
const statusMap = {
1: 0, // 待审核
2: 1, // 审核通过
3: 2, // 已拒绝
4: 3, // 退回修改
5: 4 // 永久隐藏
1: 1, // 已发布(状态为1)
2: 3, // 退回修改(状态为3)
3: 2 // 已拒绝(状态为2)
};
params.status = statusMap[this.currentStatusTab] || 0;
params.status = statusMap[this.currentStatusTab] || 1;
}
this.$u.api.supplyDemandList(params).then(res => {

Loading…
Cancel
Save