<template>
	<view class="app">
		<view class="tophealth">
			<image src="@/static/pagesC/self.png" mode=""></image>
			<span class="health">智慧健康驿站自评表</span>
			<span class="history" @tap='gohistory'>历史记录</span>
		</view>
		<view class="bodyhealth" v-for="item in list" @tap='gosurveySubject(item)'>
			<image :src="require('@/pagesC/images/books.png')"></image>
			<view class="risk">
				{{item.surveySubject==1001?'高血压评估问卷':item.surveySubject==1002?'糖尿病评估问卷':item.surveySubject==1003?
				'脑卒中评估问卷':item.surveySubject==1004?'慢阻肺评估问卷':item.surveySubject==1005?'慢病评估问卷':item.surveySubject==1006?'糖尿病肾病评估问卷':item.surveySubject==1007?
				'糖尿病眼病评估问卷':item.surveySubject==1008?'糖尿病足病评估问卷':''}}
			</view>
			<view class="estimate">风险评估</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		surveylist
	} from '@/api/pagesC/healthtest/index.js'
	export default {
		data() {
			return {
				list: [],
				total: 0,
				query: {
					pageNum: 1,
					pageSize: 10,
				}
			}
		},
		onLoad() {
			this.info();
		},
		methods: {
			gohistory() {
				uni.navigateTo({
					url: '/questionnaire/History/History'
				})
			},
			gosurveySubject(item) {
				if (!uni.getStorageSync('userinfo')) {
					this.$refs.uToast.show({
						title: '您未登录,请先登录',
						type: 'error',
						url: '/pagesB/login/login'
					})
				} else {
					if (item.surveySubject == 1001) {
						uni.navigateTo({
							url: `/questionnaire/hypertension/hypertension?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					} else if (item.surveySubject == 1002) {
						uni.navigateTo({
							url: `/questionnaire/diabetes/diabetes?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					} else if (item.surveySubject == 1003) {
						uni.navigateTo({
							url: `/questionnaire/cerebralapoplexy/cerebralapoplexy?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					} else if (item.surveySubject == 1004) {
						uni.navigateTo({
							url: `/questionnaire/copd/copd?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					} else if (item.surveySubject == 1005) {
						uni.navigateTo({
							url: `/questionnaire/chronicdisease/chronicdisease?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					} else if (item.surveySubject == 1006) {
						uni.navigateTo({
							url: `/questionnaire/nephropathy/nephropathy?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					} else if (item.surveySubject == 1007) {
						uni.navigateTo({
							url: `/questionnaire/Ophthalmopathy/Ophthalmopathy?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					} else if (item.surveySubject == 1008) {
						uni.navigateTo({
							url: `/questionnaire/Footdisease/Footdisease?item=${encodeURIComponent(JSON.stringify(item))}`
						})
					}
				}
			},
			info() {
				surveylist(this.query).then(res => {
					this.list = res.rows
					this.total = res.total
				})
			},
		},
		onReachBottom() { //下滑加载
			if (this.list.length >= this.total) {} else {
				this.query.pageNum++
				surveylist(this.query).then(res => {
					if (res.rows) {
						res.rows.forEach(e => {
							this.list.push(e)
						})
					}
				})
			}
		},
		onPullDownRefresh() { //下拉刷新
			this.query.pageNum = 1;
			this.info();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
	}
</script>

<style lang="scss">
	@import './healthtest.scss'
</style>