<template>
	<view class="app">
		<view class="address">
			<!-- 			<image src="../../static/pages/address.png" mode=""></image>
			<text>
				{{location?location:''}}
			</text> -->
		</view>
		<view class="topbar">
			<image mode="" :src="require('@/pagesB/images/wenzhenpingtai.png')" @tap="goconsultationplatform"></image>
			<image mode="" :src="require('@/pagesB/images/hulifuwu.png')" @tap="gosite"></image>
		</view>
		<view class="title">
			常用服务
		</view>
		<view class="centerbar topbar">
			<image mode="" :src="require('@/pagesB/images/yuyueshaicha.png')" @tap="goAppointmentscreening"></image>
			<image mode="" :src="require('@/pagesB/images/shaichajieguo.png')" @tap="result"></image>
			<image mode="" :src="require('@/pagesB/images/jiankangshangcheng.png')" @tap="goshopping"></image>
			<image mode="" :src="require('@/pagesB/images/xinrenfuli.png')" @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>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		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,
				location: null,
			
			};
		},
		onShow() {
			this.pageNum = 1
			this.patientId = uni.getStorageSync('patientId');
			this.userInfo = uni.getStorageSync('userinfo')
			this.cardNo = 	this.userInfo.cardNo
			this.location = uni.getStorageSync('location')
			this.getHeathHousing();
		},
		methods: {
			// 第一种 直接映射
			...mapActions(["openPopup"]),
			goAppointmentscreening() {
				this.openPopup();
				setTimeout(e => {
					// 筛查预约
					if (!this.userInfo) {
						uni.showModal({
							title: "提示",
							content: "您还未注册，是否去注册？",
							confirmText: '是',
							cancelText: '否',
							success(res) {
								if (res.confirm) {
									uni.redirectTo({
										url: "/pagesB/register/register"
									})
								} else {
									wx.exitMiniProgram()
								}
							},
						})
					} else {
						getScreening(this.cardNo).then(res => {
							if (res.code == 200) {
								let userinfo = JSON.stringify(this.userInfo)
								if (!res.data || res.data == null) {
									uni.navigateTo({
										url: `/pagesB/screenorder/screenorder?userinfo=${userinfo}`
									})
								} else {
									uni.navigateTo({
										url: `/pagesB/orderlist/orderlist?userinfo=${userinfo}`
									})
								}
							}
						})
					}
				}, 0)
			},
			//跳转健康常识item
			gohealthitem(item) {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: `/pagesB/Healthitem/Healthitem?item=${encodeURIComponent(JSON.stringify(item))}`
					})
				} else {
					this.$refs.uToast.show({
						title: '您未登录,请先登录',
						type: 'error',
						duration: '1000',
						url: '/pagesB/login/login'
					})
				}
			},
			// 健康常识
			getHeathHousing() {
				getHeathHousingList(this.pageNum, this.pageSize).then(res => {
					if (res.rows) {
						res.rows.forEach(e => {
							e.leadThumbnailUrl = baseurl + e.leadThumbnailUrl
						})
					}
					this.informationCategoryVOList = res.rows
				})
			},
			//新人福利
			gomaterialbenefits() {
				// 第二种引入
				// this.$store.dispatch("openPopup");
				// this.openPopup();
				setTimeout(e => {
					const value = uni.getStorageSync('openid');
					const value2 = uni.getStorageSync('patientId');
					if (value && value2) {
						uni.navigateTo({
							url: '/pagesB/materialbenefits/materialbenefits'
						})
					} else {
						this.$refs.uToast.show({
							title: '您未登录,请先登录',
							type: 'error',
							duration: '1000',
							url: '/pagesB/login/login'
						})
					}

				}, 0)
			},
			//跳转护理站页面
			gosite() {
				// this.openPopup();
				setTimeout(e => {
					const value = uni.getStorageSync('openid');
					const value2 = uni.getStorageSync('patientId');
					if (value && value2) {
						uni.navigateTo({
							url: '/pagesB/site/site'
						})
					} else {
						this.$refs.uToast.show({
							title: '您未登录,请先登录',
							type: 'error',
							duration: '1000',
							url: '/pagesB/login/login'
						})
					}
				}, 0)
			},
			//健康常识
			gohealth() {
				const value = uni.getStorageSync('openid');
				const value2 = uni.getStorageSync('patientId');
				if (value && value2) {
					uni.navigateTo({
						url: '/pagesB/Healthknowledge/Healthknowledge'
					})
				} else {
					this.$refs.uToast.show({
						title: '您未登录,请先登录',
						type: 'error',
						duration: '1000',
						url: '/pagesB/login/login'
					})
				}
			},
			// 筛查结果
			result() {
				this.openPopup();
				setTimeout(e => {
					const value = uni.getStorageSync('openid');
					const value2 = uni.getStorageSync('patientId');
					if (value && value2) {
						uni.navigateTo({
							url: '/pagesB/SelectItem/SelectItem'
						})
					} else {
						this.$refs.uToast.show({
							title: '您未登录,请先登录',
							type: 'error',
							duration: '1000',
							url: '/pagesB/login/login'
						})
					}
				}, 50)
			},
			//跳转商城
			goshopping() {
				setTimeout(e => {
					const value = uni.getStorageSync('openid');
					const value2 = uni.getStorageSync('patientId');
					if (value && value2) {
						uni.navigateTo({
							url: '/pagesB/shopping/shopping'
						})
					} else {
						this.$refs.uToast.show({
							title: '您未登录,请先登录',
							type: 'error',
							duration: '1000',
							url: '/pagesB/login/login'
						})
					}
				}, 0)
			},
			//问诊平台
			goconsultationplatform() {
				this.openPopup();
				setTimeout(e => {
					const value = uni.getStorageSync('openid');
					const value2 = uni.getStorageSync('patientId');
					if (value && value2) {
						uni.navigateTo({
							url: '/pagesB/consultationplatform/consultationplatform',
						})
					} else {
						this.$refs.uToast.show({
							title: '您未登录,请先登录',
							type: 'error',
							duration: '1000',
							url: '/pagesB/login/login'
						})
					}
				}, 0)
			},
		},
		//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>