<template>
	<view>
		<kevyloading v-if="loading" type="bsm-loader" color="#618af8" transparent></kevyloading>

		<wd-form ref="form" :model="formData" :rules="formRules">

			<!-- 基础信息 -->
			<wd-cell-group title="充值方案" border>
				<wd-input label="充值名称" v-model="formData.name" />
				<wd-cell-group title="支付金额" border>
					<view class="p-4">
						<wd-input-number v-model="formData.money" min="0" />
					</view>
				</wd-cell-group>

				<wd-cell-group title="赠送金额" border>
					<view class="p-4">
						<wd-input-number v-model="formData.gift_money" min="0" />
					</view>
				</wd-cell-group>
			</wd-cell-group>


			<!-- 提交按钮 -->
			<view class="mt-2 px-12 py-3 bg-slate-50">
				<wd-button type="primary" size="large" @click="handleSubmit" block>
					保存
				</wd-button>
			</view>
		</wd-form>


	</view>
</template>

<script>
import kevyloading from "@/components/kevy-loading/kevy-loading";
import utils from '@/utils/utils.js'
import rechargeApi from '@/api/store/recharge.js'

export default {
	components: {
		kevyloading
	},
	data() {
		return {
			utils,
			// 表单数据
			formData: {
				"name": "",  // 
				"money": "",  // 
				"gift_money": "",  // 
			},
			// 表单验证规则
			formRules: {
				// 在这里添加其他字段的验证规则
			},
			// 地区选择器的数据
			addrList: [
				// 在这里添加省市区的数据
			],
			classifyList: [],
			loading: false
		};
	},
	async onLoad(e) {
		// this.getDistrict();

		if (e.edit) {
			this.formData = JSON.parse(e.edit)
		}

		// this.formData = JSON.parse(e.edit)
	},
	methods: {
		/**
		 * 处理表单提交
		 */
		async handleSubmit() {
			console.log(this.formData);

			try {
				// 处理表单提交的逻辑
				const res = await rechargeApi.save({
					...this.formData,
				});

				if (res.code == 0) {
					setTimeout(() => {
						uni.showToast({
							title: '保存成功!',
							icon: 'success'
						});
					}, 100);
					uni.navigateBack()
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
				}
			} catch (error) {
				console.log(error);
				setTimeout(() => {
					uni.showToast({
						title: '请检查表单!',
						icon: 'none'
					});
				}, 100);
			}


		},
	},
};

</script>

<style>
/* 在这里添加样式，根据需要自定义表单样式 */
</style>
