<template>
	<view class="app">
		<view class="title">
			<view class="left">
			</view>
			<view class="right">
				第一步：填写个人信息
			</view>
		</view>
		<view class="item">
			<view class="text">
				现住址所在区
			</view>
			<view class="input" @tap='showPicker'>
				<view class="inputtext"
					:style="address=='请选择所属地区'?'font-size:22rpx;font-weight: 400;color: #8E8E8E !important;':''">
					{{address}}
				</view>
				<image src="../../static/huijiantou.png" mode=""></image>
			</view>
			<view class="text">
				患者姓名
			</view>
			<view class="input">
				<input v-model="formdata.patientName" class="uinput noimageuinput" placeholder="请输入患者姓名" type="text"
					placeholder-class="phsy" />
			</view>
			<view class="text">
				患者身份证号
			</view>
			<view class="input">
				<input v-model="formdata.cardNo" class="uinput noimageuinput" placeholder="请输入患者身份证号" type="text"
					placeholder-class="phsy" />
			</view>
			<view class="text">
				患者联系电话
			</view>
			<view class="input">
				<input v-model="formdata.phone" class="uinput noimageuinput" placeholder="请输入患者联系电话" type="text"
					placeholder-class="phsy" />
			</view>
			<view class="text">
				选择医生
			</view>
			<view class="select" @tap='gochoosedoctor'>
				<text v-if="!doctorName">请选择医生</text>
				<text v-else style="font-size: 26rpx;color: #303133;">{{doctorName}}</text>
				<image src="../../static/huijiantou.png" mode=""></image>
			</view>
		</view>
		<view class="title">
			<view class="left">
			</view>
			<view class="right">
				第二步：填写问诊信息
			</view>
		</view>
		<view class="item">
			<view class="text">
				问题简述
			</view>
			<view class="input">
				<input v-model="formdata.problemDescription" class="uinput noimageuinput" placeholder="不多于五个字"
					type="text" placeholder-class="phsy" :maxlength="5" />
			</view>
			<view class="text">
				患者个体情况说明
			</view>
			<view class="input" style="height: 200rpx;overflow-Y: scroll;">
				<u-input v-model="formdata.situationDescription" class="uinput noimageuinput" placeholder=" "
					type="textarea" :maxlength="100" />
			</view>
			<view class="text">
				问题描述
			</view>
			<view class="input" style="height: 200rpx;overflow-Y: scroll;">
				<u-input v-model="formdata.problemStatement" class="uinput noimageuinput" placeholder=" "
					type="textarea" :maxlength="500" />
			</view>
			<view class="text">
				既往疾病史
			</view>
			<view class="input" style="height: 200rpx;overflow-Y: scroll;">
				<u-input v-model="formdata.medicalRecord" class="uinput noimageuinput" placeholder=" " type="textarea"
					:maxlength="100" />
			</view>
		</view>
		<view class="title">
			<view class="left">
			</view>
			<view class="right">
				第三步：上传附件文件
			</view>
		</view>
		<view class="item">
			<view class="text">
				附件材料上传
			</view>
			<u-upload ref="uUpload" :max-count='9' :action="uoloadaction" :auto-upload="false" upload-text=' '
				@on-choose-complete='onchoosecomplete' @on-uploaded='onuploaded'></u-upload>
			<!-- @on-success='onsuccess' -->
			<view class="textarea">
				<view class="">
					最多支持9个文件；
				</view>
				<view class="">
					单个文件大小不允许超过10MB；
				</view>
				<view class="">
					只支持上传照片图片、视频文件，后缀类型为：JPG.PNG.MP4
				</view>
			</view>
		</view>
		<view class="btns">
			<view class="btnleft">
				返回
			</view>
			<view class="btnright" @tap='updata'>
				保存
			</view>
		</view>
		<view class="">
			<m-city style='z-index: 10076;' :provinceData="list" headTitle="请选择所属地区" ref="cityPicker"
				@funcValue="getpickerParentValue" pickerSize="4">
			</m-city>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getSubordinateRegions,
	} from '@/api/pagesB/modifyAddress/modifyAddress.js';
	import gkcity from "../../components/m-city/m-city.vue";
	import baseurl from '@/api/baseurl.js'
	import {
		consultationInfo,
		detail,
	} from '@/api/pagesB/createnewconsultation/createnewconsultation.js'

	import {
		getHospitalPersonInfo
	} from '@/api/pagesC/contractsigningprotocol/index.js'
	// import consultationplatformVueHtml from '../consultationplatform/consultationplatform.vue.html';
	export default {
		components: {
			"m-city": gkcity
		},
		data() {
			return {
				// 非真实地址
				uoloadaction: '',
				list: [],
				addresslength: null,
				imglistlength: null,
				address: '请选择所属地区', //页面所属区域
				formdata: {
					address: '', //页面所属区域
					patientId: '',
					patientName: '',
					cardNo: '',
					phone: '',
					doctorId: '',
					doctorName: '',
					consultationType: 'IMAGE_TEXT_CONSULTATION',
					problemDescription: '',
					situationDescription: '',
					problemStatement: '',
					medicalRecord: '',
					fileUrls: [],
				},
				doctorlist: [],
				doctorName: '',
				doctorId: '',
			};
		},
		onLoad(options) {
			this.uoloadaction = baseurl + '/nurseApplet/consultationInfo/uploadConsultationFile'
			this.formdata = uni.getStorageSync('userinfo')
			this.formdata.address = ''
			this.formdata.fileUrls = []
			this.infolist()
			this.areaInfo();
		},
		onShow() {
			let that = this
			uni.$on('doctordata', function(data) {
				let item = JSON.parse(data.data)
				that.formdata.doctorName = item.personName
				that.formdata.doctorId = item.id
				uni.$off('doctordata')
			})
		},
		methods: {
			updata() {
				this.formdata.doctorName = this.doctorName
				this.formdata.doctorId = this.doctorId
				if (this.imglistlength > 0) {
					this.$refs.uUpload.upload()
				} else {
					this.info();
				}
			},
			onchoosecomplete(lists, name) {
				this.imglistlength = lists.length
			},
			// onsuccess(data, index, lists, name) {
			// 	if (data.code == 200) {
			// 		this.formdata.fileUrls.push(data.fileUrl)
			// 	}
			// },
			onuploaded(lists, name) {
				this.formdata.fileUrls = []
				lists.forEach(e => {
					this.formdata.fileUrls.push(e.response.fileUrl)
				})
				this.info();
			},
			info() {
				this.$delete(this.formdata, 'id')
				this.formdata.patientId=uni.getStorageSync("patientId")
				this.formdata.consultationType = 'IMAGE_TEXT_CONSULTATION'
				if (!this.formdata.address) {
					this.$refs.uToast.show({
						title: '请选择地址',
						type: 'error',
						duration: '1500',
					})
				} else if (!this.formdata.patientName) {
					this.$refs.uToast.show({
						title: '请选择姓名',
						type: 'error',
						duration: '1500',
					})
				} else if (!this.formdata.cardNo) {
					this.$refs.uToast.show({
						title: '请选择身份证号',
						type: 'error',
						duration: '1500',
					})
				} else if (!this.formdata.phone) {
					this.$refs.uToast.show({
						title: '请选择手机号',
						type: 'error',
						duration: '1500',
					})
				} else if (!this.formdata.doctorName) {
					this.$refs.uToast.show({
						title: '请选择医生',
						type: 'error',
						duration: '1500',
					})
				} else if (!this.formdata.problemDescription) {
					this.$refs.uToast.show({
						title: '请输入问题简述',
						type: 'error',
						duration: '1500',
					})
				} else if (!this.formdata.situationDescription) {
					this.$refs.uToast.show({
						title: '请输入患者个体说明',
						type: 'error',
						duration: '1500',
					})
				} else if (!this.formdata.medicalRecord) {
					this.$refs.uToast.show({
						title: '请输入既往疾病史',
						type: 'error',
						duration: '1500',
					})
				} else {
					consultationInfo(this.formdata).then(res => {
						if (res.code == 200) {
							this.$refs.uToast.show({
								title: '新建图文问诊成功',
								type: 'success',
								duration: '1500',
								back: 1
							})
						} else if (res.code == 500) {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error',
								duration: '1500',
							})
						}
					})
				}
			},
			// 显示三级地址联动
			showPicker() {
				this.$refs.cityPicker.show();
			},
			//区街道
			areaInfo() {
				getSubordinateRegions().then(res => {
					this.list = res.data;
				})
			},
			// 三级地址联动回调
			getpickerParentValue(e) {
				e = e.filter(ele => ele.localName != '暂不选择')
				e = e.filter(ele => ele.localName != '暂无需选择')
				this.addresslength = e
				this.formdata.address = ''
				this.address = ''
				if (e && e.length >= 1) {
					e.forEach(el => {
						this.formdata.address = this.formdata.address + el.localName
						this.address = this.address + el.localName
					})
				} else {
					this.formdata.address = ''
					this.address = '请选择所属地区'
				}
			},
			infolist() {
				detail(this.formdata.cardNo).then(res => {
					var status = '1'
					if (res.code == 200) {
						getHospitalPersonInfo(res.data.dutyDoctorNo, status).then(res => {
							this.doctorName = res.data.personName
							this.doctorId = res.data.id
							this.doctorlist = res.data
						})
					} else if (res.code == 500) {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
							duration: '1500',
						})
					}
				})
			},
			gochoosedoctor() {
				console.log(this.doctorlist, '44444')
				// detail(this.formdata.cardNo).then(res => {
				// 	var status = '1'
				// 	getHospitalPersonInfo(res.data.dutyDoctorNo, status).then(res => {
				// 		console.log(res, '55')
				// 		this.doctorlist = res.data

				uni.navigateTo({
					url: `/pagesC/choosedoctor/choosedoctor?item=${JSON.stringify(this.doctorlist)}`
				})
				// })

				// })



			},
		}
	}
</script>

<style lang="scss">
	@import './createnewconsultation.scss';
</style>