points-mall.vue 12 KB

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