<template>
	<xn-form-container
		:title="'位置信息管理新增'"
		:width="800"
		:visible="visible"
		:destroy-on-close="true"
		@close="onClose"
	>
		<a-form :model="formState" name="basic" autocomplete="off" @finish="onFinish" @finishFailed="onFinishFailed">
			<div class="form">
				<a-form-item
					class="form-item"
					label="制度名称"
					name="swls"
					:label-col="{ span: 10 }"
					:rules="[{ required: true, message: 'Please input your username!' }]"
				>
					<a-input v-model:value="formState.username" />
				</a-form-item>

				<a-form-item class="form-item" label="发布人" name="username" :label-col="{ span: 10 }">
					<a-input v-model:value="formState.username" />
				</a-form-item>
				<a-form-item
					class="form-item"
					label="发布时间"
					name="username"
					:label-col="{ span: 10 }"
					:rules="[{ required: true, message: 'Please input your username!' }]"
				>
					<a-input v-model:value="formState.username" />
				</a-form-item>

				<!--  -->
			</div>
			<!-- 仓房设施设备情况 -->
			<div>仓房设施设备情况</div>
			<div class="input">
				<a-input v-model:value="formData.username" :disabled="false" placeholder="" allow-clear />
			</div>
			<div class="attachment">
				<div><span>*</span>附件</div>
				<div>
					<a-upload
						:action="uploadUrl"
						:before-upload="handleBeforeUpload"
						:on-success="handleUploadSuccess"
						:on-error="handleUploadError"
						:file-list="fileList"
						multiple
					>
						<a-button icon="upload">选择文件</a-button>
					</a-upload>
					<p>附件支持在线预览、下载、打印。</p>
				</div>
			</div>

			<a-form-item>
				<div class="item-submit">
					<a-button class="btn1" html-type="submit">保存</a-button>
					<a-button class="btn1" type="primary" html-type="submit">下发</a-button>
				</div>
			</a-form-item>
		</a-form>
		<template #footer>
			<a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
		</template>
	</xn-form-container>
</template>
<script lang="js">
	import { ref } from 'vue'
	import { cloneDeep } from 'lodash-es'
	import { required } from '@/utils/formRules'
	export default {
		name: 'FromName',
		components: {},
		setup(props, { emit }) {
			const formRef = ref()
			const disabled = ref(false)
			const formData = ref({
				name: ''
			})
			// 抽屉状态
			const visible = ref(false)
			// 打开抽屉
			const onOpen = (record, flag) => {
				visible.value = flag
			}
			const onClose = () => {
				// formRef.value.resetFields()
				// formData.value = {}
				visible.value = false
			}
			const formState = reactive({
				username: '',
				swls: ''
			})
			const onFinish = (values) => {
				console.log('Success:', values)
			}
			const onFinishFailed = (errorInfo) => {
				console.log('Failed:', errorInfo)
			}

			const options = ref([
				{
					value: 1
				}
			])

			const handleChange = (val) => {
				console.log(val)
			}

			const uploadUrl = 'https://your-upload-api-url' // 替换为实际的上传接口地址
			const fileList = ref([])

			// 处理文件上传前的操作 ,// 可以在此处对文件进行校验或处理
			// 返回 true 表示继续上传，返回 false 表示取消上传
			const handleBeforeUpload = (file) => {
				console.log('文件上传前的操作', file)
				return true
			}

			// 处理文件上传成功的操作
			const handleUploadSuccess = (response, file) => {
				const formData = new FormData()
				formData.append('file', file)
				console.log('文件上传成功', response, formData)
				// axios
				// 	.post('https://your-api-url', formData)
				// 	.then((response) => {
				// 		console.log('请求成功', response)
				// 		// 在此处处理请求成功后的逻辑
				// 	})
				// 	.catch((error) => {
				// 		console.log('请求失败', error)
				// 		// 在此处处理请求失败的逻辑
				// 	})
			}
			// 处理文件上传失败的操作
			const handleUploadError = (error, file) => {
				// 文件上传失败后的处理
				console.log('文件上传失败', error)
			}
			return {
				uploadUrl,
				handleBeforeUpload,
				handleUploadSuccess,
				handleUploadError,
				fileList,
				formState,
				onFinish,
				onFinishFailed,
				options,
				handleChange,
				disabled,
				onOpen,
				visible,
				formRef,
				onClose,
				formData
			}
		}
	}
</script>
<style lang="less" scoped>
	.box1 {
		display: flex;
		justify-content: space-between;
		.box-left {
			width: 350px;
			align-items: center;
		}
		.box-right {
			width: 350px;
			margin-right: 10px;
			align-items: center;
		}
	}
	.common {
		display: flex;
		align-items: center;
		justify-content: center;
		margin-bottom: 30px;
		.title {
			width: 130px;
			text-align: right;
			margin-right: 5px;
		}
	}
	.input {
		margin-right: 10px;
		margin-left: 40px;
		margin-top: 20px;
		.ant-input-affix-wrapper {
			height: 100px;
		}
	}
	.btnBox {
		text-align: center;
		margin-top: 100px;
		.snowy-buttom-left {
			margin-left: 100px;
		}
		.acc {
			width: 80px;
			height: 40px;
		}
	}
	.form {
		display: flex;
		flex-wrap: wrap;
		// justify-content: center;
		.form-item {
			width: 250px;
			margin-right: 120px;
		}
	}
	.item-submit {
		display: flex;
		justify-content: center;
		margin-top: 100px;
		.btn1 {
			width: 100px;
			margin-right: 20px;
		}
	}
	.ant-select {
		width: 250px;
	}
	.ant-input {
		width: 250px;
	}
	.ant-form-item-label {
		width: 150px;
	}
	.attachment {
		display: flex;
		margin-top: 30px;
		div:first-child {
			width: 110px;
			text-align: right;
			padding-right: 45px;
		}
		span {
			color: red;
			margin-right: 3px;
		}
		p {
			font-size: 12px;
			color: #eb4897;
		}
	}
</style>
