星油闪充小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.1 KiB

2 years ago
<template>
<view :style="{paddingTop:`${setingMenuData.top}px`}" class="page_body">
<view class="page_container">
<home ref="home" v-show="tabBarIndex==0"></home>
<charging-station ref='ChargingStation' v-show="tabBarIndex==1"></charging-station>
<order ref="order" v-if="tabBarIndex==3"></order>
<personal @switchTabBar='switchTabBar' v-if="tabBarIndex==4"></personal>
</view>
<tab-bar v-model="tabBarIndex"></tab-bar>
</view>
</template>
<script>
import tool from '../../utils/tool.js'
import tabBar from "@/components/tabBar/tabBar.vue"
import home from "../home/index.vue"
import ChargingStation from "../ChargingStation/index.vue"
import order from "../order/index.vue"
import personal from "../personal/index.vue"
2 years ago
import x from "./index.js"
2 years ago
export default {
components: {
tabBar,
home,
ChargingStation,
order,
personal
},
data() {
return {
user: uni.getStorageSync('user'),
location: null,
setingMenuData: null,
tabBarIndex: 0,
Anticorrosive: null
}
},
watch: {
2 years ago
tabBarIndex(n, o) {
2 years ago
let that = this
2 years ago
if (n == 1) {
2 years ago
this.$refs.ChargingStation.onshow()
2 years ago
} else if (n == 2) {
2 years ago
this.readyScanCode({
2 years ago
success() {
2 years ago
that.scanCode();
},
2 years ago
fail() {
if (n !== o) that.tabBarIndex = o;
if (n == o) that.tabBarIndex = 0;
2 years ago
}
})
2 years ago
}
2 years ago
}
},
created() {
this.init()
},
onLoad() {
2 years ago
this.onOrderUpdate();
2 years ago
},
2 years ago
onShow() {
2 years ago
this.showInit()
},
methods: {
2 years ago
readyScanCode({
success,
fail
}) {
if (!this.user) {
2 years ago
uni.showModal({
title: '提示',
content: '登录后才可扫码下单哦',
2 years ago
confirmText: '去登陆',
success: function(res) {
if (res.confirm) {
2 years ago
uni.reLaunch({
url: '/pages/login/index'
})
2 years ago
} else if (res.cancel) {
2 years ago
fail()
}
}
2 years ago
});
2 years ago
return
}
2 years ago
try {
2 years ago
success()
2 years ago
} catch (e) {
fail()
2 years ago
}
},
async scanCode() {
2 years ago
let res = await this.tool.scanCode().catch(err => {
// console.log('取消');
this.tabBarIndex = 0
2 years ago
});
2 years ago
if (res?.result) {
let routingParameter = this.tool.routingParameterGeneration({
type: 'qrCode',
qrCode: encodeURIComponent(res.result),
pointTo: 'activeScanCode'
2 years ago
})
uni.navigateTo({
url: `/ChargingStation/pages/placeOrder/index${routingParameter}`
})
}
},
switchTabBar(e) {
this.tabBarIndex = e
},
onOrderUpdate() {
uni.$on('orderUpdate', () => {
this.$refs.order.seach()
})
},
showInit() {
2 years ago
this.tool.getCards();
if (this.tabBarIndex == 2) {
2 years ago
this.tabBarIndex = 0
}
},
async getPosition(callback) {
await this.tool.getLocation().then(res => {
this.location = uni.getStorageSync('location')
}).catch(err => {});
},
async init() {
this.Anticorrosive = this.tool.Anticorrosive;
this.getSetingMenu(); //获取胶囊数据
},
getSetingMenu() {
this.setingMenuData = wx.getMenuButtonBoundingClientRect();
}
}
}
</script>
<style lang="scss" scoped>
@import 'index.scss';
</style>