shop_uniapp/pages/index/index.vue
2024-12-12 14:06:09 +08:00

332 lines
8.4 KiB
Vue

<template>
<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="{ use: false, toTop: {
bottom: '300rpx'
}}">
<view class="index index-bg" :style="[headerStyle]">
<u-sticky offset-top="0" h5-nav-height="0" bg-color="transparent">
<view class="index-bg" :style="[headerStyle]">
<u-navbar :is-fixed="false" :border-bottom="false" :background="{ background: 'transparent', }"
:is-back="false">
<view class="flex-1 flex row" style="position: relative;">
<!-- 城市 -->
<router-link v-if="appConfig.is_open_nearby" class="m-l-16 flex white row-center" to="/bundle_b/pages/city/city">
<text class="m-r-6">{{ cityInfo.name || '选择' }}</text>
<u-icon name="arrow-down" size="24" color="#FFFFFF"></u-icon>
</router-link>
<view class="flex-1">
<view class="flex row">
<router-link to="/pages/goods_search/goods_search">
<u-search wrap-bg-color="transparent" bg-color="#fff" :disabled="true" :height="62">
</u-search>
</router-link>
<button open-type="contact" hover-class="none" class="m-t-10">
<u-icon name="server-fill" size="44" color="#FFFFFF"></u-icon>
</button>
</view>
</view>
<!-- #ifdef MP -->
<view class="capsule-tips flex row-between" v-if="offPrompt">
<text class="m-r-10">添加到”我的小程序”,红包、优惠不错过</text>
<u-icon name="close" color="#FFFFFF" @click="clearIntervalFunc"></u-icon>
</view>
<!-- #endif -->
</view>
</u-navbar>
<view class="flex">
<view class="flex-1" style="min-width:600rpx">
<u-tabs active-color="#000" :show-bar="false" inactive-color="#000" :current="active" :list="cateList"
bg-color="transparent" :active-item-style="{fontSize:'36rpx'}" :bar-width="64"
:bold="true" @change="changeActive">
</u-tabs>
</view>
<router-link to="/pages/goods_cate/goods_cate" v-if="appConfig.show_goods_cate">
<view class="white flex cate-btn m-l-10">
<image class="icon-xs m-r-4" :src="aliOSS + 'uniapp/icon_cate.png'" alt="">
分类
</view>
</router-link>
</view>
</view>
</u-sticky>
<view class="tab-con">
<view v-if="appConfig.show_wait_goods && userInfo.wait_take >= 1">
<u-notice-bar mode="horizontal" :list="['您有' + userInfo.wait_take + '件商品待收货,请及时确认']" :font-size="28" :close-icon="false" :speed="100"
color="#449FFB" ></u-notice-bar>
</view>
<view v-if="appConfig.show_mini_notice" class="m-b-10">
<u-notice-bar mode="horizontal" :list="[appConfig.mini_notice]" :font-size="28" :close-icon="false" :speed="100"
color="#449FFB" ></u-notice-bar>
</view>
<view v-show="active == 0">
<index-home ref="indexHome" :home-data="homeData" :nav-list="navList" :live-list="liveLists">
</index-home>
<goods-column ref="mescrollItem" :autoGetData="false"></goods-column>
</view>
<template v-for="(item, index) in cateList">
<view v-if="index > 0" class="tab-item" v-show="active == index" :key="index">
<view>
<cate-home v-if="showCateList[index]" :top="cateTop" ref="cateItem" :i="index"
:index="active" :cate="item">
</cate-home>
</view>
</view>
</template>
</view>
</view>
<tabbar></tabbar>
</mescroll-body>
</template>
<script>
import MescrollCompMixin from "@/components/mescroll-uni/mixins/mescroll-comp";
import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins";
import {
mapGetters,
mapActions
} from 'vuex'
import {
getMenu,
getHome,
getHotGoods,
getLevelOneList
} from "@/api/store"
import { getLiveLists } from '@/api/live'
import {
getRect
} from '@/utils/tools'
import {
bindSuperior
} from '@/api/user'
import Cache from '@/utils/cache'
import { getWxCode } from "@/utils/login"
import {INVITE_CODE} from '@/config/cachekey'
const app = getApp()
const homeItem = {
name: '首页'
}
export default {
mixins: [MescrollMixin, MescrollCompMixin],
data() {
return {
offPrompt: true,
active: 0,
navBg: 0,
goodsList: [],
homeData: {},
navList: [],
enable: true,
cateList: [homeItem],
showCateList: [],
liveLists: [],
privacyWxPopShow: false
}
},
async onLoad(options) {
// 选择城市后是否刷新
if(options?.refresh) await this.getHomeFun()
// 监听是否刷新页面,目前秒杀时会用到
uni.$on('refreshhome', () => { this.getHomeFun() })
// #ifdef MP-WEIXIN
this.getLiveListsFun()
// #endif
this.bindCode()
},
onUnload() {
uni.$off('refreshhome')
},
onShow() {
this.enable = this.active == 0 ? true : false
this.getCartNum()
},
onHide() {
// #ifdef H5
this.enable = false
// #endif
},
onReady() {
// #ifdef MP
// 关闭胶囊提示
this.offPromptFunc();
// #endif
},
methods: {
...mapActions(['getCartNum']),
async bindCode() {
let _that = this;
uni.login({
success(res) {
if (res.code && uni.getStorageSync('invite_code')) {
getHome({
code: res.code,
invite_code: uni.getStorageSync('invite_code')
})
}
},
fail(res) {
reject(res);
}
});
},
// #ifdef MP
offPromptFunc() {
let time = 8;
this.offPrompt = setInterval(() => {
time -= 1;
if( time <= 0 ) this.clearIntervalFunc()
}, 1000)
},
clearIntervalFunc() {
clearInterval(this.offPrompt);
this.offPrompt = false;
},
// #endif
// 获取1级分类
async getLevelOneListFun() {
let p_id = this.$store.getters.hasPid;
let set = this.$store.getters.hasSetId;
const {
code,
data
} = await getLevelOneList({p_id, set});
if (code == 1) {
this.cateList = [homeItem, ...data]
this.showCateList = []
}
},
async getMenuFun() {
const {
code,
data
} = await getMenu({
type: 1
});
if (code == 1) {
this.navList = data
}
},
async getHomeFun() {
let p_id = this.$store.getters.hasPid;
let set = this.$store.getters.hasSetId;
const {
code,
data
} = await getHome({ city_id: this.cityInfo.id, p_id, set });
if (code == 1) {
this.homeData = data
}
},
// #ifdef MP-WEIXIN
async getLiveListsFun() {
const {
code,
data
} = await getLiveLists({ page_size: 6, page_no: 1 });
if (code == 1) {
this.liveLists = data.list
}
},
// #endif
changeActive(index) {
this.active = index
this.enable = index == 0
this.mescroll.optDown.use = index == 0
this.showCateList[index] = true
},
async downCallback() {
await this.getLevelOneListFun()
await this.getMenuFun()
await this.getHomeFun()
// #ifdef MP-WEIXIN
this.getLiveListsFun()
// #endif
this.$refs.mescrollItem.getData()
this.mescroll.endSuccess(0, false)
}
},
computed: {
...mapGetters(['sysInfo', 'inviteCode', 'appConfig', 'cityInfo', 'userInfo']),
navH() {
return this.sysInfo.navHeight + 'px'
},
// 分类栏悬浮高度
cateTop() {
return this.sysInfo.navHeight + uni.upx2px(80) + 'px'
},
headerStyle() {
const {
active,
cateList,
appConfig
} = this
let bg = cateList[active].bg_image
if (active == 0) {
bg = appConfig.index_setting.top_bg_image
}
return bg ? {
'background-image': `url(${bg})`
} : {}
}
}
}
</script>
<style lang="scss">
page {
padding: 0;
}
.index-bg {
background-image: url('#{$aliOSS-path}uploads/images/202305310842517659b6584.png');
background-size: 100% auto;
background-repeat: no-repeat;
}
.index {
min-height: calc(100vh - var(--window-bottom));
.u-navbar {
::v-deep .u-search {
padding: 0 30rpx;
}
}
// 胶囊提示
.capsule-tips {
width: 584rpx;
color: #FFFFFF;
padding: 12rpx 18rpx;
border-radius: 14rpx;
background: rgba(0, 0, 0, 0.7);
position: relative;
position: absolute;
z-index: 9999;
bottom: -80rpx;
right: -150rpx;
}
.capsule-tips::after {
content: '';
border-bottom: 14rpx solid rgba(0, 0, 0, .7);
border-right: 14rpx solid transparent;
border-left: 14rpx solid transparent;
position: absolute;
top: -14rpx;
right: 88rpx;
}
.cate-btn {
padding: 12rpx 16rpx 12rpx 20rpx;
border-radius: 60rpx 0 0 60rpx;
background-color: rgba(0, 0, 0, .4);
}
}
</style>