<template>
	<view class="questionnaire">
		<form @submit="formSubmit" >
			<template v-for="(item,index) in list">
				<view v-if="item.type == 'radio'" class="margin-top padding sict-label"  :key="item.value">
					<view v-show="!item.hidden">
						<span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx" v-if="item.required">*</span>
						{{index+1}}、 {{item.label}}
					</view>
					<view class="text-right  sict-value" v-show="!item.hidden">
						<radio-group>
							<view>
								<view class="label" v-for="(opt, optIndex) in item.opts" :key="opt.label" @click="radioChange(opt.value,item.value)">
									<radio :class="form[item.value]== opt.value ?'checked':''" :checked="form[item.value]== opt.value?true:false"
									 :value="opt.value"></radio>
									<view style="display: inline-block;" class="right">{{opt.label}}</view>
								</view>
							</view>
						</radio-group>
					</view>
				</view>
				
				<template  v-else-if="item.type == 'picker'">
					<view class="cu-form-group margin-top padding-rl"  v-show="!item.hidden" :key="item.value">
						<view :class="item.titleClass"><span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx" v-if="item.required">*</span>{{index+1}}、{{item.label}}</view>
						<picker @change="updatePickerVal($event,item.value)" range-key="label" :value="form[item.value]" :range="item.opts">
							<view class="picker">
								{{form[item.value]>-1?item.opts[form[item.value]].label:'请选择'}}
							</view>
						</picker>
					</view>
				</template>
				
				<template  v-else-if="item.type == 'date'">
					<view class="cu-form-group margin-top padding-rl" v-show="!item.hidden"  :key="item.value">
						<view :class="item.titleClass"><span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx" v-if="item.required">*</span>{{index+1}}、{{item.label}}</view>
						<picker mode="date" :value="date" start="2015-09-01" end="2020-09-01" @change="updatePickerVal($event,item.value)">
							<view class="picker">
								{{form[item.value]>-1?item.opts[form[item.value]].label:'请选择'}}
							</view>
						</picker>
					</view>
				</template>
				
				
				
			<!-- 	<view v-else-if="item.type == 'radio'" :key="index">
					<view class="margin-top  sict-label">
						<uni-collapse>
							<uni-collapse-item :title="index+1 +'、' + item.label" :open="true" :required="item.required">
								<view class="padding-lr">
									<view class="uni-list">
										<checkbox-group>
											<label class="uni-list-cell uni-list-cell-pd" v-for="(itemCheck,indexCheck) in item.opts" :key="itemCheck.value"
											 @click="radioChange2(indexCheck,item.opts,itemCheck.value)">
												<view class="list-item">
													<view class="fl">
														<checkbox :value="itemCheck.value" :checked="itemCheck.checked" />
													</view>
													<view  style="padding-left:60upx">{{itemCheck.label}}</view>
												</view>
											</label>
										</checkbox-group>
									</view>
								</view>
							</uni-collapse-item>
						</uni-collapse>
					</view>
				</view> -->
				
				<template  v-else-if="item.type == 'input'" >
					<view class="cu-form-group margin-top padding-rl" :key="item.value">
						<view :class="item.titleClass">
							<span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx" v-if="item.required">*</span>
						{{index+1}}、{{item.label}}</view>
						<input  class="text-right" :placeholder="item.placeholder" :type="item.controType" :value="form[item.value]" name="input" @input="updateInputVal($event,item.value)"></input>
					</view>
				</template>
				
				<view class="margin-top-xs" v-show="item.child && childItem.show" v-for="(childItem,childIndex) in item.child" :key="childItem.value">
						<view class="margin-top-sm padding-rl sict-label cu-form-group">
							<view>
								<span style="color:red;display: inline-block; vertical-align:inherit;margin-right:4upx" v-if="childItem.required">*</span>
								{{childItem.title}}
							</view>
							<checkbox  v-if="childItem.type == 'radio'" :class="form[childItem.value]?'checked':''" :checked="form[childItem.value]?true:false" :value="childItem.value"></checkbox>
							
							<picker v-else-if="childItem.type == 'picker'" range-key="label"  @change="updatePickerVal($event,childItem.value)" :value="form[childItem.value]" :range="childItem.opts">
								<view class="picker">
									{{form[childItem.value]>-1?childItem.opts[form[childItem.value]].label:'请选择'}}
								</view>
							</picker>
							
							<input  class="text-right" v-else-if="childItem.type == 'input'" :type="childItem.controType" :placeholder="childItem.placeholder" :value="form[childItem.value]" name="input" @input="updateInputVal($event,childItem.value)"></input>
						</view>
				</view>
			</template>
			
			<view class="padding">
				<button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg">提 交</button>
			</view>
			
		
			
		</form>
	</view>
</template>

