<template>
	<view class="screeningResult">
		<view class="conTop">
			<view style="display: flex;align-items: center;">
				<view style="background-color: #4DC2A8;height: 20px;width: 3px;margin-right: 5px;"></view>
				<view style="color: #7C7C7C;">
					筛查日期：{{ screeningResultData.screeningDate ? screeningResultData.screeningDate : '无' }}</view>
			</view>
			<view style="color: #2968F1;" @click="goToScreeningRecord" v-show="type != '1'">筛查记录</view>
		</view>
		<view class="tabbarCon">
			<view
				style="text-align: center;color: #26A888;border-bottom: 1rpx solid #26A888;padding-top: 17rpx;position: relative;left: 50%;transform: translate(-50%);display: inline-block;"
				v-if="screeningResultData.projectName">
				{{screeningResultData.projectName}}
			</view>
			<uni-segmented-control :current="Inv" :values="items" @clickItem="onClickItem" styleType="text"
				activeColor="#4AC4AB"></uni-segmented-control>
			<view class="content">
				<view v-show="Inv == 0">
					<view style="text-align: center;">
						<view class="" v-if="screeningResultData.fileType=='docx'||screeningResultData.fileType=='doc'">
							<view class="btn" @click="lookpath" v-if="screeningResultData.attachment">
								查看报告
							</view>
						</view>
						<view class="" v-else>
							<view v-if="screeningResultData.attachment && screeningResultData.attachment != '找不到指定文件!'">
								<view style="display: flex;justify-content: space-around;">
									<view style="width: 49%;" @click="xxbClick(screeningResultData.attachment)">
										<image style="width: 100%;height: 100px;"
											:src="'data:image/jpeg;base64' + screeningResultData.attachment"></image>
									</view>
									<view style="width: 49%;" @click="picClick1(screeningResultData.attachmentTwo)">
										<image style="width: 100%;height: 100px;"
											:src="'data:image/jpeg;base64' + screeningResultData.attachmentTwo"></image>
									</view>
								</view>
							</view>
						</view>
						<view v-else style="margin: 10px auto; ">
							<u-empty text="暂无照片" mode="data"></u-empty>
						</view>
					</view>
				</view>
				<view v-show="Inv == 1">
					<view>
						<view
							v-if="screeningResultData.projectRecordList[1].attachment && screeningResultData.projectRecordList[1].attachment != '找不到指定文件!'">
							<view style="width: 50%;"
								@click="xxbClick(screeningResultData.projectRecordList[1].attachment)">
								<image style="width: 100%;height: 100px;"
									:src="'data:image/jpeg;base64' + screeningResultData.projectRecordList[1].attachment">
								</image>
							</view>
						</view>
						<view v-else style="margin: 10px;">
							<u-empty text="暂无照片" mode="data"></u-empty>
						</view>
					</view>
				</view>
				<view v-show="Inv == 2">
					<view style="text-align: center;">
						<!-- <u-grid :border="false" col="3">
              <u-grid-item v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex">
                <view style="width: 100%;">
                  <image style="width: 90%;" :src="baseListItem.src" mode="widthFix"></image>
                </view>
              </u-grid-item>
            </u-grid> -->
					</view>
					<!-- <view>
            <view style="font-size: 32rpx;font-weight: bold;color: #323232;">诊断结果</view>
            基底动脉血流速度减低,左右大脑中动脉血流速度加快
          </view> -->
				</view>
			</view>
		</view>
		<u-popup :show="show" @close="close" @open="open" mode="center">
			<view style="text-align: center;">
				<image :src="'data:image/jpeg;base64' + fileImgSrc" mode="widthFix"></image>
			</view>
		</u-popup>
		<u-popup :show="show1" @close="close1" mode="center">
			<view style="text-align: center;">
				<image :src="'data:image/jpeg;base64' + fileImgSrc1" mode="widthFix"></image>
			</view>
		</u-popup>
		<u-popup :show="show2" @close="close2" mode="center">
			<view style="text-align: center;">
				<image :src="'data:image/jpeg;base64' + fileImgSrc2" mode="widthFix"></image>
			</view>
		</u-popup>
		<view style="margin: 10px;">
			<view style="font-size: 32rpx;font-weight: bold;color: #323232;">诊断结果</view>
			<view style="background-color: #fff;margin-top:10px;padding: 10px;">
				<!-- {{ myResultInfo ? myResultInfo : '无' }} -->
				{{ screeningResultData.diagnosticResult ? screeningResultData.diagnosticResult : '无' }}
			</view>
		</view>
	</view>
	</view>
</template>

