<template>
	<uni-forms ref="form" :modelValue="formData" :rules="rules" label-width="210rpx" style="margin: 12px">
		<uni-forms-item label="附件" name="files" label-position="top" required>
			<upload v-model="formData.files" />
		</uni-forms-item>
		<uni-forms-item label="是否存在问题" name="hasProblem" required>
			<uni-data-checkbox v-model="formData.hasProblem" :localdata="hasProblem" />
		</uni-forms-item>
		<uni-forms-item label="涉及人员" name="peoples" v-if="formData.hasProblem === true">
			<police-picker v-model="formData.peoples" :departId="formData.departId" />
		</uni-forms-item>
		<uni-forms-item label="检查情况" name="thingDesc" label-position="top" required v-if="formData.hasProblem === true">
			<uni-easyinput type="textarea" :input-border="false" placeholder="请输入检查情况" v-model="formData.thingDesc" />
		</uni-forms-item>
	</uni-forms>
	<view class="footer col-24 flex gap-8">
		<button class="col-12" @tap="back">取消</button>
		<button type="primary" @tap="submit" class="col-12">确定</button>
	</view>
</template>

<script>
	import {
		departTree
	} from '@/api/depart'
	import {
		addProblem
	} from '@/api/taskProblem.js'

	let _this;
	export default {
		data() {
			return {
				formData: {
					files: this.$page.options.files? JSON.parse(this.$page.options.files) : [],
					taskId: this.$page.options.taskId || '',
					contentId: this.$page.options.contentId,
					departId: this.$page.options.departId
				},
				hasProblem: [
					{
						text: '是',
						value: true
					},
					{
						text: '否',
						value: false
					},
				],
				rules: {
					files: {
						rules: [{
							validateFunction: function(rule,value,data,callback){
								if (!value || value.length === 0) {
									callback('请上传附件')
								}
								return true
							}
						}]
					},
					hasProblem: {
						rules: [{
							required: true,
							errorMessage: '请选择是否存在问题',
						}]
					},
					thingDesc: {
						rules: [{
							required: true,
							errorMessage: '请输入检测情况',
						}]
					},
				},
				needSeelctTaskFlag: true
			}
		},
		onLoad() {
			_this = this;
		},
		methods: {
			submit() {
				this.$refs.form.validate().then(res => {
					addProblem(this.formData.taskId, this.formData).then(data => {
						_this.formData = {
							files: [],
							taskId: _this.$page.options.taskId || ''
						}
						uni.navigateBack({
							
						});
					})
				}).catch(err => {
					console.log('表单错误信息：', err, this.formData);
				})
			},
			back() {
				uni.navigateBack({
					
				});
			}
		}
	}
</script>

<style>
</style>