<template>
	<view class="content pkconp">
		<view class="headerTop">
			<view class="left">
				<image :src="memInfo.headimg" class="image1"></image>
			</view>
			<view class="right">
				<view class="name">{{memInfo.name?memInfo.name:memInfo.nickname}}</view>
				<view class="top">
					<view>
						{{$t("common.infoGender")}}：{{memInfo.gender=='0'?$t("common.infoUnknown"):memInfo.gender=='1'?$t("common.infoMan"):$t("common.infoWoman")}}
					</view>
					<view class="ml-15">{{$t("common.infoAge")}}：{{user.age}}{{$t("common.infoAgeunit")}}</view>
				</view>
			</view>
		</view>
		<view class="box" v-if="acd_id==2">
			<view class="item">
				<view>{{memInfo.day?memInfo.day:'0'}}</view>
				<text>{{$t("contrast.time")}}</text>
			</view>
			<view class="item">
				<view>{{memInfo.weightdiff?Math.abs(memInfo.weightdiff):0}}</view>
				<text v-if="Number(memInfo.weightdiff)>0">{{$t("contrast.weightdiffAugment")}}(kg)</text>
				<text v-else>{{$t("contrast.weightdiff")}}(kg)</text>
			</view>
			<view class="item">
				<view>{{memInfo.fat_wdiff?Math.abs(memInfo.fat_wdiff):0}}</view>
				<text v-if="Number(memInfo.fat_wdiff)>0">{{$t("contrast.fatWdiffAugment")}}(kg)</text>
				<text v-else>{{$t("contrast.fatWdiff")}}(kg)</text>
			</view>
			<view class="time">
				<view>
					<uni-icons class="t-icon t-icon-shijian-mianxing-0"></uni-icons>{{memInfo.time}}
				</view>{{$t("contrast.changeData")}}
			</view>
		</view>
		<view class="boxTime" v-else>
			<view class=" mt-10 mb-10">
				<uni-icons class="t-icon t-icon-shijian-mianxing-0 mr-10 size18"></uni-icons>
				{{memInfo.time}}
			</view>
			{{$t("contrast.changeData")}}
		</view>
		<view class="control">
			<!-- 名称 -->
			<view class="title">
				<view class="name"></view>
				<view>{{$t("contrast.trend")}}</view>
				<view>{{$t("contrast.before")}}</view>
				<view>{{$t("contrast.after")}}</view>
			</view>
			<view v-for="(ite,ind) in listStr" :key="ind" class="li">
				<view class="name">
					<text>{{ite.title}}</text>
				</view>
				<view class="num">
					<text
						v-if="ite.diffval!=0||ite.diffval=='0.00'||ite.diffval=='00:00:00'">{{acd_id!=6?Math.abs(ite.diffval):ite.diffval}}</text>
					<icon class="t-icon t-icon-shang" v-if="Number(ite.diffval)>0"></icon>
					<icon class="t-icon t-icon-xia" v-if="Number(ite.diffval)<0"></icon>
					<icon class="t-icon t-icon-hengxian"
						v-if="!ite.diffval||ite.diffval=='0.00'||ite.diffval=='00:00:00'"></icon>
				</view>
				<view class="f">
					<view>{{ite.firstresult?ite.firstresult.value:'-'}}</view>
					<text>{{ite.firstresult.level}}</text>
				</view>
				<view class="f">
					<view>{{ite.secondresult?ite.secondresult.value:'-'}}</view>
					<text>{{ite.secondresult.level}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";

	export default {
		onLoad(options) {
			let that = this
			// 导航栏颜色
			console.log("options", options)
			if (options.info) {
				let info = JSON.parse(options.info)
				that.acd_id = info.type
				that.handleSharepic(JSON.parse(options.info))
			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('common.titleDetail'),
			})
		},
		computed: {
			...mapState(["user", "appTheme"]),
		},
		methods: {
			handleSharepic(info) {
				let that = this
				that.$model.getresultcontrast({
					type: info.type,
					before_id: info.before_id,
					after_id: info.after_id,
				}).then(res => {
					console.log("res", res)
					if (res.code != 0) {
						this.$tools.msg(res.msg)
						return
					}
					res.data.list.forEach(ite => {
						if (ite.firstresult && ite.firstresult.name == 'weight') {
							res.data.weightdiff = ite.diffval
						}
						if (ite.firstresult && ite.firstresult.name == 'fat_w') {
							res.data.fat_wdiff = ite.diffval
						}
						if (ite.firstresult || ite.secondresult) {
							ite.name = ite.firstresult ? ite.firstresult.name : ite.secondresult.name
							ite.title = ite.firstresult ? ite.firstresult.title : ite.secondresult.title
						}
					})
					that.memInfo = res.data
					that.listStr = res.data.list
				})
			},
		},
		data() {
			return {
				memInfo: {},
				listStr: [],
				acd_id: "",
			}
		},
	}
</script>

<style scoped lang="scss">
	.age {
		margin-right: 20px;
	}

	.icon {
		width: 18px;
		height: 18px;
		padding: 3px;
		margin-right: 7px;
		background-color: #aaa;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.t-icon-hengxian {
		height: 2px;
		width: 10px;
	}
</style>