list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. <template>
  2. <view class="matchmaker-list-page">
  3. <!-- 顶部导航栏 -->
  4. <view class="nav-bar">
  5. <view class="nav-left" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <view class="nav-title">红娘服务</view>
  9. <view class="nav-right"></view>
  10. </view>
  11. <!-- 筛选栏 -->
  12. <view class="filter-bar">
  13. <scroll-view scroll-x class="filter-scroll">
  14. <view class="filter-item"
  15. :class="{ active: filterType === null }"
  16. @click="filterByType(null)">
  17. 全部
  18. </view>
  19. <view class="filter-item"
  20. :class="{ active: filterType === 2 }"
  21. @click="filterByType(2)">
  22. 全职红娘
  23. </view>
  24. <view class="filter-item"
  25. :class="{ active: filterType === 1 }"
  26. @click="filterByType(1)">
  27. 兼职红娘
  28. </view>
  29. </scroll-view>
  30. </view>
  31. <!-- 红娘列表 -->
  32. <scroll-view class="matchmaker-scroll"
  33. scroll-y
  34. @scrolltolower="loadMore"
  35. :lower-threshold="100">
  36. <view class="matchmaker-list">
  37. <view class="matchmaker-card"
  38. v-for="(item, index) in matchmakerList"
  39. :key="item.matchmakerId"
  40. @click="goToDetail(item.matchmakerId)">
  41. <!-- 左侧头像 -->
  42. <view class="avatar-section">
  43. <image :src="getAvatarUrl(item.avatarUrl)"
  44. class="avatar"
  45. mode="aspectFill"
  46. @error="handleImageError(item)"
  47. @load="handleImageLoad(item)">
  48. </image>
  49. <view class="avatar-placeholder" v-if="shouldShowPlaceholder(item)">
  50. <text class="placeholder-icon">👤</text>
  51. </view>
  52. <view class="level-badge" :class="'level-' + (item.level || 1)">
  53. {{ item.levelName || '青铜红娘' }}
  54. </view>
  55. </view>
  56. <!-- 右侧信息 -->
  57. <view class="info-section">
  58. <!-- 姓名和标签 -->
  59. <view class="name-row">
  60. <text class="name">{{ item.realName }}</text>
  61. <view class="type-tag" :class="item.matchmakerType === 2 ? 'formal' : 'parttime'">
  62. {{ item.typeName || '兼职红娘' }}
  63. </view>
  64. </view>
  65. <!-- 成功案例数 -->
  66. <view class="stats-row">
  67. <text class="stats-icon">💑</text>
  68. <text class="stats-text">成功撮合 {{ item.successCouples || 0 }} 对</text>
  69. </view>
  70. <!-- 地址 -->
  71. <view class="location-row" v-if="item.cityName">
  72. <text class="location-icon">📍</text>
  73. <text class="location-text">{{ item.cityName }} {{ item.areaName || '' }}</text>
  74. </view>
  75. <!-- 简介 -->
  76. <view class="profile-row" v-if="item.profile">
  77. <text class="profile-text">{{ item.profile }}</text>
  78. </view>
  79. <!-- 操作按钮 -->
  80. <view class="action-row">
  81. <view class="contact-btn" @click.stop="contactMatchmaker(item)">
  82. <text class="btn-icon">📞</text>
  83. <text class="btn-text">联系TA</text>
  84. </view>
  85. <view class="detail-btn">
  86. <text class="btn-text">查看详情</text>
  87. <text class="arrow">→</text>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 加载状态 -->
  94. <view class="load-status">
  95. <text v-if="loading" class="loading-text">加载中...</text>
  96. <text v-else-if="noMore" class="nomore-text">没有更多了</text>
  97. </view>
  98. <!-- 空状态 -->
  99. <view class="empty-state" v-if="!loading && matchmakerList.length === 0">
  100. <text class="empty-icon">🤷‍♀️</text>
  101. <text class="empty-text">暂无红娘数据</text>
  102. </view>
  103. </scroll-view>
  104. <!-- 底部占位 -->
  105. <view class="bottom-placeholder"></view>
  106. </view>
  107. </template>
  108. <script>
  109. import api from '@/utils/api.js'
  110. import { DEFAULT_IMAGES } from '@/config/index.js'
  111. export default {
  112. data() {
  113. return {
  114. // 筛选条件
  115. filterType: 2, // 默认显示全职红娘
  116. // 红娘列表
  117. matchmakerList: [],
  118. // 分页信息
  119. pageNum: 1,
  120. pageSize: 10,
  121. total: 0,
  122. // 加载状态
  123. loading: false,
  124. noMore: false,
  125. // 默认头像
  126. defaultAvatar: DEFAULT_IMAGES.avatar
  127. }
  128. },
  129. onLoad(options) {
  130. // 从参数获取筛选类型
  131. if (options.type) {
  132. this.filterType = parseInt(options.type)
  133. }
  134. // 加载红娘列表
  135. this.loadMatchmakerList()
  136. },
  137. methods: {
  138. /**
  139. * 加载红娘列表
  140. */
  141. async loadMatchmakerList(isLoadMore = false) {
  142. if (this.loading) return
  143. this.loading = true
  144. try {
  145. // 如果不是加载更多,重置页码
  146. if (!isLoadMore) {
  147. this.pageNum = 1
  148. this.matchmakerList = []
  149. this.noMore = false
  150. }
  151. const params = {
  152. pageNum: this.pageNum,
  153. pageSize: this.pageSize,
  154. matchmakerType: this.filterType,
  155. orderBy: 'success_couples',
  156. orderType: 'desc'
  157. }
  158. const result = await api.matchmaker.getList(params)
  159. if (result && result.records) {
  160. // 日志输出:检查返回数据格式
  161. console.log('红娘列表API返回数据:', result)
  162. console.log('第一个红娘数据:', result.records[0])
  163. // 数据格式检查:确保每个红娘都有有效的ID
  164. const validRecords = result.records.map(item => {
  165. // 如果matchmakerId不存在,尝试其他可能的ID字段
  166. if (!item.matchmakerId && item.id) {
  167. console.warn('使用id字段作为matchmakerId:', item.id)
  168. item.matchmakerId = item.id
  169. }
  170. if (!item.matchmakerId && item.matchmaker_id) {
  171. console.warn('使用matchmaker_id字段作为matchmakerId:', item.matchmaker_id)
  172. item.matchmakerId = item.matchmaker_id
  173. }
  174. return item
  175. })
  176. if (isLoadMore) {
  177. this.matchmakerList = [...this.matchmakerList, ...validRecords]
  178. } else {
  179. this.matchmakerList = validRecords
  180. }
  181. this.total = result.total
  182. // 判断是否还有更多数据
  183. if (this.matchmakerList.length >= this.total) {
  184. this.noMore = true
  185. }
  186. }
  187. } catch (error) {
  188. console.error('加载红娘列表失败:', error)
  189. uni.showToast({
  190. title: '加载失败,请重试',
  191. icon: 'none'
  192. })
  193. } finally {
  194. this.loading = false
  195. }
  196. },
  197. /**
  198. * 加载更多
  199. */
  200. loadMore() {
  201. if (this.loading || this.noMore) return
  202. this.pageNum++
  203. this.loadMatchmakerList(true)
  204. },
  205. /**
  206. * 按类型筛选
  207. */
  208. filterByType(type) {
  209. if (this.filterType === type) return
  210. this.filterType = type
  211. this.loadMatchmakerList()
  212. },
  213. /**
  214. * 跳转到详情页
  215. */
  216. goToDetail(matchmakerId) {
  217. // 添加防御性检查
  218. if (!matchmakerId || matchmakerId === 'undefined' || matchmakerId === 'null') {
  219. console.error('红娘ID无效:', matchmakerId)
  220. uni.showToast({
  221. title: '红娘信息错误',
  222. icon: 'none'
  223. })
  224. return
  225. }
  226. console.log('跳转到红娘详情,ID:', matchmakerId)
  227. uni.navigateTo({
  228. url: `/pages/matchmakers/detail?id=${matchmakerId}`
  229. })
  230. },
  231. /**
  232. * 联系红娘
  233. */
  234. contactMatchmaker(matchmaker) {
  235. // 防御性检查
  236. if (!matchmaker || !matchmaker.phone) {
  237. uni.showToast({
  238. title: '红娘联系方式不可用',
  239. icon: 'none'
  240. })
  241. return
  242. }
  243. uni.showModal({
  244. title: '联系红娘',
  245. content: `电话:${matchmaker.phone}\n邮箱:${matchmaker.email || '未提供'}`,
  246. confirmText: '拨打电话',
  247. cancelText: '取消',
  248. success: (res) => {
  249. if (res.confirm) {
  250. uni.makePhoneCall({
  251. phoneNumber: matchmaker.phone,
  252. fail: () => {
  253. uni.showToast({
  254. title: '拨号失败',
  255. icon: 'none'
  256. })
  257. }
  258. })
  259. }
  260. }
  261. })
  262. },
  263. /**
  264. * 获取头像URL
  265. */
  266. getAvatarUrl(avatarUrl) {
  267. if (avatarUrl) {
  268. // 如果是完整URL(MinIO生成的预签名URL或其他有效URL)
  269. if (avatarUrl.startsWith('http')) {
  270. // 检查是否是无效的placeholder URL
  271. if (avatarUrl.includes('placeholder')) {
  272. console.log('检测到placeholder URL,使用默认头像')
  273. return this.defaultAvatar
  274. }
  275. return avatarUrl
  276. }
  277. // 如果是相对路径,添加基础路径
  278. if (!avatarUrl.startsWith('/')) {
  279. return `/static/${avatarUrl}`
  280. }
  281. return avatarUrl
  282. }
  283. // 无头像URL时使用默认头像
  284. return this.defaultAvatar
  285. },
  286. /**
  287. * 判断是否显示占位符
  288. */
  289. shouldShowPlaceholder(item) {
  290. // 防御性检查:确保item存在
  291. if (!item || typeof item !== 'object') {
  292. return true // 无效数据时显示占位符
  293. }
  294. // 如果没有头像URL,或头像加载失败,显示占位符
  295. return !item.avatarUrl || item.imageLoadError ||
  296. (item.avatarUrl && item.avatarUrl.includes('placeholder'))
  297. },
  298. /**
  299. * 图片加载成功处理
  300. */
  301. handleImageLoad(item) {
  302. // 防御性检查:确保item存在且是对象
  303. if (!item || typeof item !== 'object') {
  304. console.warn('handleImageLoad: item参数无效', item)
  305. return
  306. }
  307. this.$set(item, 'imageLoadError', false)
  308. this.$set(item, 'imageLoaded', true)
  309. },
  310. /**
  311. * 图片加载错误处理
  312. */
  313. handleImageError(item) {
  314. // 防御性检查:确保item存在且是对象
  315. if (!item || typeof item !== 'object') {
  316. console.warn('handleImageError: item参数无效', item)
  317. return
  318. }
  319. console.log('头像加载失败:', item.realName, item.avatarUrl)
  320. this.$set(item, 'imageLoadError', true)
  321. this.$set(item, 'imageLoaded', false)
  322. },
  323. /**
  324. * 返回
  325. */
  326. goBack() {
  327. uni.navigateBack({
  328. fail: () => {
  329. uni.switchTab({
  330. url: '/pages/index/index'
  331. })
  332. }
  333. })
  334. }
  335. }
  336. }
  337. </script>
  338. <style lang="scss" scoped>
  339. .matchmaker-list-page {
  340. min-height: 100vh;
  341. background-color: #F5F5F5;
  342. }
  343. /* 导航栏 */
  344. .nav-bar {
  345. display: flex;
  346. justify-content: space-between;
  347. align-items: center;
  348. height: 88rpx;
  349. padding: 0 30rpx;
  350. background-color: #FFFFFF;
  351. border-bottom: 1rpx solid #F0F0F0;
  352. .nav-left {
  353. width: 60rpx;
  354. height: 60rpx;
  355. display: flex;
  356. align-items: center;
  357. justify-content: center;
  358. .back-icon {
  359. font-size: 48rpx;
  360. color: #333333;
  361. }
  362. }
  363. .nav-title {
  364. flex: 1;
  365. text-align: center;
  366. font-size: 36rpx;
  367. font-weight: bold;
  368. color: #333333;
  369. }
  370. .nav-right {
  371. width: 60rpx;
  372. }
  373. }
  374. /* 筛选栏 */
  375. .filter-bar {
  376. background-color: #FFFFFF;
  377. padding: 20rpx 0;
  378. border-bottom: 1rpx solid #F0F0F0;
  379. .filter-scroll {
  380. white-space: nowrap;
  381. .filter-item {
  382. display: inline-block;
  383. padding: 10rpx 30rpx;
  384. margin-left: 30rpx;
  385. background-color: #F5F5F5;
  386. border-radius: 30rpx;
  387. font-size: 28rpx;
  388. color: #666666;
  389. transition: all 0.3s;
  390. &.active {
  391. background-color: #E91E63;
  392. color: #FFFFFF;
  393. }
  394. }
  395. }
  396. }
  397. /* 红娘列表 */
  398. .matchmaker-scroll {
  399. height: calc(100vh - 88rpx - 80rpx);
  400. }
  401. .matchmaker-list {
  402. padding: 20rpx 30rpx;
  403. }
  404. .matchmaker-card {
  405. display: flex;
  406. padding: 30rpx;
  407. margin-bottom: 20rpx;
  408. background-color: #FFFFFF;
  409. border-radius: 20rpx;
  410. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  411. transition: transform 0.2s;
  412. &:active {
  413. transform: scale(0.98);
  414. }
  415. /* 左侧头像区 */
  416. .avatar-section {
  417. position: relative;
  418. margin-right: 30rpx;
  419. .avatar {
  420. width: 160rpx;
  421. height: 160rpx;
  422. border-radius: 20rpx;
  423. background: linear-gradient(135deg, #F5F5F5 0%, #E0E0E0 100%);
  424. }
  425. .avatar-placeholder {
  426. position: absolute;
  427. top: 0;
  428. left: 0;
  429. width: 160rpx;
  430. height: 160rpx;
  431. border-radius: 20rpx;
  432. background: linear-gradient(135deg, #FFE5F1 0%, #FFECF3 100%);
  433. display: flex;
  434. align-items: center;
  435. justify-content: center;
  436. border: 2rpx solid rgba(233, 30, 99, 0.1);
  437. .placeholder-icon {
  438. font-size: 80rpx;
  439. color: rgba(233, 30, 99, 0.3);
  440. }
  441. }
  442. .level-badge {
  443. position: absolute;
  444. bottom: -10rpx;
  445. left: 50%;
  446. transform: translateX(-50%);
  447. padding: 5rpx 15rpx;
  448. border-radius: 20rpx;
  449. font-size: 20rpx;
  450. color: #FFFFFF;
  451. white-space: nowrap;
  452. &.level-1 {
  453. background: linear-gradient(135deg, #CD7F32 0%, #8B4513 100%);
  454. }
  455. &.level-2 {
  456. background: linear-gradient(135deg, #C0C0C0 0%, #808080 100%);
  457. }
  458. &.level-3 {
  459. background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
  460. }
  461. &.level-4 {
  462. background: linear-gradient(135deg, #00CED1 0%, #4682B4 100%);
  463. }
  464. &.level-5 {
  465. background: linear-gradient(135deg, #9370DB 0%, #8A2BE2 100%);
  466. }
  467. }
  468. }
  469. /* 右侧信息区 */
  470. .info-section {
  471. flex: 1;
  472. display: flex;
  473. flex-direction: column;
  474. gap: 15rpx;
  475. .name-row {
  476. display: flex;
  477. align-items: center;
  478. gap: 15rpx;
  479. .name {
  480. font-size: 34rpx;
  481. font-weight: bold;
  482. color: #333333;
  483. }
  484. .type-tag {
  485. padding: 5rpx 15rpx;
  486. border-radius: 10rpx;
  487. font-size: 22rpx;
  488. color: #FFFFFF;
  489. &.formal {
  490. background-color: #E91E63;
  491. }
  492. &.parttime {
  493. background-color: #FF9800;
  494. }
  495. }
  496. }
  497. .stats-row {
  498. display: flex;
  499. align-items: center;
  500. gap: 10rpx;
  501. .stats-icon {
  502. font-size: 28rpx;
  503. }
  504. .stats-text {
  505. font-size: 26rpx;
  506. color: #666666;
  507. }
  508. }
  509. .location-row {
  510. display: flex;
  511. align-items: center;
  512. gap: 10rpx;
  513. .location-icon {
  514. font-size: 24rpx;
  515. }
  516. .location-text {
  517. font-size: 26rpx;
  518. color: #999999;
  519. }
  520. }
  521. .profile-row {
  522. .profile-text {
  523. font-size: 26rpx;
  524. color: #666666;
  525. line-height: 1.5;
  526. display: -webkit-box;
  527. -webkit-box-orient: vertical;
  528. -webkit-line-clamp: 2;
  529. overflow: hidden;
  530. }
  531. }
  532. .action-row {
  533. display: flex;
  534. gap: 20rpx;
  535. margin-top: 10rpx;
  536. .contact-btn {
  537. display: flex;
  538. align-items: center;
  539. gap: 10rpx;
  540. padding: 10rpx 30rpx;
  541. background-color: #4CAF50;
  542. border-radius: 30rpx;
  543. color: #FFFFFF;
  544. font-size: 24rpx;
  545. .btn-icon {
  546. font-size: 28rpx;
  547. }
  548. }
  549. .detail-btn {
  550. flex: 1;
  551. display: flex;
  552. align-items: center;
  553. justify-content: center;
  554. gap: 10rpx;
  555. padding: 10rpx 30rpx;
  556. background-color: #E91E63;
  557. border-radius: 30rpx;
  558. color: #FFFFFF;
  559. font-size: 24rpx;
  560. .arrow {
  561. font-size: 28rpx;
  562. }
  563. }
  564. }
  565. }
  566. }
  567. /* 加载状态 */
  568. .load-status {
  569. padding: 30rpx;
  570. text-align: center;
  571. .loading-text,
  572. .nomore-text {
  573. font-size: 26rpx;
  574. color: #999999;
  575. }
  576. }
  577. /* 空状态 */
  578. .empty-state {
  579. display: flex;
  580. flex-direction: column;
  581. align-items: center;
  582. justify-content: center;
  583. padding: 200rpx 0;
  584. .empty-icon {
  585. font-size: 120rpx;
  586. margin-bottom: 30rpx;
  587. }
  588. .empty-text {
  589. font-size: 28rpx;
  590. color: #999999;
  591. }
  592. }
  593. /* 底部占位 */
  594. .bottom-placeholder {
  595. height: 20rpx;
  596. }
  597. </style>