<template>
	<view>
		<kevyloading v-if="loading" type="bsm-loader" color="#618af8" transparent></kevyloading>
		<wd-form ref="formEl" :model="dataForm" label-width="100px" class="demo-dataForm" :size="formSize" status-icon>
			<div class="form">
				<wd-form-item :prop="dataForm.pic_url" label="背景图像">
					<yUpload v-model="dataForm.pic_url" :size="1"></yUpload>
				</wd-form-item>
				<wd-form-item :prop="dataForm.rule" label="签到规则">
					<wd-input placeholder="请输入" v-model.number="dataForm.rule"></wd-input>

					<div style="color: #666;font-size: 12px;">
						注：多条内容请使用中文逗号隔开
					</div>
				</wd-form-item>
				<wd-form-item :prop="dataForm.integra" label="每日签到获得分数">
					<wd-input placeholder="请输入" v-model.number="dataForm.integra"></wd-input>
				</wd-form-item>
				<wd-form-item :prop="dataForm.continuatio" label="连续签到天数">
					<wd-input placeholder="请输入" v-model.number="dataForm.continuatio"></wd-input>

					<div style="color: #666;font-size: 12px;">
						注：只要满足连续签到天数，中间没有断签，就一直赠送奖励积分；
					</div>
				</wd-form-item>
				<wd-form-item :prop="dataForm.reward" label="连续签到奖励积分">
					<wd-input placeholder="请输入" v-model.number="dataForm.reward"></wd-input>
				</wd-form-item>

				<wd-form-item :prop="dataForm.balance_exchange" label="开启积分兑换余额：">
					<wd-switch :active-value="1" :inactive-value="0" v-model="dataForm.balance_exchange" />

					<div style="color: #666;font-size: 12px;">
						已废弃
					</div>

				</wd-form-item>
			</div>

			<!-- 提交按钮 -->
			<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 yUpload from "@/components/yUpload/index.vue";
import uniDataPicker from "@/components/uni-data-picker/components/uni-data-picker/uni-data-picker.vue";
import kevyloading from "@/components/kevy-loading/kevy-loading";
import utils from '@/utils/utils.js'
import pointsGoodsApi from '@/api/store/pointsGoods.js';

export default {
	components: {
		yUpload, uniDataPicker, kevyloading
	},
	data() {
		return {
			utils,
			// 表单数据
			dataForm: {
				pic_url: '',
				show_member: 0,
				show_sign: 0,
				show_task: 0,
				show_integral: 0,
			},
			loading: false
		};
	},
	onLoad(e) {
		this.getStoreSetting()
	},
	methods: {
		async getStoreSetting() {
			this.loading = true;
			const res = await pointsGoodsApi.PointsList();

			if (res.data) {
				this.dataForm = res.data
			}
			this.loading = false;
		},

		/**
		 * 处理表单提交
		 */
		async handleSubmit() {
			// 处理表单提交的逻辑
			const res = await pointsGoodsApi.PointsSave({
				...this.dataForm
			});

			if (res.code == 0) {
				setTimeout(() => {
					uni.showToast({
						title: '保存成功!',
						icon: 'success'
					});
				}, 100);
			}
			this.getStoreSetting()
		},
	},
};

</script>

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