<template>
	<view class="content">
		<view class="updateDoctorInfo-wrap">
			<view class="zhcx-table">				
				<view class="zhcx-table-row">
					<view class="name">
						<text>姓名</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.name"  />
					</view>
				</view>					
				<view class="zhcx-table-row">
					<view class="name">
						<text>性别</text>
					</view>
					<view class="text" >
						<radio-group @change="changeGender">
							<label>
								<radio value="0" :checked="form.gender==='0'"  /><text>男</text>
							</label>
							<label class="gender-item-woman">
								<radio value="1" :checked="form.gender==='1'"  /><text>女</text>
							</label>
						</radio-group>					
					</view>
				</view>		
				<view class="zhcx-table-row">
					<view class="name">
						<text>身份证</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.idCard"  />
					</view>
				</view>				
				<view class="zhcx-table-row">
					<view class="name">
						<text>住址</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.address" />
					</view>
				</view>		
				<view class="zhcx-table-row">
					<view class="name">
						<text>所属医院</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.hospital" />
					</view>
				</view>	
				<view class="zhcx-table-row">
					<view class="name">
						<text>科室</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.offices" />
					</view>
				</view>		
				<view class="zhcx-table-row">
					<view class="name">
						<text>医生资格证号</text>
					</view>
					<view class="text" >
						<input type="text" v-model="form.doctorQualificationsNumber" />
					</view>
				</view>	
				<view class="zhcx-table-row">
					<view class="name">
						<text>资格证照片</text>
					</view>
					<view class="text" v-show="0">
						<input type="text" v-model="form.qualificationsImg" />
					</view>			
				</view>	
				<view class="zhcx-upload" @click="uploadBt">
					<div class="icon"></div>
					<text class="uploadTitle">点击上传</text>
				</view>							
			</view>				
		</view>	
		<view class="handle-wrap">
			<view class="submit-BT" @click="submit">
				<text>提交</text>
			</view>			
		</view>
	</view>
</template>
<script>
	import {modifyinfo} from '@/api/doctor';
	import {upload} from '@/api/index';
	export default {
		data() {
			return {
				form:{
					name:"",
					idCard:"",
					gender:"",
					address:"",
					hospital:"",
					offices:"",		
					doctorQualificationsNumber:"",
					qualificationsImg:""
				}
			}
		},
		created() {
			this.init();
		},
		methods: {
			init(){
				let doctorAccountInfo=uni.getStorageSync('doctorAccountInfo');
	            this.$set(this.form,'name',doctorAccountInfo.doctorName);
	            this.$set(this.form,'gender',doctorAccountInfo.doctorSex);
	            this.$set(this.form,'idCard',doctorAccountInfo.doctorIdCard);
	            this.$set(this.form,'hospital',doctorAccountInfo.doctorHospital);
	            this.$set(this.form,'offices',doctorAccountInfo.doctorDepartment);
	            this.$set(this.form,'doctorQualificationsNumber',doctorAccountInfo.doctorQualificationsNumber);
	            this.$set(this.form,'doctorQualificationsImg',doctorAccountInfo.qualificationsImg);
	            this.$set(this.form,'doctorJob',doctorAccountInfo.doctorJobTitle);	
				this.$set(this.form,'address',doctorAccountInfo.doctorAddress);
			},
			changeGender({detail}){
				this.form.gender=detail.value;
			},
			submit(){	
				let form=this.form;	
				let doctorAccountInfo=uni.getStorageSync('doctorAccountInfo');
				var params={
					doctorId:doctorAccountInfo.doctorId,
					doctorSex:form['gender'],
					doctorIdCard:form['idCard'],
					doctorHospital:form['hospital'],
					doctorDepartment:form['offices'],
					doctorQualificationsNumber:form['doctorQualificationsNumber'],
					doctorQualificationsImg:form['qualificationsImg'],
					doctorAddress:form['address'],
					accountRealName:form['name'],
					doctorName:form['name']
				}
				modifyinfo(params).then(()=>{
					uni.showToast({
						title:"补传资料成功！请等待审核员审核！",
						icon:'none'
					})
					setTimeout(()=>{
						uni.reLaunch({
							url:"/pages/login/index"
						})
					},1500)
				})
			},
			uploadBt(){
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;		
						this.uploadSubmit(tempFilePaths[0])
					}
				});			
			},
			uploadSubmit(filePath){
				let callback=this.onProgressUpdate;
				upload({filePath,callback}).then((res)=>{
					let cont=JSON.parse(res)
					this.form.qualificationsImg=cont.data.path;
				}).catch((msg)=>{
					console.log(msg)
				})	
			}			
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		.updateDoctorInfo-wrap{
			.zhcx-table-row{
				.text{
					text-align: left;
					.gender-item-woman{
						margin-left: 40upx;
					}
				}
			}
			.zhcx-upload{
				margin-top: 20upx;
			}
		}
	}
	.handle-wrap{
		&{
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			padding: 10upx 0;
		}
		.submit-BT{
			width: 702upx;
			height: 100upx;
			line-height: 100upx;
			text-align: center;
			background-color: #3384FF;
			border-radius: 12upx;	
			color: #fff;
			font-size: 32upx;
			margin: 0 auto;
		}				
	}
</style>
