<template>
	<view class="container">
		<form @submit="onSubmit">
			<view class="page-block">
				<view class="page-title-block">
					<view class="title">类型信息</view>
				</view>
				<view class="content">
					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>类型名称</text>
						</view>
						<view class="desc">
							<input type="text" :value="info.name" name="name" class="input-box" placeholder="请输入类型名称"
								placeholder-class="desc-placeholder">
						</view>
					</view>
					
					
					<view class="cell flex flex-y-center">
						<view class="title-block ">
							<text>分类标识</text>
						</view>
						<view class="desc">
							<input type="text" :value="info.mark" name="mark" class="input-box" placeholder="请输入分类标识"
								placeholder-class="desc-placeholder">
						</view>
					</view>
					
					
					<view class="cell flex flex-y-center">
						<view class="title-block ">
							<text>使用人数备注</text>
						</view>
						<view class="desc">
							<input type="text" :value="info.content" name="content" class="input-box" placeholder="请输入使用人数备注"
								placeholder-class="desc-placeholder">
						</view>
					</view>

					<view class="cell flex flex-y-center">
						<view class="title-block ">
							<text>排序</text>
						</view>
						<view class="desc">
							<input type="number" name="num" :value="info.num" class="input-box" placeholder="请输入排序"
								placeholder-class="desc-placeholder">
						</view>
					</view>
				</view>
			</view>

			<view class="footer-bar">
				<view class="content flex flex-center" style="background: none;">
					<!-- <view class="btn">立即添加</view> -->
					<button class="btn" hover-class="none" form-type="submit">
						{{info.id?'修改类型':'立即添加'}}
					</button>
				</view>
			</view>
		</form>



	</view>
</template>

<script>
	export default {
		data() {
			return {
				tableTypeList: ['大桌', '中桌', '小桌'],
				tableType: "",
				store_id:"",
				info:{},
			}
		},
		onLoad(e) {
			if(e.id){
				// this.info=e;
				this.getData(e.id)
			}
			this.store_id=uni.getStorageSync("store_id");
	
		},
		methods: {
			getData(id) {
				this.request({
					url: 'Smdcshop/table_type_update_info',
					data: {
						id: id
					}
				}).then(res => {
					if (res.code == "200") {
						this.info = res.data
					} else {
						this.is_bottom = true
					}
				})
			},
			
			onSubmit(e) {
			
				let params = {
					admin_id:uni.getStorageSync("admin_id"),
					store_id: this.store_id,
					name: e.detail.value.name,
					num: e.detail.value.num,
					source:0,
					mark:e.detail.value.mark,
					content:e.detail.value.content,
				},url;

				if(this.info.id){
				  	params.id=this.info.id
					url="Smdcshop/table_type_update"
				}else{
					url='Smdcshop/table_type_add'
				}
				if (params.name == "") {
					uni.showToast({
						title: "请输入名称",
						icon: 'none'
					})
					return false
				}
				this.request({
					url,
					data: params
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						setTimeout(()=>{
							  uni.navigateBack()
							},2000)
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},


		}
	}
</script>

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

	page {
		background-color: #F4F5F7;
	}
</style>
