<template>
	<view class="m-3 mb-5">
		<view class="centerY mt-3">
			<view class="bule_line" style=""></view>
			<text class="font-bold text-dark ml-2 fs-16 line-height1">检测结果一栏</text>
		</view>
		<view class="mt-3 bg-white p-3">
			<view class="">
				<view class="mtable-title centerY bg-primary text-white fs-12">
					<view class="text-center w-25">
						检查项
					</view>
					<view class=" text-center w-40">
						标准值
					</view>
					<view class="text-center  w-35">
						当前结果
					</view>
				</view>
				<view class="mtable-body-item centerY fs-12" v-for="(item,index) in datatable1" style="color: #868687;">
					<view class="text-center w-25">
						{{item.title}}
					</view>
					<view class="text-center w-40 text-green2" v-if="propData.patient.sex==1">
						{{item.standard1}}
					</view>
					<view class="text-center w-40 text-green2" v-if="propData.patient.sex==2">
						{{item.standard2}}
					</view>
					<view class="text-center w-40">
						<span v-if="item.type==1">{{item.value}} {{item.value=='未测量'?'':item.unit}}</span>
						<span v-if="item.type==0" class="text-error">{{item.value }}
							{{item.value=='未测量'?'':item.unit}}</span>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const config = {
		pulse: [60, 100],
		temperature: [36.5, 37.5],
		shrink: [90, 139],
		diastole: [60, 90],
		shrinktop: [90, 149], //大于65
		shrinklow: [90, 139], //小于65  
		bmi: [18.50, 23.90],
		urine1: [
			[53, 106],
			[44, 97], "肌酐"
		],
		urine2: [0, 30, "微量白蛋白"],
		urine3: [8.4, 13.2, "尿微/肌酐"],
		kidney1: [
			[208, 428],
			[155, 357], "血尿酸"
		],
		kidney2: [
			[54, 133],
			[44, 97], "血肌酐"
		],
		kidney3: [13.9, 6.1, "尿素氮"],
		bloodFat1: [0.45, 1.7, "甘油三酯"],
		bloodFat2: [2.85, 5.69, "总胆固醇"],
		bloodFat3: [0, 3.4, "低密度脂蛋白"],
		bloodFat4: [1.16, 1.55, "高密度脂蛋白"],
		lvision: [1.0, 5.0, '左视力'],
		rvision: [1.0, 5.0, '右视力'],
		bloodGlucose: [3.9, 6.9, '血糖'],
		chol: [2.85, 5.69, '总胆固醇'],
		ua: [
			[149, 416],
			[89, 357], '尿酸'
		],
		spo2: [95, 99, '血氧'],
		rxyl: [0, 0],
		ryjl: [0, 0],
	}
	let data1 = {
		checkList: [],
		visit: {
			"id": 1336,
			"isSend": 0,
			"sendTime": null,
			"idCard": "123456200001011212",
			"opUserId": 35,
			"type": "gxy",
			"sfys": "王医生",
			"sffs": "门诊",
			"zg": "继续随访",
			"zdsf": 1,
			"mqzz": "[\"无症状\"]",
			"xltz": "良好",
			"zyxw": "良好",
			"fyqk": "规律",
			"ywfy": "无",
			"rxyl": 0,
			"rxylzd": 0,
			"ryjl": 0,
			"ryjlzd": 0,
			"ydcs": 2,
			"ydcszd": 6,
			"ydsj": 30,
			"ydsjzd": 30,
			"sycd": "中",
			"sycdzd": "轻",
			"zs": null,
			"zszd": null,
			"tzzd": 29,
			"bmizd": 23.8,
			"ywzd": 89,
			"sffl": "控制满意",
			"gljb": "三级管理",
			"xcyy": "2022-10-06",
			"zz": 0,
			"zzyy": "",
			"zzjg": "",
			"jkcf": "1. 定期检查血脂，控制高脂肪饮食，不吃动物的内脏及其制品，可常食用黑木耳、山楂等。肥胖者需控制体重。\n2. 建议接种流感疫苗和肺炎疫苗。\n3. 饮食宜用低盐饮食，食盐每天不超过5～10克(1～2钱)。\n4. 从卧位到立位时不能太快，以防止发生直立性低血压。\n5. 保持大便畅通。",
			"zdmbd": "触及正常",
			"yds": "无",
			"ydsyl": "",
			"dxtfy": "无",
			"xtlx": "空腹血糖",
			"xtz": 0,
			"thxhdb": "",
			"jcrq": "2022-09-06",
			"bqgss": "",
			"zzqt": "无",
			"tzqt": "无",
			"height": 112,
			"weight": 50,
			"bmi": 39.9,
			"waist": 1231,
			"shrink": 123,
			"diastole": 11,
			"pulse": 31,
			"temperature": 312,
			"bloodGlucose1": null,
			"bloodGlucose2": null,
			"medicinalList": "[{\"id\":773,\"idCard\":\"123456200001011212\",\"opUserId\":1,\"name\":\"拉西地平片\",\"type\":\"Gxy\",\"medicinalUnit\":\"mg\",\"unit\":\"4\",\"medicinalUse\":\"口服\",\"medicinalInterval\":\"1天/1次\",\"untowardReaction\":\"无\",\"medicinalId\":null,\"medicineUnitId\":null,\"usageId\":null,\"wayId\":null,\"createTime\":\"2022-08-05\"}]",
			"visitSendId": null,
			"doctorId": null,
			"jkdaGljb": "",
			"bloodFat1": null,
			"bloodFat2": null,
			"bloodFat3": null,
			"bloodFat4": null,
			"createTime": "2022-09-06T10:30:09",
			"updateTime": "2022-09-06T10:30:09",
			"isDelete": 0,
			"otherDisease": "无",
			"lgmjzsj": null,
			"fymjzsj": null,
			"qttz1": "无",
			"lgymjzyy": "0",
			"ymgz": "0",
			"fyymjzyy": "0",
			"outVisterDoctor": null,
			"brjy": null,
			"outVisterSign": null,
			"BackVisitorDate": null
		}
	}
	export default {
		name: 'DetectionResult',
		data() {
			return {
				datatable1: [{
						title: 'BMI',
						value: '',
						standard1: '18.5~24 kg/m²',
						standard2: '18.5~24 kg/m²',
						type: 1,
						key: 'visit',
						key1: 'bmi',
						unit: 'kg/m²',
					},
					{
						title: '腰围',
						value: '',
						standard1: '<90 cm',
						standard2: '<85 cm',
						type: 1,
						key: 'visit',
						key1: 'waist',
						unit: 'cm',
					},
					{
						title: '收缩压',
						value: '',
						standard1: '<140 mmHg',
						standard2: '<140 mmHg',
						type: 1,
						key: 'visit',
						key1: 'shrink',
						unit: 'mmHg',
					},
					{
						title: '舒张压',
						value: '',
						standard1: '<90 mmHg',
						standard2: '<90 mmHg',
						type: 1,
						key: 'visit',
						key1: 'diastole',
						unit: 'mmHg',
					},
					{
						title: '心率',
						value: '',
						standard1: '60~90 次/分钟',
						standard2: '60~90 次/分钟',
						type: 1,
						key: '',
						key1: 'pulse',
						unit: '次/分钟',
					},
					{
						title: '吸烟',
						value: '',
						standard1: '戒烟',
						standard2: '戒烟',
						type: 1,
						key: '',
						key1: 'rxyl',
						unit: '根 ',
					},
					{
						title: '喝酒',
						value: '',
						standard1: '戒酒',
						standard2: '戒酒',
						type: 1,
						key: '',
						key1: 'ryjl',
						unit: 'ml',
					},
					{
						title: '血糖',
						value: '',
						standard1: '3.9~6.9 mmol/L',
						standard2: '3.9~6.9 mmol/L',
						type: 1,
						key: 'checkList',
						key1: 'bloodGlucose',
						unit: 'mmol/L',
					},
					{
						title: '血氧',
						value: '',
						standard1: '>=90 %',
						standard2: '>=90 %',
						type: 1,
						key: 'checkList',
						key1: 'spo2',
						unit: '%',
					},
					{
						title: '糖化血红蛋白',
						value: '',
						standard1: '<6.5%',
						standard2: '<6.5%',
						type: 1,
						key: '',
						key1: 'thxhdb',
						unit: '%',
					},
					{
						title: '总胆固醇',
						value: '',
						standard1: '2.85~5.69 mmol/L',
						standard2: '2.85~5.69 mmol/L',
						type: 1,
						key: 'checkList',
						key1: 'chol',
						unit: 'mmol/L',
					},
					{
						title: '甘油三酯',
						value: '',
						standard1: '0.45~1.7 mmol/L',
						standard2: '0.45~1.7 mmol/L',
						type: 1,
						key: 'checkList',
						key1: 'bloodFat1',
						unit: 'mmol/L',
					},
					{
						title: '低密度脂蛋白',
						value: '',
						standard1: '0~3.4 mmol/L',
						standard2: '0~3.4 mmol/L',
						type: 1,
						key: 'checkList',
						key1: 'bloodFat3',
						unit: 'mmol/L',
					},
					{
						title: '高密度脂蛋白',
						value: '',
						standard1: '1.16~1.55 mmol/L',
						standard2: '1.16~1.55 mmol/L',
						type: 1,
						key: 'checkList',
						key1: 'bloodFat4',
						unit: 'mmol/L',
					},
					{
						title: '肌酐',
						value: '',
						standard1: '53~106 μmol/L',
						standard2: '44~97 μmol/L',
						type: 1,
						key: 'checkList',
						key1: 'urine1',
						unit: 'μmol/L',
					},
					{
						title: '微量白蛋白',
						value: '',
						standard1: '0~30 mg/L',
						standard2: '0~30 mg/L',
						type: 1,
						key: 'checkList',
						key1: 'urine2',
						unit: 'mg/L',
					},
					{
						title: '尿酸',
						value: '',
						standard1: '149~416 μmol/L',
						standard2: '89~357 μmol/L',
						type: 1,
						key: 'checkList',
						key1: 'ua',
						unit: 'μmol/L',
					},
				],
			}
		},
		props:{
			propData: {
				type: Object,
				default () {
					return {
						patient: {},
						checkResult:{}
					}
				},
			},
		},
		watch: {
			propData: {
				handler(val) {
					if(val.patient.id){
						this.setlist(val.checkResult)
					}
				},
			},
		},
		created() {
			
		},
		methods: {
			setlist(checkResult) {
				if (checkResult.bmi) {
					let checkList = data1.checkList[0] || {}
					this.datatable1.map((item, index) => {
						if (item.key == 'checkList') {
							this.datatable1[index].value = this.filterA(
								checkList[item.key1],
								item.key1
							).value
							this.datatable1[index].type = this.filterA(
								checkList[item.key1],
								item.key1
							).type
						} else {
							this.datatable1[index].value = this.filterA(
								data1.visit[item.key1],
								item.key1
							).value
							this.datatable1[index].type = this.filterA(
								data1.visit[item.key1],
								item.key1
							).type
						}
					})
				} else {
					this.datatable1.map((item, index) => {
						this.datatable1[index].value = '未测量'
						this.datatable1[index].type = 1
					})
				}
			},
			filterA(val, key) {
				// console.log(key, val)
				if ((val != 0 && this.$mf.isEmpty(val)) || String(val) == '') {
					// console.log(key, val, val != 0, '0' == '')
					return {
						value: '未测量',
						type: 1
					}
				}
				return {
					value: val,
					type: this.check({
							type: key,
			  		value: val,
							age: this.propData.patient.age,
							sex: this.propData.patient.sex,
						}) ?
						0 :
						1,
				}
			},
			check({
				type,
				value,
				age,
				sex
			}) {
				let msg = this.propData.patient
				let arr = config

				if (!arr[type]) {
					return false
				}
				if (type == 'shrink' && age) {
					if (msg.age > 65) {
						if (value > arr['shrinktop'][1]) {
							return true
						}
						if (value < arr['shrinktop'][0]) {
							return true
						}
					} else {
						if (value > arr['shrinklow'][1]) {
							return true
						}
						if (value < arr['shrinklow'][0]) {
							return true
						}
					}
				}

				if (sex) {
					if (msg.sex == 1) {
						if (value > arr[type][0][1]) {
							return true
						}
						if (value < arr[type][0][0]) {
							return true
						}
					} else {
						if (value > arr[type][1][1]) {
							return true
						}
						if (value < arr[type][1][0]) {
							return true
						}
					}
				}

				if (value > arr[type][1]) {
					return true
				}
				if (value < arr[type][0]) {
					return true
				}
				return false
			},
			

		}
	}
</script>

<style lang="scss">
	page {
		background: #F5F9FF;
	}

	.mtable {
		&-title {
			border-radius: 50rpx;
			padding: 20rpx 0 20rpx 20rpx;
			box-shadow: 0px 2px 7px 1px rgba(45, 142, 255, 0.5);
		}

		&-body {
			&-item {
				margin-top: 20rpx;
				border-radius: 50rpx;
				padding: 14rpx 0 14rpx 20rpx;
				background-color: #F6F9FE;
				color: #868687;
			}
		}
	}
</style>
