<template>
	<view class="app">
		<view class="address">
			<image src="../../static/pages/address.png" mode=""></image>
			<text>
				济南市
			</text>
		</view>
		<view class="topbar">
			<image src="../../static/pages/wenzhenpingtai.png" mode="" @tap="goconsultationplatform"></image>
			<image src="../../static/pages/hulifuwu.png" mode="" @tap="gosite"></image>
		</view>
		<view class="title">
			常用服务
		</view>
		<view class="centerbar topbar">
			<image src="../../static/pages/yuyueshaicha.png" mode="" @tap="goAppointmentscreening"></image>
			<image src="../../static/pages/shaichajieguo.png" mode="" @tap="result"></image>
			<image src="../../static/pages/jiankangshangcheng.png" mode="" @tap="goshopping"></image>
			<image src="../../static/pages/xinrenfuli.png" mode="" @tap="gomaterialbenefits"></image>
		</view>
		<view class="title">
			<text>健康咨询</text>
			<view class="" @tap='gohealth'>
				<text>
					查看更多
				</text>
				<image src="../../static/huijiantou.png" mode=""></image>
			</view>
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in informationCategoryVOList" :key="index" @tap='gohealthitem(item)'>
				<view class="text">
					{{item.informationTitle}}
				</view>
				<view class="author"></view>
				<image :src="item.leadThumbnailUrl" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from "vuex";
	import {
		getPoserInfoListByType,
		getScreening
	} from '@/api/pages/medicalservice/index.js'
	import {
		getHeathHousingList
	} from '@/api/pagesB/Healthknowledge/index.js'
	import baseurl from '../../api/baseurl';
	export default {
		data() {
			return {
				pageNum: 1,
				pageSize: 5,
				informationCategoryVOList: [], //咨询信息
				patientId: '',
				userInfo: null,
			};
		},
		onShow() {
			this.pageNum = 1
			this.patientId = uni.getStorageSync('patientId');
			this.userInfo = uni.getStorageSync('userinfo')
			this.getHeathHousing();
		},
		methods: {
			goAppointmentscreening() {
				// 筛查预约
				if (!this.userInfo) {
					uni.showModal({
						title: "提示",
						content: "您还未注册，是否去注册？",
						confirmText: '是',
						cancelText: '否',
						success(res) {
							if (res.confirm) {
								uni.redirectTo({
									url: "/pages/register/register"
								})
							} else {
								wx.exitMiniProgram()
							}
						},
					})
				} else {
					getScreening(this.patientId).then(res => {
						if (res.code == 200) {
							let userinfo = JSON.stringify(userInfo)
							if (!res.data) {
								uni.navigateTo({
									url: `/pagesB/screenorder/screenorder?userinfo=${userinfo}`
								})
							} else {
								uni.navigateTo({
									url: `/pagesB/orderlist/orderlist?userinfo=${userinfo}`
								})
							}
						}
					})
				}
				// uni.navigateTo({
				// 		url: '/pagesB/screenorder/screenorder'
				// })
				// uni.navigateTo({
				// 		url: '/pagesB/orderlist/orderlist'
				// })
			},
			//跳转健康常识item
			gohealthitem(item) {
				uni.navigateTo({
					url: `/pagesB/Healthitem/Healthitem?item=${encodeURIComponent(JSON.stringify(item))}`
				})
			},
			// 健康常识
			getHeathHousing() {
				getHeathHousingList(this.pageNum, this.pageSize).then(res => {
					if (res.rows) {
						res.rows.forEach(e => {
							e.leadThumbnailUrl = baseurl + e.leadThumbnailUrl
						})
					}
					this.informationCategoryVOList = res.rows
				})
			},
			//新人福利
			// 第一种 直接映射
			...mapActions(["openPopup"]),
			gomaterialbenefits() {
				// 第二种引入
				// this.$store.dispatch("openPopup");
				// this.openPopup();
				setTimeout(e => {
					uni.navigateTo({
						url: '/pagesB/materialbenefits/materialbenefits'
					})
				}, 0)
			},
			//跳转护理站页面
			gosite() {
				// this.openPopup();
				setTimeout(e => {
					uni.navigateTo({
						url: '/pagesB/site/site'
					})
				}, 0)
			},
			//健康常识
			gohealth() {
				uni.navigateTo({
					url: '/pagesB/Healthknowledge/Healthknowledge'
				})
			},
			// 筛查结果
			result() {
				uni.navigateTo({
					url: '/pagesB/SelectItem/SelectItem'
				})


			},
			//跳转商城
			goshopping() {
				// this.openPopup();
				setTimeout(e => {
					uni.navigateTo({
						url: '/pagesB/shopping/shopping'
					})
				}, 0)
			},
			//问诊平台
			goconsultationplatform() {
				uni.navigateTo({
					url: '/pagesB/consultationplatform/consultationplatform',
				})
			},
		},
		//1.分享给朋友
		onShareAppMessage(res) {
			let pages = getCurrentPages();
			let url = pages[pages.length - 1].$page.fullPath
			return {
				title: '新医路健康服务平台',
				path: url,
			}
		},
		//2.分享到朋友圈
		onShareTimeline(res) {
			let pages = getCurrentPages();
			let url = pages[pages.length - 1].$page.fullPath
			return {
				title: '新医路健康服务平台',
				path: url,
			}
		},
	}
</script>

<style lang="scss">
	@import "./medicalservice.scss";
</style>