<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>性别：{{memInfo.gender=='0'?'未知':memInfo.gender=='1'?'男':'女'}}</view>
					<view>年龄：{{user.age}}岁</view>
				</view>
			</view>
		</view>
		<view class="box" v-if="acd_id==2">
			<view class="item">
				<view>{{memInfo.day?memInfo.day:'0'}}</view>
				<text>时间(天)</text>
			</view>
			<view class="item">
				<view>{{memInfo.weightdiff?Math.abs(memInfo.weightdiff):0}}</view>
				<text v-if="Number(memInfo.weightdiff)>0">增重(kg)</text>
				<text v-else>减重(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">增脂(kg)</text>
				<text v-else>减脂(kg)</text>
			</view>
			<view class="time">
				<view>
					<uni-icons class="t-icon t-icon-shijian-mianxing-0"></uni-icons>{{memInfo.time}}
				</view>数据变化
			</view>
		</view>
		<view class="boxTime" v-else>
			<view class="">
				<uni-icons class="t-icon t-icon-shijian-mianxing-0"></uni-icons>
				{{memInfo.time}}
			</view>
			数据变化
		</view>
		<view class="control">
			<!-- 名称 -->
			<view class="title">
				<view class="name"></view>
				<view>趋势</view>
				<view>之前</view>
				<view>之后</view>
			</view>
			<view v-for="(ite,ind) in listStr" :key="ind" class="li">
				<view class="name">
					<!-- 	<view class="icon">
						<view class="t-icon" :class="'t-icon-'+ite.name"></view>
					</view> -->
					<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))
			}
		},
		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>