index.vue 9.4 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="otherCouponFlag"
  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 shareEntry from '@/mixins/shareEntry.js'
  65. import { mapGetters, mapMutations, mapActions } from 'vuex'
  66. export default {
  67. components: {
  68. banner,
  69. CmActivePopup,
  70. CmSelectorCoupons,
  71. CmProduct
  72. },
  73. mixins: [shareEntry],
  74. data() {
  75. return {
  76. StaticUrl: this.$Static,
  77. isSticky: false,
  78. clickPath: '/pages/goods/search',
  79. productFloor: [], //商品列表
  80. bannerImageList: [], //轮播
  81. pageNum: 1,
  82. pageSize: 20,
  83. hasNextPage: false,
  84. isScrollTop: false,
  85. isRequest: true,
  86. activePopupVisible: false, // 活动弹窗
  87. tipVisible: true //优惠券领取提示
  88. }
  89. },
  90. onLoad(option) {
  91. // 处理分享链接
  92. this.shareHandle(option)
  93. setTimeout(() => {
  94. this.init()
  95. }, 1000)
  96. },
  97. computed: {
  98. ...mapGetters(['hasLogin', 'activePopupType', 'userId', 'otherCouponFlag', 'showCouponPopup']),
  99. couponActivityIcon() {
  100. let icon = 'news'
  101. switch (this.activePopupType) {
  102. case 1:
  103. icon = 'get'
  104. break
  105. case 2:
  106. icon = 'news'
  107. break
  108. }
  109. return `${this.StaticUrl}icon-coupons-${icon}.png`
  110. }
  111. },
  112. watch: {
  113. activePopupType(val) {
  114. if (val === 0 || !this.showCouponPopup) return
  115. // 定时开启弹窗
  116. setTimeout(() => {
  117. this.activePopupVisible = true
  118. }, 1000)
  119. }
  120. },
  121. methods: {
  122. ...mapMutations('coupon', ['updatePopupType']),
  123. ...mapMutations('user', ['setInviteUserId']),
  124. ...mapActions('cart', ['getCartNumber']),
  125. ...mapActions('coupon', ['getCouponActivity']),
  126. // 首页初始化
  127. async init() {
  128. try {
  129. await this.GetHomeBanner() // 轮播图
  130. await this.GetHomeProductList() // 楼层
  131. this.isRequest = false
  132. } catch (e) {
  133. this.$util.msg(e.msg, 2000)
  134. }
  135. },
  136. //初始化首页数据
  137. GetHomeBanner() {
  138. return this.CommonService.GetProductCarousel().then(response => {
  139. let data = response.data
  140. this.bannerImageList = data
  141. })
  142. },
  143. //初始化首页商品数据
  144. GetHomeProductList() {
  145. return this.ProductService.QueryProductFloor({ userId: this.userId }).then(response => {
  146. this.productFloor = response.data
  147. })
  148. },
  149. handleSelectorClick() {
  150. this.$api.navigateTo('/pages/user/activity/coupon-find-list')
  151. },
  152. //跳转楼层
  153. navToDetailPage(floor) {
  154. this.$api.navigateTo(`/pages/goods/goods-floorMore?floorId=${floor.floorId}&title=${floor.title}`)
  155. },
  156. // 点击了活动弹窗
  157. activeClick() {
  158. this.activePopupVisible = false
  159. this.updatePopupType(0)
  160. uni.setStorageSync('couponPopupType', new Date().getDay())
  161. this.$api.navigateTo('/pages/user/activity/coupon-find-list')
  162. },
  163. // 活动弹窗关闭
  164. activeClosed() {
  165. this.activePopupVisible = false
  166. console.log(this.activePopupType)
  167. this.updatePopupType(this.activePopupType - 1)
  168. uni.setStorageSync('couponPopupType', new Date().getDay())
  169. }
  170. },
  171. onPageScroll(e) {
  172. this.isSticky = e.scrollTop > 0
  173. this.isScrollTop = e.scrollTop > 400
  174. },
  175. //下拉刷新
  176. onPullDownRefresh() {
  177. this.GetHomeBanner()
  178. this.GetHomeProductList()
  179. setTimeout(() => {
  180. uni.stopPullDownRefresh()
  181. }, 2000)
  182. },
  183. onShareAppMessage(res) {
  184. // 加密参数
  185. const shareData = {
  186. type: 0,
  187. inviteUserId: this.userId
  188. }
  189. // 加密
  190. const state_str = encodeURIComponent(this.$crypto.encrypt(shareData))
  191. return {
  192. title: '国内外知名美容院线护肤品线上商城~',
  193. path: `pages/tabBar/index/index?state_str=${state_str}`,
  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>