<template>
	<view class="main">
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">头像</view>
				<image class="cu-avatar radius bg-gray" @click="ChooseImage" :src='imgList[0]' mode='aspectFill'>
				</image>
			</view>
			<view class="cu-form-group">
				<view class="title">就诊人姓名:</view>
				<input v-model="name" placeholder-style="text-align:right" style="text-align: right;" placeholder="请输入姓名"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">就诊人性别:</view>
				<u-radio-group v-model="value" @change="radioGroupChange">
					<u-radio v-for="(item, index) in list" :key="index" :name="item.name" :disabled="item.disabled">
						{{item.name}}
					</u-radio>
				</u-radio-group>
			</view>
			<view class="cu-form-group">
				<view class="title">出身年月:</view>
				<picker mode="date" :value="date" @change="bindDateChange">
					<view class="picker">
						{{date}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group" @click="show=!show">
				<view class="title">与就诊人关系:</view>
				<picker :value="guanxi" @change="confirm" :range="guanxilist" range-key="label">
					<view class="picker">
						{{guanxi}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">就诊信息(非必填)</view>
			</view>
			<view class="cu-form-group">
				<view class="title">就诊人身份证:</view>
				<input v-model="idcrad" placeholder-style="text-align:right" style="text-align: right;" placeholder="请输入就诊人身份证号"></input>
			</view>
			<view class="padding-sm bg-white" style="color: #C0C0C0;">
				注：就诊人信息用于平台审核和医疗业务使用，不会外传。请正却确填写就诊人信息，如需修改身份信息可电话联系客服修改（13330431369）
			</view>
		</form>
		<view class="cu-bar bg-white tabbar" style="position: fixed;bottom: 0;width: 100%;">
			<view class="submit" style="background-color: #0B73B9;color: white;" @click="addarchives">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad(options) {

		},
		onShow() {

		},
		data() {
			return {
				imgList: '',
				name: "",
				list: [{
						name: '男',
						disabled: false
					},
					{
						name: '女',
						disabled: false
					},
				],
				value: '男',
				date: "请选择出生日期",
				show: false,
				guanxi: "请选择",
				guanxiindex: -1,
				guanxilist: [{
						value: '1',
						label: '父亲'
					},
					{
						value: '2',
						label: '母亲'
					},
					{
						value: '3',
						label: '祖父'
					},
					{
						value: '4',
						label: '祖母'
					},
					{
						value: '5',
						label: '外祖父'
					},
					{
						value: '6',
						label: '外祖母'
					},
					{
						value: '7',
						label: '叔侄'
					}
				],
				idcrad: "",
				touxiang: ""
			}
		},
		methods: {
			ChooseImage() {
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: (res) => {
						this.imgList = res.tempFilePaths
						this.$request.upload("/api/v1/common/uploadFile", this.imgList[0]).then(data => {
							let re = JSON.parse(data)
							if (re.status == 0) {
								this.touxiang = re.data.url
								console.log(this.touxiang)
							}
						})

					}
				});
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				this.value = e
			},
			bindDateChange({
				detail
			}) {
				this.date = detail.value
			},
			confirm(e) {
				this.guanxiindex = e.detail.value
				this.guanxi = this.guanxilist[e.detail.value].label
			},
			addarchives: async function() {
				let num = 0
				if (this.value == "男") {
					num = 1
				} else {
					num = 2
				}
				if (this.imgList[0] !== undefined && this.name != "" && this.date != "请选择出生日期" && this.guanxiindex != -1 && this.idcrad !=
					"" && this.$util.isIdCard(this.idcrad)) {
					let res = await this.$request.post("/api/v1/patient/createPatient", {
						name: this.name,
						sex: num,
						avatar: this.touxiang,
						birthday: this.date,
						relationship_type: this.guanxiindex,
						card_type: 1,
						card_number: this.idcrad
					})
					console.log(res)
					if (res.status == 0) {
						uni.showToast({
							title: "提交成功",
							icon: "none",
							duration: 1500
						})
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1500)
					}

				} else {
					uni.showToast({
						title: "请填写完整",
						icon: "none"
					})
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	.main {}
</style>
