<template>
	<view class='content'>
		<view class='wrap'>
			<view>
				{{currectData.shopNames}}
				<image src="@/static/image/yjt.png" mode="" style="margin-left:10rpx;width:12rpx;height: 21rpx;"></image>
			</view>
			<view class='title'>营业管理</view>
			<u-cell-group>
				<u-cell title="营业时间" :isLink="true" arrow-direction="right">
					<view @click='selectTime' slot="title" class="u-slot-title flex justify-space-between">
						<view>营业时间</view>
						{{currectData.startDate}}~{{currectData.endDate}}
					</view>
				</u-cell>
				<u-cell  title="店铺上架" :isLink="true" arrow-direction="right">
					<!-- <u-badge count="99" :absolute="false" slot="right-icon"></u-badge> -->
					<view slot="title" class="u-slot-title flex justify-space-between align-item-center">
						<view class="">
							店铺上架
						</view>
						<view class='flex  align-item-center'>
							<view style='margin-right:10rpx;'>{{currectData.status}}</view>
							<u-switch @change="change" slot="right-icon" v-model="checked"></u-switch>	
						</view>
					</view>
				</u-cell>
				<u-cell title="删除店铺" :isLink="true" arrow-direction="right">
					<view @click='del' slot="title" class="u-slot-title">
						<view class="">
							删除店铺
						</view>
					</view>	
				</u-cell>
			</u-cell-group>
			<view class='title'>店铺信息</view>
			<u-cell-group>
				<u-cell title="店铺信息" :isLink="true" arrow-direction="right">
					<view  @click='toDetail("/pageA/enter/myCateringdustry/shopSetting/editShopInformation")' slot="title" class="u-slot-title">
						<view class="">
							店铺信息
						</view>
					</view>	
				</u-cell>
				<u-cell title="店铺图片" :isLink="true" arrow-direction="right">
					<view @click='toDetail("/pageA/enter/myCateringdustry/shopSetting/editShopImage")' slot="title" class="u-slot-title">
						<view class="">
							店铺图片
						</view>
					</view>	
				</u-cell>
				<u-cell title="证照图片" :isLink="true" arrow-direction="right">
					<view @click='toDetail("/pageA/enter/myCateringdustry/shopSetting/editCertificate")' slot="title" class="u-slot-title">
						<view class="">
							证照图片
						</view>
					</view>	
				</u-cell>
				
				<u-cell @click='toDetail("/pageA/enter/myCateringdustry/shopSetting/editFoodClassify")' title="菜品分类" :isLink="true" arrow-direction="right">
					<view slot="title" class="u-slot-title">
						<view class="">
							菜品分类
						</view>
					</view>	
				</u-cell>
				<u-cell  title="允许用户查看菜品价格" :isLink="true" arrow-direction="right">
					<view slot="title" class="u-slot-title flex justify-space-between">
						<view class="">
							允许用户查看菜品价格
						</view>
						<u-switch @change='change1' slot="right-icon" v-model="checked1"></u-switch>
					</view>	
				</u-cell>
				
			</u-cell-group>
		</view>
		<view style='margin:10px;' class='flex justify-space-between align-item-center'>
			<view @click='toDetail("/pageA/enter/myCateringdustry/shopSetting/foodInfomation")' class='mercharts_button'>菜品信息</view>
			<!-- <view @click='toDetail("/pageA/enter/myCateringdustry/shopSetting/editFoodClassify")' class='mercharts_button'>团购信息</view> -->
		</view>
		<smh-time-range :is-under='show' :time="time" @confrim="confrim" @cancel="cancel"></smh-time-range>
		<u-modal :show="isSubmit" :content='content' @confirm="$u.debounce(confirmSubmit, 500)" showCancelButton
			@cancel="isSubmit=false" @close="isSubmit=false" closeOnClickOverlay></u-modal>
			<u-modal :show="isDel" content='确定删除店铺？' @confirm="$u.debounce(confirmDelSubmit, 500)" showCancelButton
				@cancel="isDel=false" @close="isDel=false" closeOnClickOverlay></u-modal>
		<u-modal :show="isStatus" :content='content' @confirm="$u.debounce(confirmStatusSubmit, 500)" showCancelButton
			@cancel="isStatus=false" @close="isStatus=false" closeOnClickOverlay></u-modal>
	</view>
</template>

