<template>
	<div class="body">		
		<uni-forms ref="form" label-position="top" :rules="rules" :model="form">
			<uni-forms-item label="是否异常" name="status" required>
				<uni-data-select
					v-model="form.status"
					:localdata="status"
				></uni-data-select>
			</uni-forms-item>
			<uni-forms-item label="评审人" name="user" required v-if="form.status===1">
				<uni-data-select
					v-model="form.user"
					:localdata="users"
				></uni-data-select>
			</uni-forms-item>
			<uni-forms-item label="描述" name="desc" required>
				<uni-easyinput type="textarea" autoHeight v-model="form.desc" placeholder="请输入描述"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="附件">
				<div class="upload-container">
					<image @click="upload" class="upload" src="/static/icon/upload.png" mode="widthFix"></image>
					<p class="tip">注：单个附件上传不超过10M，附件累计不超过20M</p>					
				</div>
			</uni-forms-item>
		</uni-forms>	
		<view class="footer" @click="onSubmit">提交</view>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				status: [
				  { value: 0, text: "否" },
				  { value: 1, text: "是" }
				],
				users:[
				  { value: 0, text: "张三" },
				  { value: 1, text: "李四" }					
				],
				rules:{
					status:{
						rules:[
							{
								required: true,
								errorMessage: '请选择是否异常'
							}					
						],
						validateTrigger:'submit'
					},
					user:{
						rules:[
							{
								required: true,
								errorMessage: '请选择评审人',
							},						
						],
					},
					desc:{
						rules:[
							{
								required: true,
								errorMessage: '请填写描述',
							},						
						]						
					}
				},
				form:{
					status:"",
					user:"",
					desc:"",
					attachList:[]
				}
			}
		},
		methods: {
			upload(){
				uni.chooseFile({
					success: (files) => {
						const tempFilePaths = files.tempFilePaths;
						uni.uploadFile({
							url: 'https://www.example.com/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'user': 'test'
							},
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data);
							}
						});
					}
				});
			},
			onSubmit(){
				this.$refs.form.validate().then(res=>{
					console.log('表单数据信息：', res);
				}).catch(err =>{
					console.log('表单错误信息：', err);
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.body{
	height: 100vh;
	box-sizing: border-box;
	padding:21rpx 16rpx;
	background-color: #F3F5FB;
	::v-deep .uni-forms-item__content{
		.uni-easyinput,.uni-select{
			background-color: #fff;
		}	
	}
	.upload-container{
		.upload{
			width: 216rpx;
			display: block;
		}
		.tip{
			font-size: 24rpx;
			line-height: 28rpx;
			color: #999999;
			padding-top: 20rpx;
		}
	}
	.footer{
		width: 100%;
		height: 136upx;
		background: #FFFFFF;
		border-radius: 16upx 16upx 0px 0px;
		position: fixed;
		left: 0;
		bottom: 0;
		text-align: center;
		color: #168DEC;
		font-size: 32upx;
		padding-top: 20upx;
		letter-spacing: 2px;
	}
}
</style>
