shop.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="shop-index">
  3. <uv-sticky bgColor="#fff">
  4. <uv-tabs :list="navList" @click="changeNav" :scrollable="false"></uv-tabs>
  5. </uv-sticky>
  6. <uv-swiper keyName="image" :list="topicList" height="200" radius="0" imgMode="scaleToFill"></uv-swiper>
  7. <view v-if="hotList.length>0">
  8. <view class="gl-title">热门推荐</view>
  9. <uv-list>
  10. <uv-list-item v-for="(item,index) in hotList" :key="item.id" border>
  11. <template #body>
  12. <view class="gl-item" @click="$navigateTo('/subPages/shopPage/good/good?id='+item.id)">
  13. <view class="gl-img">
  14. <uv-image width="170rpx" height="170rpx" :src="item.img">
  15. </uv-image>
  16. </view>
  17. <view>
  18. <view class="gl-name">{{item.name}}</view>
  19. <view class="gl-descript">{{item.descript}}</view>
  20. <view class="gl-price">¥{{formatPrice(item.price)}}</view>
  21. </view>
  22. </view>
  23. </template>
  24. </uv-list-item>
  25. </uv-list>
  26. </view>
  27. <view v-if="newList.length>0">
  28. <view class="gl-title">新品推荐</view>
  29. <uv-list>
  30. <uv-list-item v-for="(item,index) in newList" :key="item.id" border
  31. @click="$navigateTo('/subPages/shopPage/good/good?id='+item.id)">
  32. <template #body>
  33. <view class="gl-item">
  34. <view class="gl-img">
  35. <uv-image width="170rpx" height="170rpx" :src="item.img">
  36. </uv-image>
  37. </view>
  38. <view>
  39. <view class="gl-name">{{item.name}}</view>
  40. <view class="gl-descript">{{item.descript}}</view>
  41. <view class="gl-price">¥{{formatPrice(item.price)}}</view>
  42. </view>
  43. </view>
  44. </template>
  45. </uv-list-item>
  46. </uv-list>
  47. </view>
  48. <view class="shop-cart">
  49. <view class="cartbox" @click="$navigateTo('/subPages/shopPage/cart/cart')">
  50. <uv-badge :value="cartCount" type="error" :offset="[0,0]" max="99" numberType="overflow" absolute
  51. :customStyle="{
  52. zIndex:99
  53. }">
  54. </uv-badge>
  55. <uv-icon name="shopping-cart" size="30"></uv-icon>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. getCategoryList,
  63. getTopicList,
  64. getSearchHot,
  65. getSearchNew,
  66. getCartCount
  67. } from '@/request/api/shop.js'
  68. export default {
  69. data() {
  70. return {
  71. navList: [],
  72. newList: [],
  73. hotList: [],
  74. topicList: [],
  75. cartCount: 0
  76. }
  77. },
  78. onShow() {
  79. this.init()
  80. },
  81. methods: {
  82. async init() {
  83. if (uni.getStorageSync('shopMobileToken')) this.getCartCount();
  84. let navData = await getCategoryList();
  85. if (navData.state) {
  86. let navList = navData.data;
  87. navList.splice(0, 0, {
  88. name: '推荐',
  89. id: '0'
  90. })
  91. this.navList = navList;
  92. }
  93. this.queryGoods();
  94. this.queryTopic();
  95. },
  96. async getCartCount() {
  97. let countData = await getCartCount();
  98. if (countData.state) this.cartCount = countData.data;
  99. },
  100. changeNav(index) {
  101. },
  102. async queryGoods() {
  103. let hotData = await getSearchHot();
  104. if (hotData.state) this.hotList = hotData.data.map(node => {
  105. node['img'] = this.shopImage(node.pic);
  106. return node;
  107. });
  108. let newData = await getSearchNew();
  109. if (newData.state) this.newList = newData.data.map(node => {
  110. node['img'] = this.shopImage(node.pic);
  111. return node;
  112. });
  113. },
  114. async queryTopic() {
  115. const baseApi = this.baseApi;
  116. let topicData = await getTopicList();
  117. if (topicData.state) this.topicList = topicData.data.map(node => {
  118. node['image'] = this.shopImage(node.article.img);
  119. return node;
  120. });
  121. },
  122. toTopic(id) {
  123. this.$u.route({
  124. url: '/pages/topic/detail',
  125. params: {
  126. id: id
  127. }
  128. })
  129. },
  130. formatPrice(price) {
  131. return (price / 100).toFixed(2);
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .shop-index {
  138. padding-bottom: 40rpx;
  139. .tabs {
  140. background: #fff;
  141. }
  142. }
  143. .shop-cart {
  144. position: fixed;
  145. bottom: 80rpx;
  146. right: 30rpx;
  147. width: 100rpx;
  148. height: 100rpx;
  149. .cartbox {
  150. width: 100%;
  151. height: 100%;
  152. border-radius: 50%;
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. box-shadow: 0px 2px 10px rgba(3, 3, 3, 0.1);
  157. background-color: #ffffff;
  158. }
  159. }
  160. .gl-body {
  161. background: #fff;
  162. }
  163. .gl-title {
  164. padding: 20rpx;
  165. }
  166. .gl-item {
  167. width: 100%;
  168. display: flex;
  169. align-items: center;
  170. }
  171. .gl-img {
  172. width: 170rpx;
  173. height: 170rpx;
  174. margin-right: 30rpx;
  175. }
  176. .gl-name {
  177. font-size: 32rpx;
  178. font-weight: bold;
  179. }
  180. .gl-descript {
  181. font-size: 24rpx;
  182. }
  183. .gl-price {
  184. font-size: 32rpx;
  185. color: #FA3534;
  186. margin-top: 20rpx;
  187. }
  188. </style>