<template>
	<view class="container">
		<form @submit="onSubmit">
			<view class="page-block">
				<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 arr-r">
						<view class="title-block">
							<text>来源</text>
						</view>
						
						<view class="desc">
							<picker mode="selector" :range="TypeList" @change="onTableTypeChange">
								<view>
									{{TypeList[TypeActive]}}
								</view>
							</picker>
						</view>
					</view>

					<view class="cell flex flex-y-center">
						<view class="title-block">
							<text>简介</text>
						</view>
						<view class="desc">
							<input type="text" :value="info.desc" name="desc" class="input-box" placeholder="请输入"
								placeholder-class="desc-placeholder">
						</view>
					</view>
					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>appid</text>
						</view>
						<view class="desc">
							<input type="text" :value="info.appid" name="appid" 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.pages" name="pages" class="input-box" placeholder="请输入"
								placeholder-class="desc-placeholder">
						</view>
					</view>
				</view>
			</view>
			
			<view style="height: 150rpx;"></view>
			
			<view class="footer-bar">
				<view class="content flex flex-center" style="background: none;">
					<button hover-class="none" class="btn" form-type="submit">
						{{id?'保存':'立即添加'}}
					</button>
				</view>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			
			return {
				admin_id: "",
				id: "",
				TypeList: [
					"微信",
					"支付宝",
				],
				
				TypeActive: 0,
				
				table_type_id: "",
				info:{},
			}
		},
		
		
		onLoad(options) {
			this.admin_id = uni.getStorageSync('admin_id')
			if (options.id) {
				this.id = options.id;
				this.applet_info()
			} 
			
			
		},
		methods: {
			
			onTableTypeChange(e) {
				this.TypeActive = e.detail.value
			},
			
			//获取桌台分类
			applet_info() {
				this.request({
					url: 'Smdcshop/applet_info',
					data: {
						id: this.id
					}
				}).then(res => {
					if (res.code == '200' || res.code == 200) {
						this.info = res.data
						
						this.TypeActive = Number(res.data.type-1);
						
					}
				})
			},

			onSubmit(e) {
				let detail=e.detail.value;
				if (!detail.name) {
					uni.showToast({
						title: "请输入名称",
						icon: 'none'
					})
					return false
				}
				if (!detail.appid) {
					uni.showToast({
						title: "请输入appid",
						icon: 'none'
					})
					return false
				}
				detail.admin_id = this.admin_id;
				detail.type= Number(this.TypeActive)+1;
				if (this.id) {
					detail.id = this.id;
				}
				this.request({
					url: this.id?'Smdcshop/applet_update':'Smdcshop/applet_add',
					data: detail
				}).then(res => {
					if (res.code == 200) {
						uni.showModal({
							content: this.table_id ? '编辑成功' : '添加成功',
							showCancel: false,
							success: (r) => {
								uni.navigateBack();
							}
						})
					}
				})
			},
		}
	}
</script>

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

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