<template>
	<view class="container">
		<view class="page-block">
			<view class="page-title-block">
				<view class="title">修改信息</view>
			</view>
			
			
			<view class="content">
				
				<view class="cell flex flex-y-center arr-r" v-if="type==1">
					<view class="title-block required">
						<text>所属门店</text>
					</view>
					<view class="desc">
						<picker mode="selector" :range="tableTypeList" range-key="title"
							@change="onTableTypeChange">
							<view>
								{{tableTypeActive}}
							</view>
						</picker>
					</view>
				</view>
				
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>打印方式</text>
					</view>
					
					<view class="desc" @click="onPrinterStatusChange">
						<view class="input-box">{{printerStatus}}</view>
					</view>
					
				</view>
				<view class="cell flex flex-y-center">
					<view class="title-block">
						<text>打印时间</text>
					</view>
					<view class="desc">
						<view class="input-box">下单打印</view>
					</view>
				</view>
			</view>
		</view>
		
		<view class="ft26 red">
			*该设置对后厨打印机有效
		</view>
		
		<view style="height:30rpx;"></view>
		<view class="footer-bar">
			<view class="content flex flex-center" style="background: none;">
				<!-- <view class="btn">立即添加</view> -->
				<button class="btn" hover-class="none" @click="enit">
				 立即提交
				</button>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {},
				printerStatus:"整单打印",
				print_type:1,
				type:2,
				store_id:"",tableTypeList:[],
				tableTypeActive:'请选择',
			}
		},
		onLoad(e) {
			this.type=e.type||2;
			if (e.type == 1) {
				this.shop_store_index()
			} else {
				this.store_id = uni.getStorageSync("store_id");
				this.storesetinfo();
			}
			this.info = e;
		},
		methods: {
			
			shop_store_index() {
				this.request({
					url: 'Smdcshop/shop_store_index',
					data: {
						admin_id: uni.getStorageSync("admin_id"),
					}
				}).then(res => {
					if (res.code == 200) {
						this.tableTypeList = res.data;
					}
				})
			},
			

			onTableTypeChange(e) {
				this.tableTypeActive = this.tableTypeList[e.detail.value].title;
				this.store_id = this.tableTypeList[e.detail.value].id;
				this.storesetinfo();
			},
			
			storesetinfo(){
				this.request({
					url: 'Smdcshop/storesetinfo',
					data: {
						store_id: this.store_id,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === 200 || res.code === "200") {
				        this.printerStatus = res.data.print_type==1?"整单打印":"分单打印"
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: "none",
					})
				});
			},
			
			enit(e) {
				if(!this.store_id){
					uni.showToast({
						title: '请选择门店',
						icon: "none",
					})
					return
				}
				
	            this.request({
	            	url: 'Smdcshop/storeset',
	            	data: {
						store_id: this.store_id,
	            		print_type: this.print_type,
						print_mode:1
	            	},
	            }).then(res => {
	            	console.log(res, "res")
	            	if (res.code === 200 || res.code === "200") {
	            		uni.showToast({
	            			title: res.message,
	            			icon: "none",
	            		})
	            		setTimeout(() => {
	            			uni.navigateBack()
	            		}, 2000)
	            	}
	            }).catch((res) => {
	            	uni.showToast({
	            		title: res.message,
	            		icon: "none",
	            	})
	            });
			},
			
			onPrinterStatusChange() {
				let statusArr = ['整单打印', '分单打印']
				uni.showActionSheet({
					itemList: statusArr,
					success: (r) => { 
						console.log(r.tapIndex)
						this.print_type = Number(r.tapIndex) + 1
						this.printerStatus = statusArr[r.tapIndex]
					}
				})
			},
		
		}
	}
</script>

<style>
	@import url("../static/css/common.css");
	page {
		background-color: #F4F5F7;
	}
	.red{
		padding: 20rpx;
		color: red;
	}
</style>
