index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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('user', ['wechatlogin']),
  121. ...mapActions('cart', ['getCartNumber']),
  122. // 首页初始化
  123. async init() {
  124. this.wechatlogin()
  125. try {
  126. await this.GetHomeBanner() // 轮播图
  127. await this.GetHomeProductList() // 楼层
  128. this.isRequest = false
  129. this.tipVisible = this.otherCouponFlag
  130. } catch (e) {
  131. this.$util.msg(e.msg, 2000)
  132. }
  133. if (this.tipVisible) {
  134. setTimeout(() => {
  135. this.tipVisible = false
  136. }, 5000)
  137. }
  138. },
  139. //初始化首页数据
  140. GetHomeBanner() {
  141. return this.CommonService.GetProductCarousel().then(response => {
  142. let data = response.data
  143. this.bannerImageList = data
  144. })
  145. },
  146. //初始化首页商品数据
  147. GetHomeProductList() {
  148. return this.ProductService.QueryProductFloor().then(response => {
  149. this.productFloor = response.data
  150. })
  151. },
  152. handleSelectorClick() {
  153. this.$api.navigateTo('/pages/user/activity/coupon-find-list')
  154. },
  155. //跳转楼层
  156. navToDetailPage(floor) {
  157. this.$api.navigateTo(`/pages/goods/good-floorMore?floorId=${floor.floorId}&title=${floor.title}`)
  158. },
  159. // 点击了活动弹窗
  160. activeClick() {
  161. this.activePopupVisible = false
  162. this.updatePopupType(0)
  163. uni.setStorageSync('couponPopupType', new Date().getDay())
  164. this.$api.navigateTo('/pages/user/activity/coupon-find-list')
  165. },
  166. // 活动弹窗关闭
  167. activeClosed() {
  168. this.activePopupVisible = false
  169. console.log(this.activePopupType)
  170. this.updatePopupType(this.activePopupType - 1)
  171. uni.setStorageSync('couponPopupType', new Date().getDay())
  172. }
  173. },
  174. onPageScroll(e) {
  175. this.isSticky = e.scrollTop > 0
  176. this.isScrollTop = e.scrollTop > 400
  177. },
  178. //下拉刷新
  179. onPullDownRefresh() {
  180. this.GetHomeBanner()
  181. this.GetHomeProductList()
  182. setTimeout(() => {
  183. uni.stopPullDownRefresh()
  184. }, 2000)
  185. },
  186. onShareAppMessage(res) {
  187. //分享转发
  188. if (res.from === 'button') {
  189. // 来自页面内转发按钮
  190. }
  191. return {
  192. title: '国内外知名美容院线护肤品线上商城~',
  193. path: `pages/tabBar/index/index?type=share&inviteUserId=${this.userId}`,
  194. imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
  195. }
  196. },
  197. onShow() {
  198. if (this.hasLogin) {
  199. this.getCartNumber()
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .home {
  206. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png) no-repeat top center;
  207. background-size: 750rpx auto;
  208. background-position-y: -50rpx;
  209. }
  210. .swiper-content {
  211. &.top {
  212. padding-top: 120rpx;
  213. }
  214. }
  215. .container-section {
  216. width: 100%;
  217. padding: 12rpx 24rpx;
  218. background-color: #f7f7f7;
  219. box-sizing: border-box;
  220. .product-list {
  221. display: flex;
  222. justify-content: space-between;
  223. flex-wrap: wrap;
  224. .product {
  225. margin: 12rpx 0;
  226. }
  227. }
  228. .floor-title {
  229. display: flex;
  230. justify-content: space-between;
  231. align-items: center;
  232. padding: 12rpx 0;
  233. .title {
  234. .name {
  235. font-size: 34rpx;
  236. font-weight: bold;
  237. text-align: left;
  238. line-height: 49rpx;
  239. color: #333;
  240. }
  241. .desc {
  242. color: #999999;
  243. font-size: $font-size-26;
  244. }
  245. }
  246. .more {
  247. text {
  248. font-size: $font-size-26;
  249. text-align: right;
  250. line-height: 49rpx;
  251. color: #999999;
  252. }
  253. .iconfont {
  254. font-size: $font-size-30;
  255. color: #999999;
  256. }
  257. }
  258. }
  259. }
  260. .search-input {
  261. width: 100%;
  262. padding: 24rpx;
  263. box-sizing: border-box;
  264. background: linear-gradient(180deg, #fa55bf 0%, #f8458b 100%);
  265. &.fixed {
  266. position: fixed;
  267. top: 0;
  268. left: 0;
  269. z-index: 99;
  270. }
  271. .search-content {
  272. display: flex;
  273. justify-content: flex-start;
  274. align-items: center;
  275. width: 702rpx;
  276. height: 66rpx;
  277. border-radius: 33rpx;
  278. color: #8a8a8a;
  279. background: #fff;
  280. box-sizing: border-box;
  281. padding: 0 24rpx;
  282. .iconfont {
  283. font-size: $font-size-34;
  284. margin-right: 12rpx;
  285. }
  286. .search-text {
  287. font-size: $font-size-24;
  288. }
  289. }
  290. }
  291. </style>