home.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class="container">
  3. <tui-skeleton v-if="isRequest" :loadingType="3" :isLoading="true"></tui-skeleton>
  4. <!-- 首页自定义导航栏 -->
  5. <view class="search-input sticky-top">
  6. <view class="search-content" @click="handleToSearch">
  7. <text class="iconfont icon-sousuo"></text>
  8. <view class="search-text">搜索商品</view>
  9. </view>
  10. </view>
  11. <!-- 轮播图 -->
  12. <cm-banner :list="bannerList" :current="current" @change="index => (current = index)"></cm-banner>
  13. <!-- 金刚区菜单 -->
  14. <cm-navbar :modal="navbarList" @click="onNavbarClick"></cm-navbar>
  15. <!-- 加入我们 -->
  16. <view class="grid"></view>
  17. <view class="join-us">
  18. <image :src="staticUrl + 'icon-join-us.png'" class="join-icon"></image>
  19. <view class="join-content">
  20. <view class="join-label-title">呵呵商城福利群</view>
  21. <view class="join-label-text">进群第一时间得知优惠福利!</view>
  22. </view>
  23. <view class="join-button" @click="handleJoinUs">加入我们</view>
  24. </view>
  25. <view class="grid"></view>
  26. <!-- 优惠券专区 -->
  27. <view class="coupon-area" v-if="couponList.length > 0">
  28. <cm-floor-title title="优惠券专区" @click="onMoreCoupon"></cm-floor-title>
  29. <cm-coupon-area :couponList="couponList"></cm-coupon-area>
  30. </view>
  31. <!-- 楼层区域 -->
  32. <view class="cm-floor" v-for="floorData in floorList" :key="floorData.id">
  33. <cm-floor-template
  34. :floorData="floorData"
  35. @onBannerClick="onBannerClick"
  36. @more="onMoreProduct"
  37. ></cm-floor-template>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { fetchHomeCarousel, fetchHomeNavbar, fetchHomeFloorData, fetchHomeCouponList } from '@/services/api/home.js'
  43. import { fetchProductFloorList } from '@/services/api/goods.js'
  44. import { shareDataResult } from '@/common/share.helper.js'
  45. import { mapActions, mapGetters } from 'vuex'
  46. export default {
  47. data() {
  48. return {
  49. isRequest: true,
  50. bannerList: [],
  51. navbarList: [],
  52. floorInfo: {},
  53. floorList: [],
  54. couponList: [],
  55. current: 0,
  56. isRefresh: false
  57. }
  58. },
  59. computed: {
  60. ...mapGetters(['userId'])
  61. },
  62. onPullDownRefresh() {
  63. setTimeout(() => uni.stopPullDownRefresh(), 2000)
  64. },
  65. onShareAppMessage() {
  66. const shareData = { type: 0, inviteUserId: this.userId }
  67. return shareDataResult(shareData)
  68. },
  69. onShow() {
  70. this.fetchCartKindCount()
  71. },
  72. onLoad() {
  73. this.initHomeInfo()
  74. },
  75. methods: {
  76. ...mapActions('cart', ['fetchCartKindCount']),
  77. // 搜索
  78. handleToSearch() {},
  79. // 金刚区菜单导航
  80. onNavbarClick(navbar) {
  81. this.$setStorage('NAVBAR', {
  82. type: 'navbar',
  83. id: navbar.id
  84. })
  85. this.$router.navigateTo('goods/goods-list')
  86. },
  87. // 更多优惠券
  88. onMoreCoupon() {
  89. this.$router.navigateTo('coupon/coupon-receive')
  90. },
  91. // 商品楼层轮播图点击事件
  92. onBannerClick(banner) {
  93. console.log(banner)
  94. },
  95. // 更多商品
  96. onMoreProduct(floor) {
  97. this.$setStorage('NAVBAR', {
  98. type: 'floor',
  99. id: floor.id
  100. })
  101. this.$router.navigateTo('goods/goods-list')
  102. },
  103. // 加入我们
  104. handleJoinUs() {
  105. this.$router.navigateTo('others/join-us')
  106. },
  107. // 初始化首页信息
  108. async initHomeInfo() {
  109. this.fetchCarousel()
  110. this.fetchNavbar()
  111. this.fetchFloorData()
  112. this.fetchCouponList()
  113. this.isRequest = false
  114. },
  115. // 获取轮播图列表
  116. async fetchCarousel() {
  117. try {
  118. const resultCarousel = await fetchHomeCarousel() // 轮播图
  119. this.bannerList = resultCarousel.data.map(item => item.image)
  120. } catch (e) {
  121. console.log('获取轮播图列表失败')
  122. }
  123. },
  124. // 获取金刚区菜单
  125. async fetchNavbar() {
  126. try {
  127. const resultNavbar = await fetchHomeNavbar() // 轮播图
  128. this.navbarList = resultNavbar.data
  129. } catch (e) {
  130. console.log('获取金刚区菜单失败')
  131. }
  132. },
  133. // 获取楼层信息
  134. async fetchFloorData() {
  135. try {
  136. const resultFloorData = await fetchHomeFloorData({ userId: this.userId }) // 商品楼层信息
  137. this.floorInfo = resultFloorData.data.page
  138. this.floorList = resultFloorData.data.floorList
  139. } catch (e) {
  140. console.log('获取楼层信息失败')
  141. }
  142. },
  143. // 获取优惠券列表
  144. async fetchCouponList() {
  145. try {
  146. const resultCouponData = await fetchHomeCouponList({ userId: this.userId })
  147. this.couponList = resultCouponData.data
  148. } catch (e) {
  149. console.log('获取优惠券列表失败')
  150. }
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .grid {
  157. height: 24rpx;
  158. background-color: #f7f7f7;
  159. }
  160. .container {
  161. min-height: 100vh;
  162. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png) no-repeat top center;
  163. background-size: 750rpx auto;
  164. background-position-y: -220rpx;
  165. .search-input {
  166. width: 100%;
  167. padding: 24rpx;
  168. box-sizing: border-box;
  169. background: linear-gradient(180deg, #fa55bf 0%, #f8458b 100%);
  170. .search-content {
  171. @extend .cm-flex-center;
  172. justify-content: flex-start;
  173. width: 702rpx;
  174. height: 66rpx;
  175. border-radius: 33rpx;
  176. color: #8a8a8a;
  177. background: #fff;
  178. box-sizing: border-box;
  179. padding: 0 24rpx;
  180. .iconfont {
  181. font-size: 34rpx;
  182. margin-right: 12rpx;
  183. }
  184. .search-text {
  185. font-size: 24rpx;
  186. }
  187. }
  188. }
  189. // 加入我们
  190. .join-us {
  191. @extend .cm-flex-between;
  192. padding: 24rpx;
  193. background-color: #fff;
  194. .join-icon {
  195. width: 136rpx;
  196. height: 136rpx;
  197. display: block;
  198. }
  199. .join-content {
  200. @extend .cm-flex-center;
  201. flex-direction: column;
  202. align-items: flex-start;
  203. .join-label-title {
  204. font-size: 30rpx;
  205. font-weight: bold;
  206. color: #333333;
  207. margin-bottom: 24rpx;
  208. }
  209. .join-label-text {
  210. font-size: 24rpx;
  211. color: #333333;
  212. }
  213. }
  214. .join-button {
  215. width: 136rpx;
  216. height: 56rpx;
  217. text-align: center;
  218. line-height: 56rpx;
  219. font-size: 26rpx;
  220. font-weight: 400;
  221. color: #ffffff;
  222. background: #ff457b;
  223. border-radius: 8rpx;
  224. }
  225. }
  226. // 优惠券专区
  227. .coupon-area {
  228. padding-top: 24rpx;
  229. }
  230. .cm-floor {
  231. margin-bottom: 60rpx;
  232. }
  233. }
  234. </style>