index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view class="home">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <template v-if="!isRequest">
  5. <!-- 首页自定义导航栏 -->
  6. <view class="search-input" :class="{ fixed: isSticky }">
  7. <view class="search-content" @click="this.$api.navigateTo(clickPath)">
  8. <text class="iconfont icon-sousuo"></text> <view class="search-text">搜索商品</view>
  9. </view>
  10. </view>
  11. <!-- 主页内容 -->
  12. <view class="swiper-content" :class="{ top: isSticky }">
  13. <!-- 轮播 -->
  14. <banner :list="bannerImageList"></banner>
  15. </view>
  16. <!-- 商品列表 -->
  17. <view class="container-section">
  18. <view v-for="(floor, i) in productFloor" :key="i">
  19. <!-- 楼层标题区域 -->
  20. <view class="floor-title">
  21. <view class="title">
  22. <view class="name">{{ floor.title }}</view>
  23. <view class="desc">{{ floor.description }}</view>
  24. </view>
  25. <view class="more" @click="navToDetailPage(floor)">
  26. <template v-if="floor.productList.length >= 6">
  27. <text>更多</text> <text class="iconfont tui-icon-arrowright"></text>
  28. </template>
  29. </view>
  30. </view>
  31. <!-- 商品列表区域 -->
  32. <view class="product-list">
  33. <template v-for="(product, index) in floor.productList">
  34. <cm-product class="product" :key="index" :data="product"></cm-product>
  35. </template>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 侧边 -->
  40. <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
  41. <!-- 活动弹窗 -->
  42. <active-popup
  43. :visible="activePopupVisible"
  44. :image="StaticUrl + 'icon-coupons-news.png'"
  45. @click="activeClick"
  46. @closed="activeClosed"
  47. ></active-popup>
  48. <!-- 领取优惠券提醒 -->
  49. <selector-coupons
  50. :visible="tipVisible"
  51. title="呵呵商城"
  52. subTitle="您已获得优惠券奖励,赶紧去领取吧!"
  53. :image="StaticUrl + 'logo.png'"
  54. ></selector-coupons>
  55. </template>
  56. </view>
  57. </template>
  58. <script>
  59. import authorize from '@/common/authorize.js'
  60. import banner from '@/components/cm-module/homeIndex/banner.vue'
  61. import CmProduct from '@/components/cm-module/cm-product/cm-product.vue'
  62. import ActivePopup from '@/components/cm-module/active-popup/active-popup.vue'
  63. import SelectorCoupons from '@/components/cm-module/selector-coupons/selector-coupons.vue'
  64. import { mapGetters, mapMutations, mapActions } from 'vuex'
  65. export default {
  66. components: {
  67. banner,
  68. ActivePopup,
  69. SelectorCoupons,
  70. CmProduct
  71. },
  72. data() {
  73. return {
  74. StaticUrl: this.$Static,
  75. isSticky: false,
  76. clickPath: '/pages/goods/search',
  77. productFloor: [], //商品列表
  78. bannerImageList: [], //轮播
  79. pageNum: 1,
  80. pageSize: 20,
  81. hasNextPage: false,
  82. isScrollTop: false,
  83. isRequest: true,
  84. activePopupVisible: false, // 活动弹窗
  85. tipVisible: false //优惠券领取提示
  86. }
  87. },
  88. onLoad() {
  89. this.init()
  90. },
  91. computed: {
  92. ...mapGetters(['hasLogin'])
  93. },
  94. methods: {
  95. ...mapActions('user', ['wechatlogin']),
  96. ...mapActions('cart', ['getCartNumber']),
  97. // 首页初始化
  98. async init() {
  99. this.wechatlogin()
  100. try {
  101. await this.GetHomeBanner()
  102. await this.GetHomeProductList()
  103. this.isRequest = false
  104. } catch (e) {
  105. this.$util.msg(e.msg, 2000)
  106. }
  107. setTimeout(() => {
  108. this.tipVisible = false
  109. }, 5000)
  110. },
  111. //初始化首页数据
  112. GetHomeBanner() {
  113. return this.CommonService.GetProductCarousel().then(response => {
  114. let data = response.data
  115. this.bannerImageList = data
  116. })
  117. },
  118. //初始化首页商品数据
  119. GetHomeProductList() {
  120. return this.ProductService.QueryProductFloor().then(response => {
  121. this.productFloor = response.data
  122. })
  123. },
  124. //跳转楼层
  125. navToDetailPage(floor) {
  126. this.$api.navigateTo(`/pages/goods/good-floorMore?floorId=${floor.floorId}&title=${floor.title}`)
  127. },
  128. activeClick() {
  129. this.activePopupVisible = false
  130. console.log('点击了活动弹窗')
  131. },
  132. activeClosed() {
  133. this.activePopupVisible = false
  134. console.log('活动弹窗关闭')
  135. }
  136. },
  137. onPageScroll(e) {
  138. this.isSticky = e.scrollTop > 0
  139. this.isScrollTop = e.scrollTop > 400
  140. },
  141. //下拉刷新
  142. onPullDownRefresh() {
  143. this.GetHomeBanner()
  144. this.GetHomeProductList()
  145. setTimeout(() => {
  146. uni.stopPullDownRefresh()
  147. }, 2000)
  148. },
  149. onShareAppMessage(res) {
  150. //分享转发
  151. if (res.from === 'button') {
  152. // 来自页面内转发按钮
  153. }
  154. return {
  155. title: '国内外知名美容院线护肤品线上商城~',
  156. path: 'pages/tabBar/index/index',
  157. imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
  158. }
  159. },
  160. onShow() {
  161. if (this.hasLogin) {
  162. this.getCartNumber()
  163. }
  164. }
  165. }
  166. </script>
  167. <style lang="scss">
  168. .home {
  169. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png) no-repeat top center;
  170. background-size: 750rpx auto;
  171. background-position-y: -50rpx;
  172. }
  173. .swiper-content {
  174. &.top {
  175. padding-top: 120rpx;
  176. }
  177. }
  178. .container-section {
  179. width: 100%;
  180. padding: 12rpx 24rpx;
  181. background-color: #f7f7f7;
  182. box-sizing: border-box;
  183. .product-list {
  184. display: flex;
  185. justify-content: space-between;
  186. flex-wrap: wrap;
  187. .product {
  188. margin: 12rpx 0;
  189. }
  190. }
  191. .floor-title {
  192. display: flex;
  193. justify-content: space-between;
  194. align-items: center;
  195. padding: 12rpx 0;
  196. .title {
  197. .name {
  198. font-size: 34rpx;
  199. font-weight: bold;
  200. text-align: left;
  201. line-height: 49rpx;
  202. color: #333;
  203. }
  204. .desc {
  205. color: #999999;
  206. font-size: $font-size-26;
  207. }
  208. }
  209. .more {
  210. text {
  211. font-size: $font-size-26;
  212. text-align: right;
  213. line-height: 49rpx;
  214. color: #999999;
  215. }
  216. .iconfont {
  217. font-size: $font-size-30;
  218. color: #999999;
  219. }
  220. }
  221. }
  222. }
  223. .search-input {
  224. width: 100%;
  225. padding: 24rpx;
  226. box-sizing: border-box;
  227. background: linear-gradient(180deg, #fa55bf 0%, #f8458b 100%);
  228. &.fixed {
  229. position: fixed;
  230. top: 0;
  231. left: 0;
  232. z-index: 99;
  233. }
  234. .search-content {
  235. display: flex;
  236. justify-content: flex-start;
  237. align-items: center;
  238. width: 702rpx;
  239. height: 66rpx;
  240. border-radius: 33rpx;
  241. color: #8a8a8a;
  242. background: #fff;
  243. box-sizing: border-box;
  244. padding: 0 24rpx;
  245. .iconfont {
  246. font-size: $font-size-34;
  247. margin-right: 12rpx;
  248. }
  249. .search-text {
  250. font-size: $font-size-24;
  251. }
  252. }
  253. }
  254. </style>