list.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. console.log('成功案例列表页面加载')
  83. console.log('默认案例数据:', this.caseList.length)
  84. // 数据健康检查
  85. this.checkDataHealth()
  86. this.loadCaseList()
  87. },
  88. onReachBottom() {
  89. if (this.hasMore && !this.loading) {
  90. this.pageNum++
  91. this.loadCaseList()
  92. }
  93. },
  94. methods: {
  95. // 加载成功案例列表
  96. async loadCaseList() {
  97. if (this.loading) return
  98. this.loading = true
  99. try {
  100. console.log('尝试加载成功案例API数据...')
  101. const data = await api.successCase.getList({
  102. pageNum: this.pageNum,
  103. pageSize: this.pageSize
  104. })
  105. if (data && data.length > 0) {
  106. if (this.pageNum === 1) {
  107. // 第一页,替换数据
  108. this.caseList = data
  109. } else {
  110. // 后续页,追加数据
  111. this.caseList = [...this.caseList, ...data]
  112. }
  113. this.hasMore = data.length >= this.pageSize
  114. console.log('API数据加载成功:', data.length, '条')
  115. } else {
  116. this.hasMore = false
  117. console.log('API返回数据为空,使用默认数据')
  118. }
  119. } catch (error) {
  120. console.error('加载成功案例失败:', error)
  121. // API失败时,如果是第一页且当前列表为空,保留默认数据
  122. if (this.pageNum === 1 && this.caseList.length === 0) {
  123. console.log('API失败,保留默认数据')
  124. uni.showToast({
  125. title: '使用示例数据',
  126. icon: 'none'
  127. })
  128. } else {
  129. uni.showToast({
  130. title: '加载失败',
  131. icon: 'none'
  132. })
  133. }
  134. this.hasMore = false
  135. } finally {
  136. this.loading = false
  137. }
  138. },
  139. // 格式化日期
  140. formatDate(dateStr) {
  141. if (!dateStr) return '未知日期'
  142. const date = this.$util && this.$util.parseDate ? this.$util.parseDate(dateStr) : new Date(String(dateStr).replace(/-/g,'/'))
  143. const year = date.getFullYear()
  144. const month = date.getMonth() + 1
  145. const day = date.getDate()
  146. return `${year}年${month}月${day}日`
  147. },
  148. // 跳转到详情
  149. goToDetail(caseNo) {
  150. console.log('跳转到案例详情, caseNo:', caseNo)
  151. uni.navigateTo({
  152. url: `/pages/success-case/detail?caseNo=${caseNo}`,
  153. success: () => {
  154. console.log('跳转成功')
  155. },
  156. fail: (err) => {
  157. console.error('跳转失败:', err)
  158. uni.showToast({
  159. title: '跳转失败',
  160. icon: 'none'
  161. })
  162. }
  163. })
  164. },
  165. // 返回
  166. goBack() {
  167. console.log('返回上一页')
  168. uni.navigateBack({
  169. fail: () => {
  170. // 返回失败时跳转首页
  171. uni.navigateTo({
  172. url: '/pages/index/index'
  173. })
  174. }
  175. })
  176. },
  177. // 数据健康检查
  178. checkDataHealth() {
  179. console.log('=== 成功案例列表页面数据健康检查 ===')
  180. console.log('caseList长度:', this.caseList.length)
  181. console.log('DEFAULT_IMAGES:', this.DEFAULT_IMAGES)
  182. console.log('第一个案例:', this.caseList[0])
  183. // 确保每个案例都有必要的字段
  184. this.caseList.forEach((item, index) => {
  185. if (!item.case_no) {
  186. item.case_no = `CASE00${index + 1}`
  187. }
  188. if (!item.image_url) {
  189. item.image_url = this.DEFAULT_IMAGES.couple
  190. }
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss" scoped>
  197. .success-case-page {
  198. min-height: 100vh;
  199. background-color: #FFF9F9;
  200. padding-top: 90rpx;
  201. }
  202. /* 自定义导航栏 */
  203. .custom-navbar {
  204. position: fixed;
  205. top: 0;
  206. left: 0;
  207. right: 0;
  208. height: 90rpx;
  209. display: flex;
  210. align-items: center;
  211. justify-content: space-between;
  212. padding: 0 20rpx;
  213. background-color: #E91E63;
  214. z-index: 999;
  215. .navbar-left,
  216. .navbar-right {
  217. width: 80rpx;
  218. }
  219. .back-icon {
  220. font-size: 40rpx;
  221. color: #FFFFFF;
  222. font-weight: bold;
  223. }
  224. .navbar-title {
  225. flex: 1;
  226. text-align: center;
  227. font-size: 32rpx;
  228. font-weight: bold;
  229. color: #FFFFFF;
  230. }
  231. }
  232. /* 成功案例列表 */
  233. .case-list {
  234. padding: 20rpx 30rpx;
  235. .case-card {
  236. position: relative;
  237. margin-bottom: 20rpx;
  238. background-color: #FFFFFF;
  239. border-radius: 20rpx;
  240. overflow: hidden;
  241. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  242. .case-image {
  243. width: 100%;
  244. height: 400rpx;
  245. background-color: #F5F5F5;
  246. }
  247. .case-info {
  248. padding: 30rpx;
  249. .case-names {
  250. font-size: 32rpx;
  251. font-weight: bold;
  252. color: #333333;
  253. margin-bottom: 15rpx;
  254. }
  255. .case-quote {
  256. font-size: 28rpx;
  257. color: #666666;
  258. line-height: 1.6;
  259. margin-bottom: 20rpx;
  260. display: -webkit-box;
  261. -webkit-box-orient: vertical;
  262. -webkit-line-clamp: 2;
  263. overflow: hidden;
  264. }
  265. .case-meta {
  266. font-size: 24rpx;
  267. color: #999999;
  268. margin-bottom: 20rpx;
  269. }
  270. .case-btn {
  271. display: inline-block;
  272. padding: 10rpx 30rpx;
  273. background-color: #E91E63;
  274. color: #FFFFFF;
  275. border-radius: 30rpx;
  276. font-size: 24rpx;
  277. }
  278. }
  279. .success-badge {
  280. position: absolute;
  281. top: 20rpx;
  282. right: 20rpx;
  283. width: 60rpx;
  284. height: 60rpx;
  285. background-color: #4CAF50;
  286. border-radius: 50%;
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. box-shadow: 0 4rpx 12rpx rgba(76, 175, 80, 0.3);
  291. .badge-icon {
  292. color: #FFFFFF;
  293. font-size: 36rpx;
  294. font-weight: bold;
  295. }
  296. }
  297. }
  298. }
  299. /* 加载更多 */
  300. .load-more,
  301. .no-more {
  302. padding: 30rpx 0;
  303. text-align: center;
  304. .load-text,
  305. .no-more-text {
  306. font-size: 24rpx;
  307. color: #999999;
  308. }
  309. }
  310. </style>