<template>
	<div class="padding-lr">
		<div class="solid-bottom padding-tb margin-bottom text-bold">基本配置</div>
		<el-form ref="gpsRef" :model="form" :rules="rules" label-width="120px">
			<div v-loading="loading">
				<el-form-item label="串口" prop="comValue">
					<el-select v-model="form.comValue" placeholder="选择串口">
						<el-option label="485" :value="0" />
						<el-option label="232" :value="1" />
					</el-select>
				</el-form-item>
				<el-form-item label="语音编号" prop="song">
					<el-input style="width: 214px;" v-model="form.song" type="number" min="0" placeholder="请输入音量大小"/>
					<el-button type="success" class="margin-left-sm" @click="setPlay">下发测试</el-button>
				</el-form-item>
				<el-form-item label="音量大小" prop="volume">
					<el-input style="width: 214px;" v-model="form.volume" type="number" min="1" max="30" placeholder="请输入音量大小"/>
					<el-button type="primary" class="margin-left-sm" @click="setWare">保存配置</el-button>
				</el-form-item>
			</div>
		</el-form>
	</div>
</template>

<script setup>
	import { setAlarmWare, setAlarmPlay } from "@/api/settConfiguration";
	const { proxy } = getCurrentInstance();
	const loading = ref(false);
	const data = reactive({
		form: {
			"volume" : 6,
			"comValue": 0,
			"song" : 0
		},
		rules: {
			comValue: [{
				required: true,
				message: "请选择串口",
				trigger: "blur",
			}],
			song: [{
				required: true,
				message: "请填写语音编号",
				trigger: "blur",
			}],
			volume: [{
				required: true,
				message: "请填写音量大小",
				trigger: "blur",
			}]
		}
	})
	const { form, rules } = toRefs(data);
	
	const setPlay = () => {
		if((form.value.song+"").length){
			loading.value = true;
			let _query = {
				"com": (form.value.comValue == 0?"/dev/ttyS2":"/dev/ttyS1"),
				"song": form.value.song
			};
			setAlarmPlay(_query).then((response) => {
				console.log(response)
				proxy.$modal.msgSuccess("下发成功");
				loading.value = false;
			});
		}
	}
	const setWare = () => {
		if((form.value.volume+"").length){
			loading.value = true;
			let _query = {
				"com": (form.value.comValue == 0?"/dev/ttyS2":"/dev/ttyS1"),
				"volume": form.value.volume
			};
			setAlarmWare(_query).then((response) => {
				console.log(response)
				proxy.$modal.msgSuccess("设置成功");
				loading.value = false;
			});
		}
	}
</script>

<style>
</style>