Commit 01b800ad by songbingqi

修改自定义tabar

parent d01d92b9
<template> <template>
<div> <div>
<u-popup :show="show" :round="10" mode="bottom" @close="close" :safeAreaInsetBottom="false"> <u-popup :show="show" :round="10" mode="bottom" @close="close" :safeAreaInsetBottom="false">
<view class="bigBox" :style="{'height':'1380rpx'}"> <view class="bigBox" :style="{'height':'90vh'}">
<div class="order_flow" > <div class="order_flow" >
<div class="code">取单码 {{ orderInfo.orderNum }}</div> <div class="code">取单码 {{ orderInfo.orderNum }}</div>
<!-- <image mode="scaleToFill" :src="qrCode" class="qr_code"></image> --> <!-- <image mode="scaleToFill" :src="qrCode" class="qr_code"></image> -->
......
<template> <template>
<view class="page-body"> <view class="page-body">
<scroll-view class="nav-left" :class="[buied?'buiedcss':'',shopCarFlag?'shopCarcss':'' ]" scroll-y :scroll-top="scrollLeftTop" scroll-with-animation> <scroll-view class="nav-left" :style="[heightStyle]" :class="[shopCarFlag?'shopCarcss':'' ]" scroll-y :scroll-top="scrollLeftTop" scroll-with-animation>
<view class="nav-left-item" v-for="item in classifyData" @click="categoryClickMain(item.id)" :key="item.id" <view class="nav-left-item" v-for="item in classifyData" @click="categoryClickMain(item.id)" :key="item.id"
:class="item.id == categoryId ? 'active' : ''"> :class="item.id == categoryId ? 'active' : ''">
<span>{{ item.name }}</span> <span>{{ item.name }}</span>
<view :class="item.id == categoryId ? 'active-line' : ''"></view> <view :class="item.id == categoryId ? 'active-line' : ''"></view>
</view> </view>
</scroll-view> </scroll-view>
<scroll-view class="nav-right" :class="[buied?'buiedcss':'',shopCarFlag?'shopCarcss':'' ]" scroll-y :scroll-top="scrollTop" @scroll="scroll" @touchstart="openScroll" <scroll-view class="nav-right" :style="[heightStyle]" :class="[shopCarFlag?'shopCarcss':'' ]" scroll-y :scroll-top="scrollTop" @scroll="scroll" @touchstart="openScroll"
scroll-with-animation> scroll-with-animation>
<view v-for="category in classifyData" :id="category.id" :key="category.id" class="box"> <view v-for="category in classifyData" :id="category.id" :key="category.id" class="box">
<view :style="loads" class="right-title">{{ category.name }}</view> <view :style="loads" class="right-title">{{ category.name }}</view>
...@@ -52,6 +52,9 @@ export default { ...@@ -52,6 +52,9 @@ export default {
props:['buied'], props:['buied'],
data() { data() {
return { return {
heightStyle: {
'--scroll-height': 0
},
Utils, Utils,
classifyData: [], classifyData: [],
categoryId: '', categoryId: '',
...@@ -60,18 +63,28 @@ export default { ...@@ -60,18 +63,28 @@ export default {
scrollTop: 0, scrollTop: 0,
scrolled: true, scrolled: true,
goods:[], goods:[],
shopCarFlag:false shopCarFlag:false,
taBarHeight:0
} }
}, },
watch:{ watch:{
goods(val){ goods(val){
this.shopCarFlag = val.length>0 this.shopCarFlag = val.length>0
},
buied(val) {
if(val){
this.heightStyle['--scroll-height'] = (this.taBarHeight+293)+'rpx'
}
} }
}, },
created() { created() {
$EventBus.$off('updateCar'); $EventBus.$off('updateCar');
}, },
mounted(){ mounted(){
this.$nextTick(()=>{
this.taBarHeight = uni.getStorageSync('taBarHeight')
this.heightStyle['--scroll-height'] = (this.taBarHeight)+'rpx'
})
this.goods = uni.getStorageSync('shopCarInfo') || []; this.goods = uni.getStorageSync('shopCarInfo') || [];
$EventBus.$on('updateCar', () => { $EventBus.$on('updateCar', () => {
this.goods = uni.getStorageSync('shopCarInfo') || []; this.goods = uni.getStorageSync('shopCarInfo') || [];
...@@ -378,8 +391,9 @@ export default { ...@@ -378,8 +391,9 @@ export default {
width: 160rpx; width: 160rpx;
background: #fff; background: #fff;
border-right: 2rpx solid #EEEEEE; border-right: 2rpx solid #EEEEEE;
height: calc(100vh - 376rpx); height: calc(100vh - var(--scroll-height));
overflow: auto; overflow: auto;
// background: var(--header-color);
} }
.nav-left-item { .nav-left-item {
...@@ -400,7 +414,7 @@ export default { ...@@ -400,7 +414,7 @@ export default {
.nav-right { .nav-right {
box-sizing: border-box; box-sizing: border-box;
height: calc(100vh - 376rpx); height: calc(100vh - var(--scroll-height));
overflow: auto; overflow: auto;
padding-top: 50rpx; padding-top: 50rpx;
width: 585.21rpx; width: 585.21rpx;
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
</view> </view>
</u-popup> </u-popup>
<view class="end" v-if="goods.length"> <view class="end" v-if="goods.length" :style="{'bottom':shopCar+'rpx'}">
<view @click.stop="openShopCar" class="end-left"> <view @click.stop="openShopCar" class="end-left">
<view style="display:flex"> <view style="display:flex">
<view class="car-img"> <view class="car-img">
...@@ -101,13 +101,16 @@ export default { ...@@ -101,13 +101,16 @@ export default {
goods: [],//购物车商品信息 goods: [],//购物车商品信息
loginInfo: "", loginInfo: "",
imgPath: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F01%2F82%2F40%2F596fa6dc00bb4_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633499781&t=d37222e32213957ddbdd01d62e071309', imgPath: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F01%2F82%2F40%2F596fa6dc00bb4_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633499781&t=d37222e32213957ddbdd01d62e071309',
Utils Utils,
shopCar:0
} }
}, },
created() { created() {
$EventBus.$off('updateCar'); $EventBus.$off('updateCar');
}, },
mounted() { mounted() {
this.shopCar = uni.getStorageSync('shopCar')
console.log(this.shopCar)
if(!this.userms){ if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{ User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo this.loginInfo = loginInfo
...@@ -118,6 +121,7 @@ export default { ...@@ -118,6 +121,7 @@ export default {
this.goods = uni.getStorageSync('shopCarInfo') || []; this.goods = uni.getStorageSync('shopCarInfo') || [];
}); });
}, },
methods: { methods: {
// 切换购物车列表显示隐藏 // 切换购物车列表显示隐藏
openShopCar() { openShopCar() {
...@@ -477,11 +481,10 @@ export default { ...@@ -477,11 +481,10 @@ export default {
height: 92rpx; height: 92rpx;
background-color: rgb(253, 253, 253); background-color: rgb(253, 253, 253);
position: fixed; position: fixed;
bottom: 0;
left: 0; left: 0;
box-shadow: 0px -4px 8px 0px rgba(102, 102, 102, 0.1); box-shadow: 0px -4px 8px 0px rgba(102, 102, 102, 0.1);
display: flex; display: flex;
z-index: 10075; z-index: 1024;
align-items: center; align-items: center;
&-left { &-left {
......
<template>
<view class="tabbar">
<view class="navigator">
<view class="navigator-item" v-for="(item,index) in tabBar.list" :key="item.pagePath"
@click="switchTab(index)">
<img :src="item.iconPath" class="icon" v-if="selectedIndex !== index">
<img :src="item.selectedIconPath" class="icon" v-else>
<text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
props:['select'],
watch:{
select(val){
this.selectedIndex = Number(val)
}
},
mounted(){
// console.log(this.select)
// this.selectedIndex = Number(this.select)
// this.selectedIndex = 0
// const url = uni.getStorageSync('url')
// const nowUrl = this.tabBar.list.findIndex(item => url === item.pagePath)
// this.selectedIndex = nowUrl
// console.log(nowUrl)
},
data() {
return {
selectedIndex: 0,
showselected: false,
tabBar: {
list: [
{
"iconPath": "/static/imgs/caidanweixuanzhong.png",
"selectedIconPath": "/static/imgs/caidanxuanzhong.png",
"pagePath": "pages/menu/menu",
"text": "菜单"
},
{
"iconPath": "/static/imgs/dingdanweixuanzhong.png",
"selectedIconPath": "/static/imgs/dingdanxuanzhong.png",
"pagePath": "pages/order/order",
"text": "订单"
},
{
"iconPath": "/static/imgs/wodeweixuanzhong.png",
"selectedIconPath": "/static/imgs/wodexuanzhong.png",
"pagePath": "pages/mine/mine",
"text": "我的"
}
]
},
}
},
// beforeCreate() {
// this.__path__ = this.$route.path
// },
methods: {
switchTab(index, item) {
this.$emit('changeIndex',index)
}
},
}
</script>
<style>
.tabbar {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 100rpx;
z-index: 999;
background: #F5F5F5;
border-top: 2rpx solid #eee;
}
.navigator {
display: flex;
justify-content: space-between;
width: 85%;
margin: 0 auto;
padding: 20rpx;
}
.navigator-item {
display: flex;
align-items: center;
flex-direction: column;
width: 50rpx;
height: 100%;
}
.item-text {
margin-top: 6rpx;
color: #777E86;
font-size: 24rpx;
}
.text-active {
color: #2E92FD !important;
}
.icon {
width: 20px;
height: 20px;
}
</style>
\ No newline at end of file
<template> <template>
<!-- Tab --> <view class="tabbar" :style="{'padding-bottom':BottomSafeHeight+'px'}">
<u-tabbar zIndex="10075" v-model="selectedTabbar" :border="false" inactive-color="#000000" height="50" <view class="navigator">
active-color="#006ECF" :fixed="true" :safeAreaInsetBottom="true" @change="beforeSwitch"> <view class="navigator-item" v-for="(item,index) in tabBar.list" :key="item.pagePath"
<u-tabbar-item v-for="(item, index) in list" :key="item.text" :text="item.text" @click="switchTab(index,item)">
:icon="selectedTabbar == index ? item.activeIcon : item.icon"></u-tabbar-item> <img :src="item.iconPath" class="icon" v-if="selectedIndex !== index">
</u-tabbar> <img :src="item.selectedIconPath" class="icon" v-else>
<text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
</view>
</view>
</view>
</view>
</template> </template>
<script> <script>
export default {
export default { props:['select'],
data() { mounted(){
return {} this.BottomSafeHeight = uni.getStorageSync('BottomSafeHeight')||10
}, uni.setStorageSync("taBarHeight",(this.BottomSafeHeight+376))
props: ['selectedTabbar'], uni.setStorageSync("shopCar",this.BottomSafeHeight==10?120:(this.BottomSafeHeight+288)/2)
computed: { uni.setStorageSync("orderBottom",(this.BottomSafeHeight+150))
list() { this.selectedIndex = Number(this.select)
// tabbar List },
return this.$store.state.list; data() {
} return {
}, selectedIndex: 0,
methods: { showselected: false,
//点击tab BottomSafeHeight:0,
tabBar: {
beforeSwitch(index) { list: [
{
uni.switchTab({ url: this.list[index].pagePath }); "iconPath": "/static/imgs/caidanweixuanzhong.png",
return true; "selectedIconPath": "/static/imgs/caidanxuanzhong.png",
} "pagePath": "pages/menu/menu",
} "text": "菜单"
} },
{
"iconPath": "/static/imgs/dingdanweixuanzhong.png",
"selectedIconPath": "/static/imgs/dingdanxuanzhong.png",
"pagePath": "pages/order/order",
"text": "订单"
},
{
"iconPath": "/static/imgs/wodeweixuanzhong.png",
"selectedIconPath": "/static/imgs/wodexuanzhong.png",
"pagePath": "pages/mine/mine",
"text": "我的"
}
]
},
}
},
// beforeCreate() {
// this.__path__ = this.$route.path
// },
methods: {
switchTab(index, item) {
let url = '/' + item.pagePath
uni.switchTab({
url
})
return
}
},
}
</script> </script>
<style> <style>
.tabbar {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 100rpx;
z-index: 999;
background: #FFFFFF;
border-top: 2rpx solid #FFFFFF;
}
.navigator {
display: flex;
justify-content: space-around;
width: 85%;
margin: 0 auto;
padding: 20rpx;
}
.navigator-item {
display: flex;
align-items: center;
flex-direction: column;
width: 50rpx;
height: 100%;
}
.item-text {
margin-top: 12rpx;
color: #777E86;
font-size: 24rpx;
}
.text-active {
color: #2E92FD !important;
}
.icon {
width: 40rpx;
height: 40rpx;
}
</style> </style>
\ No newline at end of file
...@@ -14,32 +14,17 @@ import User from '@/request/user'; ...@@ -14,32 +14,17 @@ import User from '@/request/user';
// main.js // main.js
import initToast from "@/components/bocft-toast/initToast.js" import initToast from "@/components/bocft-toast/initToast.js"
import showToast from "@/components/bocft-toast/bocft-toast.vue" import showToast from "@/components/bocft-toast/bocft-toast.vue"
import taBar from "@/components/tabBar/tabBar.vue"
initToast(Vue); initToast(Vue);
Vue.component('show-toast',showToast); Vue.component('show-toast',showToast);
Vue.component('taBar',taBar);
Vue.use(uView); Vue.use(uView);
Vue.prototype.$utils = utils; Vue.prototype.$utils = utils;
Vue.prototype.setPrice = (price) => price && Number(price).toFixed(2); Vue.prototype.setPrice = (price) => price && Number(price).toFixed(2);
// #ifdef MP-WEIXIN
Vue.mixin({
methods:{
setTabBarIndex(index) {
if (typeof this.$mp.page.getTabBar === 'function' &&
this.$mp.page.getTabBar()) {
this.$mp.page.getTabBar().setData({
selected: index
})
}
}
}
})
// #endif
Vue.prototype.loginByPhoneNumber = (e) => { Vue.prototype.loginByPhoneNumber = (e) => {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
User.getPhoneNumber(e); User.getPhoneNumber(e);
......
...@@ -441,6 +441,7 @@ export default { ...@@ -441,6 +441,7 @@ export default {
height: 48rpx; height: 48rpx;
margin-right: 32rpx; margin-right: 32rpx;
line-height: 48rpx; line-height: 48rpx;
min-width: 120rpx;
.default { .default {
......
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
"backgroundColor": "#ffffff" "backgroundColor": "#ffffff"
}, },
"tabBar": { "tabBar": {
"custom": false, "custom": true,
"color": "#999999", "color": "#999999",
"selectedColor": "#003AE9", "selectedColor": "#003AE9",
"iconWidth": "30rpx", "iconWidth": "30rpx",
......
<template>
<view>
<Menu v-if="selectIndex===0"></Menu>
<Order v-else-if="selectIndex===1"></Order>
<Mine v-else-if="selectIndex===2"></Mine>
<taBar :select="selectIndex" @changeIndex="acceptIndex"></taBar>
</view>
</template>
<script>
import Menu from '../menu/menu.vue'
import Mine from '../mine/mine.vue'
import Order from '../order/order.vue'
export default {
components:{
Menu,
Mine,
Order
},
data(){
return {
selectIndex: 0
}
},
methods:{
acceptIndex(e){
console.log(e)
this.selectIndex = e
}
}
}
</script>
<style>
</style>
\ No newline at end of file
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
<view class="barCode-dis">点击二维码取单</view> <view class="barCode-dis">点击二维码取单</view>
</view> </view>
</view> </view>
<ShopCar ref="shopbar" />
<MenuAssembly ref="MenuAssembly" @getallNum="getallNum" :buied="buied"/> <MenuAssembly ref="MenuAssembly" @getallNum="getallNum" :buied="buied"/>
<u-picker @cancel="show = false" :show="show" :immediateChange="true" ref="uPicker" :columns="columns" <u-picker @cancel="show = false" :show="show" :immediateChange="true" ref="uPicker" :columns="columns"
@confirm="confirm" keyName="name" @change="changeHandler"></u-picker> @confirm="confirm" keyName="name" @change="changeHandler"></u-picker>
...@@ -53,6 +52,8 @@ ...@@ -53,6 +52,8 @@
<canvas class="canvas-code" canvas-id="myQrcode2" <canvas class="canvas-code" canvas-id="myQrcode2"
style="background:#fff;width: 200px;height: 200px; display:block; left:-800rpx;position:absolute;" /> style="background:#fff;width: 200px;height: 200px; display:block; left:-800rpx;position:absolute;" />
<show-toast ref="toast"/> <show-toast ref="toast"/>
<taBar select="0"></taBar>
<ShopCar ref="shopbar" />
</view> </view>
</template> </template>
<script> <script>
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
</view> </view>
</view> </view>
</view> </view>
<taBar select="2"></taBar>
</view> </view>
</template> </template>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<view class="empty_text">——您还未登录,请先登录——</view> <view class="empty_text">——您还未登录,请先登录——</view>
<button class="empty_button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">去品尝</button> <button class="empty_button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">去品尝</button>
</view> </view>
<view class="orders"> <view class="orders" :style="{'padding-bottom':orderBottom+'rpx'}">
<view class="order_item" v-for="item in list" :key="item.id" @click="openInfo(item)"> <view class="order_item" v-for="item in list" :key="item.id" @click="openInfo(item)">
<view class="order_header"> <view class="order_header">
<view> <view>
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
</view> </view>
</view> </view>
<show-toast ref="toast"/> <show-toast ref="toast"/>
<taBar select="1"></taBar>
</view> </view>
</template> </template>
...@@ -89,12 +90,17 @@ export default { ...@@ -89,12 +90,17 @@ export default {
empty: false, empty: false,
list: [], list: [],
loginInfo:"", loginInfo:"",
Utils Utils,
orderBottom:0
} }
}, },
onShow() { onShow() {
this.getList() // this.getList()
}, },
mounted() {
this.orderBottom = uni.getStorageSync('orderBottom')
this.getList()
},
computed: { computed: {
userms() { userms() {
return this.$store.getters.Authorization; return this.$store.getters.Authorization;
......
...@@ -21,6 +21,7 @@ export default { ...@@ -21,6 +21,7 @@ export default {
callback && callback(1, params); callback && callback(1, params);
}, },
fail: function (res) { fail: function (res) {
console.log(res)
const params = uni.getStorageSync('location'); const params = uni.getStorageSync('location');
callback && callback(0, params); callback && callback(0, params);
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment