<template>
	<view class="flex gap-16 info">
		<view class="police-info-avatar">
			<net-image :filepath="people.avatarUrl" v-if="people.avatarUrl" />
			<image src="/static/police.png" v-else></image>
		</view>
		<view style="width: calc(100% - 168rpx)">
			<view>
				<view class="row">
					<view class="col col-12">
						<view class="label">姓名：</view>
						<view class="content">{{ people.name }}</view>
					</view>
					<view class="col col-12">
						<view class="label">警号：</view>
						<view class="content">{{ people.empNo }}</view>
					</view>
					<view class="col col-12">
						<view class="label">所属单位：</view>
						<view class="content">{{ people.departName }}</view>
					</view>
					<view class="col col-12">
						<view class="label">职位：</view>
						<view class="content">{{ people.position }}</view>
					</view>
					<view class="col col-24">
						<view class="label">联系电话：</view>
						<view class="content">{{ people.mobile || '/' }}</view>
					</view>
				</view>

			</view>
			<view style="color: red">待检测</view>
		</view>
	</view>
	<uni-forms ref="form" :modelValue="formData" :rules="rules" label-width="80px" style="margin: 12px">
		<uni-forms-item label="检测时间" name="testingTime" required>
			<uni-datetime-picker type="datetime" v-model="formData.testingTime" :border="false" placeholder="请选择检测时间" />
		</uni-forms-item>
		<uni-forms-item label="检测情况" name="testingResult" required>
			<uni-data-checkbox v-model="formData.testingResult" :localdata="testingResult" />
		</uni-forms-item>
		<uni-forms-item label="测酒结果" name="drinkResult" required v-if="formData.testingResult === '已检测'">
			<uni-data-checkbox v-model="formData.drinkResult" :localdata="drinkResult" />
		</uni-forms-item>
		<uni-forms-item label="酒精含量" name="alcoholContent" required v-if="formData.testingResult === '已检测' && formData.drinkResult === '饮酒'">
			<uni-easyinput type="number" v-model="formData.alcoholContent" placeholder="请输入酒精含量" :inputBorder="false" />
		</uni-forms-item>
		<uni-forms-item label="测酒照片" name="testingFiles" label-position="top" required
			v-if="formData.testingResult === '已检测'">
			<upload v-model="formData.testingFiles" />
		</uni-forms-item>
		<uni-forms-item label="情况说明" name="unTestingDesc" required v-if="formData.testingResult === '未检测'">
			<uni-easyinput type="textarea" v-model="formData.unTestingDesc" placeholder="请输入未检测现场情况说明"
				:inputBorder="false" />
		</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 store from '@/store'
	import { now } from '@/common/util'
	
	import {
		updateTestingAlcoholPeople
	} from '@/api/testingAlcohol'
	
	let _this;
	export default {
		data() {
			return {
				BASE_PATH: store.state.fileRequestUrl,
				people: JSON.parse(this.$page.options.people),
				formData: {
					testingTime: now('YYYY-MM-DD HH:mm:ss'),
					testingFiles: []
				},
				rules: {
					testingTime: {
						rules: [
							{
								required: true,
								errorMessage: '请选择检测时间',
							}
						]
					},
					testingResult: {
						rules: [
							{
								required: true,
								errorMessage: '请选择检测情况',
							}
						]
					},
					drinkResult: {
						rules: [
							{
								required: true,
								errorMessage: '请选择测酒结果',
							}
						]
					},
					alcoholContent: {
						rules: [
							{
								required: true,
								errorMessage: '请输入酒精含量',
							}
						]
					},
					unTestingDesc: {
						rules: [
							{
								required: true,
								errorMessage: '请输入未检测现场情况说明',
							}
						]
					},
					testingFiles: {
						rules: [{
							validateFunction: function(rule,value,data,callback){
								if (!value || value.length === 0) {
									callback('请上传测酒现场照片')
								}
								return true
							}
						}]
					},
				},
				testingResult: [{
						text: '已检测',
						value: '已检测'
					},
					{
						text: '未检测',
						value: '未检测'
					}
				],
				drinkResult: [{
						text: '未饮酒',
						value: '未饮酒'
					},
					{
						text: '饮酒',
						value: '饮酒'
					},
				]
			}
		},
		onLoad() {
			_this = this;
		},
		methods: {
			submit() {
				this.$refs.form.validate().then(res=>{
					this.formData.empNo = this.people.empNo
					updateTestingAlcoholPeople(this.people.taskId, this.formData).then(data => {
						uni.navigateBack({
							
						});
					})
				}).catch(err =>{
					console.log('表单错误信息：', err);
				})
				
			},
			back() {
				uni.navigateBack({
					
				});
			}
		}
	}
</script>

<style lang="scss">
	.info {
		padding: 12px;
		box-shadow: inset 0 -1px 0 0 #eee;
	}
	.police-info-avatar {
		width: 136rpx;
		height: 205rpx;
		image {
			width: 100%;
			height: 100%;
		}
	}
</style>