shop.vue 3.1 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. if (uni.getStorageSync('shopMobileToken')) this.getCartCount();
  73. this.queryTopic();
  74. this.queryGoodsHot();
  75. this.queryGoodsHotNew();
  76. },
  77. async getCartCount() {
  78. let countData = await getCartCount();
  79. if (countData.state) this.cartCount = countData.data;
  80. },
  81. async queryGoodsHot() {
  82. let hotData = await getSearchHot();
  83. if (hotData.state) this.hotList = hotData.data;
  84. },
  85. async queryGoodsHotNew() {
  86. let newData = await getSearchNew();
  87. if (newData.state) this.newList = newData.data;
  88. },
  89. async queryTopic() {
  90. const baseApi = this.baseApi;
  91. let topicData = await getTopicList();
  92. if (topicData.state) this.topicList = topicData.data.map(node => this.shopImage(node.article.img));
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .shop-index {
  99. padding-bottom: 40rpx;
  100. .tabs {
  101. background: #fff;
  102. }
  103. }
  104. .gl-title {
  105. padding: 20rpx;
  106. }
  107. .shop-cart {
  108. position: fixed;
  109. bottom: 80rpx;
  110. right: 30rpx;
  111. width: 100rpx;
  112. height: 100rpx;
  113. .cartbox {
  114. width: 100%;
  115. height: 100%;
  116. border-radius: 50%;
  117. display: flex;
  118. align-items: center;
  119. justify-content: center;
  120. box-shadow: 0px 2px 10px rgba(3, 3, 3, 0.1);
  121. background-color: #ffffff;
  122. }
  123. &.tab {
  124. bottom: 200rpx;
  125. }
  126. }
  127. </style>