shop.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="shop-index">
  3. <uv-swiper keyName="image" :list="topicList" height="200" indicator indicatorMode="line" circular radius="0"
  4. imgMode="scaleToFill" v-if="topicList.length > 0">
  5. </uv-swiper>
  6. <view v-if="hotList.length>0">
  7. <view class="gl-title">热门推荐</view>
  8. <uv-list>
  9. <uv-list-item v-for="(item,index) in hotList" :key="item.id" border>
  10. <template #body>
  11. <view style="width: 100%;">
  12. <good-item :item="item"></good-item>
  13. </view>
  14. </template>
  15. </uv-list-item>
  16. </uv-list>
  17. </view>
  18. <view v-if="newList.length>0">
  19. <view class="gl-title">新品推荐</view>
  20. <uv-list>
  21. <uv-list-item v-for="(item,index) in newList" :key="item.id" border>
  22. <template #body>
  23. <view style="width: 100%;">
  24. <good-item :item="item"></good-item>
  25. </view>
  26. </template>
  27. </uv-list-item>
  28. </uv-list>
  29. </view>
  30. <view class="shop-cart">
  31. <view class="cartbox" @click="$navigateTo('/subPages/shopPage/cart/cart')">
  32. <uv-badge :value="cartCount" type="error" :offset="[0,0]" max="99" numberType="overflow" absolute
  33. :customStyle="{
  34. zIndex:99
  35. }">
  36. </uv-badge>
  37. <uv-icon name="shopping-cart" size="30"></uv-icon>
  38. </view>
  39. </view>
  40. <view class="shop-cart tab">
  41. <view class="cartbox" @click="$navigateTo('/subPages/shopPage/menu/menu')">
  42. <text>分类</text>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import {
  49. getTopicList,
  50. getSearchHot,
  51. getSearchNew,
  52. getCartCount
  53. } from '@/request/api/shop.js'
  54. import goodItem from '@/components/common/goodItem.vue';
  55. export default {
  56. components: {
  57. goodItem
  58. },
  59. data() {
  60. return {
  61. newList: [],
  62. hotList: [],
  63. topicList: [],
  64. cartCount: 0
  65. }
  66. },
  67. onShow() {
  68. this.init();
  69. },
  70. methods: {
  71. async init() {
  72. this.cartCount = 0;
  73. if (uni.getStorageSync('shopMobileToken')) this.getCartCount();
  74. this.queryTopic();
  75. this.queryGoodsHot();
  76. this.queryGoodsHotNew();
  77. },
  78. async getCartCount() {
  79. let countData = await getCartCount();
  80. if (countData.state) this.cartCount = countData.data;
  81. },
  82. async queryGoodsHot() {
  83. let hotData = await getSearchHot();
  84. if (hotData.state) this.hotList = hotData.data;
  85. },
  86. async queryGoodsHotNew() {
  87. let newData = await getSearchNew();
  88. if (newData.state) this.newList = newData.data;
  89. },
  90. async queryTopic() {
  91. const baseApi = this.baseApi;
  92. let topicData = await getTopicList();
  93. if (topicData.state) this.topicList = topicData.data.map(node => this.shopImage(node.article.img));
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .shop-index {
  100. padding-bottom: 40rpx;
  101. .tabs {
  102. background: #fff;
  103. }
  104. }
  105. .gl-title {
  106. padding: 20rpx;
  107. }
  108. .shop-cart {
  109. position: fixed;
  110. bottom: 80rpx;
  111. right: 30rpx;
  112. width: 100rpx;
  113. height: 100rpx;
  114. .cartbox {
  115. width: 100%;
  116. height: 100%;
  117. border-radius: 50%;
  118. display: flex;
  119. align-items: center;
  120. justify-content: center;
  121. box-shadow: 0px 2px 10px rgba(3, 3, 3, 0.1);
  122. background-color: #ffffff;
  123. }
  124. &.tab {
  125. bottom: 200rpx;
  126. }
  127. }
  128. </style>