<template>
	<view class="page">
		<view class="swiper-container">
			<view class="swiper-page" v-show="currentIndex == 0">
				<view @click="updateStatus" style="margin-top: 500rpx;">
					营业状态：<text>{{businessStatus == '1'?'暂停营业':'正常营业'}}</text>
				</view>
				<view @click="nishuode">商品该分类</view>
			</view>
			<view class="swiper-page" v-show="currentIndex == 1">
				<de-livery ref="deLivery"></de-livery>
			</view>
			<view class="swiper-page" v-show="currentIndex == 2">
				<my-center ref="myCenter"></my-center>
			</view>
		</view>
		<tab-bar :width="width" @tab-index="changeIndex" :currentIndex="currentIndex"></tab-bar>
	</view>
</template>

<script>
	import tabBar from "@/components/tab-bar/tab-bar.vue";
	import deLivery from "@/components/tab-bar/delivery.vue";
	import myCenter from "@/components/tab-bar/myCenter.vue";
	export default {
		data() {
			return {
				width: 0,
				currentIndex: 0,
				businessStatus:1,
			}
		},
		components: {
			tabBar,
			deLivery,
			myCenter
		},
		onShow() {
			let that = this
			uni.getSystemInfo({
				success: function(info) {
					that.width = info.screenWidth * 2;
				}
			});
		},
		onLoad() {

		},
		methods: {
			nishuode(){
				
				uni.navigateTo({
					url: '/pages/goods/goodsList'
				})
			},
			//获取营业状态
			getBusinessStatus(){
				this.NB.sendRequest('/app/shoptakeaway/getByShopId', {
					shopId: uni.getStorageSync('shopId')
				}, false, 'get', 'application/x-www-form-urlencoded').then(res => {
					if (res.code == 200) {
						this.businessStatus = res.result.status
						
					} else {
						uni.showToast(res.message)
					}
				})
			},
			//更改营业状态
			updateStatus(){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '要更改营业状态吗？',
					success: function (res1) {
						if (res1.confirm) {
							that.NB.sendRequest('/app/shoptakeaway/update', {
								shopId:uni.getStorageSync('shopId'),
								status:that.businessStatus == "1"?'0':that.businessStatus == "0"?'1':'2'
							}, false, 'post', 'application/x-www-form-urlencoded').then(res => {
								if (res.code == 200) {
									uni.showToast("更改成功")
									that.businessStatus = that.businessStatus == "1"?'0':that.businessStatus == "0"?'1':'2'
								} else {
									uni.showToast(res.message)
								}
							})
						}
					}
				});
				
			},
			//底部tab切换组件状态改变
			changeIndex(index) {
				let that = this;
				this.lastIndex = this.currentIndex
				this.currentIndex = index
				switch (index) {
					case 1:
						that.$refs.deLivery.init()
						break;
					case 2:
						that.$refs.myCenter.init()
						break;
				}

			}
		}
	}
</script>

<style>
	@import url("./index.css");
</style>