home.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <view class="container">
  3. <tui-skeleton v-if="isRequest" :loadingType="3" :isLoading="true"></tui-skeleton>
  4. <!-- 首页自定义导航栏 -->
  5. <view class="search-input sticky-top">
  6. <view class="search-content" @click="handleToSearch">
  7. <text class="iconfont icon-sousuo"></text>
  8. <view class="search-text">搜索商品</view>
  9. </view>
  10. </view>
  11. <!-- 轮播图 -->
  12. <cm-banner :list="bannerList" :current="current" @change="index => (current = index)"></cm-banner>
  13. <!-- 金刚区菜单 -->
  14. <cm-navbar :modal="navbarList" @click="onNavbarClick"></cm-navbar>
  15. <!-- 加入我们 -->
  16. <view class="grid"></view>
  17. <view class="join-us">
  18. <image :src="staticUrl + 'icon-join-us.png'" class="join-icon"></image>
  19. <view class="join-content">
  20. <view class="join-label-title">呵呵商城福利群</view>
  21. <view class="join-label-text">进群第一时间得知优惠福利!</view>
  22. </view>
  23. <view class="join-button" @click="handleJoinUs">加入我们</view>
  24. </view>
  25. <view class="grid"></view>
  26. <!-- 优惠券专区 -->
  27. <view class="coupon-area" v-if="couponList.length > 0">
  28. <cm-floor-title title="优惠券专区" @click="onMoreCoupon"></cm-floor-title>
  29. <cm-coupon-area :couponList="couponList" @click="onCouponClick"></cm-coupon-area>
  30. </view>
  31. <!-- 楼层区域 -->
  32. <view class="cm-floor" v-for="floorData in floorList" :key="floorData.id">
  33. <cm-floor-template
  34. :floorData="floorData"
  35. @onBannerClick="onBannerClick"
  36. @more="onMoreProduct"
  37. ></cm-floor-template>
  38. </view>
  39. <!-- 优惠券活动弹窗 -->
  40. <cm-active-alert></cm-active-alert>
  41. </view>
  42. </template>
  43. <script>
  44. import { fetchHomeCarousel, fetchHomeNavbar, fetchHomeFloorData, fetchHomeCouponList } from '@/services/api/home.js'
  45. import { fetchProductFloorList } from '@/services/api/goods.js'
  46. import { shareDataResult } from '@/common/share.helper.js'
  47. import { mapActions, mapGetters } from 'vuex'
  48. export default {
  49. data() {
  50. return {
  51. isRequest: true,
  52. bannerList: [],
  53. navbarList: [],
  54. floorInfo: {},
  55. floorList: [],
  56. couponList: [],
  57. current: 0,
  58. isRefresh: false
  59. }
  60. },
  61. computed: {
  62. ...mapGetters(['userId'])
  63. },
  64. onPullDownRefresh() {
  65. this.initHomeInfo()
  66. },
  67. onShareAppMessage() {
  68. const shareData = { type: 0, inviteUserId: this.userId }
  69. return shareDataResult(shareData)
  70. },
  71. onShow() {
  72. this.fetchCartKindCount() // 购物车商品数量
  73. this.checkCouponAlert() // 优惠券弹窗
  74. },
  75. onLoad() {
  76. this.initHomeInfo()
  77. },
  78. methods: {
  79. ...mapActions('cart', ['fetchCartKindCount']),
  80. ...mapActions('coupon', ['checkCouponAlert']),
  81. // 搜索
  82. handleToSearch() {
  83. this.$router.navigateTo('goods/goods-search')
  84. },
  85. // 金刚区菜单导航
  86. onNavbarClick(navbar) {
  87. this.$setStorage('NAVBAR', {
  88. type: 'navbar',
  89. id: navbar.id
  90. })
  91. this.$router.navigateTo('goods/goods-list')
  92. },
  93. // 更多优惠券
  94. onMoreCoupon() {
  95. this.$router.navigateTo('coupon/coupon-receive')
  96. },
  97. // 优惠券点击(领取)
  98. onCouponClick(coupon) {
  99. coupon = { ...coupon }
  100. if (coupon.controlType === 'receive') {
  101. const index = this.couponList.findIndex(item => item.couponId === coupon.couponId)
  102. this.couponList.splice(index, 1)
  103. coupon.controlType = 'use'
  104. this.$set(this.couponList, index, coupon)
  105. }
  106. },
  107. // 商品楼层轮播图点击事件
  108. onBannerClick(banner) {
  109. console.log(banner)
  110. },
  111. // 更多商品
  112. onMoreProduct(floor) {
  113. this.$setStorage('NAVBAR', {
  114. type: 'floor',
  115. id: floor.id
  116. })
  117. this.$router.navigateTo('goods/goods-list')
  118. },
  119. // 加入我们
  120. handleJoinUs() {
  121. this.$router.navigateTo('others/join-us')
  122. },
  123. // 初始化首页信息
  124. initHomeInfo() {
  125. this.fetchCarousel()
  126. this.fetchNavbar()
  127. this.fetchFloorData()
  128. this.fetchCouponList()
  129. },
  130. // 获取轮播图列表
  131. async fetchCarousel() {
  132. try {
  133. const resultCarousel = await fetchHomeCarousel() // 轮播图
  134. this.bannerList = resultCarousel.data.map(item => item.image)
  135. } catch (e) {
  136. console.log('获取轮播图列表失败')
  137. }
  138. },
  139. // 获取金刚区菜单
  140. async fetchNavbar() {
  141. try {
  142. const resultNavbar = await fetchHomeNavbar() // 轮播图
  143. this.navbarList = resultNavbar.data
  144. } catch (e) {
  145. console.log('获取金刚区菜单失败')
  146. }
  147. },
  148. // 获取楼层信息
  149. async fetchFloorData() {
  150. try {
  151. const resultFloorData = await fetchHomeFloorData({ userId: this.userId }) // 商品楼层信息
  152. this.floorInfo = resultFloorData.data.page
  153. this.floorList = resultFloorData.data.floorList
  154. // 楼层信息加载成功
  155. this.isRequest = false
  156. uni.stopPullDownRefresh()
  157. } catch (e) {
  158. console.log('获取楼层信息失败')
  159. }
  160. },
  161. // 获取优惠券列表
  162. async fetchCouponList() {
  163. try {
  164. const resultCouponData = await fetchHomeCouponList({ userId: this.userId })
  165. this.couponList = [
  166. ...resultCouponData.data.map(item => {
  167. item.controlType = 'receive'
  168. return item
  169. }),
  170. ...this.generateCouponTips()
  171. ]
  172. } catch (e) {
  173. console.log('获取优惠券列表失败')
  174. }
  175. },
  176. // 生成优惠券说明
  177. generateCouponTips() {
  178. return [
  179. {
  180. type: 'tip',
  181. id: 1,
  182. name: '好友邀请券福利'
  183. },
  184. {
  185. type: 'tip',
  186. id: 2,
  187. name: '好友消费券福利'
  188. },
  189. {
  190. type: 'tip',
  191. id: 3,
  192. name: '分享券福利'
  193. }
  194. ]
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .grid {
  201. height: 24rpx;
  202. background-color: #f7f7f7;
  203. }
  204. .container {
  205. min-height: 100vh;
  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: -220rpx;
  209. .search-input {
  210. width: 100%;
  211. padding: 24rpx;
  212. box-sizing: border-box;
  213. background: linear-gradient(180deg, #fa55bf 0%, #f8458b 100%);
  214. .search-content {
  215. @extend .cm-flex-center;
  216. justify-content: flex-start;
  217. width: 702rpx;
  218. height: 66rpx;
  219. border-radius: 33rpx;
  220. color: #8a8a8a;
  221. background: #fff;
  222. box-sizing: border-box;
  223. padding: 0 24rpx;
  224. .iconfont {
  225. font-size: 34rpx;
  226. margin-right: 12rpx;
  227. }
  228. .search-text {
  229. font-size: 24rpx;
  230. }
  231. }
  232. }
  233. // 加入我们
  234. .join-us {
  235. @extend .cm-flex-between;
  236. padding: 24rpx;
  237. background-color: #fff;
  238. .join-icon {
  239. width: 136rpx;
  240. height: 136rpx;
  241. display: block;
  242. }
  243. .join-content {
  244. @extend .cm-flex-center;
  245. flex-direction: column;
  246. align-items: flex-start;
  247. .join-label-title {
  248. font-size: 30rpx;
  249. font-weight: bold;
  250. color: #333333;
  251. margin-bottom: 24rpx;
  252. }
  253. .join-label-text {
  254. font-size: 24rpx;
  255. color: #333333;
  256. }
  257. }
  258. .join-button {
  259. width: 136rpx;
  260. height: 56rpx;
  261. text-align: center;
  262. line-height: 56rpx;
  263. font-size: 26rpx;
  264. font-weight: 400;
  265. color: #ffffff;
  266. background: #ff457b;
  267. border-radius: 8rpx;
  268. }
  269. }
  270. // 优惠券专区
  271. .coupon-area {
  272. padding-top: 24rpx;
  273. }
  274. .cm-floor {
  275. margin-bottom: 60rpx;
  276. }
  277. }
  278. </style>