123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544 |
- <template>
- <view class="home tui-skeleton clearfix">
- <tui-skeleton v-if="skeletonShow" :isLoading="true" :loadingType="2"></tui-skeleton>
- <!-- 首页自定义导航栏 -->
- <view
- class="navbar-wrap"
- :style="{ height: CustomBar + 55 + 'px', paddingTop: StatusBar + 'px' }"
- :class="inputActive"
- >
- <view
- class="navbar-text"
- :style="{
- color: navbarData.textColor ? navbarData.textColor : '',
- lineHeight: CustomBar - StatusBar + 'px;',
- fontSize: fontSizeSetting + 'px;',
- paddingLeft: navbarData.textLeft ? '' : 12 + 'px'
- }"
- :class="platformClass"
- >
- {{ navbarData.title ? navbarData.title : ' ' }}
- </view>
- <view class="search-input">
- <view class="gosearch-btn" @click="this.$api.navigateTo(clickPath)">
- <view class="search-icon"> <text class="iconfont icon-sousuo"></text> </view>
- <view class="search-text">搜索商品</view>
- </view>
- </view>
- </view>
- <!-- 主页内容 -->
- <view class="container-home " :style="{ paddingTop: CustomBar + 'px' }">
- <!-- 轮播 -->
- <banner :list="bannerImageList"></banner>
- </view>
- <!-- 商品列表 -->
- <view class="container-section">
- <view class="clearfix" v-for="(floor, index1) in productFloor" :key="index1">
- <!-- 楼层标题区域 -->
- <view class="tui-group-name">
- <view class="tui-group-title ">
- <view class="tui-group-l">{{ floor.title }}</view>
- <view class="tui-group-r" @click="NavToDetailPage(floor)" v-if="floor.productList.length >= 6">
- <text>更多</text> <tui-icon name="arrowright" :size="20" margin="0 0 0 -4rpx"></tui-icon>
- </view>
- </view>
- <view class="tui-sub__desc">{{ floor.description }}</view>
- </view>
- <!-- 商品列表区域 -->
- <view
- class="product-list"
- v-for="(pro, index2) in floor.productList"
- :key="index2"
- @click.stop="Details(pro)"
- >
- <view class="product-list-image">
- <image class="product-image" :src="pro.mainImage" mode=""></image>
- <!-- 推荐 -->
- <image
- class="product-icon"
- :src="StaticUrl + 'recommend.png'"
- mode=""
- v-if="pro.recommend === '1'"
- ></image>
- </view>
- <view class="product-list-msg">
- <view class="product-msg-name">{{ pro.name }}</view>
- <view class="product-list-tag" v-if="pro.activeStatus == 1">
- <text class="tag tag-02">活动价</text>
- </view>
- <view class="product-list-pri">
- <view class="price">¥{{ pro.price | PriceFormat }}</view>
- <view class="carts" @click.stop="handAddCarts(pro)">
- <view class="carts-add"> <text class="iconfont icon-gouwuche"></text> </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <!-- 侧边 -->
- <scroll-top :isScrollTop="isScrollTop" :bottom="160"></scroll-top>
- </view>
- </template>
- <script>
- import authorize from '@/common/authorize.js'
- import banner from '@/components/cm-module/homeIndex/banner.vue'
- import { mapGetters, mapMutations } from 'vuex'
- export default {
- components: {
- banner
- },
- data() {
- return {
- StaticUrl: this.$Static,
- navbarData: {
- //顶部自定义导航
- showCapsule: 1, // 是否显示左上角图标 1表示显示 0表示不显示,
- showSearch: 0,
- title: '呵呵商城', // 导航栏 中间的标题
- haveBack: false,
- textLeft: this.$store.getters.isIphone,
- textColor: '#FFFFFF'
- },
- inputActive: 'bgnone',
- clickPath: '/pages/goods/search',
- CustomBar: this.CustomBar, // 顶部导航栏高度
- StatusBar: this.StatusBar,
- fontSizeSetting: this.fontSizeSetting,
- screenWidth: this.screenWidth,
- capsule: this.capsule,
- platformClass: this.platformClass,
- userId: 0,
- modallayer: false,
- skeletonShow: true,
- userIdentity: '',
- productFloor: [], //商品列表
- bannerImageList: [], //轮播
- pageNum: 1,
- pageSize: 20,
- hasNextPage: false,
- isScrollTop: false,
- isRequest: false
- }
- },
- filters: {
- //处理金额
- PriceFormat: function(text) {
- return Number(text).toFixed(2)
- }
- },
- onLoad() {
- this.modallayer = false
- this.InitAuthorize()
- },
- computed: {
- ...mapGetters(['hasLogin'])
- },
- methods: {
- ...mapMutations('app', ['login', 'logout']),
- async GetWxAuthorize() {
- const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
- this.UserService.UserWechatAuthorLogin({ code: wechatCode })
- .then(response => {
- const _data = JSON.parse(response.data)
- uni.setStorageSync('openId', _data.openId)
- this.userId = _data.userId
- this.userIdentity = _data.userIdentity
- this.$store.commit('app/updateStatus', _data)
- this.login(_data)
- this.GetHomeBanner()
- this.GetHomeProductList()
- })
- .catch(error => {
- console.log(error)
- const _data = JSON.parse(error.data)
- this.logout()
- this.$store.commit('app/updateStatus', _data)
- uni.setStorageSync('openId', _data.openId)
- this.GetHomeBanner()
- this.GetHomeProductList()
- })
- },
- GetHomeBanner() {
- //初始化首页数据
- this.CommonService.GetProductCarousel()
- .then(response => {
- let data = response.data
- this.bannerImageList = data
- this.skeletonShow = false
- })
- .catch(error => {
- this.$util.msg(error.msg, 2000)
- })
- },
- GetHomeProductList() {
- //初始化首页商品数据
- this.ProductService.QueryProductFloor()
- .then(response => {
- this.productFloor = response.data
- this.GetCartNumber()
- })
- .catch(error => {
- this.$util.msg(error.msg, 2000)
- })
- },
- NavToDetailPage(floor) {
- console.log('跳转')
- //跳转
- this.$api.navigateTo(`/pages/goods/good-floorMore?floorId=${floor.floorId}&title=${floor.title}`)
- },
- Details(pro) {
- this.$api.navigateTo(`/pages/goods/product?productId=${pro.productId}`)
- },
- handAddCarts(pro) {
- if (!this.hasLogin) {
- this.$api.navigateTo('/pages/login/login')
- } else {
- this.ProductService.shoppingAddCart({
- productId: pro.productId,
- userId: this.userId,
- productCount: 1,
- heUserId: 0
- })
- .then(response => {
- this.$util.msg('加入购物车成功', 1500, true, 'success')
- this.GetCartNumber()
- })
- .catch(error => {
- this.$util.msg(error.msg, 2000)
- })
- }
- },
- GetCartNumber() {
- //查询购物车数量
- this.ProductService.QueryShoppingQuantity({
- userId: this.userId
- })
- .then(response => {
- this.$store.commit('app/updateAllNum', response.data)
- })
- .catch(error => {
- console.log('查询购物车数量错误信息', error)
- })
- },
- handleClick(data) {
- this.$api.navigateTo('/h5/pages/activity/meobohui')
- this.$store.commit('app/setActivity', data)
- uni.setStorageSync('lockTime', Date.now())
- uni.setStorageSync('isActivityStatus', true)
- },
- handleCancelClick(data) {
- this.$store.commit('app/setActivity', data)
- uni.setStorageSync('lockTime', Date.now())
- uni.setStorageSync('isActivityStatus', true)
- },
- InitAuthorize() {
- //是否已授权 0:为取消授权 1:为已授权 2:为未操作
- this.GetWxAuthorize()
- }
- },
- onPageScroll(e) {
- //实时获取到滚动的值
- if (e.scrollTop > 50) {
- this.inputActive = 'bgclass'
- } else {
- this.inputActive = 'bgnone'
- }
- if (e.scrollTop > 400) {
- this.isScrollTop = true
- } else {
- this.isScrollTop = false
- }
- },
- //下拉刷新
- onPullDownRefresh() {
- this.GetHomeBanner()
- this.GetHomeProductList()
- setTimeout(() => {
- uni.stopPullDownRefresh()
- }, 2000)
- },
- // onReachBottom() {
- // console.log("用户把这个页面上拉100时触发我的")
- // if(this.hasNextPage){
- // this.GetOnReachBottomProductList()
- // }
- // },
- onShareAppMessage(res) {
- //分享转发
- if (res.from === 'button') {
- // 来自页面内转发按钮
- }
- return {
- title: '国内外知名美容院线护肤品线上商城~',
- path: 'pages/tabBar/index/index',
- imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
- }
- },
- onShow() {
- this.GetCartNumber()
- }
- }
- </script>
- <style lang="scss">
- page {
- background-color: #ffffff;
- }
- .navbar-wrap {
- position: fixed;
- width: 100%;
- top: 0;
- z-index: 100000;
- box-sizing: border-box;
- background-image: linear-gradient(0deg, #f83c6c 0%, #fa55bf 100%);
- background-size: cover;
- border-bottom: none;
- &.bgnone {
- background: rgba(255, 255, 255, 0);
- }
- &.bgclass {
- background: #f94a9b;
- }
- }
- .navbar-text {
- font-size: 30rpx;
- color: #000000;
- font-weight: 500;
- }
- .navbar-text.center {
- text-align: center;
- }
- .navbar-text.left {
- text-align: left;
- padding-left: 45px;
- }
- .navbar-icon {
- position: fixed;
- display: flex;
- box-sizing: border-box;
- }
- .navbar-icon .iconfont {
- display: inline-block;
- overflow: hidden;
- font-size: 44rpx;
- padding-right: 40rpx;
- margin-top: 1px;
- }
- .navbar-icon .icon-iconfonticonfontsousuo1 {
- color: #000000;
- }
- .navbar-icon view {
- height: 18px;
- border-left: 0.5px solid rgba(0, 0, 0, 0.3);
- margin-top: 6px;
- }
- .navbar-loading {
- background: #fff;
- text-align: center;
- }
- .search-input {
- width: 100%;
- height: 110rpx;
- padding: 20rpx 24rpx;
- box-sizing: border-box;
- .gosearch-btn {
- width: 100%;
- height: 100%;
- border-radius: 40rpx;
- background: #f0f0f0;
- margin: 0 auto;
- font-size: 28rpx;
- line-height: 70rpx;
- color: #8a8a8a;
- background: #ffffff;
- position: relative;
- box-sizing: border-box;
- padding-left: 80rpx;
- .search-icon {
- width: 80rpx;
- height: 70rpx;
- position: absolute;
- left: 0;
- top: 0;
- text-align: center;
- line-height: 70rpx;
- .icon-iconfonticonfontsousuo1 {
- margin: 0 6rpx;
- font-size: $font-size-34;
- color: #8a8a8a;
- z-index: 10;
- }
- }
- .search-text {
- font-size: $font-size-24;
- line-height: 70rpx;
- color: #8a8a8a;
- }
- }
- }
- .container-home {
- background: #f7f7f7 url(https://static.caimei365.com/app/mini-hehe/icon/icon-index-bg.png) top center no-repeat;
- background-size: contain;
- min-height: 485rpx;
- }
- .container-section {
- width: 100%;
- height: auto;
- background-color: #f7f7f7;
- box-sizing: border-box;
- padding: 0 24rpx;
- .product-list {
- width: 339rpx;
- height: 532rpx;
- float: left;
- margin-right: 24rpx;
- margin-bottom: 24rpx;
- background-color: #ffffff;
- border-radius: 16rpx;
- &:nth-child(2n + 1) {
- margin-right: 0;
- }
- .product-list-image {
- width: 100%;
- height: 339rpx;
- float: left;
- position: relative;
- .product-image {
- width: 100%;
- height: 100%;
- display: block;
- border-radius: 16rpx 16rpx 0 0;
- }
- .product-icon {
- width: 68rpx;
- height: 55rpx;
- display: block;
- position: absolute;
- top: 0;
- left: 34rpx;
- }
- }
- .product-list-msg {
- width: 100%;
- height: 193rpx;
- box-sizing: border-box;
- padding: 16rpx 24rpx;
- float: left;
- position: relative;
- .product-msg-name {
- width: 100%;
- height: 72rpx;
- line-height: 35rpx;
- text-overflow: ellipsis;
- overflow: hidden;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- line-clamp: 2;
- -webkit-box-orient: vertical;
- font-size: $font-size-26;
- color: #333333;
- text-align: justify;
- float: left;
- }
- .product-list-tag {
- position: relative;
- z-index: 9;
- width: 100%;
- height: 30rpx;
- margin-top: 8rpx;
- float: left;
- .tag {
- display: inline-block;
- height: 32rpx;
- font-size: 22rpx;
- line-height: 30rpx;
- text-align: center;
- color: #f83c6c;
- float: left;
- margin-right: 10rpx;
- &.tag-02 {
- width: 80rpx;
- background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
- no-repeat;
- background-size: contain;
- }
- &.tag-01 {
- width: 56rpx;
- color: #fff;
- background-color: #f83c6c;
- border-radius: 4rpx;
- }
- }
- }
- .product-list-pri {
- width: 100%;
- height: 44rpx;
- float: left;
- position: absolute;
- bottom: 16rpx;
- left: 0;
- box-sizing: border-box;
- padding: 0 24rpx;
- .price {
- float: left;
- font-size: $font-size-26;
- color: #f83c6c;
- font-weight: bold;
- line-height: 44rpx;
- }
- .carts {
- float: right;
- .carts-add {
- width: 44rpx;
- height: 44rpx;
- text-align: center;
- line-height: 44rpx;
- background-color: #ff457b;
- border-radius: 50%;
- .iconfont {
- font-size: 32rpx;
- color: #ffffff;
- }
- }
- }
- }
- }
- }
- }
- .tui-group-name {
- width: 100%;
- height: 92rpx;
- padding: 20rpx 0;
- }
- .tui-group-title {
- width: 100%;
- float: left;
- .tui-group-l {
- float: left;
- font-size: 34rpx;
- font-weight: bold;
- text-align: left;
- line-height: 49rpx;
- color: #333;
- }
- .tui-group-r {
- float: right;
- font-size: $font-size-26;
- text-align: right;
- line-height: 49rpx;
- color: #999999;
- .icon-xiayibu {
- font-size: $font-size-30;
- color: #999999;
- }
- }
- }
- .tui-sub__desc {
- width: 100%;
- float: left;
- color: rgba(153, 153, 153, 0.9);
- font-size: $font-size-26;
- }
- </style>
|