<script>
	import uniCollapse from '@/components/uni-collapse/uni-collapse.vue'
	import uniCollapseItem from '@/components/uni-collapse-item/uni-collapse-item.vue'
	import validate from '@/utils/validate.js'
	export default {
		components: {
			uniCollapse,
			uniCollapseItem
		},
		data() {
			return {
				id:'',
				radio:[],
				shanghaiList:[
					{
						label:'是否离沪',
						required:true,
						value:'relativesGastricCount',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'是'},{value:'b',label:'否'}]
					},
					{
						label:'离沪原因',
						required:true,
						value:'relativesGastricCount',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'探亲'},{value:'b',label:'出差'},{value:'b',label:'旅游'},{value:'b',label:'其他'}]
					},
					{
						label:'离沪出发日期',
						required:true,
						value:'relativesGastricCount2222',
						titleClass:'title',
						type:'date',
					},
					{
						label:'离沪方式',
						required:true,
						value:'relativesGastricCount2222',
						titleClass:'title',
						type:'date',
						opts:[{value:'a',label:'火车	'},{value:'飞机',label:'否'},{value:'客车',label:'否'},{value:'自驾',label:'否'}]
					},
					{
						label:'离沪车次/航班',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入地址',
						type:'input',
					},
					{
						label:'离沪到达日期',
						required:true,
						value:'relativesGastricCount2222',
						titleClass:'title',
						type:'date',
						opts:[{value:'a',label:'是'},{value:'b',label:'否'}]
					},
					{
						label:'离沪目的地',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入地址',
						type:'input',
					},
					{
						label:'离沪具体地址',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入地址',
						type:'input',
					},
					{
						label:'离沪同行者姓名（没有填无）',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入',
						type:'input',
					},
					{
						label:'离沪同行者联系方式（没有填无）',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入',
						type:'input',
					},
					{
						label:'是否返沪',
						required:true,
						value:'relativesGastricCount',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'是'},{value:'b',label:'否'}]
					},
					{
						label:'返沪出发地',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入',
						type:'input',
					},
					{
						label:'返沪出发日期',
						required:true,
						value:'relativesGastricCount2222',
						titleClass:'title',
						type:'date',
					},
					{
						label:'返沪方式',
						required:true,
						value:'relativesGastricCount2222',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'火车	'},{value:'飞机',label:'否'},{value:'客车',label:'否'},{value:'自驾',label:'否'}]
					},
					{
						label:'返沪车次/航班',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入地址',
						type:'input',
					},
					{
						label:'返沪到达日期',
						required:true,
						value:'relativesGastricCount2222',
						titleClass:'title',
						type:'date',
					},
					{
						label:'返沪同行者姓名（没有填无）',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入',
						type:'input',
					},
					{
						label:'返沪同行者联系方式（没有填无）',
						required:true,
						value:'relativesGastricAge',
						titleClass:'title',
						placeholder:'请输入',
						type:'input',
					},
					{
						label:'当前状况',
						required:true,
						value:'relativesGastricCount',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'已经确诊'},{value:'b',label:'疑似诊断'},{value:'b',label:'亲密接触者'},{value:'b',label:'正在接受集中医学观察'},{value:'b',label:'居家观察'},{value:'b',label:'已解除集中医学观察'},{value:'b',label:'无上述情况'}]
					},
					{
						label:'湖北接触史',
						required:true,
						value:'relativesGastricCount',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'已经确诊'},{value:'b',label:'疑似诊断'},{value:'b',label:'亲密接触者'},{value:'b',label:'正在接受集中医学观察'},{value:'b',label:'居家观察'},{value:'b',label:'已解除集中医学观察'},{value:'b',label:'无上述情况'}]
					}
				],
				
				list:[
					{
						label:'单位名称',
						required:true,
						value:'orgId',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'一位'},{value:'b',label:'多位'}]
					},
					{
						label:'所在部门',
						required:true,
						value:'department',
						titleClass:'title',
						placeholder:'请输入所在部门',
						type:'input',
					},
					{  
						label:'职务',
						required:true,
						value:'position',
						titleClass:'title',
						placeholder:'请输入职务',
						type:'input',
					},
					{
						label:'员工姓名',
						required:true, 
						value:'name',
						titleClass:'title',
						placeholder:'请输入员工姓名',
						type:'input',
					},
					{
						label:'联系方式',
						required:true,
						value:'phone',
						titleClass:'title',
						placeholder:'请输入联系方式',
						type:'input',
					},
					{
						label:'国籍',  
						required:true,
						value:'nationality',
						titleClass:'title',
						type:'picker',
						opts:[{value:'a',label:'中国'},{value:'b',label:'其它'}]
					},
					{
						label:'身份证号/护照号',
						required:true,
						value:'idCard',
						titleClass:'title',
						placeholder:'请输入身份证号/护照号',
						type:'input',
					},
					{
						label:'户籍地址',
						required:true,
						value:'householdAddress',
						titleClass:'title',
						placeholder:'请输入户籍地址',
						type:'input',
					},
					{
						label:'在沪居住（暂住）地址',
						required:true,
						value:'residenceAddress', 
						titleClass:'title',
						placeholder:'请输入地址',
						type:'input',
					},
					{
						label:'是否复工',
						required:true,
						value:'returnToWork',
						titleClass:'title',
						type:'radio',
						opts:[{value:'a',label:'是'},{value:'b',label:'否'}],
					},
					{
						label:'计划复工日期',
						hidden:true,
						required:true,
						value:'relativesGastricCount2222',
						titleClass:'title',
						type:'date'
					}
				],
				form:{
					orgId:'',
					department:'',
					position:'',
					name:'',
					phone:'',
					nationality:'',
					idCard:'',
					householdAddress:'',
					residenceAddress:'',
					planReturnDate:''
				}
			}
		},
		
		onLoad(option) {
			// this.id = option.id || ''
			// if(option.id){
			// 	this.getInfo(option.id)
			// }
			this.getOrg()
		},
		
		
		methods: {
			getOrg(){
				const data = {
					params: {
						pageNum: 1,
						pageSize: 1000000
					}
				}
				this.$http.get(`/sict-ncov/org/page`, data).then(res => {
					const d = res.data
					if (d.code == 1) {
						console.log(d)
					}
				}).catch(err => {
					console.log(err)
				})
			},
			// 获取信息
			getInfo(id){
				// this.$http.get(`/ewell-gastric-cancer-data/report/selectReportBySampleId?id=${id}`).then(res => {
				// 	const d = res.data
				// 	if(d.code == 1){
				// 		this.form =  Object.assign(this.form,d.object.reportContent.data)    
				// 		this.isShowChild()
				// 	}
				// }).catch(err => {
				// 	console.log(err)
				// })
			},
			
			radioChange(val,prop){
				this.$set(this.form,prop,val)
				this.isShowChild()
			},
			
			isShowChild(){
				this.list[11].hidden = this.form['returnToWork'] == 'a'
			},
			
			Switch(e,prop){
				this.form[prop] = e.detail.value
			},
			// 更新输入框绑定的表单内容
			updateInputVal(event, props) {
				this.form[props] = event.target.value
			},
			// 更新下拉框绑定的表单内容
			updatePickerVal(event,props){
				this.$set(this.form, props, event.detail.value)
			},
			// 提交信息
			formSubmit(){
				console.log(this.form)
				let flag = true
				let msg = ''
				for (let i = 0; i < this.list.length; i++) {
					if(this.list[i].required){
						if(!this.form[this.list[i].value]){
							flag = false
							uni.showToast({
								icon: 'none',
								title: "第"+(i+1)+"项有必填数据未填写"
							})
							break
						}
						if(!flag){
							break
						}
					}
				}
				
				if(!flag){
					return false
				}else{
					this.$http.post(`/ewell-gastric-cancer-data/wechat/report`,obj).then(res => {
						const d = res.data
						if(d.code == 1){
							
						}else{
							uni.showToast({
								icon: 'none',
								title: d.message
							})
						}
					}).catch(err => {
						console.log(err)
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.sict-title {
		padding: 20upx 0;
		padding-right: 20upx;
		word-break: break-all;
		text-align: justify
	}

	.sict-label {
		background-color: white;
		font-size: 30upx;
		text-align: justify;
	}

	.sict-value {
		margin-top: 15upx;
		.right {
			margin-left: 10upx;
			vertical-align: bottom;
		}
		.label {
			// display: inline-block;
			text-align: left;
			padding: 20upx 0;
			padding-left: 30upx;
			border-bottom: 2upx solid #d3d3d3;
			&:last-child {
				border-bottom: 0;
			}
		}
	}

	uni-radio-group {
		border: 2upx solid #d3d3d3;
		border-radius: 8upx;
		margin-left: 20upx;
		display: block;
	}

	radio-group {
		border: 2upx solid #d3d3d3;
		border-radius: 8upx;
		margin-left: 20upx;
		display: block;
	}

	.icon-right {
		font-family: cuIcon;
		font-size: 34upx;
		color: #8799a3;
		line-height: 100upx;
		width: 60upx;
		text-align: right;
		margin: auto;
	}

	.uni-list-cell {
		.list-item {
			border-bottom: 2upx solid #d3d3d3;
			padding: 20upx 0;
			padding-left: 30upx;
		}

		&:last-child {
			.list-item {
				border-bottom: 0;
			}
		}
	}

	.uni-list {
		margin-left: 20upx;
		border: 2upx solid #d3d3d3;
		border-radius: 8upx;
	}
</style>

<style>
	.questionnaire .uni-collapse-cell__title:after {
		border-bottom: 0 !important;
	}
</style>
