points-mall.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. <template>
  2. <view class="points-mall">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <view class="back-icon" @click="handleBack"></view>
  6. <text class="header-title">积分商城</text>
  7. <view class="header-right">
  8. <view class="search-icon"></view>
  9. <view class="cart-icon">
  10. <text class="cart-badge">{{ cartCount }}</text>
  11. </view>
  12. </view>
  13. </view>
  14. <!-- 积分显示区域 -->
  15. <view class="points-section">
  16. <view class="points-header">
  17. <text class="points-label">我的积分</text>
  18. <text class="points-value">{{ userPoints }}</text>
  19. <text class="points-icon">💰</text>
  20. </view>
  21. <view class="points-actions">
  22. <view class="action-btn" @click="handlePointsDetail">积分明细</view>
  23. <view class="action-btn" @click="handleEarnPoints">赚取积分</view>
  24. </view>
  25. </view>
  26. <!-- 分类标签 -->
  27. <view class="category-tabs">
  28. <view
  29. v-for="(category, index) in categories"
  30. :key="index"
  31. class="category-tab"
  32. :class="{ active: activeCategory === index }"
  33. @click="activeCategory = index"
  34. >
  35. {{ category }}
  36. </view>
  37. </view>
  38. <!-- 商品区域 -->
  39. <scroll-view scroll-y class="products-container">
  40. <!-- 商品标题 -->
  41. <view class="section-header">
  42. <text class="section-title">{{ activeCategory === 0 ? '全部商品' : categories[activeCategory] }}</text>
  43. <text class="product-count">共 {{ displayProducts.length }} 件</text>
  44. </view>
  45. <!-- 空状态 -->
  46. <view v-if="displayProducts.length === 0 && !loading" class="empty-state">
  47. <text>暂无商品</text>
  48. </view>
  49. <!-- 商品网格 -->
  50. <view class="products-grid">
  51. <view
  52. v-for="(product, index) in displayProducts"
  53. :key="product.id"
  54. class="product-card"
  55. @click="handleProductClick(product)"
  56. >
  57. <view class="product-image">
  58. <image :src="product.image || defaultImage" mode="aspectFit" @error="handleImageError($event, index)"></image>
  59. </view>
  60. <view class="product-info">
  61. <text class="product-name">{{ product.name }}</text>
  62. <view class="product-price">
  63. <text class="price-value">{{ product.points }}</text>
  64. <text class="price-unit">💰</text>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <!-- 底部空白 -->
  70. <view class="bottom-spacer"></view>
  71. </scroll-view>
  72. </view>
  73. </template>
  74. <script>
  75. import api from '@/utils/api.js'
  76. export default {
  77. name: 'points-mall',
  78. data() {
  79. return {
  80. userPoints: 0,
  81. cartCount: 0,
  82. activeCategory: 0,
  83. categories: ['全部', '实物商品', '虚拟商品'],
  84. recommendedProducts: [],
  85. allProducts: [],
  86. makerId: null,
  87. loading: false,
  88. defaultImage: 'https://img.zcool.cn/community/01b8d95d3f8a8fa801211d53e8c6b0.jpg@1280w_1l_2o_100sh.jpg'
  89. }
  90. },
  91. computed: {
  92. // 根据分类筛选商品
  93. displayProducts() {
  94. if (this.activeCategory === 0) {
  95. return this.allProducts
  96. }
  97. return this.allProducts.filter(p => p.category === this.activeCategory)
  98. }
  99. },
  100. onLoad() {
  101. this.initData()
  102. },
  103. onShow() {
  104. // 每次显示页面时刷新积分余额
  105. if (this.makerId) {
  106. this.loadBalance()
  107. }
  108. },
  109. methods: {
  110. // 初始化数据
  111. async initData() {
  112. // 获取红娘ID
  113. const userInfo = uni.getStorageSync('userInfo')
  114. if (userInfo && userInfo.matchmakerId) {
  115. this.makerId = userInfo.matchmakerId
  116. } else if (userInfo && userInfo.userId) {
  117. this.makerId = userInfo.userId
  118. }
  119. await Promise.all([
  120. this.loadBalance(),
  121. this.loadProducts(),
  122. this.loadRecommendProducts()
  123. ])
  124. },
  125. // 加载积分余额
  126. async loadBalance() {
  127. if (!this.makerId) return
  128. try {
  129. const res = await api.pointsMall.getBalance(this.makerId)
  130. this.userPoints = res.balance || 0
  131. } catch (e) {
  132. console.error('获取积分余额失败:', e)
  133. }
  134. },
  135. // 加载商品列表
  136. async loadProducts() {
  137. this.loading = true
  138. try {
  139. const res = await api.pointsMall.getProducts({ pageNum: 1, pageSize: 50 })
  140. this.allProducts = (res.list || []).map(item => ({
  141. id: item.id,
  142. name: item.name,
  143. points: item.pointsPrice,
  144. image: item.imageUrl || this.defaultImage,
  145. category: item.category,
  146. stock: item.stock,
  147. description: item.description
  148. }))
  149. } catch (e) {
  150. console.error('获取商品列表失败:', e)
  151. } finally {
  152. this.loading = false
  153. }
  154. },
  155. // 加载推荐商品
  156. async loadRecommendProducts() {
  157. try {
  158. const res = await api.pointsMall.getRecommendProducts(10)
  159. this.recommendedProducts = (res || []).map(item => ({
  160. id: item.id,
  161. name: item.name,
  162. points: item.pointsPrice,
  163. image: item.imageUrl || this.defaultImage,
  164. category: item.category,
  165. stock: item.stock
  166. }))
  167. } catch (e) {
  168. console.error('获取推荐商品失败:', e)
  169. }
  170. },
  171. // 返回上一页
  172. handleBack() {
  173. uni.navigateBack()
  174. },
  175. // 查看积分明细
  176. handlePointsDetail() {
  177. uni.navigateTo({
  178. url: '/pages/matchmaker-workbench/points-detail'
  179. })
  180. },
  181. // 赚取积分
  182. handleEarnPoints() {
  183. uni.navigateTo({
  184. url: '/pages/matchmaker-workbench/earn-points'
  185. })
  186. },
  187. // 查看更多
  188. handleViewMore() {
  189. // 切换到全部分类
  190. this.activeCategory = 0
  191. },
  192. // 商品点击 - 跳转到商品详情
  193. handleProductClick(product) {
  194. uni.navigateTo({
  195. url: `/pages/matchmaker-workbench/product-detail?id=${product.id}`
  196. })
  197. },
  198. // 图片加载失败处理
  199. handleImageError(e, index) {
  200. if (this.recommendedProducts[index]) {
  201. this.$set(this.recommendedProducts[index], 'image', this.defaultImage)
  202. }
  203. }
  204. }
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .points-mall {
  209. min-height: 100vh;
  210. background: #FFF9F9;
  211. display: flex;
  212. flex-direction: column;
  213. }
  214. /* 顶部导航栏 */
  215. .header {
  216. display: flex;
  217. align-items: center;
  218. justify-content: space-between;
  219. padding: 25rpx 30rpx;
  220. padding-top: calc(25rpx + env(safe-area-inset-top));
  221. background: #FFF9F9;
  222. border-bottom: 1rpx solid #F0F0F0;
  223. .back-icon {
  224. width: 44rpx;
  225. height: 44rpx;
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. font-size: 32rpx;
  230. color: #333;
  231. &::before {
  232. content: '‹';
  233. }
  234. }
  235. .header-title {
  236. font-size: 38rpx;
  237. font-weight: bold;
  238. color: #333;
  239. }
  240. .header-right {
  241. display: flex;
  242. align-items: center;
  243. gap: 20rpx;
  244. .search-icon {
  245. width: 44rpx;
  246. height: 44rpx;
  247. display: flex;
  248. align-items: center;
  249. justify-content: center;
  250. font-size: 32rpx;
  251. color: #999;
  252. &::before {
  253. content: '🔍';
  254. }
  255. }
  256. .cart-icon {
  257. width: 44rpx;
  258. height: 44rpx;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. font-size: 32rpx;
  263. color: #999;
  264. position: relative;
  265. &::before {
  266. content: '🛒';
  267. }
  268. .cart-badge {
  269. position: absolute;
  270. top: -8rpx;
  271. right: -8rpx;
  272. width: 32rpx;
  273. height: 32rpx;
  274. display: flex;
  275. align-items: center;
  276. justify-content: center;
  277. background-color: #FF4444;
  278. color: #FFFFFF;
  279. font-size: 20rpx;
  280. font-weight: bold;
  281. border-radius: 50%;
  282. }
  283. }
  284. }
  285. }
  286. /* 积分显示区域 */
  287. .points-section {
  288. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  289. padding: 40rpx 30rpx;
  290. border-radius: 0 0 30rpx 30rpx;
  291. .points-header {
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. gap: 20rpx;
  296. margin-bottom: 30rpx;
  297. .points-label {
  298. font-size: 28rpx;
  299. color: #666666;
  300. }
  301. .points-value {
  302. font-size: 64rpx;
  303. font-weight: bold;
  304. color: #333333;
  305. }
  306. .points-icon {
  307. font-size: 48rpx;
  308. }
  309. }
  310. .points-actions {
  311. display: flex;
  312. justify-content: space-around;
  313. .action-btn {
  314. padding: 15rpx 40rpx;
  315. background-color: rgba(255, 255, 255, 0.8);
  316. color: #9C27B0;
  317. border-radius: 30rpx;
  318. font-size: 28rpx;
  319. font-weight: bold;
  320. transition: all 0.3s;
  321. &:active {
  322. background-color: rgba(255, 255, 255, 1);
  323. }
  324. }
  325. }
  326. }
  327. /* 分类标签 */
  328. .category-tabs {
  329. display: flex;
  330. gap: 20rpx;
  331. padding: 20rpx 30rpx;
  332. background: #FFFFFF;
  333. overflow-x: auto;
  334. white-space: nowrap;
  335. .category-tab {
  336. padding: 12rpx 24rpx;
  337. background: #F5F5F5;
  338. color: #666;
  339. border-radius: 20rpx;
  340. font-size: 26rpx;
  341. white-space: nowrap;
  342. transition: all 0.3s;
  343. &.active {
  344. background: #9C27B0;
  345. color: #FFFFFF;
  346. font-weight: bold;
  347. }
  348. }
  349. }
  350. /* 商品容器 */
  351. .products-container {
  352. flex: 1;
  353. background: #FFFFFF;
  354. padding: 20rpx 30rpx;
  355. }
  356. /* 分类标题 */
  357. .section-header {
  358. display: flex;
  359. align-items: center;
  360. justify-content: space-between;
  361. margin-bottom: 20rpx;
  362. .section-title {
  363. font-size: 32rpx;
  364. font-weight: bold;
  365. color: #333;
  366. }
  367. .product-count {
  368. font-size: 24rpx;
  369. color: #999;
  370. }
  371. .view-more {
  372. display: flex;
  373. align-items: center;
  374. gap: 5rpx;
  375. .view-more-text {
  376. font-size: 24rpx;
  377. color: #9C27B0;
  378. }
  379. .arrow {
  380. font-size: 28rpx;
  381. color: #9C27B0;
  382. }
  383. }
  384. }
  385. /* 空状态 */
  386. .empty-state {
  387. text-align: center;
  388. padding: 100rpx 0;
  389. color: #999;
  390. font-size: 28rpx;
  391. }
  392. /* 废弃的view-more样式 */
  393. .view-more-deprecated {
  394. display: flex;
  395. align-items: center;
  396. gap: 5rpx;
  397. .view-more-text {
  398. font-size: 24rpx;
  399. color: #9C27B0;
  400. }
  401. .arrow {
  402. font-size: 28rpx;
  403. color: #9C27B0;
  404. }
  405. }
  406. /* 商品网格 */
  407. .products-grid {
  408. display: grid;
  409. grid-template-columns: repeat(2, 1fr);
  410. gap: 20rpx;
  411. margin-bottom: 20rpx;
  412. .product-card {
  413. background: #FFFFFF;
  414. border-radius: 16rpx;
  415. overflow: hidden;
  416. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  417. transition: all 0.3s;
  418. &:active {
  419. transform: translateY(-4rpx);
  420. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.12);
  421. }
  422. .product-image {
  423. width: 100%;
  424. height: 300rpx;
  425. background: #F5F5F5;
  426. display: flex;
  427. align-items: center;
  428. justify-content: center;
  429. image {
  430. width: 100%;
  431. height: 100%;
  432. object-fit: cover;
  433. }
  434. }
  435. .product-info {
  436. padding: 15rpx;
  437. .product-name {
  438. display: block;
  439. font-size: 24rpx;
  440. color: #333;
  441. margin-bottom: 10rpx;
  442. overflow: hidden;
  443. text-overflow: ellipsis;
  444. white-space: nowrap;
  445. }
  446. .product-price {
  447. display: flex;
  448. align-items: center;
  449. gap: 5rpx;
  450. .price-value {
  451. font-size: 28rpx;
  452. font-weight: bold;
  453. color: #9C27B0;
  454. }
  455. .price-unit {
  456. font-size: 24rpx;
  457. }
  458. }
  459. }
  460. }
  461. }
  462. /* 底部空白 */
  463. .bottom-spacer {
  464. height: 40rpx;
  465. }
  466. </style>