list.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <view class="success-case-page">
  3. <!-- 自定义导航栏 -->
  4. <view class="custom-navbar">
  5. <view class="navbar-left" @click="goBack">
  6. <text class="back-icon">←</text>
  7. </view>
  8. <view class="navbar-title">成功案例</view>
  9. <view class="navbar-right"></view>
  10. </view>
  11. <!-- 成功案例列表 -->
  12. <view class="case-list">
  13. <view class="case-card" v-for="(item, index) in caseList" :key="index"
  14. @click="goToDetail(item.case_no)">
  15. <image :src="item.image_url || DEFAULT_IMAGES.couple" class="case-image" mode="aspectFill"></image>
  16. <view class="case-info">
  17. <view class="case-names">{{ item.male_user_nickname }} & {{ item.female_user_nickname }}</view>
  18. <view class="case-quote">{{ item.quote }}</view>
  19. <view class="case-meta">
  20. <text class="case-date">💑 {{ formatDate(item.marriage_date) }}</text>
  21. </view>
  22. <view class="case-btn">查看他们的故事</view>
  23. </view>
  24. <view class="success-badge">
  25. <text class="badge-icon">✓</text>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 加载更多 -->
  30. <view class="load-more" v-if="hasMore">
  31. <text class="load-text">{{ loading ? '加载中...' : '上拉加载更多' }}</text>
  32. </view>
  33. <view class="no-more" v-else>
  34. <text class="no-more-text">没有更多了</text>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import api from '@/utils/api.js'
  40. import { DEFAULT_IMAGES } from '@/config/index.js'
  41. export default {
  42. data() {
  43. return {
  44. caseList: [
  45. // 默认数据,确保页面有内容
  46. {
  47. case_no: 'CASE001',
  48. male_user_nickname: '张先生',
  49. female_user_nickname: '李女士',
  50. image_url: DEFAULT_IMAGES.couple,
  51. quote: '从第一次咖啡约会到领证,只用了90天',
  52. marriage_date: '2024-08-20',
  53. story: '我们通过平台相识,第一次见面是在咖啡厅...'
  54. },
  55. {
  56. case_no: 'CASE002',
  57. male_user_nickname: '王先生',
  58. female_user_nickname: '赵女士',
  59. image_url: DEFAULT_IMAGES.couple,
  60. quote: '感谢红娘的专业服务,让我们相遇相知',
  61. marriage_date: '2024-09-15',
  62. story: '感谢红娘阿姨的介绍,让我们找到了彼此...'
  63. },
  64. {
  65. case_no: 'CASE003',
  66. male_user_nickname: '刘先生',
  67. female_user_nickname: '陈女士',
  68. image_url: DEFAULT_IMAGES.couple,
  69. quote: '缘分天注定,感恩平台让我们走到一起',
  70. marriage_date: '2024-10-01',
  71. story: '国庆节的婚礼特别有意义...'
  72. }
  73. ],
  74. pageNum: 1,
  75. pageSize: 10,
  76. hasMore: true,
  77. loading: false,
  78. DEFAULT_IMAGES
  79. }
  80. },
  81. onLoad() {
  82. // 数据健康检查
  83. this.checkDataHealth()
  84. this.loadCaseList()
  85. },
  86. onReachBottom() {
  87. if (this.hasMore && !this.loading) {
  88. this.pageNum++
  89. this.loadCaseList()
  90. }
  91. },
  92. methods: {
  93. // 加载成功案例列表
  94. async loadCaseList() {
  95. if (this.loading) return
  96. this.loading = true
  97. try {
  98. const data = await api.successCase.getList({
  99. pageNum: this.pageNum,
  100. pageSize: this.pageSize
  101. })
  102. if (data && data.length > 0) {
  103. if (this.pageNum === 1) {
  104. // 第一页,替换数据
  105. this.caseList = data
  106. } else {
  107. // 后续页,追加数据
  108. this.caseList = [...this.caseList, ...data]
  109. }
  110. this.hasMore = data.length >= this.pageSize
  111. } else {
  112. this.hasMore = false
  113. }
  114. } catch (error) {
  115. console.error('加载成功案例失败:', error)
  116. // API失败时,如果是第一页且当前列表为空,保留默认数据
  117. if (this.pageNum === 1 && this.caseList.length === 0) {
  118. uni.showToast({
  119. title: '使用示例数据',
  120. icon: 'none'
  121. })
  122. } else {
  123. uni.showToast({
  124. title: '加载失败',
  125. icon: 'none'
  126. })
  127. }
  128. this.hasMore = false
  129. } finally {
  130. this.loading = false
  131. }
  132. },
  133. // 格式化日期
  134. formatDate(dateStr) {
  135. if (!dateStr) return '未知日期'
  136. const date = this.$util && this.$util.parseDate ? this.$util.parseDate(dateStr) : new Date(String(dateStr).replace(/-/g,'/'))
  137. const year = date.getFullYear()
  138. const month = date.getMonth() + 1
  139. const day = date.getDate()
  140. return `${year}年${month}月${day}日`
  141. },
  142. // 跳转到详情
  143. goToDetail(caseNo) {
  144. uni.navigateTo({
  145. url: `/pages/success-case/detail?caseNo=${caseNo}`,
  146. success: () => {
  147. },
  148. fail: (err) => {
  149. console.error('跳转失败:', err)
  150. uni.showToast({
  151. title: '跳转失败',
  152. icon: 'none'
  153. })
  154. }
  155. })
  156. },
  157. // 返回
  158. goBack() {
  159. uni.navigateBack({
  160. fail: () => {
  161. // 返回失败时跳转首页
  162. uni.navigateTo({
  163. url: '/pages/index/index'
  164. })
  165. }
  166. })
  167. },
  168. // 数据健康检查
  169. checkDataHealth() {
  170. // 确保每个案例都有必要的字段
  171. this.caseList.forEach((item, index) => {
  172. if (!item.case_no) {
  173. item.case_no = `CASE00${index + 1}`
  174. }
  175. if (!item.image_url) {
  176. item.image_url = this.DEFAULT_IMAGES.couple
  177. }
  178. })
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .success-case-page {
  185. min-height: 100vh;
  186. background-color: #FFF9F9;
  187. padding-top: 90rpx;
  188. margin-top: 40px;
  189. }
  190. /* 自定义导航栏 */
  191. .custom-navbar {
  192. position: fixed;
  193. top: 0;
  194. left: 0;
  195. right: 0;
  196. height: 110rpx;
  197. display: flex;
  198. align-items: center;
  199. justify-content: space-between;
  200. padding: 0 20rpx;
  201. padding-top: 30px;
  202. background-color: #E91E63;
  203. z-index: 999;
  204. .navbar-left,
  205. .navbar-right {
  206. width: 100rpx;
  207. }
  208. .back-icon {
  209. font-size: 40rpx;
  210. color: #FFFFFF;
  211. font-weight: bold;
  212. }
  213. .navbar-title {
  214. flex: 1;
  215. text-align: center;
  216. font-size: 32rpx;
  217. font-weight: bold;
  218. color: #FFFFFF;
  219. }
  220. }
  221. /* 成功案例列表 */
  222. .case-list {
  223. padding: 20rpx 30rpx;
  224. .case-card {
  225. position: relative;
  226. margin-bottom: 20rpx;
  227. background-color: #FFFFFF;
  228. border-radius: 20rpx;
  229. overflow: hidden;
  230. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  231. .case-image {
  232. width: 100%;
  233. height: 400rpx;
  234. background-color: #F5F5F5;
  235. }
  236. .case-info {
  237. padding: 30rpx;
  238. .case-names {
  239. font-size: 32rpx;
  240. font-weight: bold;
  241. color: #333333;
  242. margin-bottom: 15rpx;
  243. }
  244. .case-quote {
  245. font-size: 28rpx;
  246. color: #666666;
  247. line-height: 1.6;
  248. margin-bottom: 20rpx;
  249. display: -webkit-box;
  250. -webkit-box-orient: vertical;
  251. -webkit-line-clamp: 2;
  252. overflow: hidden;
  253. }
  254. .case-meta {
  255. font-size: 24rpx;
  256. color: #999999;
  257. margin-bottom: 20rpx;
  258. }
  259. .case-btn {
  260. display: inline-block;
  261. padding: 10rpx 30rpx;
  262. background-color: #E91E63;
  263. color: #FFFFFF;
  264. border-radius: 30rpx;
  265. font-size: 24rpx;
  266. }
  267. }
  268. .success-badge {
  269. position: absolute;
  270. top: 20rpx;
  271. right: 20rpx;
  272. width: 60rpx;
  273. height: 60rpx;
  274. background-color: #4CAF50;
  275. border-radius: 50%;
  276. display: flex;
  277. align-items: center;
  278. justify-content: center;
  279. box-shadow: 0 4rpx 12rpx rgba(76, 175, 80, 0.3);
  280. .badge-icon {
  281. color: #FFFFFF;
  282. font-size: 36rpx;
  283. font-weight: bold;
  284. }
  285. }
  286. }
  287. }
  288. /* 加载更多 */
  289. .load-more,
  290. .no-more {
  291. padding: 30rpx 0;
  292. text-align: center;
  293. .load-text,
  294. .no-more-text {
  295. font-size: 24rpx;
  296. color: #999999;
  297. }
  298. }
  299. </style>