<script>
	var that
	export default {
		data() {
			return {
				content:'确定下架店铺？',
				isSubmit:false,
				isStatus:false,
				isDel:false,
				checked:true,
				checked1:true,
				show:false,
				time:[],
				currectStatus:1,
				currectData:{
					
				},
				hoursList:[
					'00:00',
					'00:30',
					'01:00',
					'01:30',
					'02:00',
					'02:30',
					'03:00',
					'03:30',
					'04:00',
					'04:30',
					'05:00',
					'05:30',
					'06:00',
					'06:30',
					'07:00',
					'07:30',
					'08:00',
					'08:30',
					'09:00',
					'09:30',
					'10:00',
					'10:00',
					'11:00',
					'11:30',
					'12:00',
					'12:30',
					'13:00',
					'13:30',
					'14:00',
					'14:30',
					'15:00',
					'15:30',
					'16:00',
					'16:30',
					'17:00',
					'17:30',
					'18:00',
					'18:30',
					'19:00',
					'19:30',
					'20:00',
					'20:30',
					'21:00',
					'21:30',
					'22:00',
					'22:30',
					'23:00',
					'23:30',
					'24:00'],
			}
		},
		onLoad() {
			that = this
		},
		onShow(){
			if(uni.getStorageSync('myCateringdustry')){
				this.currectData=JSON.parse(uni.getStorageSync('myCateringdustry'))
				var start = 0,end = 0
				for(var i=0;i<this.hoursList.length;i++){
					if(this.currectData.startDate==this.hoursList[i]){
						start = i
					}
					if(this.currectData.endDate==this.hoursList[i]){
						end = i
					}
				}
				if(this.currectData.status=='显示中'){
					this.checked=true
				}else if(this.currectData.status=='已隐藏'){
					this.checked=false
				}
				if(this.currectData.lookFlag==0){
					this.checked1 =true
				}else{
					this.checked1 =false
				}
				this.time=[start,'0',end]
				console.log(this.time)
			}
		},
		methods: {
			change1(e){
				console.log(1111111)
				this.currectStatus = 2
				if(!this.checked1){
					this.content='确定禁止用户查看菜品价格？'
					this.isStatus = true
				}else{
					this.confirmStatusSubmit()
				}
			},
			toDetail(url){
				uni.navigateTo({
					url:url
				})
			},
			del(){
				this.isDel = true
			},
			change(e){
				this.currectStatus = 1
				console.log(e,this.checked)
				if(!this.checked){
					this.content='确定下架店铺？'
					this.isStatus = true
				}else{
					this.confirmStatusSubmit()
				}
			},
			confirmDelSubmit(){
				this.$request.baseRequest('admin.tourism.foodInfo', 'delete', {
					id: this.currectData.id
				}, failres => {
					uni.showToast({
						icon: "none",
						title: failres.errmsg,
						duration: 3000
					});
							
					uni.hideLoading()
				}).then(res => {
					uni.showToast({
						icon: "success",
						title: '删除成功',
						duration: 2000
					});
					this.isStatus = false
					uni.navigateBack()
				})
			},
			confirmStatusSubmit(){
				if(this.currectStatus==1){
					if(!this.checked){
						this.currectData.status='已隐藏'
					}else{
						this.currectData.status='显示中'
					}
				}else{
					if(!this.checked1){
						this.currectData.lookFlag=1
					}else{
						this.currectData.lookFlag=0
					}
				}
				this.$request.baseRequest('admin.tourism.foodInfo', 'update', {
					foodInfo: JSON.stringify(this.currectData)
				}, failres => {
					uni.showToast({
						icon: "none",
						title: failres.errmsg,
						duration: 3000
					});
							
					uni.hideLoading()
				}).then(res => {
					uni.showToast({
						icon: "success",
						title: this.currectStatus==1?this.checked?'店铺已上架':'店铺已下架':this.checked1?'开启成功':'关闭成功',
						duration: 2000
					});
					uni.setStorageSync('myCateringdustry',JSON.stringify(this.currectData))
					this.isStatus = false
				})
			},
			selectTime(){
				this.show = true
			},
			confrim(e){
				this.currectData.startDate=e.start
				this.currectData.endDate=e.end
				this.$request.baseRequest('admin.tourism.foodInfo', 'update', {
					foodInfo: JSON.stringify(this.currectData)
				}, failres => {
					uni.showToast({
						icon: "none",
						title: failres.errmsg,
						duration: 3000
					});
							
					uni.hideLoading()
				}).then(res => {
					uni.showToast({
						icon: "success",
						title: '修改营业时间成功',
						duration: 2000
					});
					this.show = false
					uni.setStorageSync('myCateringdustry',JSON.stringify(this.currectData))

				})
			},
			cancel(){
				this.show = false
			}
		}
	}
</script>

<style lang='scss' scoped>
.title{
	padding:20rpx;
	font-weight:600;
}
</style>
