quality-resources.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. <template>
  2. <view class="quality-resources">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-icon" @click="handleBack"></view>
  6. <text class="header-title">优质资源</text>
  7. <view class="filter-icon" @click="handleFilter"></view>
  8. </view>
  9. <!-- 搜索栏 -->
  10. <view class="search-bar">
  11. <view class="search-input-wrapper">
  12. <view class="search-icon-small"></view>
  13. <input type="text" class="search-input" placeholder="请输入搜索关键词" placeholder-style="color: #999;" v-model="searchKeyword" @input="handleSearch" />
  14. </view>
  15. </view>
  16. <!-- 资源列表 -->
  17. <scroll-view scroll-y class="content" @scrolltolower="loadMore" :scroll-with-animation="true">
  18. <view v-if="loading" class="loading-wrapper">
  19. <text class="loading-text">加载中...</text>
  20. </view>
  21. <view v-else-if="resources.length === 0" class="empty-wrapper">
  22. <text class="empty-text">暂无优质资源</text>
  23. </view>
  24. <view class="resource-item" v-for="(resource, index) in resources" :key="getResourceKey(resource, index)" @click="handleResourceClick(index)">
  25. <view class="resource-header">
  26. <image
  27. :src="getAvatarUrl(resource) || '/static/default-avatar.svg'"
  28. mode="aspectFill"
  29. class="avatar"
  30. @error="handleImageError(index)"
  31. ></image>
  32. <view class="resource-info">
  33. <view class="name-gender">
  34. <text class="name">{{ resource.name }}</text>
  35. <text class="gender">{{ resource.gender === 1 ? '男' : '女' }}</text>
  36. </view>
  37. <view class="status-tag-wrapper">
  38. <text class="status-tag register-tag registered">已注册</text>
  39. <text class="status-tag match-tag" :class="{ 'matched': getIsMatch(resource) === 1, 'unmatched': getIsMatch(resource) === 0 || !getIsMatch(resource) }">
  40. {{ getIsMatch(resource) === 1 ? '已匹配' : '未匹配' }}
  41. </text>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="resource-details">
  46. <view class="labels" v-if="resource.tags && resource.tags.length > 0">
  47. <text class="label" v-for="(tag, tagIndex) in resource.tags" :key="tagIndex">{{ tag }}</text>
  48. </view>
  49. <view class="requirement-box">
  50. <text class="requirement-label">择偶要求:</text>
  51. <text class="requirement-content">{{ getMateSelectionCriteria(resource) || '暂无' }}</text>
  52. </view>
  53. <view class="contact-box">
  54. <text class="contact-label">联系方式:</text>
  55. <text class="contact-number">{{ getMaskedPhone(resource.phone) || '暂无' }}</text>
  56. <text class="copy-btn" @click.stop="handleCopy(resource.phone)">复制</text>
  57. </view>
  58. <view class="action-buttons">
  59. <view class="action-btn add-resource-btn" @click.stop="handleAddToMyResources(index)">添加到我的资源</view>
  60. <view class="action-btn chat-btn" @click.stop="handleChat(resource)">牵线聊聊</view>
  61. </view>
  62. </view>
  63. </view>
  64. <view v-if="hasMore && !loading" class="load-more-wrapper">
  65. <text class="load-more-text">上拉加载更多</text>
  66. </view>
  67. <view v-if="!hasMore && resources.length > 0" class="no-more-wrapper">
  68. <text class="no-more-text">没有更多数据了</text>
  69. </view>
  70. </scroll-view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. name: 'quality-resources',
  76. data() {
  77. return {
  78. resources: [],
  79. searchKeyword: '',
  80. pageNum: 1,
  81. pageSize: 10,
  82. loading: false,
  83. hasMore: true,
  84. currentUserId: null // 当前登录用户的用户ID
  85. }
  86. },
  87. onLoad() {
  88. // 获取当前登录用户的ID
  89. const userId = uni.getStorageSync('userId')
  90. if (userId) {
  91. const rawUserId = parseInt(userId)
  92. if (!isNaN(rawUserId) && rawUserId > 0) {
  93. this.currentUserId = rawUserId
  94. console.log('当前登录用户ID:', this.currentUserId)
  95. }
  96. }
  97. this.loadResources()
  98. },
  99. methods: {
  100. // 返回上一页
  101. handleBack() {
  102. uni.navigateBack()
  103. },
  104. // 筛选
  105. handleFilter() {
  106. // 实现筛选功能
  107. },
  108. // 搜索
  109. handleSearch() {
  110. this.pageNum = 1
  111. this.resources = []
  112. this.hasMore = true
  113. this.loadResources()
  114. },
  115. // 加载资源列表
  116. async loadResources() {
  117. if (this.loading) return
  118. try {
  119. this.loading = true
  120. const baseUrl = process.env.NODE_ENV === 'development'
  121. ? 'http://localhost:8083/api' // 开发环境 - 通过网关
  122. : 'https://your-domain.com/api' // 生产环境
  123. // 构建请求参数
  124. const requestData = {
  125. tagName: '优质资源',
  126. keyword: this.searchKeyword || '',
  127. pageNum: this.pageNum,
  128. pageSize: this.pageSize
  129. }
  130. // 如果已登录,传递currentUserId,用于排除该红娘已拥有的资源
  131. if (this.currentUserId) {
  132. requestData.currentUserId = this.currentUserId
  133. }
  134. const [error, res] = await uni.request({
  135. url: `${baseUrl}/my-resource/list-by-tag`,
  136. method: 'GET',
  137. data: requestData,
  138. timeout: 10000
  139. })
  140. if (error) {
  141. console.error('加载优质资源失败:', error)
  142. uni.showToast({
  143. title: '加载失败',
  144. icon: 'none'
  145. })
  146. return
  147. }
  148. if (res.statusCode === 200 && res.data && res.data.code === 200) {
  149. const pageData = res.data.data
  150. if (pageData && pageData.records) {
  151. // 调试:打印第一条数据的详细信息
  152. if (pageData.records.length > 0) {
  153. const firstRecord = pageData.records[0]
  154. console.log('=== 第一条资源数据 ===')
  155. console.log('完整数据:', JSON.stringify(firstRecord, null, 2))
  156. console.log('isUser值:', firstRecord.isUser, '类型:', typeof firstRecord.isUser)
  157. console.log('is_user值:', firstRecord.is_user, '类型:', typeof firstRecord.is_user)
  158. console.log('userId值:', firstRecord.userId, '类型:', typeof firstRecord.userId)
  159. console.log('user_id值:', firstRecord.user_id, '类型:', typeof firstRecord.user_id)
  160. console.log('mateSelectionCriteria (驼峰):', firstRecord.mateSelectionCriteria)
  161. console.log('mate_selection_criteria (下划线):', firstRecord.mate_selection_criteria)
  162. console.log('phone:', firstRecord.phone)
  163. }
  164. if (this.pageNum === 1) {
  165. this.resources = pageData.records
  166. } else {
  167. this.resources = this.resources.concat(pageData.records)
  168. }
  169. // 判断是否还有更多数据
  170. this.hasMore = pageData.records && pageData.records.length >= this.pageSize
  171. console.log('加载优质资源成功,数量:', this.resources.length)
  172. } else {
  173. console.error('加载优质资源失败:', res.data.message)
  174. }
  175. } else {
  176. console.error('加载优质资源失败:', res.data.message)
  177. uni.showToast({
  178. title: res.data.message || '加载失败',
  179. icon: 'none'
  180. })
  181. }
  182. } catch (e) {
  183. console.error('加载优质资源异常:', e)
  184. uni.showToast({
  185. title: '加载异常',
  186. icon: 'none'
  187. })
  188. } finally {
  189. this.loading = false
  190. }
  191. },
  192. // 加载更多
  193. loadMore() {
  194. if (this.hasMore && !this.loading) {
  195. this.pageNum++
  196. this.loadResources()
  197. }
  198. },
  199. // 图片加载错误处理
  200. handleImageError(index) {
  201. if (this.resources[index]) {
  202. // 设置头像为空,让CSS默认背景显示
  203. // 支持下划线和驼峰两种格式
  204. this.resources[index].avatarUrl = ''
  205. this.resources[index].avatar_url = ''
  206. this.resources[index].avatar = ''
  207. }
  208. },
  209. // 复制联系方式
  210. handleCopy(contact) {
  211. if (!contact) {
  212. uni.showToast({
  213. title: '联系方式为空',
  214. icon: 'none'
  215. })
  216. return
  217. }
  218. uni.setClipboardData({
  219. data: contact,
  220. success: () => {
  221. uni.showToast({
  222. title: '复制成功',
  223. icon: 'success'
  224. })
  225. }
  226. })
  227. },
  228. // 牵线聊聊
  229. handleChat(resource) {
  230. console.log('=== 牵线聊聊 ===')
  231. console.log('资源信息:', resource)
  232. console.log('资源信息类型:', typeof resource)
  233. console.log('资源信息的所有键:', resource ? Object.keys(resource) : 'resource为空')
  234. // 验证 resource 对象是否存在
  235. if (!resource) {
  236. console.error('❌ resource对象为空')
  237. uni.showToast({
  238. title: '资源信息为空',
  239. icon: 'none'
  240. })
  241. return
  242. }
  243. // 检查用户是否已注册(只有已注册用户才能聊天)
  244. // 支持下划线和驼峰两种格式
  245. const isUser = resource.isUser !== undefined ? resource.isUser :
  246. (resource.is_user !== undefined ? resource.is_user : 0)
  247. if (isUser !== 1 && isUser !== '1') {
  248. console.warn('⚠️ 用户未注册,无法聊天')
  249. uni.showToast({
  250. title: '该用户尚未注册,无法聊天',
  251. icon: 'none',
  252. duration: 3000
  253. })
  254. return
  255. }
  256. // 尝试多种方式获取用户ID
  257. let targetUserId = null
  258. // 方式1: 使用 userId 字段(驼峰格式)
  259. if (resource.userId !== null && resource.userId !== undefined && resource.userId !== '') {
  260. targetUserId = String(resource.userId)
  261. console.log('✅ 从 resource.userId 获取用户ID:', targetUserId)
  262. }
  263. // 方式2: 使用 user_id 字段(下划线格式)
  264. else if (resource.user_id !== null && resource.user_id !== undefined && resource.user_id !== '') {
  265. targetUserId = String(resource.user_id)
  266. console.log('✅ 从 resource.user_id 获取用户ID:', targetUserId)
  267. }
  268. // 方式3: 使用 id 字段
  269. else if (resource.id !== null && resource.id !== undefined && resource.id !== '') {
  270. targetUserId = String(resource.id)
  271. console.log('✅ 从 resource.id 获取用户ID:', targetUserId)
  272. }
  273. // 如果仍然没有获取到用户ID
  274. if (!targetUserId || targetUserId === 'null' || targetUserId === 'undefined' || targetUserId === '') {
  275. console.error('❌ 无法获取用户ID')
  276. console.log('resource对象完整内容:', JSON.stringify(resource, null, 2))
  277. uni.showToast({
  278. title: '无法获取用户ID,请刷新重试',
  279. icon: 'none',
  280. duration: 3000
  281. })
  282. return
  283. }
  284. // 获取其他必要信息(支持下划线和驼峰格式)
  285. const targetUserName = resource.name || '用户'
  286. const targetUserAvatar = resource.avatarUrl || resource.avatar_url || resource.avatar || '/static/default-avatar.svg'
  287. console.log('跳转参数:')
  288. console.log(' - targetUserId:', targetUserId)
  289. console.log(' - targetUserName:', targetUserName)
  290. console.log(' - targetUserAvatar:', targetUserAvatar)
  291. // 跳转到聊天页面
  292. // 注意:fromMatchmaker=1 表示来自红娘工作台,会跳过消息限制和审核
  293. uni.navigateTo({
  294. url: `/pages/message/chat?targetUserId=${targetUserId}&targetUserName=${encodeURIComponent(targetUserName)}&targetUserAvatar=${encodeURIComponent(targetUserAvatar)}&fromMatchmaker=1`,
  295. success: () => {
  296. console.log('✅ 跳转聊天页面成功')
  297. },
  298. fail: (err) => {
  299. console.error('❌ 跳转聊天页面失败:', err)
  300. uni.showToast({
  301. title: '跳转失败,请重试',
  302. icon: 'none'
  303. })
  304. }
  305. })
  306. },
  307. // 获取资源项的key(用于v-for)
  308. getResourceKey(resource, index) {
  309. if (!resource) return `resource-${index}`
  310. // 支持下划线和驼峰两种格式
  311. const resourceId = resource.resourceId || resource.resource_id
  312. if (resourceId !== null && resourceId !== undefined && resourceId !== '') {
  313. return `resource-${resourceId}`
  314. }
  315. return `resource-${index}`
  316. },
  317. // 点击资源项
  318. handleResourceClick(index) {
  319. console.log('=== 点击资源项 ===')
  320. console.log('传入的index:', index)
  321. console.log('resources数组长度:', this.resources.length)
  322. // 检查index是否有效
  323. if (index === undefined || index === null || index < 0 || index >= this.resources.length) {
  324. console.error('❌ index无效:', index)
  325. uni.showToast({
  326. title: '资源索引无效',
  327. icon: 'none'
  328. })
  329. return
  330. }
  331. // 从数组中获取resource对象
  332. const resource = this.resources[index]
  333. console.log('从数组获取的resource对象:', JSON.stringify(resource, null, 2))
  334. if (!resource) {
  335. console.error('❌ resource对象为空')
  336. uni.showToast({
  337. title: '资源信息为空',
  338. icon: 'none'
  339. })
  340. return
  341. }
  342. // 支持下划线和驼峰两种格式
  343. const resourceId = resource.resourceId || resource.resource_id
  344. const isUser = resource.isUser !== undefined ? resource.isUser :
  345. (resource.is_user !== undefined ? resource.is_user : 0)
  346. console.log('resource.resourceId:', resourceId)
  347. console.log('resource.isUser:', isUser)
  348. // 检查resourceId是否有效
  349. if (!resourceId || resourceId === null || resourceId === undefined || resourceId === '') {
  350. console.error('❌ resourceId无效:', resourceId)
  351. uni.showToast({
  352. title: '资源ID无效,无法查看详情',
  353. icon: 'none'
  354. })
  355. return
  356. }
  357. // 判断是否为已注册用户
  358. if (isUser === 1 || isUser === '1') {
  359. // 已注册,跳转到客户详情页面,添加fromQualityResources参数标识来源
  360. console.log('准备跳转,resourceId:', resourceId)
  361. uni.navigateTo({
  362. url: `/pages/matchmaker-workbench/client-detail?resourceId=${resourceId}&fromQualityResources=1`,
  363. success: () => {
  364. console.log('✅ 跳转成功,resourceId:', resourceId)
  365. },
  366. fail: (err) => {
  367. console.error('❌ 跳转失败:', err)
  368. uni.showToast({
  369. title: '跳转失败,请重试',
  370. icon: 'none'
  371. })
  372. }
  373. })
  374. } else {
  375. // 未注册,提示用户(虽然后端已经过滤了,但为了容错仍然保留)
  376. uni.showToast({
  377. title: '该用户还未注册用户端',
  378. icon: 'none',
  379. duration: 2000
  380. })
  381. }
  382. },
  383. // 添加到我的资源
  384. async handleAddToMyResources(index) {
  385. console.log('=== 添加到我的资源 ===')
  386. console.log('index:', index)
  387. // 检查index是否有效
  388. if (index === undefined || index === null || index < 0 || index >= this.resources.length) {
  389. console.error('❌ index无效:', index)
  390. uni.showToast({
  391. title: '资源索引无效',
  392. icon: 'none'
  393. })
  394. return
  395. }
  396. // 从数组中获取resource对象
  397. const resource = this.resources[index]
  398. console.log('从数组获取的resource对象:', JSON.stringify(resource, null, 2))
  399. if (!resource) {
  400. console.error('❌ resource对象为空')
  401. uni.showToast({
  402. title: '资源信息为空',
  403. icon: 'none'
  404. })
  405. return
  406. }
  407. // 检查是否已登录
  408. if (!this.currentUserId) {
  409. uni.showToast({
  410. title: '请先登录',
  411. icon: 'none'
  412. })
  413. return
  414. }
  415. try {
  416. uni.showLoading({
  417. title: '添加中...'
  418. })
  419. const baseUrl = process.env.NODE_ENV === 'development'
  420. ? 'http://localhost:8083/api' // 开发环境 - 通过网关
  421. : 'https://your-domain.com/api' // 生产环境
  422. // 构建要添加的资源数据(复制原资源的所有信息,但使用当前红娘的matchmaker_id)
  423. const resourceData = {
  424. name: resource.name,
  425. age: resource.age,
  426. gender: resource.gender,
  427. constellation: resource.constellation,
  428. height: resource.height,
  429. weight: resource.weight,
  430. marrStatus: resource.marrStatus || resource.marr_status,
  431. diploma: resource.diploma,
  432. income: resource.income,
  433. address: resource.address,
  434. domicile: resource.domicile,
  435. occupation: resource.occupation,
  436. house: resource.house,
  437. phone: resource.phone,
  438. backupPhone: resource.backupPhone || resource.backup_phone,
  439. car: resource.car,
  440. mateSelectionCriteria: resource.mateSelectionCriteria || resource.mate_selection_criteria,
  441. isUser: resource.isUser || resource.is_user || 1,
  442. userId: resource.userId || resource.user_id
  443. }
  444. // 获取标签ID列表
  445. let tagIds = []
  446. // 方法1: 如果resource有resourceId,直接根据resourceId获取标签ID
  447. const resourceId = resource.resourceId || resource.resource_id
  448. if (resourceId) {
  449. try {
  450. const [tagError, tagRes] = await uni.request({
  451. url: `${baseUrl}/my-resource/tag-ids/${resourceId}`,
  452. method: 'GET'
  453. })
  454. if (!tagError && tagRes.statusCode === 200 && tagRes.data && tagRes.data.code === 200) {
  455. tagIds = tagRes.data.data || []
  456. console.log('根据resourceId获取的标签ID:', tagIds)
  457. }
  458. } catch (e) {
  459. console.warn('根据resourceId获取标签ID失败,将使用标签名称查询:', e)
  460. }
  461. }
  462. // 方法2: 如果方法1失败或没有resourceId,根据标签名称查询标签ID
  463. if (tagIds.length === 0 && resource.tags && resource.tags.length > 0) {
  464. try {
  465. // 获取所有标签列表
  466. const [tagListError, tagListRes] = await uni.request({
  467. url: `${baseUrl}/tag/list`,
  468. method: 'GET'
  469. })
  470. if (!tagListError && tagListRes.statusCode === 200 && tagListRes.data && tagListRes.data.code === 200) {
  471. const allTags = tagListRes.data.data || []
  472. console.log('所有标签列表:', allTags)
  473. // 根据标签名称匹配标签ID
  474. for (const tagName of resource.tags) {
  475. const matchedTag = allTags.find(tag => {
  476. const tagNameField = tag.name || tag.tag_name || tag.tagName
  477. return tagNameField === tagName
  478. })
  479. if (matchedTag) {
  480. const tagId = matchedTag.id || matchedTag.tag_id
  481. if (tagId && !tagIds.includes(tagId)) {
  482. tagIds.push(tagId)
  483. console.log(`找到标签 "${tagName}" 的ID:`, tagId)
  484. }
  485. } else {
  486. console.warn(`未找到标签 "${tagName}" 的ID`)
  487. }
  488. }
  489. console.log('根据标签名称查询到的标签ID列表:', tagIds)
  490. }
  491. } catch (e) {
  492. console.error('根据标签名称查询标签ID异常:', e)
  493. }
  494. }
  495. // 确保tagIds是整数数组
  496. tagIds = tagIds.map(id => parseInt(id)).filter(id => !isNaN(id) && id > 0)
  497. if (tagIds.length === 0) {
  498. console.warn('⚠️ 未获取到任何标签ID,资源将不包含标签')
  499. } else {
  500. console.log('✅ 最终获取到的标签ID列表:', tagIds)
  501. }
  502. // 调用后端API添加资源
  503. const url = `${baseUrl}/my-resource/add?currentUserId=${this.currentUserId}`
  504. console.log('添加资源请求URL:', url)
  505. console.log('添加资源数据:', JSON.stringify(resourceData, null, 2))
  506. console.log('标签ID列表:', tagIds)
  507. const [error, res] = await uni.request({
  508. url: url,
  509. method: 'POST',
  510. data: {
  511. ...resourceData,
  512. tagIds: tagIds
  513. },
  514. header: {
  515. 'Content-Type': 'application/json'
  516. }
  517. })
  518. uni.hideLoading()
  519. if (error) {
  520. console.error('添加到我的资源失败:', error)
  521. uni.showToast({
  522. title: '添加失败,请重试',
  523. icon: 'none'
  524. })
  525. return
  526. }
  527. if (res.statusCode === 200 && res.data && res.data.code === 200) {
  528. uni.showToast({
  529. title: '添加成功',
  530. icon: 'success'
  531. })
  532. // 发送刷新事件,通知我的资源页面刷新列表
  533. uni.$emit('refreshResourceList')
  534. } else {
  535. console.error('添加到我的资源失败:', res.data.message)
  536. uni.showToast({
  537. title: res.data.message || '添加失败',
  538. icon: 'none',
  539. duration: 2000
  540. })
  541. }
  542. } catch (e) {
  543. uni.hideLoading()
  544. console.error('添加到我的资源异常:', e)
  545. uni.showToast({
  546. title: '添加异常,请稍后重试',
  547. icon: 'none'
  548. })
  549. }
  550. },
  551. // 获取头像URL(支持驼峰和下划线格式)
  552. getAvatarUrl(resource) {
  553. if (!resource) return ''
  554. // 优先使用 avatarUrl(驼峰),如果没有则使用 avatar_url(下划线),最后使用 avatar
  555. return resource.avatarUrl || resource.avatar_url || resource.avatar || ''
  556. },
  557. // 获取匹配状态(支持驼峰和下划线格式)
  558. getIsMatch(resource) {
  559. if (!resource) return 0
  560. // 支持 isMatch(驼峰)和 is_match(下划线)两种格式
  561. return resource.isMatch !== undefined ? resource.isMatch :
  562. (resource.is_match !== undefined ? resource.is_match : 0)
  563. },
  564. // 获取择偶要求(支持驼峰和下划线格式)
  565. getMateSelectionCriteria(resource) {
  566. if (!resource) {
  567. console.warn('getMateSelectionCriteria: resource为空')
  568. return ''
  569. }
  570. // 支持 mateSelectionCriteria(驼峰)和 mate_selection_criteria(下划线)两种格式
  571. let criteria = resource.mateSelectionCriteria || resource.mate_selection_criteria || ''
  572. // 如果为空,直接返回
  573. if (!criteria || criteria.trim() === '') {
  574. return ''
  575. }
  576. // 去除首尾空格
  577. criteria = criteria.trim()
  578. // 如果获取到的是电话号码格式(11位数字或脱敏后的格式),则返回空字符串,让模板显示"暂无"
  579. // 检查是否是纯数字(11位)或包含****的脱敏格式
  580. const phonePattern = /^(\d{3}\*{4}\d{4}|\d{11})$/
  581. if (phonePattern.test(criteria)) {
  582. console.warn('⚠️ 择偶要求字段包含电话号码格式,返回空字符串', {
  583. criteria: criteria,
  584. phone: resource.phone,
  585. 'resource完整对象': resource
  586. })
  587. return ''
  588. }
  589. // 如果择偶要求等于电话号码(未脱敏),也返回空
  590. if (criteria === resource.phone || criteria === (resource.phone || '').replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')) {
  591. console.warn('⚠️ 择偶要求等于电话号码,返回空字符串', {
  592. criteria: criteria,
  593. phone: resource.phone
  594. })
  595. return ''
  596. }
  597. return criteria
  598. },
  599. // 获取脱敏手机号
  600. getMaskedPhone(phone) {
  601. if (!phone) return ''
  602. // 手机号脱敏:显示前3位和后4位,中间用****代替
  603. return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
  604. }
  605. }
  606. }
  607. </script>
  608. <style lang="scss" scoped>
  609. .quality-resources {
  610. min-height: 100vh;
  611. background: #FFF9F9;
  612. display: flex;
  613. flex-direction: column;
  614. }
  615. /* 顶部导航栏 */
  616. .header {
  617. display: flex;
  618. align-items: center;
  619. justify-content: space-between;
  620. padding: 25rpx 30rpx;
  621. padding-top: calc(25rpx + env(safe-area-inset-top));
  622. background: #FFF9F9;
  623. border-bottom: 1rpx solid #F0F0F0;
  624. .back-icon {
  625. width: 44rpx;
  626. height: 44rpx;
  627. background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></svg>');
  628. background-size: contain;
  629. background-repeat: no-repeat;
  630. background-position: center;
  631. }
  632. .header-title {
  633. font-size: 38rpx;
  634. font-weight: bold;
  635. color: #9C27B0;
  636. }
  637. .filter-icon {
  638. width: 44rpx;
  639. height: 44rpx;
  640. background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/></svg>');
  641. background-size: contain;
  642. background-repeat: no-repeat;
  643. background-position: center;
  644. }
  645. }
  646. /* 搜索栏 */
  647. .search-bar {
  648. padding: 20rpx 30rpx;
  649. background: #FFF9F9;
  650. .search-input-wrapper {
  651. display: flex;
  652. align-items: center;
  653. background: #FFFFFF;
  654. border-radius: 25rpx;
  655. padding: 15rpx 20rpx;
  656. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  657. .search-icon-small {
  658. width: 32rpx;
  659. height: 32rpx;
  660. background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>');
  661. background-size: contain;
  662. background-repeat: no-repeat;
  663. background-position: center;
  664. margin-right: 15rpx;
  665. }
  666. .search-input {
  667. flex: 1;
  668. font-size: 28rpx;
  669. color: #333;
  670. placeholder-color: #999;
  671. }
  672. }
  673. }
  674. /* 内容区域 */
  675. .content {
  676. flex: 1;
  677. padding: 0 30rpx 20rpx;
  678. }
  679. /* 资源列表项 */
  680. .resource-item {
  681. background: #FFFFFF;
  682. border-radius: 20rpx;
  683. padding: 25rpx;
  684. margin-bottom: 20rpx;
  685. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  686. }
  687. .resource-header {
  688. display: flex;
  689. align-items: flex-start;
  690. margin-bottom: 20rpx;
  691. .avatar {
  692. width: 100rpx;
  693. height: 100rpx;
  694. border-radius: 50%;
  695. background: #F0F0F0;
  696. margin-right: 20rpx;
  697. flex-shrink: 0;
  698. }
  699. .resource-info {
  700. flex: 1;
  701. .name-gender {
  702. display: flex;
  703. align-items: center;
  704. gap: 15rpx;
  705. margin-bottom: 10rpx;
  706. .name {
  707. font-size: 32rpx;
  708. font-weight: bold;
  709. color: #333;
  710. }
  711. .gender {
  712. font-size: 24rpx;
  713. color: #999;
  714. padding: 4rpx 12rpx;
  715. background: #F5F5F5;
  716. border-radius: 12rpx;
  717. }
  718. }
  719. .status-tag-wrapper {
  720. display: flex;
  721. align-items: center;
  722. gap: 10rpx;
  723. margin-bottom: 10rpx;
  724. .status-tag {
  725. font-size: 22rpx;
  726. padding: 6rpx 14rpx;
  727. border-radius: 12rpx;
  728. font-weight: 500;
  729. &.register-tag {
  730. &.registered {
  731. color: #4CAF50;
  732. background: #E8F5E9;
  733. border: 1rpx solid #C8E6C9;
  734. }
  735. }
  736. &.match-tag {
  737. &.matched {
  738. color: #2196F3;
  739. background: #E3F2FD;
  740. border: 1rpx solid #BBDEFB;
  741. }
  742. &.unmatched {
  743. color: #FF9800;
  744. background: #FFF3E0;
  745. border: 1rpx solid #FFE0B2;
  746. }
  747. }
  748. }
  749. }
  750. }
  751. }
  752. .resource-details {
  753. .labels {
  754. display: flex;
  755. flex-wrap: wrap;
  756. gap: 10rpx;
  757. margin-bottom: 15rpx;
  758. .label {
  759. display: inline-block;
  760. padding: 6rpx 14rpx;
  761. background: #F3E5F5;
  762. color: #9C27B0;
  763. border-radius: 15rpx;
  764. font-size: 22rpx;
  765. font-weight: 500;
  766. }
  767. }
  768. .requirement-box {
  769. background: #F3E5F5;
  770. border-radius: 12rpx;
  771. padding: 16rpx 20rpx;
  772. margin-bottom: 15rpx;
  773. display: flex;
  774. align-items: center;
  775. flex-wrap: wrap;
  776. .requirement-label {
  777. font-size: 28rpx;
  778. color: #7B1FA2;
  779. font-weight: 500;
  780. margin-right: 8rpx;
  781. white-space: nowrap;
  782. }
  783. .requirement-content {
  784. font-size: 28rpx;
  785. color: #7B1FA2;
  786. font-weight: 400;
  787. }
  788. }
  789. .contact-box {
  790. margin-bottom: 20rpx;
  791. display: flex;
  792. align-items: center;
  793. flex-wrap: wrap;
  794. .contact-label {
  795. font-size: 26rpx;
  796. color: #333;
  797. font-weight: 500;
  798. margin-right: 10rpx;
  799. white-space: nowrap;
  800. }
  801. .contact-number {
  802. flex: 1;
  803. font-size: 26rpx;
  804. color: #333;
  805. font-weight: 400;
  806. min-width: 0;
  807. }
  808. .copy-btn {
  809. font-size: 24rpx;
  810. color: #9C27B0;
  811. font-weight: 500;
  812. margin-left: 15rpx;
  813. white-space: nowrap;
  814. cursor: pointer;
  815. }
  816. }
  817. .action-buttons {
  818. display: flex;
  819. justify-content: flex-end;
  820. align-items: center;
  821. gap: 15rpx;
  822. .action-btn {
  823. padding: 14rpx 30rpx;
  824. border-radius: 25rpx;
  825. font-size: 26rpx;
  826. font-weight: 500;
  827. text-align: center;
  828. &.add-resource-btn {
  829. background: #FF9800;
  830. color: #FFFFFF;
  831. }
  832. &.chat-btn {
  833. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  834. color: #FFFFFF;
  835. }
  836. }
  837. }
  838. }
  839. .loading-wrapper,
  840. .empty-wrapper,
  841. .load-more-wrapper,
  842. .no-more-wrapper {
  843. display: flex;
  844. justify-content: center;
  845. align-items: center;
  846. padding: 40rpx 0;
  847. .loading-text,
  848. .empty-text,
  849. .load-more-text,
  850. .no-more-text {
  851. font-size: 26rpx;
  852. color: #999;
  853. }
  854. }
  855. .empty-text {
  856. color: #666;
  857. }
  858. .no-more-text {
  859. color: #999;
  860. }
  861. </style>