<template>
	<view class="app">
		<view class="content">
			<image src="/static/pageC/homepage.png" mode=""></image>
			<view class="loginmount" @tap="city">
				<!-- <image src="/static/pageC/TAB.png" mode=""></image> -->
				<image src="../../static/pages/address.png" mode=""></image>
				<text v-if="address">
					{{address}}
				</text>
				<text v-else>
					请选择城市
				</text>
			</view>
			<!-- 			<view class="address" @tap="city">
				<image src="../../static/pages/address.png" mode=""></image>
				<text v-if="address">
					{{address}}
				</text>
				<text v-else>
					请选择城市
				</text>
			</view> -->
		</view>
		<view class="contentcenter">
			<view class="home" @tap="goonline">
				<image src="/static/pageC/qianyue.png" mode=""></image>
				<view class="name">
					家医签约
				</view>
			</view>
			<!-- <view class="home" @tap="goHealthrecords">
				<image src="/static/pageC/health.png" mode=""></image>
				<view class="name">
					健康档案
				</view>
			</view> -->
			<view class="home" @tap="goappoint">
				<image src="/static/pageC/serveappoint.png" mode=""></image>
				<view class="name">
					服务预约
				</view>
			</view>
			<view class="home" @tap="count">
				<image src="/static/pageC/exchange.png" mode=""></image>
				<view class="name">
					积分兑换
				</view>
			</view>
			<view class="home" @tap="myappointment">
				<image src="/static/pageC/appointmen.png" mode=""></image>
				<view class="name">
					我的预约
				</view>
			</view>
			<view class="home" @tap="servicerecord">
				<image src="/static/pageC/SERVERECOD.png" mode=""></image>
				<view class="name">
					服务记录
				</view>
			</view>
		</view>
		<view class="contentbottom">
			<view class="health">
				健康管理
			</view>
			<view class="item">
				<view class="signmyself" @tap="sign">
					<image src="/static/pageC/tizheng.png" mode=""></image>
				</view>
				<view class="sign">
					<image @tap="healthtest" src="/static/pageC/healthmyself.png" mode=""></image>
					<image @tap="gorecords" src="/static/pageC/records.png" mode=""></image>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getOpenId,
		detail,
		checkSignApply
	} from '@/api/pages/homepage/homepage.js'
	export default {
		data() {
			return {
				patientName: '',
				userinfo: null,
				infotitle: null,
				region: '',
				checkSign: null,
				address: '',
				openid: '',
			}
		},
		onLoad() {
			// this.login()
		},
		onShow() {
			this.address = uni.getStorageSync('location')
			this.openid = uni.getStorageSync('openid');
			if (uni.getStorageSync('userinfo')) {
				this.userinfo = uni.getStorageSync('userinfo')
				this.cityCode = this.userinfo.cityCode;
			}
			if (this.address == '德州市') {
				uni.setStorageSync("region", 1)
			} else if (this.address == '东营市') {
				uni.setStorageSync("region", 2)
			} else if (this.address == '济南市') {
				uni.setStorageSync("region", 3)
			}
			this.region = uni.getStorageSync('region')
			if (this.userinfo && this.region != 3) {
				this.patientName = this.userinfo.patientName
				checkSignApply(this.userinfo.cardNo).then(res => {
					if (res.data) {
						this.checkSign = res.data.code
						this.infotitle = res.data.info
					}
					// if (res.data.code == 0) {
					// 	this.checkSign = true
					// } else {
					// 	this.checkSign = false
					// }
				})
			} else {
				this.patientName = ''
			}
		},
		methods: {
			city() {
				uni.navigateTo({
					url: '/pages/location/location'
				})
			},
			// 登录
			login() {
				uni.navigateTo({
					url: "/pages/login/login"
				})
			},
			gologin() {
				this.$refs.uToast.show({
					title: '您未登录,请先登录',
					type: 'error',
					duration: '1000',
					url: '/pages/login/login'
				})
			},
			// 家医功能提示
			family() {
				this.$refs.uToast.show({
					title: '当前绑定地市不支持',
					type: 'error',
					duration: '3000',
				})
			},
			// 家医签约
			goonline() {
				if (!this.userinfo) {
					this.gologin();
				} else {
					if (this.region == 3) {
						this.family()
					} else {
						if (this.cityCode == 1 || this.cityCode == 2) {
							if (this.checkSign == "0") {
								this.$refs.uToast.show({
									title: '未签约，请先签约',
									type: 'error',
									url: "/pagesC/Onlinesigning/Onlinesigning"
								})
							} else if (this.checkSign == "01") {
								this.$refs.uToast.show({
									title: this.infotitle,
									type: 'error',
								})
							} else {
								uni.navigateTo({
									url: "/pagesB/mysigning/mysigning"
								})
							}
						} else {
							this.family()
						}
					}
				}
			},
			// 积分兑换
			count() {
				if (!this.userinfo) {
					this.gologin();
				} else {
					if (this.region == 3) {
						this.family()
					} else {
						if (this.cityCode == 1 || this.cityCode == 2) {
							if (this.checkSign == "0") {
								this.$refs.uToast.show({
									title: this.infotitle,
									type: 'error',
									url: "/pagesC/Onlinesigning/Onlinesigning"
								})
							} else if (this.checkSign == "01") {
								this.$refs.uToast.show({
									title: this.infotitle,
									type: 'error',
								})
							} else if (this.checkSign == "01") {
								this.$refs.uToast.show({
									title: this.infotitle,
									type: 'error',
								})
							} else {
								uni.navigateTo({
									url: '/pagesB/Behaviorpoints/Behaviorpoints'
								})
							}
						} else {
							this.family()
						}
					}
				}
			},
			// 健康档案
			goHealthrecords() {
				if (!this.userinfo) {
					this.gologin();
				} else {
					uni.navigateTo({
						url: "/pagesC/Healthrecords/Healthrecords"
					})
				}
			},
			// 筛查记录
			gorecords() {
				uni.navigateTo({
					url: "/pagesC/Screeningrecords/Screeningrecords"
				})
				// if (!this.userinfo) {
				// 	this.gologin();
				// } else {
				// 	uni.navigateTo({
				// 		url: "/pagesC/Screeningrecords/Screeningrecords"
				// 	})
				// }
			},
			// 健康自评
			healthtest() {
				if (!this.userinfo) {
					this.gologin();
				} else {
					uni.navigateTo({
						url: "/pagesC/healthtest/healthtest"
					})
				}
			},
			// 体征检测
			sign() {
				uni.navigateTo({
					url: "/pagesC/Physicalexamination/Physicalexamination"
				})
				// if (!this.userinfo) {
				// 	this.gologin();
				// } else {
				// 	uni.navigateTo({
				// 		url: "/pagesC/Physicalexamination/Physicalexamination"
				// 	})
				// }
			},
			// 服务预约
			goappoint() {
				if (!this.userinfo) {
					this.gologin();
				} else {
					// if (this.region == 3) {
					// 	this.family()
					// } else {
					// if (this.cityCode == 1 || this.cityCode == 2) {
					if (this.checkSign == "0") {
						this.$refs.uToast.show({
							title: '未签约，请先签约',
							type: 'error',
							url: "/pagesC/Onlinesigning/Onlinesigning"
						})
					} else if (this.checkSign == "01") {
						this.$refs.uToast.show({
							title: this.infotitle,
							type: 'error',
						})
					} else {
						uni.navigateTo({
							url: "/pagesC/ServiceAppointment/ServiceAppointment"
						})
					}
					// } else {
					// 	this.family()
					// }
					// }
					// }
				}
			},
			// 服务记录
			servicerecord() {
				if (!this.userinfo) {
					this.gologin();
				} else {
					if (this.region == 3) {
						this.family()
					} else {
						if (this.cityCode == 1 || this.cityCode == 2) {
							if (this.checkSign == "0") {
								this.$refs.uToast.show({
									title: '未签约，请先签约',
									type: 'error',
									url: "/pagesC/Onlinesigning/Onlinesigning"
								})
							} else if (this.checkSign == "01") {
								this.$refs.uToast.show({
									title: this.infotitle,
									type: 'error',
								})
							} else {
								uni.navigateTo({
									url: "/pagesC/servicerecord/servicerecord"
								})
							}
						} else {
							this.family()
						}
					}
				}
			},
			// 我的预约
			myappointment() {
				if (!this.userinfo) {
					this.gologin();
				} else {
					if (this.region == 3) {
						this.family()
					} else {
						if (this.cityCode == 1 || this.cityCode == 2) {
							if (this.checkSign == "0") {
								this.$refs.uToast.show({
									title: '未签约，请先签约',
									type: 'error',
									url: "/pagesC/Onlinesigning/Onlinesigning"
								})
							} else if (this.checkSign == "01") {
								this.$refs.uToast.show({
									title: this.infotitle,
									type: 'error',
								})
							} else {
								uni.navigateTo({
									url: "/pagesC/Myappointment/Myappointment"
								})
							}
						} else {
							this.family()
						}
					}
				}
			},
		}
	}
</script>

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