<template>
	<lay-form :model="editDataInfo" style="max-width:96%; margin:30px 0;">
		<lay-form-item label="名称" prop="FName">
			<lay-input v-model="editDataInfo.FName"></lay-input>
		</lay-form-item>
		<lay-form-item label="数据值" prop="FValue">
			<lay-input v-model="editDataInfo.FValue"></lay-input>
		</lay-form-item>
		<lay-form-item label="排序" prop="FOrder">
			<lay-input v-model="editDataInfo.FOrder"></lay-input>
		</lay-form-item>
		<lay-form-item label="备注" prop="FRemark">
			<lay-input v-model="editDataInfo.FPhone"></lay-input>
		</lay-form-item>
		<lay-form-item label="状态" prop="FState">
			<lay-radio v-model="editDataInfo.FState" name="FState" value="1">有效</lay-radio>
			<lay-radio v-model="editDataInfo.FState" name="FState" value="0">无效</lay-radio>
		</lay-form-item>
		<lay-form-item>
			<lay-button type="normal" @click="submitClick">{{ editDataInfo.FID ? "修改" : "新增" }}</lay-button>
			<lay-button @click="cancelClick">取消</lay-button>
		</lay-form-item>
	</lay-form>
</template>

<script>
	import {
		ref
	} from 'vue';
	import {
		changeDataCode
	} from "/src/api/api/common";

	export default {
		setup() {
			const editDataInfo = ref({});
			return {
				editDataInfo
			}
		},
		props: {
			objInfoObj: {
				type: Object,
				default: () => {},
			}
		},
		mounted() {
			let editDataInfo = JSON.parse(JSON.stringify(this.objInfoObj));
			let state = this.objInfoObj.FState;
			state = state == undefined ? "true" : (state + "");
			editDataInfo.FState = state == "true" ? "1" : "0";
			delete editDataInfo["FUserOpt"]
			delete editDataInfo["FDateOpt"]
			this.editDataInfo = editDataInfo;
		},
		methods: {
			cancelClick(isRefresh) {
				isRefresh = isRefresh || false;
				this.$emit('cancelClick', isRefresh == true);
			},
			async submitClick() {
				delete this.editDataInfo["indentSize"];
				await changeDataCode(this.editDataInfo);
				this.cancelClick(true);
			}
		}
	}
</script>
