index.vue 9.5 KB

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