home.vue 9.6 KB

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