list.vue 14 KB

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