<script>
	import {
		lastScreeningResult,
		screeningResultDetail
	} from '@/api/pagesB/screeningResult/screeningResult.js'
	import baseurl from '@/api/baseurl.js'
	export default {
		data() {
			return {
				myResultInfo: '',
				show: false,
				show1: false,
				show2: false,
				Inv: 0,
				// items: ['眼底病变筛查', '血小板功能筛查', '动脉粥样筛查'],
				//'糖尿病眼底病变筛查', '糖尿病血小板功能筛查',
				items: [],
				baseList: [{
					src: '../../static/ydPic.png'
				}, {
					src: '../../static/xxbPic.png'
				}, {
					src: '../../static/ydPic.png'
				}, {
					src: '../../static/ydPic.png'
				}],
				baseList1: [{
					src: '../../static/xxbPic.png'
				}],
				screeningResultData: '',
				type: '',
				fileImgSrc: '',
				fileImgSrc1: '',
				fileImgSrc2: '',
				registerId: "",
				baseurl: '',
			};
		},
		onShow() {
			this.baseurl = baseurl
		},
		onLoad(e) {
			this.type = e.type
			if (e) {
				this.registerId = e.registerId
				this.projectId = e.projectId
			}
			if (e.screeningId) {
				screeningResultDetail(e.screeningId).then(res => {
					this.items.push(res.data.projectName)
					this.screeningResultData = res.data
				})
			} else {
				this.userinfo = uni.getStorageSync('userinfo');
				this.patientld = this.userinfo.id;
				this.getLastScreeningResult()
			}
		},
		methods: {
			lookpath() {
				var that = this
				var url = that.baseurl +
					`/nurseApplet/screening/record/fileview?filePath=${that.screeningResultData.attachment}`
				uni.downloadFile({
					url: url,
					responseType: 'blob',
					success: function(resp) {
						var filePath = resp.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							fileType: that.screeningResultData.fileType.toLowerCase(),
							showMenu: true,
							success: function(respp) {},
							fail(err) {}
						});
					}
				})
			},
			onClickItem(e) {
				if (this.Inv != e.currentIndex) {
					this.Inv = e.currentIndex;
					this.getLastScreeningResult()
				}
			},
			isResult(inv) {
				for (let item in this.screeningResultData.projectRecordList) {
					if (this.screeningResultData.projectRecordList[item].projectName == (inv == 0 ? '糖尿病-眼底病变筛查' : (inv ==
							1 ?
							'糖尿病-血小板筛查' : ''))) {
						this.myResultInfo = this.screeningResultData.projectRecordList[item].diagnosticResult
						return
					}
				}
			},
			picClick(e) {
				this.show = true
				this.fileImgSrc = e
			},
			picClick1(e) {
				this.show1 = true
				this.fileImgSrc1 = e
			},
			xxbClick(e) {
				this.show2 = true
				this.fileImgSrc2 = e
			},
			close1() {
				this.show1 = false
			},
			close2() {
				this.show2 = false
			},
			open() {},
			close() {
				this.show = false
			},
			// 获取最新的筛查结果
			getLastScreeningResult() {
				lastScreeningResult(this.patientld, this.projectId).then(res => {
					if (res.code == 200 && res.data.projectName) {
						this.items.push(res.data.projectName)
					}
					this.screeningResultData = res.data
					this.isResult(this.Inv)
				})
			},
			changeTab(Inv) {
				that.navIdx = Inv;
			},
			goToScreeningRecord() {
				uni.navigateTo({
					// url: `../screeningRecord/screeningRecord?registerId=${this.registerId}`
					url: `/pagesB/screeningRecord/screeningRecord?registerId=${this.patientld}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.screeningResult {
		width: 96%;
		margin: 0 auto;

		.conTop {
			margin-top: 10px;
			display: flex;
			background-color: #F6F6F6;
			justify-content: space-between;
			align-items: center;
		}
	}

	/deep/ .segmented-control__text {
		font-size: 16px !important;
	}

	.tabbarCon {
		margin-top: 10px;
		background-color: #fff;
	}

	.content {
		padding: 30rpx 25rpx;
	}

	.inv-h-w {
		background-color: #FFFFFF;
		height: 100upx;
		display: flex;
		margin-bottom: 40rpx
	}

	.inv-h {
		font-size: 26rpx;
		flex: 1;
		text-align: center;
		color: #747474;
		height: 100upx;
		line-height: 100upx;
		position: relative;
	}

	.inv-h-se {
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 28rpx;
		color: #393939;
		border-bottom: 3px solid #4DC2A8;
	}
</style>