<template>
	<view class="search-image-content zhcx-table">
		<text class="head">添加医学影像</text>
		<p class="tip">支持各类图片，文件不大于10M</p>
		<view class="zhcx-upload" @click="uploadBt">
			<div class="icon"></div>
			<text class="uploadTitle">点击上传</text>
		</view>
		<button type="primary" class="submit-BT" @click="submit()">提交</button>	
	</view>
</template>

<script>
	import {upload} from '@/api/index';
	import {searchSubmit} from '@/api/patient';
	import {parseTime,notEmpty,deepClone} from '@/libs/index';	
	export default{
		data(){
			return{
				diseaseImgDesc:[]
			}
		},
		methods:{
			submit(){
				searchSubmit({
					diseaseDesc:"",
					seekTime:parseTime(new Date()),
					site:"[]",
					diseaseImgDesc:JSON.stringify(this.diseaseImgDesc)
				}).then((res)=>{
					if(res.code===0){
						/**检索成功返回ai推荐数据 */
						uni.setStorageSync('aidiagnoseInfo',res.data)
						uni.navigateTo({
							url: '/views/patientItems/diagnose/index'
						});
					}
				})		
			},			
			uploadBt(){
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;		
						this.uploadSubmit(tempFilePaths[0])
					}
				});			
			},
			uploadSubmit(filePath){
				let diseaseImgDesc=deepClone(this.diseaseImgDesc);
				upload({filePath}).then((res)=>{
					let cont=JSON.parse(res);
					uni.showToast({
						title:"上传成功",
						icon:'success'
					})				
					diseaseImgDesc.push({
						path:cont.data.path
					})
					this.diseaseImgDesc=diseaseImgDesc;
				}).catch((msg)=>{
					uni.showToast({
						title:"上传失败"
					})
				})	
			},			
		}
	}
</script>
	
<style lang="scss" scoped>
	.search-image-content{
		padding-top: 100upx;
		.head{
			padding-left: 59upx;
			font-size: 30upx;
			color: #333;
		}
		.tip{
			padding: 8upx 0 16upx 59upx;
			font-size: 24upx;
			color: #3584FF;
		}	
		.submit-BT{
			display: block;
			width: 702upx;
			height: 98upx;
			line-height: 98upx;
			text-align: center;
			color: #fff;
			font-size: 32upx;
			letter-spacing: 4upx;
			margin-top: 240upx;
			background-color: #3384FF;
		}		
	}

</style>
