index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. <template>
  2. <view class="home tui-skeleton clearfix">
  3. <tui-skeleton v-if="skeletonShow" :isLoading="true" :loadingType="2"></tui-skeleton>
  4. <!-- 首页自定义导航栏 -->
  5. <view
  6. class="navbar-wrap"
  7. :style="{ height: CustomBar + 55 + 'px', paddingTop: StatusBar + 'px' }"
  8. :class="inputActive"
  9. >
  10. <view
  11. class="navbar-text"
  12. :style="{
  13. color: navbarData.textColor ? navbarData.textColor : '',
  14. lineHeight: CustomBar - StatusBar + 'px;',
  15. fontSize: fontSizeSetting + 'px;',
  16. paddingLeft: navbarData.textLeft ? '' : 12 + 'px'
  17. }"
  18. :class="platformClass"
  19. >
  20. {{ navbarData.title ? navbarData.title : ' ' }}
  21. </view>
  22. <view class="search-input">
  23. <view class="gosearch-btn" @click="this.$api.navigateTo(clickPath)">
  24. <view class="search-icon"> <text class="iconfont icon-sousuo"></text> </view>
  25. <view class="search-text">搜索商品</view>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 主页内容 -->
  30. <view class="container-home " :style="{ paddingTop: CustomBar + 'px' }">
  31. <!-- 轮播 -->
  32. <banner :list="bannerImageList"></banner>
  33. </view>
  34. <!-- 商品列表 -->
  35. <view class="container-section">
  36. <view class="clearfix" v-for="(floor, index1) in productFloor" :key="index1">
  37. <!-- 楼层标题区域 -->
  38. <view class="tui-group-name">
  39. <view class="tui-group-title ">
  40. <view class="tui-group-l">{{ floor.title }}</view>
  41. <view class="tui-group-r" @click="NavToDetailPage(floor)" v-if="floor.productList.length >= 6">
  42. <text>更多</text> <tui-icon name="arrowright" :size="20" margin="0 0 0 -4rpx"></tui-icon>
  43. </view>
  44. </view>
  45. <view class="tui-sub__desc">{{ floor.description }}</view>
  46. </view>
  47. <!-- 商品列表区域 -->
  48. <view
  49. class="product-list"
  50. v-for="(pro, index2) in floor.productList"
  51. :key="index2"
  52. @click.stop="Details(pro)"
  53. >
  54. <view class="product-list-image">
  55. <image class="product-image" :src="pro.mainImage" mode=""></image>
  56. <!-- 推荐 -->
  57. <image
  58. class="product-icon"
  59. :src="StaticUrl + 'recommend.png'"
  60. mode=""
  61. v-if="pro.recommend === '1'"
  62. ></image>
  63. </view>
  64. <view class="product-list-msg">
  65. <view class="product-msg-name">{{ pro.name }}</view>
  66. <view class="product-list-tag" v-if="pro.activeStatus == 1">
  67. <text class="tag tag-02">活动价</text>
  68. </view>
  69. <view class="product-list-pri">
  70. <view class="price">¥{{ pro.price | PriceFormat }}</view>
  71. <view class="carts" @click.stop="handAddCarts(pro)">
  72. <view class="carts-add"> <text class="iconfont icon-gouwuche"></text> </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <!-- 侧边 -->
  80. <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
  81. </view>
  82. </template>
  83. <script>
  84. import authorize from '@/common/authorize.js'
  85. import banner from '@/components/cm-module/homeIndex/banner.vue'
  86. import { mapGetters, mapMutations } from 'vuex'
  87. export default {
  88. components: {
  89. banner
  90. },
  91. data() {
  92. return {
  93. StaticUrl: this.$Static,
  94. navbarData: {
  95. //顶部自定义导航
  96. showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
  97. showSearch: 0,
  98. title: '呵呵商城', // 导航栏 中间的标题
  99. haveBack: false,
  100. textLeft: this.$store.getters.isIphone,
  101. textColor: '#FFFFFF'
  102. },
  103. inputActive: 'bgnone',
  104. clickPath: '/pages/goods/search',
  105. CustomBar: this.CustomBar, // 顶部导航栏高度
  106. StatusBar: this.StatusBar,
  107. fontSizeSetting: this.fontSizeSetting,
  108. screenWidth: this.screenWidth,
  109. capsule: this.capsule,
  110. platformClass: this.platformClass,
  111. userId: 0,
  112. modallayer: false,
  113. skeletonShow: true,
  114. userIdentity: '',
  115. productFloor: [], //商品列表
  116. bannerImageList: [], //轮播
  117. pageNum: 1,
  118. pageSize: 20,
  119. hasNextPage: false,
  120. isScrollTop: false,
  121. isRequest: false
  122. }
  123. },
  124. filters: {
  125. //处理金额
  126. PriceFormat: function(text) {
  127. return Number(text).toFixed(2)
  128. }
  129. },
  130. onLoad() {
  131. this.modallayer = false
  132. this.InitAuthorize()
  133. },
  134. computed: {
  135. ...mapGetters(['hasLogin'])
  136. },
  137. methods: {
  138. ...mapMutations('app', ['login', 'logout']),
  139. async GetWxAuthorize() {
  140. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  141. this.UserService.UserWechatAuthorLogin({ code: wechatCode })
  142. .then(response => {
  143. const _data = JSON.parse(response.data)
  144. uni.setStorageSync('openId', _data.openId)
  145. this.userId = _data.userId
  146. this.userIdentity = _data.userIdentity
  147. this.$store.commit('app/updateStatus', _data)
  148. this.login(_data)
  149. this.GetHomeBanner()
  150. this.GetHomeProductList()
  151. })
  152. .catch(error => {
  153. console.log(error)
  154. const _data = JSON.parse(error.data)
  155. this.logout()
  156. this.$store.commit('app/updateStatus', _data)
  157. uni.setStorageSync('openId', _data.openId)
  158. this.GetHomeBanner()
  159. this.GetHomeProductList()
  160. })
  161. },
  162. GetHomeBanner() {
  163. //初始化首页数据
  164. this.CommonService.GetProductCarousel()
  165. .then(response => {
  166. let data = response.data
  167. this.bannerImageList = data
  168. this.skeletonShow = false
  169. })
  170. .catch(error => {
  171. this.$util.msg(error.msg, 2000)
  172. })
  173. },
  174. GetHomeProductList() {
  175. //初始化首页商品数据
  176. this.ProductService.QueryProductFloor()
  177. .then(response => {
  178. this.productFloor = response.data
  179. this.GetCartNumber()
  180. })
  181. .catch(error => {
  182. this.$util.msg(error.msg, 2000)
  183. })
  184. },
  185. NavToDetailPage(floor) {
  186. console.log('跳转')
  187. //跳转
  188. this.$api.navigateTo(`/pages/goods/good-floorMore?floorId=${floor.floorId}&title=${floor.title}`)
  189. },
  190. Details(pro) {
  191. this.$api.navigateTo(`/pages/goods/product?productId=${pro.productId}`)
  192. },
  193. handAddCarts(pro) {
  194. if (!this.hasLogin) {
  195. this.$api.navigateTo('/pages/login/login')
  196. } else {
  197. this.ProductService.shoppingAddCart({
  198. productId: pro.productId,
  199. userId: this.userId,
  200. productCount: 1,
  201. heUserId: 0
  202. })
  203. .then(response => {
  204. this.$util.msg('加入购物车成功', 1500, true, 'success')
  205. this.GetCartNumber()
  206. })
  207. .catch(error => {
  208. this.$util.msg(error.msg, 2000)
  209. })
  210. }
  211. },
  212. GetCartNumber() {
  213. //查询购物车数量
  214. this.ProductService.QueryShoppingQuantity({
  215. userId: this.userId
  216. })
  217. .then(response => {
  218. this.$store.commit('app/updateAllNum', response.data)
  219. })
  220. .catch(error => {
  221. console.log('查询购物车数量错误信息', error)
  222. })
  223. },
  224. handleClick(data) {
  225. this.$api.navigateTo('/h5/pages/activity/meobohui')
  226. this.$store.commit('app/setActivity', data)
  227. uni.setStorageSync('lockTime', Date.now())
  228. uni.setStorageSync('isActivityStatus', true)
  229. },
  230. handleCancelClick(data) {
  231. this.$store.commit('app/setActivity', data)
  232. uni.setStorageSync('lockTime', Date.now())
  233. uni.setStorageSync('isActivityStatus', true)
  234. },
  235. InitAuthorize() {
  236. //是否已授权 0:为取消授权 1:为已授权 2:为未操作
  237. this.GetWxAuthorize()
  238. }
  239. },
  240. onPageScroll(e) {
  241. //实时获取到滚动的值
  242. if (e.scrollTop > 50) {
  243. this.inputActive = 'bgclass'
  244. } else {
  245. this.inputActive = 'bgnone'
  246. }
  247. if (e.scrollTop > 400) {
  248. this.isScrollTop = true
  249. } else {
  250. this.isScrollTop = false
  251. }
  252. },
  253. //下拉刷新
  254. onPullDownRefresh() {
  255. this.GetHomeBanner()
  256. this.GetHomeProductList()
  257. setTimeout(() => {
  258. uni.stopPullDownRefresh()
  259. }, 2000)
  260. },
  261. // onReachBottom() {
  262. // console.log("用户把这个页面上拉100时触发我的")
  263. // if(this.hasNextPage){
  264. // this.GetOnReachBottomProductList()
  265. // }
  266. // },
  267. onShareAppMessage(res) {
  268. //分享转发
  269. if (res.from === 'button') {
  270. // 来自页面内转发按钮
  271. }
  272. return {
  273. title: '国内外知名美容院线护肤品线上商城~',
  274. path: 'pages/tabBar/index/index',
  275. imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
  276. }
  277. },
  278. onShow() {
  279. this.GetCartNumber()
  280. }
  281. }
  282. </script>
  283. <style lang="scss">
  284. page {
  285. background-color: #ffffff;
  286. }
  287. .navbar-wrap {
  288. position: fixed;
  289. width: 100%;
  290. top: 0;
  291. z-index: 100000;
  292. box-sizing: border-box;
  293. background-image: linear-gradient(0deg, #f83c6c 0%, #fa55bf 100%);
  294. background-size: cover;
  295. border-bottom: none;
  296. &.bgnone {
  297. background: rgba(255, 255, 255, 0);
  298. }
  299. &.bgclass {
  300. background: #f94a9b;
  301. }
  302. }
  303. .navbar-text {
  304. font-size: 30rpx;
  305. color: #000000;
  306. font-weight: 500;
  307. }
  308. .navbar-text.center {
  309. text-align: center;
  310. }
  311. .navbar-text.left {
  312. text-align: left;
  313. padding-left: 45px;
  314. }
  315. .navbar-icon {
  316. position: fixed;
  317. display: flex;
  318. box-sizing: border-box;
  319. }
  320. .navbar-icon .iconfont {
  321. display: inline-block;
  322. overflow: hidden;
  323. font-size: 44rpx;
  324. padding-right: 40rpx;
  325. margin-top: 1px;
  326. }
  327. .navbar-icon .icon-iconfonticonfontsousuo1 {
  328. color: #000000;
  329. }
  330. .navbar-icon view {
  331. height: 18px;
  332. border-left: 0.5px solid rgba(0, 0, 0, 0.3);
  333. margin-top: 6px;
  334. }
  335. .navbar-loading {
  336. background: #fff;
  337. text-align: center;
  338. }
  339. .search-input {
  340. width: 100%;
  341. height: 110rpx;
  342. padding: 20rpx 24rpx;
  343. box-sizing: border-box;
  344. .gosearch-btn {
  345. width: 100%;
  346. height: 100%;
  347. border-radius: 40rpx;
  348. background: #f0f0f0;
  349. margin: 0 auto;
  350. font-size: 28rpx;
  351. line-height: 70rpx;
  352. color: #8a8a8a;
  353. background: #ffffff;
  354. position: relative;
  355. box-sizing: border-box;
  356. padding-left: 80rpx;
  357. .search-icon {
  358. width: 80rpx;
  359. height: 70rpx;
  360. position: absolute;
  361. left: 0;
  362. top: 0;
  363. text-align: center;
  364. line-height: 70rpx;
  365. .icon-iconfonticonfontsousuo1 {
  366. margin: 0 6rpx;
  367. font-size: $font-size-34;
  368. color: #8a8a8a;
  369. z-index: 10;
  370. }
  371. }
  372. .search-text {
  373. font-size: $font-size-24;
  374. line-height: 70rpx;
  375. color: #8a8a8a;
  376. }
  377. }
  378. }
  379. .container-home {
  380. background: #f7f7f7 url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png) top center no-repeat;
  381. background-size: contain;
  382. min-height: 485rpx;
  383. }
  384. .container-section {
  385. width: 100%;
  386. height: auto;
  387. background-color: #f7f7f7;
  388. box-sizing: border-box;
  389. padding: 0 24rpx;
  390. .product-list {
  391. width: 339rpx;
  392. height: 532rpx;
  393. float: left;
  394. margin-right: 24rpx;
  395. margin-bottom: 24rpx;
  396. background-color: #ffffff;
  397. border-radius: 16rpx;
  398. &:nth-child(2n + 1) {
  399. margin-right: 0;
  400. }
  401. .product-list-image {
  402. width: 100%;
  403. height: 339rpx;
  404. float: left;
  405. position: relative;
  406. .product-image {
  407. width: 100%;
  408. height: 100%;
  409. display: block;
  410. border-radius: 16rpx 16rpx 0 0;
  411. }
  412. .product-icon {
  413. width: 68rpx;
  414. height: 55rpx;
  415. display: block;
  416. position: absolute;
  417. top: 0;
  418. left: 34rpx;
  419. }
  420. }
  421. .product-list-msg {
  422. width: 100%;
  423. height: 193rpx;
  424. box-sizing: border-box;
  425. padding: 16rpx 24rpx;
  426. float: left;
  427. position: relative;
  428. .product-msg-name {
  429. width: 100%;
  430. height: 72rpx;
  431. line-height: 35rpx;
  432. text-overflow: ellipsis;
  433. overflow: hidden;
  434. display: -webkit-box;
  435. -webkit-line-clamp: 2;
  436. line-clamp: 2;
  437. -webkit-box-orient: vertical;
  438. font-size: $font-size-26;
  439. color: #333333;
  440. text-align: justify;
  441. float: left;
  442. }
  443. .product-list-tag {
  444. position: relative;
  445. z-index: 9;
  446. width: 100%;
  447. height: 30rpx;
  448. margin-top: 8rpx;
  449. float: left;
  450. .tag {
  451. display: inline-block;
  452. height: 32rpx;
  453. font-size: 22rpx;
  454. line-height: 30rpx;
  455. text-align: center;
  456. color: #f83c6c;
  457. float: left;
  458. margin-right: 10rpx;
  459. &.tag-02 {
  460. width: 80rpx;
  461. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  462. no-repeat;
  463. background-size: contain;
  464. }
  465. &.tag-01 {
  466. width: 56rpx;
  467. color: #fff;
  468. background-color: #f83c6c;
  469. border-radius: 4rpx;
  470. }
  471. }
  472. }
  473. .product-list-pri {
  474. width: 100%;
  475. height: 44rpx;
  476. float: left;
  477. position: absolute;
  478. bottom: 16rpx;
  479. left: 0;
  480. box-sizing: border-box;
  481. padding: 0 24rpx;
  482. .price {
  483. float: left;
  484. font-size: $font-size-26;
  485. color: #f83c6c;
  486. font-weight: bold;
  487. line-height: 44rpx;
  488. }
  489. .carts {
  490. float: right;
  491. .carts-add {
  492. width: 44rpx;
  493. height: 44rpx;
  494. text-align: center;
  495. line-height: 44rpx;
  496. background-color: #ff457b;
  497. border-radius: 50%;
  498. .iconfont {
  499. font-size: 32rpx;
  500. color: #ffffff;
  501. }
  502. }
  503. }
  504. }
  505. }
  506. }
  507. }
  508. .tui-group-name {
  509. width: 100%;
  510. height: 92rpx;
  511. padding: 20rpx 0;
  512. }
  513. .tui-group-title {
  514. width: 100%;
  515. float: left;
  516. .tui-group-l {
  517. float: left;
  518. font-size: 34rpx;
  519. font-weight: bold;
  520. text-align: left;
  521. line-height: 49rpx;
  522. color: #333;
  523. }
  524. .tui-group-r {
  525. float: right;
  526. font-size: $font-size-26;
  527. text-align: right;
  528. line-height: 49rpx;
  529. color: #999999;
  530. .icon-xiayibu {
  531. font-size: $font-size-30;
  532. color: #999999;
  533. }
  534. }
  535. }
  536. .tui-sub__desc {
  537. width: 100%;
  538. float: left;
  539. color: rgba(153, 153, 153, 0.9);
  540. font-size: $font-size-26;
  541. }
  542. </style>