|
|
@@ -59,7 +59,7 @@
|
|
|
</view>
|
|
|
<view class="action-buttons">
|
|
|
<view class="action-btn add-resource-btn" @click.stop="handleAddToMyResources(index)">添加到我的资源</view>
|
|
|
- <view class="action-btn chat-btn" @click.stop="handleChat(resource, index)">牵线聊聊</view>
|
|
|
+ <view class="action-btn chat-btn" @click.stop="handleChat(resource)">牵线聊聊</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -171,13 +171,10 @@ export default {
|
|
|
console.log('phone:', firstRecord.phone)
|
|
|
}
|
|
|
|
|
|
- // 过滤掉空元素,确保数组中不包含 null 或 undefined
|
|
|
- const validRecords = pageData.records.filter(record => record !== null && record !== undefined)
|
|
|
-
|
|
|
if (this.pageNum === 1) {
|
|
|
- this.resources = validRecords
|
|
|
+ this.resources = pageData.records
|
|
|
} else {
|
|
|
- this.resources = this.resources.concat(validRecords)
|
|
|
+ this.resources = this.resources.concat(pageData.records)
|
|
|
}
|
|
|
|
|
|
// 判断是否还有更多数据
|
|
|
@@ -241,73 +238,26 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
// 牵线聊聊
|
|
|
- handleChat(resource, index) {
|
|
|
+ handleChat(resource) {
|
|
|
console.log('=== 牵线聊聊 ===')
|
|
|
- console.log('传入的resource:', resource)
|
|
|
- console.log('传入的index:', index, '类型:', typeof index)
|
|
|
- console.log('resources数组长度:', this.resources ? this.resources.length : 'resources未定义')
|
|
|
-
|
|
|
- // 优先使用传入的 resource 对象,如果为空则通过 index 获取
|
|
|
- let targetResource = resource
|
|
|
-
|
|
|
- // 如果传入的 resource 为空,尝试通过 index 获取
|
|
|
- if (!targetResource || targetResource === null || targetResource === undefined) {
|
|
|
- console.warn('⚠️ 传入的resource为空,尝试通过index获取')
|
|
|
-
|
|
|
- // 检查 resources 数组是否存在
|
|
|
- if (!this.resources || !Array.isArray(this.resources)) {
|
|
|
- console.error('❌ resources数组不存在或不是数组')
|
|
|
- uni.showToast({
|
|
|
- title: '资源列表异常,请刷新重试',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 检查index是否有效
|
|
|
- if (index === undefined || index === null || isNaN(index) || index < 0 || index >= this.resources.length) {
|
|
|
- console.error('❌ index无效:', index, '数组长度:', this.resources.length)
|
|
|
- console.log('resources数组内容:', JSON.stringify(this.resources, null, 2))
|
|
|
- uni.showToast({
|
|
|
- title: '资源索引无效',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 从数组中获取resource对象
|
|
|
- targetResource = this.resources[index]
|
|
|
- console.log('从数组获取的resource对象:', targetResource)
|
|
|
- }
|
|
|
-
|
|
|
- console.log('最终使用的resource对象:', targetResource)
|
|
|
- console.log('资源信息类型:', typeof targetResource)
|
|
|
- console.log('资源信息是否为null:', targetResource === null)
|
|
|
- console.log('资源信息是否为undefined:', targetResource === undefined)
|
|
|
- console.log('资源信息的所有键:', targetResource ? Object.keys(targetResource) : 'resource为空')
|
|
|
+ console.log('资源信息:', resource)
|
|
|
+ console.log('资源信息类型:', typeof resource)
|
|
|
+ console.log('资源信息的所有键:', resource ? Object.keys(resource) : 'resource为空')
|
|
|
|
|
|
// 验证 resource 对象是否存在
|
|
|
- if (!targetResource || targetResource === null || targetResource === undefined) {
|
|
|
+ if (!resource) {
|
|
|
console.error('❌ resource对象为空')
|
|
|
- console.error('传入的resource:', resource)
|
|
|
- console.error('传入的index:', index)
|
|
|
- console.error('resources数组:', JSON.stringify(this.resources, null, 2))
|
|
|
- if (index !== undefined && index !== null && !isNaN(index) && index >= 0 && index < (this.resources ? this.resources.length : 0)) {
|
|
|
- console.error('resources[index]:', this.resources[index])
|
|
|
- }
|
|
|
uni.showToast({
|
|
|
- title: '资源信息为空,请刷新重试',
|
|
|
- icon: 'none',
|
|
|
- duration: 3000
|
|
|
+ title: '资源信息为空',
|
|
|
+ icon: 'none'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 使用 targetResource 继续后续处理
|
|
|
// 检查用户是否已注册(只有已注册用户才能聊天)
|
|
|
// 支持下划线和驼峰两种格式
|
|
|
- const isUser = targetResource.isUser !== undefined ? targetResource.isUser :
|
|
|
- (targetResource.is_user !== undefined ? targetResource.is_user : 0)
|
|
|
+ const isUser = resource.isUser !== undefined ? resource.isUser :
|
|
|
+ (resource.is_user !== undefined ? resource.is_user : 0)
|
|
|
if (isUser !== 1 && isUser !== '1') {
|
|
|
console.warn('⚠️ 用户未注册,无法聊天')
|
|
|
uni.showToast({
|
|
|
@@ -322,25 +272,25 @@ export default {
|
|
|
let targetUserId = null
|
|
|
|
|
|
// 方式1: 使用 userId 字段(驼峰格式)
|
|
|
- if (targetResource.userId !== null && targetResource.userId !== undefined && targetResource.userId !== '') {
|
|
|
- targetUserId = String(targetResource.userId)
|
|
|
- console.log('✅ 从 targetResource.userId 获取用户ID:', targetUserId)
|
|
|
+ if (resource.userId !== null && resource.userId !== undefined && resource.userId !== '') {
|
|
|
+ targetUserId = String(resource.userId)
|
|
|
+ console.log('✅ 从 resource.userId 获取用户ID:', targetUserId)
|
|
|
}
|
|
|
// 方式2: 使用 user_id 字段(下划线格式)
|
|
|
- else if (targetResource.user_id !== null && targetResource.user_id !== undefined && targetResource.user_id !== '') {
|
|
|
- targetUserId = String(targetResource.user_id)
|
|
|
- console.log('✅ 从 targetResource.user_id 获取用户ID:', targetUserId)
|
|
|
+ else if (resource.user_id !== null && resource.user_id !== undefined && resource.user_id !== '') {
|
|
|
+ targetUserId = String(resource.user_id)
|
|
|
+ console.log('✅ 从 resource.user_id 获取用户ID:', targetUserId)
|
|
|
}
|
|
|
// 方式3: 使用 id 字段
|
|
|
- else if (targetResource.id !== null && targetResource.id !== undefined && targetResource.id !== '') {
|
|
|
- targetUserId = String(targetResource.id)
|
|
|
- console.log('✅ 从 targetResource.id 获取用户ID:', targetUserId)
|
|
|
+ else if (resource.id !== null && resource.id !== undefined && resource.id !== '') {
|
|
|
+ targetUserId = String(resource.id)
|
|
|
+ console.log('✅ 从 resource.id 获取用户ID:', targetUserId)
|
|
|
}
|
|
|
|
|
|
// 如果仍然没有获取到用户ID
|
|
|
if (!targetUserId || targetUserId === 'null' || targetUserId === 'undefined' || targetUserId === '') {
|
|
|
console.error('❌ 无法获取用户ID')
|
|
|
- console.log('targetResource对象完整内容:', JSON.stringify(targetResource, null, 2))
|
|
|
+ console.log('resource对象完整内容:', JSON.stringify(resource, null, 2))
|
|
|
uni.showToast({
|
|
|
title: '无法获取用户ID,请刷新重试',
|
|
|
icon: 'none',
|
|
|
@@ -350,8 +300,8 @@ export default {
|
|
|
}
|
|
|
|
|
|
// 获取其他必要信息(支持下划线和驼峰格式)
|
|
|
- const targetUserName = targetResource.name || '用户'
|
|
|
- const targetUserAvatar = targetResource.avatarUrl || targetResource.avatar_url || targetResource.avatar || '/static/default-avatar.svg'
|
|
|
+ const targetUserName = resource.name || '用户'
|
|
|
+ const targetUserAvatar = resource.avatarUrl || resource.avatar_url || resource.avatar || '/static/default-avatar.svg'
|
|
|
|
|
|
console.log('跳转参数:')
|
|
|
console.log(' - targetUserId:', targetUserId)
|
|
|
@@ -496,63 +446,13 @@ export default {
|
|
|
|
|
|
try {
|
|
|
uni.showLoading({
|
|
|
- title: '检查中...'
|
|
|
+ title: '添加中...'
|
|
|
})
|
|
|
|
|
|
const baseUrl = process.env.NODE_ENV === 'development'
|
|
|
? 'http://localhost:8083/api' // 开发环境 - 通过网关
|
|
|
: 'https://your-domain.com/api' // 生产环境
|
|
|
|
|
|
- // 获取要添加的手机号和备用手机号
|
|
|
- const phone = resource.phone
|
|
|
- const backupPhone = resource.backupPhone || resource.backup_phone
|
|
|
-
|
|
|
- // 检查手机号是否已存在(检查整个my_resource表,不限制红娘)
|
|
|
- const checkUrl = `${baseUrl}/my-resource/check-phone?phone=${encodeURIComponent(phone || '')}${backupPhone ? '&backupPhone=' + encodeURIComponent(backupPhone) : ''}`
|
|
|
- const [checkError, checkRes] = await uni.request({
|
|
|
- url: checkUrl,
|
|
|
- method: 'GET'
|
|
|
- })
|
|
|
-
|
|
|
- if (checkError) {
|
|
|
- console.error('检查手机号失败:', checkError)
|
|
|
- uni.hideLoading()
|
|
|
- uni.showToast({
|
|
|
- title: '检查手机号失败,请重试',
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if (checkRes.statusCode === 200 && checkRes.data && checkRes.data.code === 200) {
|
|
|
- const checkResult = checkRes.data.data
|
|
|
- const existingResource = checkResult.existingResource
|
|
|
-
|
|
|
- // 如果发现重复的手机号,提示用户
|
|
|
- if (checkResult.phoneExists || checkResult.backupPhoneExists || checkResult.phoneAsBackupExists || checkResult.backupPhoneAsMainExists) {
|
|
|
- let message = '该手机号已经绑定资源啦'
|
|
|
-
|
|
|
- // 根据不同的检查结果,显示具体的手机号类型
|
|
|
- if (checkResult.phoneExists) {
|
|
|
- message = '该主手机号已经绑定资源啦'
|
|
|
- } else if (checkResult.phoneAsBackupExists) {
|
|
|
- message = '该主手机号已经作为备用手机号绑定资源啦'
|
|
|
- } else if (checkResult.backupPhoneAsMainExists) {
|
|
|
- message = '该备用手机号已经作为主手机号绑定资源啦'
|
|
|
- } else if (checkResult.backupPhoneExists) {
|
|
|
- message = '该备用手机号已经绑定资源啦'
|
|
|
- }
|
|
|
-
|
|
|
- uni.hideLoading()
|
|
|
- uni.showToast({
|
|
|
- title: message,
|
|
|
- icon: 'none',
|
|
|
- duration: 3000
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
// 构建要添加的资源数据(复制原资源的所有信息,但使用当前红娘的matchmaker_id)
|
|
|
const resourceData = {
|
|
|
name: resource.name,
|
|
|
@@ -568,18 +468,14 @@ export default {
|
|
|
domicile: resource.domicile,
|
|
|
occupation: resource.occupation,
|
|
|
house: resource.house,
|
|
|
- phone: phone,
|
|
|
- backupPhone: backupPhone,
|
|
|
+ phone: resource.phone,
|
|
|
+ backupPhone: resource.backupPhone || resource.backup_phone,
|
|
|
car: resource.car,
|
|
|
mateSelectionCriteria: resource.mateSelectionCriteria || resource.mate_selection_criteria,
|
|
|
isUser: resource.isUser || resource.is_user || 1,
|
|
|
userId: resource.userId || resource.user_id
|
|
|
}
|
|
|
|
|
|
- uni.showLoading({
|
|
|
- title: '添加中...'
|
|
|
- })
|
|
|
-
|
|
|
// 获取标签ID列表
|
|
|
let tagIds = []
|
|
|
|