index.vue 9.4 KB

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