<template>
	<view>
		<homebar titlenav=""></homebar>
		<view class="box">
			<view style="line-height: 60rpx;">
				<view style="font-size: 18px;font-weight: 600;">
					请先完善个人信息
				</view>
				<view class="">
					信息安全保护中，请放心填写
				</view>
			</view>
			<view class="" style="margin-top: 40rpx;">
				<u--form labelPosition="left" labelWidth="100" :model="formData" :rules="rules" ref="uForm">
					<u-form-item label="您的姓名" prop="userInfo.name" borderBottom>
						<u--input v-model="formData.name" placeholder="请输入姓名"></u--input>
					</u-form-item>
					<u-form-item label="性别" prop="name" borderBottom>
						<u-radio-group v-model="radiovalue1" placement="row" @change="groupChange">
							<u-radio :customStyle="{marginLeft: '20px'}" v-for="(item, index) in radiolist1"
								:key="index" :label="item.name" :name="item.name" @change="radioChange">
							</u-radio>
						</u-radio-group>
					</u-form-item>
					<u-form-item label="生日" borderBottom @click="dateShow = true;">
						<u--input v-model="formData.time" disabled disabledColor="#ffffff" placeholder="请选择生日"
							border="none"></u--input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
				<!-- 	<view class="flexbetween">
						<view class="" style="width: 50%;">
							<view class="" style="display: flex;line-height: 30px;font-size: 12px;">
								<view style="color: #FA5852;">
									*
								</view>
								<view style="color: #999999;">
									身份证正面
								</view>
							</view>
							<view>
								<u-upload :previewFullImage="true" width='140' height='80' :fileList="fileListcardImg"
									@afterRead="afterRead" @delete="deletePic" name="cardImg" multiple :maxCount="1"
									style="display: block; margin-left: auto;flex: none;">
								</u-upload>
							</view>
						</view>
						<view class="" style="width: 50%;">
							<view class="" style="display: flex;line-height: 30px;font-size: 12px;">
								<view style="color: #FA5852;">
									*
								</view>
								<view style="color: #999999;">
									身份证反面
								</view>
							</view>
							<view>
								<u-upload :previewFullImage="true" width='140' height='80' :fileList="fileListcardImgB"
									@afterRead="afterRead" @delete="deletePic" name="cardImgB" multiple :maxCount="1"
									style="display: block; margin-left: auto;flex: none;">
								</u-upload>
							</view>
						</view>
					</view> -->
				</u--form>
			</view>
			<view style="position: fixed;bottom: 0;left: 0;width: 100%;padding: 40rpx;">
				<u-button text="下一步" type="success" @click="toNext('/pages/workNext/index2')" shape="circle"></u-button>
			</view>
			<u-datetime-picker @confirm="confirm" @cancel="dateShow = false" :minDate="minDate" :maxDate="maxDate" ref="datetimePicker"
				:show="dateShow" mode="date"></u-datetime-picker>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileListcardImg:[],
				fileListcardImgB:[],
				dateShow: false,
				minDate: null,
				maxDate: null,
				formData: {
					time: null,
					name: null,
				},
				rules: {
					'name': {
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					},
				},
				radiolist1: [{
						name: '男',
						disabled: false
					},
					{
						name: '女',
						disabled: false
					}
				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				radiovalue1: '苹果',
			};
		},
		onLoad() {
			this.minDate = Number(new Date('1950-01-01'))
			this.maxDate = Number(new Date())
		},
		methods: {
			toNext(url){
				uni.navigateTo({
					url:url
				})
			},
			confirm(val) {
				let date = new Date(val.value)
				let Y = date.getFullYear() + '-';
				let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				let D = date.getDate()>9?date.getDate() + ' ':'0' + date.getDate() + ' ';
				// document.write(Y + M + D + h + m + s);
				this.formData.time = Y + M + D
				this.dateShow = false
			},
			groupChange(n) {
				console.log('groupChange', n);
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilesPromise(lists[i].url)
					result.url = this.baseurl + result.fileName
					this.form[`${event.name}`] = result.fileName;
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		margin: 40rpx;
	}
	.flexbetween {
		display: flex;
		justify-content: space-between;
	}
</style>