<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="num" :value="obj.name" name="name" class="input-box"
								placeholder="请输入充值名称" placeholder-class="desc-placeholder">
						</view>
					</view>

					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>支付金额</text>
						</view>
						<view class="desc">
							<input type="num" :value="obj.pay_price" name="pay_price" class="input-box"
								placeholder="用户支付多少就充值多少" placeholder-class="desc-placeholder">		
						</view>
					</view>

					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>赠送金额</text>
						</view>
						<view class="desc">
							<input type="num" :value="obj.send_price" name="send_price" class="input-box"
								placeholder="用户充值时，赠送的金额，默认为0" placeholder-class="desc-placeholder">
						</view>
					</view>


					<view class="cell flex flex-y-center">
						<view class="title-block requsired">
							<text>排序</text>
						</view>
						<view class="desc">
							<input type="num" :value="obj.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;">
					<button class="btn" hover-class="none" form-type="submit">
						{{obj.id?'修改':'添加'}}
					</button>
				</view>
			</view>

		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				is_integral:0,
				device_type: 1,
				tableType: "",
				store_id: "",
				info: {},
				obj:{},
			}
		},

		onLoad(e) {
			if (e.id) {
				this.info = e;
				this.http();
				uni.setNavigationBarTitle({
					title:"修改充值方案"
				})
			}
		
			
			this.admin_id = uni.getStorageSync("admin_id");
		},
		methods: {
			
			http(){
				this.request({
					url:"Smdcshop/recharge_info",
					data: {
						id:this.info.id,
					}
				}).then(res => {
					if (res.code == 200) {
						this.obj=res.data;
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},
			
			onSubmit(e) {
				let params = e.detail.value,
					url;
					params.admin_id=this.admin_id;
				if (this.info.id) {
					params.id = this.info.id
					url = "Smdcshop/recharge_update"
				} else {
					url = 'Smdcshop/recharge_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>
