index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view class="home">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <template v-else>
  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. <cm-active-popup
  43. :visible="activePopupVisible"
  44. :image="couponActivityIcon"
  45. @click="activeClick"
  46. @closed="activeClosed"
  47. ></cm-active-popup>
  48. <!-- 领取优惠券提醒 -->
  49. <cm-selector-coupons
  50. :visible="tipVisible"
  51. title="呵呵商城"
  52. subTitle="您已获得优惠券奖励,赶紧去领取吧!"
  53. :image="StaticUrl + 'logo.png'"
  54. @click="handleSelectorClick"
  55. ></cm-selector-coupons>
  56. </template>
  57. </view>
  58. </template>
  59. <script>
  60. import banner from '@/components/cm-module/homeIndex/banner.vue'
  61. import CmProduct from '@/components/cm-module/cm-product/cm-product.vue'
  62. import CmActivePopup from '@/components/cm-module/cm-active-popup/cm-active-popup.vue'
  63. import CmSelectorCoupons from '@/components/cm-module/cm-selector-coupons/cm-selector-coupons.vue'
  64. import { mapGetters, mapMutations, mapActions } from 'vuex'
  65. export default {
  66. components: {
  67. banner,
  68. CmActivePopup,
  69. CmSelectorCoupons,
  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: true //优惠券领取提示
  86. }
  87. },
  88. onLoad(option) {
  89. // 收集分享信息
  90. if (option.type && option.type === 'share') this.setInviteUserId(option.inviteUserId)
  91. this.init()
  92. },
  93. computed: {
  94. ...mapGetters(['hasLogin', 'activePopupType', 'userId', 'otherCouponFlag', 'showCouponPopup']),
  95. couponActivityIcon() {
  96. let icon = 'news'
  97. switch (this.activePopupType) {
  98. case 1:
  99. icon = 'get'
  100. break
  101. case 2:
  102. icon = 'news'
  103. break
  104. }
  105. return `${this.StaticUrl}icon-coupons-${icon}.png`
  106. }
  107. },
  108. watch: {
  109. activePopupType(val) {
  110. if (val === 0 || !this.showCouponPopup) return
  111. // 定时开启弹窗
  112. setTimeout(() => {
  113. this.activePopupVisible = true
  114. }, 1000)
  115. }
  116. },
  117. methods: {
  118. ...mapMutations('coupon', ['updatePopupType']),
  119. ...mapMutations('user', ['setInviteUserId']),
  120. ...mapActions('cart', ['getCartNumber']),
  121. // 首页初始化
  122. async init() {
  123. try {
  124. await this.GetHomeBanner() // 轮播图
  125. await this.GetHomeProductList() // 楼层
  126. this.isRequest = false
  127. this.tipVisible = this.otherCouponFlag
  128. } catch (e) {
  129. this.$util.msg(e.msg, 2000)
  130. }
  131. if (this.tipVisible) {
  132. setTimeout(() => {
  133. this.tipVisible = false
  134. }, 5000)
  135. }
  136. },
  137. //初始化首页数据
  138. GetHomeBanner() {
  139. return this.CommonService.GetProductCarousel().then(response => {
  140. let data = response.data
  141. this.bannerImageList = data
  142. })
  143. },
  144. //初始化首页商品数据
  145. GetHomeProductList() {
  146. return this.ProductService.QueryProductFloor({ userId: this.userId}).then(response => {
  147. this.productFloor = response.data
  148. })
  149. },
  150. handleSelectorClick() {
  151. this.$api.navigateTo('/pages/user/activity/coupon-find-list')
  152. },
  153. //跳转楼层
  154. navToDetailPage(floor) {
  155. this.$api.navigateTo(`/pages/goods/good-floorMore?floorId=${floor.floorId}&title=${floor.title}`)
  156. },
  157. // 点击了活动弹窗
  158. activeClick() {
  159. this.activePopupVisible = false
  160. this.updatePopupType(0)
  161. uni.setStorageSync('couponPopupType', new Date().getDay())
  162. this.$api.navigateTo('/pages/user/activity/coupon-find-list')
  163. },
  164. // 活动弹窗关闭
  165. activeClosed() {
  166. this.activePopupVisible = false
  167. console.log(this.activePopupType)
  168. this.updatePopupType(this.activePopupType - 1)
  169. uni.setStorageSync('couponPopupType', new Date().getDay())
  170. }
  171. },
  172. onPageScroll(e) {
  173. this.isSticky = e.scrollTop > 0
  174. this.isScrollTop = e.scrollTop > 400
  175. },
  176. //下拉刷新
  177. onPullDownRefresh() {
  178. this.GetHomeBanner()
  179. this.GetHomeProductList()
  180. setTimeout(() => {
  181. uni.stopPullDownRefresh()
  182. }, 2000)
  183. },
  184. onShareAppMessage(res) {
  185. //分享转发
  186. if (res.from === 'button') {
  187. // 来自页面内转发按钮
  188. }
  189. return {
  190. title: '国内外知名美容院线护肤品线上商城~',
  191. path: `pages/tabBar/index/index?type=share&inviteUserId=${this.userId}`,
  192. imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
  193. }
  194. },
  195. onShow() {
  196. if (this.hasLogin) {
  197. this.getCartNumber()
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .home {
  204. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png) no-repeat top center;
  205. background-size: 750rpx auto;
  206. background-position-y: -50rpx;
  207. }
  208. .swiper-content {
  209. &.top {
  210. padding-top: 120rpx;
  211. }
  212. }
  213. .container-section {
  214. width: 100%;
  215. padding: 12rpx 24rpx;
  216. background-color: #f7f7f7;
  217. box-sizing: border-box;
  218. .product-list {
  219. display: flex;
  220. justify-content: space-between;
  221. flex-wrap: wrap;
  222. .product {
  223. margin: 12rpx 0;
  224. }
  225. }
  226. .floor-title {
  227. display: flex;
  228. justify-content: space-between;
  229. align-items: center;
  230. padding: 12rpx 0;
  231. .title {
  232. .name {
  233. font-size: 34rpx;
  234. font-weight: bold;
  235. text-align: left;
  236. line-height: 49rpx;
  237. color: #333;
  238. }
  239. .desc {
  240. color: #999999;
  241. font-size: $font-size-26;
  242. }
  243. }
  244. .more {
  245. text {
  246. font-size: $font-size-26;
  247. text-align: right;
  248. line-height: 49rpx;
  249. color: #999999;
  250. }
  251. .iconfont {
  252. font-size: $font-size-30;
  253. color: #999999;
  254. }
  255. }
  256. }
  257. }
  258. .search-input {
  259. width: 100%;
  260. padding: 24rpx;
  261. box-sizing: border-box;
  262. background: linear-gradient(180deg, #fa55bf 0%, #f8458b 100%);
  263. &.fixed {
  264. position: fixed;
  265. top: 0;
  266. left: 0;
  267. z-index: 99;
  268. }
  269. .search-content {
  270. display: flex;
  271. justify-content: flex-start;
  272. align-items: center;
  273. width: 702rpx;
  274. height: 66rpx;
  275. border-radius: 33rpx;
  276. color: #8a8a8a;
  277. background: #fff;
  278. box-sizing: border-box;
  279. padding: 0 24rpx;
  280. .iconfont {
  281. font-size: $font-size-34;
  282. margin-right: 12rpx;
  283. }
  284. .search-text {
  285. font-size: $font-size-24;
  286. }
  287. }
  288. }
  289. </style>