<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>
			<wd-timeline>
				<wd-timeline-item timestamp="基本设置" placement="top">
					<div class="form">
						<wd-form-item :prop="dataForm.image" label="背景图像">
							<yUpload v-model="dataForm.image" :size="1"></yUpload>
						</wd-form-item>
						<wd-form-item :prop="dataForm.show_member" label="显示等级">
							<wd-switch active-value="1" inactive-value="0" v-model="dataForm.show_member" />
						</wd-form-item>
						<wd-form-item :prop="dataForm.show_task" label="显示折扣">
							<wd-switch active-value="1" inactive-value="0" v-model="dataForm.show_task" />
						</wd-form-item>
						<wd-form-item prop="dataForm.show_sign" label="显示签到">
							<wd-switch active-value="1" inactive-value="0" v-model="dataForm.show_sign" />
						</wd-form-item>
						<wd-form-item :prop="dataForm.show_integral" label="显示积分">
							<wd-switch active-value="1" inactive-value="0" v-model="dataForm.show_integral" />
						</wd-form-item>
					</div>
				</wd-timeline-item>

				<wd-timeline-item timestamp="成长值设置" placement="top">
					<div class="form">
						<wd-form-item :prop="dataForm.order_growth" label="下单成长值：">
							<wd-input placeholder="请输入下单成长值" v-model.number="dataForm.order_growth"></wd-input>
						</wd-form-item>

						<wd-form-item :prop="dataForm.sign_growth" label="签到成长值：">
							<wd-input placeholder="请输入签到成长值" v-model.number="dataForm.sign_growth"></wd-input>
						</wd-form-item>

						<wd-form-item :prop="dataForm.reg_growth" label="下级注册成长值：">
							<wd-input placeholder="请输入下级注册成长值" v-model.number="dataForm.reg_growth"></wd-input>
						</wd-form-item>
					</div>
				</wd-timeline-item>
			</wd-timeline>

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

/**
 * 从本地存储中获取用户信息
 */
const user_info = uni.getStorageSync("user_info");

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

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

		/**
		 * 处理省市区选择变化
		 * @param {Object} value - 选择的值
		 */
		areaChange(value) {
			// 处理省市区选择变化的逻辑
		},

		/**
		 * 处理省市区选择
		 * @param {Object} detail - 选择器详细信息
		 */
		select({ detail }) {
			if (detail.value.length) {
				const [province_id, city_id, district_id] = detail.value.map(
					(el) => el.value
				);

				this.dataForm.province_id = province_id;
				this.dataForm.city_id = city_id;
				this.dataForm.district_id = district_id;
				this.dataForm.district = [province_id, city_id, district_id];
			}
		},

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

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

</script>

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