<template>
	<view class="my-data">
		<uni-nav-bar @clickLeft="goBack()"  class="nav-bar" height="110rpx" leftWidth="200rpx" leftText="人员选择"
			leftIcon="left" border backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="wrap-view" style="box-shadow: 0 0 15px 5px #eeeeee;padding-bottom: 20upx;">
			<view class="item">
				<view class="title">信息修改：</view>
				<view class="content"></view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">访客</view>
				<view class="content">
					<uni-data-select name="visitor" :localdata="userRange" v-model="formData.visitor">
					</uni-data-select>
				</view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">返乡时间</view>
				<view class="content">
					<uni-datetime-picker
						v-model="formData.return_date"
						type="date"
						:hide-second="true"
					/>
				</view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">来源地</view>
				<view class="content">
					<input type="text" v-model="formData.come_place" maxlength="20" placeholder="请输入来源地" />
				</view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">行程轨迹</view>
				<view class="content">
					<input type="text" v-model="formData.trip_desc" maxlength="20" placeholder="请输入行程轨迹" />
				</view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">管控措施</view>
				<view class="content">
					<uni-data-select name="measure" :localdata="measureRange" v-model="formData.measure">
					</uni-data-select>
				</view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">核酸检测日期</view>
				<view class="content">
					<uni-datetime-picker
						v-model="formData.test_date"
						type="date"
						:hide-second="true"
					/>
				</view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">是否报备</view>
				<view class="content">
					<switch name="is_main" v-model="formData.is_reported" />
				</view>
			</view>
			<view class="item item_bottom_border">
				<view class="title">是否主访客</view>
				<view class="content">
					<switch name="is_main" v-model="formData.is_main" />
				</view>
			</view>
			<view class="item item_bottom_border" style="height: fit-content;">
				<view class="title">健康码</view>
				<view style="flex: 3;">
					<u-upload :action="vuex_apifile" :header="header" ref="uUpload" max-count="1" @on-success="imgUpdataHealth"></u-upload>
					<!-- <imgUpload :count="1" :header="header" :url="vuex_apifile" @obtain_img="imgUpdataHealth" :list="healthFileList"></imgUpload> -->
				</view>
			</view>
			<view class="item item_bottom_border" style="height: fit-content;">
				<view class="title">行程码</view>
				<view style="flex: 3;">
					<u-upload :action="vuex_apifile" :header="header" ref="uUpload" max-count="1" @on-success="imgUpdataTravel"></u-upload>
					<!-- <imgUpload :count="1" :header="header" :url="vuex_apifile" @obtain_img="imgUpdataTravel" :list="travelFileList"></imgUpload> -->
				</view>
			</view>
			<view class="item item_bottom_border" style="height: fit-content;">
				<view class="title">核酸报告</view>
				<view style="flex: 3;">
					<u-upload :action="vuex_apifile" :header="header" ref="uUpload" max-count="1" @on-success="imgUpdataReport"></u-upload>
					<!-- <imgUpload :count="1" :header="header" :url="vuex_apifile" @obtain_img="imgUpdataReport" :list="reportFileList"></imgUpload> -->
				</view>
			</view>
		</view>
		 <view class="btn">
			<button type="default" class="save-btn" @click="formSubmit">确定</button>
		</view> 
	</view>
</template>

<script>
	import imgUpload from '@/components/linzq-imgUpload/linzq-imgUpload.vue';
	import nonNullCheck from '../../../utils/nonNullCheck.js';
	export default {
		components: {
					imgUpload
				},
		data() {
			return {
				formData: {
					visit: '',
					visitor: '',
					return_date: '',
					come_place: '',
					trip_desc: '',
					test_date:'',
					measure: '',
					health_code: '',
					travel_code: '',
					test_report: '',
					is_main: false,
					is_reported: false,
				},
				head: {
					Authorization: "Bearer " + this.vuex_token
				},
				userRange: [],
				measureRange: [
					{value:'集中隔离',text:'集中隔离'},
					{value:'居家隔离',text:'居家隔离'},
					{value:'居家健康检测',text:'居家健康检测'},
					{value:'排除风险',text:'排除风险'},
				],
				healthFileList:[],
				travelFileList:[],
				reportFileList:[],
				hasPhoto:false,
				header:'',
				visitId:''
			}
		},
		onLoad(params) {
			debugger;
			if (params.visitId) {
				this.formData.visit = params.visitId;
				this.visitId = params.visitId;
			} 
		},
		onShow() {
			this.getHeader();
			this.getUserRange();
		},
		methods: {
			getHeader() {
				this.header = {
					Authorization: "Bearer " + this.vuex_token
				}
			},
			getHeader() {
				this.header = {
					Authorization: "Bearer " + this.vuex_token
				}
			},
			imgUpdataHealth(data){
				this.formData.health_code = data.path;
			},
			imgUpdataTravel(data){
				this.formData.travel_code = data.path;
			},
			imgUpdataReport(data){
				this.formData.test_report = data.path;
			},
			/* imgUpdataReport(data){
				this.formData.test_report = data[0];
			}, */
			//获取所有已注册游客
			getUserRange() {
				let that = this;
				that.$u.api.vmVisitor({
					page: 0
				}).then(res => {
					that.userRange = [];
					let user = [];
					let obj = {};
					res.forEach(item => {
						obj = item;
						obj.value = item.id;
						obj.text = item.name;
						user.push(obj);
					})
					that.userRange = user
				})
			},
			
			/* 参数验证 */
			paramsCheck() {
				if (!nonNullCheck(this.formData.visitor)) {
					uni.showToast({
						title: '请选择访客',
						icon: "none"
					})
					return false;
				}
				return true;
			},
			
			formSubmit(val) {
				let that = this;
				that.$u.api.vpeopleCreate(that.formData).then(res => {
					if (res.err_msg) {} else {
						uni.navigateBack({
							delta: 1
						})
					}
				})
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},

		}
	}
</script>

<style scoped>
	>>>.uni-navbar__header,
	>>>.uni-status-bar {
		background-image: linear-gradient(254deg,
				#0ca7ee 0%,
				#005aff 100%,
				#2a8cff 100%,
				#54bdff 100%),
			linear-gradient(#e60012,
				#e60012);
	}
>>>uni-image{
	height: 200upx;
	width: 200upx;
}
	.my-data {
		background-color: #f3fbff;
		padding-bottom: 227rpx;
	}

	.nav-bar>>>.uni-navbar-btn-text text {
		font-size: 32rpx !important;
	}

	.wrap-view {
		width: 720rpx;
		margin: 0 auto;
		background-color: #ffffff;
		border-radius: 10rpx;
		line-height: 94rpx;
		font-family: PingFang-SC-Medium;
		font-size: 30rpx;
	}
	.wrap-top{
		padding: 20upx 0;
		line-height: 60upx;
	}
	.item {
		margin: 0rpx 32rpx;
		display: flex;
		margin-top: 20rpx;
	}
	
	.item_bottom_border{
		border-bottom: 1rpx solid #eeeeee;
	}
	
	.title {
		color: #212121;
		flex: 1;
	}

	.content {
		flex: 3;
		color: #414141;

	}

	.content input {
		height: 100%;
	}

	.save-btn {
		width: 400rpx;
		height: 80rpx;
		background-color: #2c6fd9;
		border-radius: 40rpx;
		font-size: 30rpx;
		line-height: 80rpx;
		color: #f3fbff;
		margin-top: 21rpx;
	}
</style>
