points-mall.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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. // 如果没有matchmakerId,通过API获取
  118. try {
  119. const res = await api.matchmaker.getByUserId(userInfo.userId)
  120. let matchmaker = res
  121. if (res && res.data) {
  122. matchmaker = res.data
  123. }
  124. if (matchmaker && (matchmaker.matchmakerId || matchmaker.matchmaker_id)) {
  125. this.makerId = matchmaker.matchmakerId || matchmaker.matchmaker_id
  126. // 保存到userInfo中
  127. userInfo.matchmakerId = this.makerId
  128. uni.setStorageSync('userInfo', userInfo)
  129. }
  130. } catch (e) {
  131. }
  132. }
  133. await Promise.all([
  134. this.loadBalance(),
  135. this.loadProducts(),
  136. this.loadRecommendProducts()
  137. ])
  138. },
  139. // 加载积分余额
  140. async loadBalance() {
  141. if (!this.makerId) return
  142. try {
  143. const res = await api.pointsMall.getBalance(this.makerId)
  144. this.userPoints = res.balance || 0
  145. } catch (e) {
  146. }
  147. },
  148. // 加载商品列表
  149. async loadProducts() {
  150. this.loading = true
  151. try {
  152. const res = await api.pointsMall.getProducts({ pageNum: 1, pageSize: 50 })
  153. this.allProducts = (res.list || []).map(item => ({
  154. id: item.id,
  155. name: item.name,
  156. points: item.pointsPrice,
  157. image: item.imageUrl || this.defaultImage,
  158. category: item.category,
  159. stock: item.stock,
  160. description: item.description
  161. }))
  162. } catch (e) {
  163. } finally {
  164. this.loading = false
  165. }
  166. },
  167. // 加载推荐商品
  168. async loadRecommendProducts() {
  169. try {
  170. const res = await api.pointsMall.getRecommendProducts(10)
  171. this.recommendedProducts = (res || []).map(item => ({
  172. id: item.id,
  173. name: item.name,
  174. points: item.pointsPrice,
  175. image: item.imageUrl || this.defaultImage,
  176. category: item.category,
  177. stock: item.stock
  178. }))
  179. } catch (e) {
  180. }
  181. },
  182. // 返回上一页
  183. handleBack() {
  184. uni.navigateBack()
  185. },
  186. // 查看积分明细
  187. handlePointsDetail() {
  188. uni.navigateTo({
  189. url: '/pages/matchmaker-workbench/points-detail'
  190. })
  191. },
  192. // 赚取积分
  193. handleEarnPoints() {
  194. uni.navigateTo({
  195. url: '/pages/matchmaker-workbench/earn-points'
  196. })
  197. },
  198. // 查看更多
  199. handleViewMore() {
  200. // 切换到全部分类
  201. this.activeCategory = 0
  202. },
  203. // 商品点击 - 跳转到商品详情
  204. handleProductClick(product) {
  205. uni.navigateTo({
  206. url: `/pages/matchmaker-workbench/product-detail?id=${product.id}`
  207. })
  208. },
  209. // 图片加载失败处理
  210. handleImageError(e, index) {
  211. if (this.recommendedProducts[index]) {
  212. this.$set(this.recommendedProducts[index], 'image', this.defaultImage)
  213. }
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .points-mall {
  220. min-height: 100vh;
  221. background: #FFF9F9;
  222. display: flex;
  223. flex-direction: column;
  224. }
  225. /* 顶部导航栏 */
  226. .header {
  227. display: flex;
  228. align-items: center;
  229. justify-content: space-between;
  230. padding: 25rpx 30rpx;
  231. padding-top: calc(25rpx + env(safe-area-inset-top));
  232. background: #FFF9F9;
  233. border-bottom: 1rpx solid #F0F0F0;
  234. .back-icon {
  235. width: 44rpx;
  236. height: 44rpx;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. font-size: 32rpx;
  241. color: #333;
  242. &::before {
  243. content: '‹';
  244. }
  245. }
  246. .header-title {
  247. font-size: 38rpx;
  248. font-weight: bold;
  249. color: #333;
  250. }
  251. .header-right {
  252. display: flex;
  253. align-items: center;
  254. gap: 20rpx;
  255. .search-icon {
  256. width: 44rpx;
  257. height: 44rpx;
  258. display: flex;
  259. align-items: center;
  260. justify-content: center;
  261. font-size: 32rpx;
  262. color: #999;
  263. &::before {
  264. content: '🔍';
  265. }
  266. }
  267. .cart-icon {
  268. width: 44rpx;
  269. height: 44rpx;
  270. display: flex;
  271. align-items: center;
  272. justify-content: center;
  273. font-size: 32rpx;
  274. color: #999;
  275. position: relative;
  276. &::before {
  277. content: '🛒';
  278. }
  279. .cart-badge {
  280. position: absolute;
  281. top: -8rpx;
  282. right: -8rpx;
  283. width: 32rpx;
  284. height: 32rpx;
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. background-color: #FF4444;
  289. color: #FFFFFF;
  290. font-size: 20rpx;
  291. font-weight: bold;
  292. border-radius: 50%;
  293. }
  294. }
  295. }
  296. }
  297. /* 积分显示区域 */
  298. .points-section {
  299. background: linear-gradient(135deg, #FCE4EC 0%, #F8BBD0 100%);
  300. padding: 40rpx 30rpx;
  301. border-radius: 0 0 30rpx 30rpx;
  302. .points-header {
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. gap: 20rpx;
  307. margin-bottom: 30rpx;
  308. .points-label {
  309. font-size: 28rpx;
  310. color: #666666;
  311. }
  312. .points-value {
  313. font-size: 64rpx;
  314. font-weight: bold;
  315. color: #333333;
  316. }
  317. .points-icon {
  318. font-size: 48rpx;
  319. }
  320. }
  321. .points-actions {
  322. display: flex;
  323. justify-content: space-around;
  324. .action-btn {
  325. padding: 15rpx 40rpx;
  326. background-color: rgba(255, 255, 255, 0.8);
  327. color: #9C27B0;
  328. border-radius: 30rpx;
  329. font-size: 28rpx;
  330. font-weight: bold;
  331. transition: all 0.3s;
  332. &:active {
  333. background-color: rgba(255, 255, 255, 1);
  334. }
  335. }
  336. }
  337. }
  338. /* 分类标签 */
  339. .category-tabs {
  340. display: flex;
  341. gap: 20rpx;
  342. padding: 20rpx 30rpx;
  343. background: #FFFFFF;
  344. overflow-x: auto;
  345. white-space: nowrap;
  346. .category-tab {
  347. padding: 12rpx 24rpx;
  348. background: #F5F5F5;
  349. color: #666;
  350. border-radius: 20rpx;
  351. font-size: 26rpx;
  352. white-space: nowrap;
  353. transition: all 0.3s;
  354. &.active {
  355. background: #9C27B0;
  356. color: #FFFFFF;
  357. font-weight: bold;
  358. }
  359. }
  360. }
  361. /* 商品容器 */
  362. .products-container {
  363. flex: 1;
  364. background: #FFFFFF;
  365. padding: 20rpx 30rpx;
  366. }
  367. /* 分类标题 */
  368. .section-header {
  369. display: flex;
  370. align-items: center;
  371. justify-content: space-between;
  372. margin-bottom: 20rpx;
  373. .section-title {
  374. font-size: 32rpx;
  375. font-weight: bold;
  376. color: #333;
  377. }
  378. .product-count {
  379. font-size: 24rpx;
  380. color: #999;
  381. }
  382. .view-more {
  383. display: flex;
  384. align-items: center;
  385. gap: 5rpx;
  386. .view-more-text {
  387. font-size: 24rpx;
  388. color: #9C27B0;
  389. }
  390. .arrow {
  391. font-size: 28rpx;
  392. color: #9C27B0;
  393. }
  394. }
  395. }
  396. /* 空状态 */
  397. .empty-state {
  398. text-align: center;
  399. padding: 100rpx 0;
  400. color: #999;
  401. font-size: 28rpx;
  402. }
  403. /* 废弃的view-more样式 */
  404. .view-more-deprecated {
  405. display: flex;
  406. align-items: center;
  407. gap: 5rpx;
  408. .view-more-text {
  409. font-size: 24rpx;
  410. color: #9C27B0;
  411. }
  412. .arrow {
  413. font-size: 28rpx;
  414. color: #9C27B0;
  415. }
  416. }
  417. /* 商品网格 */
  418. .products-grid {
  419. display: grid;
  420. grid-template-columns: repeat(2, 1fr);
  421. gap: 20rpx;
  422. margin-bottom: 20rpx;
  423. .product-card {
  424. background: #FFFFFF;
  425. border-radius: 16rpx;
  426. overflow: hidden;
  427. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.08);
  428. transition: all 0.3s;
  429. &:active {
  430. transform: translateY(-4rpx);
  431. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.12);
  432. }
  433. .product-image {
  434. width: 100%;
  435. height: 300rpx;
  436. background: #F5F5F5;
  437. display: flex;
  438. align-items: center;
  439. justify-content: center;
  440. image {
  441. width: 100%;
  442. height: 100%;
  443. object-fit: cover;
  444. }
  445. }
  446. .product-info {
  447. padding: 15rpx;
  448. .product-name {
  449. display: block;
  450. font-size: 24rpx;
  451. color: #333;
  452. margin-bottom: 10rpx;
  453. overflow: hidden;
  454. text-overflow: ellipsis;
  455. white-space: nowrap;
  456. }
  457. .product-price {
  458. display: flex;
  459. align-items: center;
  460. gap: 5rpx;
  461. .price-value {
  462. font-size: 28rpx;
  463. font-weight: bold;
  464. color: #9C27B0;
  465. }
  466. .price-unit {
  467. font-size: 24rpx;
  468. }
  469. }
  470. }
  471. }
  472. }
  473. /* 底部空白 */
  474. .bottom-spacer {
  475. height: 40rpx;
  476. }
  477. </style>