list.vue 14 KB

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