list.vue 14 KB

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