<template>
	<view class="container">
		<scroll-view class="content-box" scroll-y="true">
			<view class="user-section">
				<view class="user-info-box ">
					<view class="detail flex">
						<view class="portrait-box" @click="navTo('/pages/set/userinfo')">
							<image class="portrait" :src="user.avatar || '/static/error/missing-face.png'"></image>
						</view>
						<view class="info-box">
							<view class="username flex-start">
								<text class="clamp padding-r-20">
									{{ user.nickname || '游客' }}
								</text>

								<view class="tipLevel flex-shrink-false">
								</view>
							</view>
							<view class="flex-start flex">
								<view class="authentication">{{user.mobile}}</view>
							</view>
						</view>
						<view class="righ-tbox flex">
							<image class="right-tip" src="../../static/icon/tiptop.png" mode="scaleToFill"></image>
							<block v-if="!user.work_type_title">
								普通用户
							</block>
							<block v-else>
								{{user.work_type_title}}
							</block>
						</view>
					</view>
				</view>
			</view>
			<view class="nav-model flex" @click="navcard">
				<view class="right-card">
					<view class="title">
						我的数字名片
					</view>
					<view class="tip" v-if="user.info_audit_status==-2">
						审核成功即可获得母婴界数字名片
					</view>
					<view class="tip" v-else-if="user.info_audit_status==1">
						点击查看您的母婴界数字名片
					</view>
					<view class="tip" v-else-if="user.info_audit_status==0&&user.work_type_id<=0">
						数字名片资料审核中请等待审核完毕
					</view>
					<view class="tip" v-else-if="user.info_audit_status==0&&user.work_type_id>0">
						修改数字名片资料审核中请等待审核完毕
					</view>
				</view>
				<image class="next" src="../../static/icon/next2.png" mode="scaleToFill"></image>
			</view>
			<!-- <view class="nav-model-rz flex" v-if="user.work_type_id>0&&user.type_audit_status!=1"
				@click="user.type_audit_status==0||navTo('/pages/user/model/shoprz')">
				<view class="tiptext" v-if="user.type_audit_status==-2">
					您未完成平台认证，请立即认证>>
				</view>
				<view class="tiptext" v-else-if="user.type_audit_status==-1">
					您平台认证失败，请重新认证>>
				</view>
				<view class="tiptext" v-else-if="user.type_audit_status==-3">
					您平台认证已失效，请重新认证>>
				</view>
				<view class="tiptext" v-else-if="user.type_audit_status==0">
					您已提交认证信息请等待认证结束
				</view>
				<view class="rztext" v-if="user.type_audit_status==-2">
					立即认证
				</view>
				<view class="rztext" v-else-if='user.type_audit_status==-3||user.type_audit_status==-1'>
					重新生成
				</view>
			</view> -->
			<view class="cover-container">
				<view class="listBox">
					<view class="list">
						<!-- <view class="flex listItem" @click="navTo('/pages/user/myCart/myCart')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/mymoney.png" mode="widthFix"></image>
								<text class="title">我的钱包</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view> -->
						<view v-if="is_open == 1" class="flex listItem" @click="navTo('/pages/user/forum/index')"
							>
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/forum.png" mode="widthFix"></image>
								<text class="title">论坛</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/jf/bill')"
							>
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myjf.png" mode="widthFix"></image>
								<text class="title">我的积分</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/model/phb')"
							>
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/guanjun.png" mode="widthFix"></image>
								<text class="title">人气排行</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/signing/mySig')"
							v-if="user.info_audit_status==-2">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myyy.png" mode="widthFix"></image>
								<text class="title">我的预约</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view v-else class="flex listItem" @click="navTo('/pages/user/signing/mySig')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myht.png" mode="widthFix"></image>
								<text class="title">我的合同</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/myteam')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myshare.png" mode="widthFix"></image>
								<text class="title">影响指数</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/shareQrCode')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myshareimg.png" mode="widthFix">
								</image>
								<text class="title">邀请海报</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/model/mymodellist')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/mymodel.png" mode="widthFix"></image>
								<text class="title">我的模板</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<!-- <view class="flex listItem" @click="navTo('/pages/user/myCart/myCart')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myaddress.png" mode="widthFix"></image>
								<text class="title">收货地址</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view> -->
						<view class="flex listItem" @click="openCode">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myCode.png" mode="widthFix"></image>
								<text class="title">激活模版</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/mySc')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myinfo.png" mode="widthFix"></image>
								<text class="title">我的收藏</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/user/jf/order')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myorder.png" mode="widthFix"></image>
								<text class="title">我的订单</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<!-- #ifdef MP -->
						<button hover-class="none" class="flex listItem" @click="openEnterpriseWechat">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myserve.png" mode="widthFix"></image>
								<text class="title">客服中心</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</button>
						<!-- #endif -->
						<!-- #ifndef APP -->
						<!-- <view class="flex listItem" @click="navTo('/pages/user/shareQrCode')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myshare.png" mode="widthFix"></image>
								<text class="title">邀请好友</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view> -->
						<!-- #endif -->
						<!-- #ifdef APP -->
						<view class="flex listItem" @click="shareDomApp">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myshare.png" mode="widthFix"></image>
								<text class="title">邀请好友</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<!-- #endif -->
						<!-- #ifndef MP -->
						<view class="flex listItem" @click="navTo('/pages/public/workwork')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myinfo.png" mode="widthFix"></image>
								<text class="title">关于我们</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
						<!-- #endif -->
						<view class="flex listItem" @click="navTo('/pages/set/set')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myset.png" mode="widthFix"></image>
								<text class="title">系统设置</text>
							</view>
							<view class="right flex">
								<text></text>
								<image class="img" src="../../static/icon/next1.png" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<uni-popup ref="popup" type="center">
			<swiper class="alertBox" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="ls in ggList">
					<image @click="openXcx(ls)" class="alertImage" :src="ls.img" mode="scaleToFill"></image>
				</swiper-item>
			</swiper>
		</uni-popup>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		share
	} from '@/api/wx';
	import {
		getUser,
		useCode
	} from '@/api/user.js';
	// #ifdef MP
	// 不要删，删除会导致修改资料页面报错无法引用到该对象
	// import setAll from '@/api/set';
	// #endif
	import {
		articleList,
		notify
	} from '@/api/index.js';
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	import {
		getBannerList
	} from '@/api/model.js';
	export default {
		data() {
			return {
				is_open: 0,
				user: {
					avatar: '', //头像
					nickname: '', //昵称
				},
				shareData: {},
				ggList: [], //弹窗广告列表
				showGG: false, //判断是否已经显示广告
			};
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
			...mapState(['baseURL', 'urlFile']),
			...mapState(['fx']),
			// #ifdef MP
			...mapState(['systeam']),
			// #endif
			// 总消息条数
			notic() {
				return this.user.question_sum + this.user.notice_sum;
			},
		},
		// 创建时获取分享信息
		onLoad() {
			console.log(11223344);
			this.getShow()
			this.getGG();
		},
		onShow() {
			this.getUser();
			console.log(this.showGG, 'this.showGG');
			// 判断是否要显示广告弹窗
			if (!this.showGG && this.hasLogin && this.ggList.length > 0) {
				this.showGG = true;
				this.$nextTick(() => {
					this.$refs.popup.open()
				})
			}
		},
		methods: {
			...mapMutations('user', ['setUserInfo']),
			getShow() {
				console.log('zhel');
				share({}).then(({
					data
				}) => {
					
					this.is_open = data.is_show
				});
			},
			// #ifdef MP-WEIXIN
			openEnterpriseWechat() {
				uni.showLoading({
					title: '正在打开企业微信...'
				});
				wx.openCustomerServiceChat({
					corpId: 'wwaff436832bc11deb', // 必填：企业微信的corpId，从企业微信管理后台获取
					extInfo:{
						url:'https://work.weixin.qq.com/kfid/kfc2e05cbe1de7cb887'
					},
					success: (res) => {
						uni.hideLoading();
						console.log('打开企业微信成功', res);
						uni.showToast({
							title: '已打开企业微信',
							icon: 'success'
						});
					},
					fail: (err) => {
						uni.hideLoading();
						console.error('打开企业微信失败', err);
						// 常见失败原因：未安装企业微信、corpid错误、小程序未配置权限等
						uni.showToast({
							title: '打开失败，请检查是否安装企业微信',
							icon: 'none',
							duration: 3000
						});
					}
				});
			},
			// #endif
			getGG() {
				getBannerList({
					page_id: 73
				}).then(
					(res) => {
						this.ggList = res.data.list.map((re) => {
							if (re.data.length > 0) {
								const json = JSON.parse(re.data)
								for (var i = 0; i < json.length; i++) {
									const item = json[i]
									const key = item.code;
									re[key] = item[key] ? item[key] : ''
								}
							}
							return re
						})
						console.log(this.ggList)
					}
				).catch(
					(res) => {
						console.log(res);
					}
				)
			},
			// 打开小程序
			openXcx(item) {
				// #ifdef MP
				if (item.wxcode.length > 0) {
					wx.navigateToMiniProgram({
						appId: item.wxcode,
						path: item.url,
					})
				} else {
					if (item.url == '') {
						this.$refs.popup.close()
					} else {
						uni.navigateTo({
							url: item.url
						})
					}
				}
				// #endif
			},
			// 激活验证码
			openCode() {
				uni.showModal({
					title: '联系客服中心领取激活码',
					placeholderText: '请输入激活key',
					editable: true,
					confirmText: '激活',
					success: res => {
						if (res.confirm) {
							useCode({
								code: res.content
							}).then((e) => {
								uni.showToast({
									title: '激活成功'
								});
							}).catch((e) => {
								console.log(e)
								uni.showToast({
									title: e.msg,
									icon: "error"
								});
							})
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			// 跳转卡片页面
			navcard() {
				if (this.hasLogin) {
					// 判断是否已经认证
					if (this.user.work_type_id <= 0) {
						if (this.user.info_audit_status == 1) {
							this.navTo('/pages/user/model/model?mtype=' + this.user.show_template_id + '&type=3')
						} else {
							this.navTo('/pages/user/model/modelrz?modelid=' + this.user.show_template_id)
						}
					} else {
						if (this.user.show_template_id) {
							this.navTo('/pages/user/model/model?mtype=' + this.user.show_template_id + '&type=3')
						} else {
							if (this.systeam == 'ios') {
								uni.showModal({
									title: '错误',
									content: 'IOS暂不支持',
									showCancel: false,
								});
							} else {
								uni.showModal({
									title: '错误',
									content: '您未购买模板请先购买',
									showCancel: false,
								});
							}
						}
					}
				} else {
					saveUrl()
					interceptor()
				}
			},
			//#ifdef APP
			shareDomApp() {
				uni.share({
					provider: 'weixin',
					type: 0,
					title: '母婴界严选',
					summary: '',
					imageUrl: this.shareData.img,
					href: this.baseURL + this.urlFile + '/pages/public/register?spread=' + this.userInfo.uid
				})
			},
			//#endif
			// 获取用户数据
			getUser() {
				const that = this;
				getUser({}).then((e) => {
					this.user = e.data;
					this.setUserInfo(e.data)

				}).catch((e) => {
					console.log(e, 'sj');
				})
			},
			changeTab() {
				this.$emit('tab', true)
			},
			navTo(url) {
				if (!this.hasLogin) {
					// 保存地址
					saveUrl();
					// 登录拦截
					interceptor();
				} else {
					uni.navigateTo({
						url,
						fail(e) {
							console.log(e);
						}
					});
				}
			},
		}
	};
</script>
<style lang="scss">
	page {
		height: 100%;
	}

	.listBox {
		margin-top: 20rpx;
		overflow: hidden;
	}

	.list {
		.listItem {
			padding: 35rpx 40rpx;
			margin-bottom: 15rpx;
			background-color: #FFFFFF;
			border-radius: 20rpx;
			border: none;
			line-height: 1;

			&::after {
				border: none;
			}
		}

		.listIconImg {
			width: 36rpx;
			height: 36rpx;
		}

		.right {
			.img {
				width: 26rpx;
			}
		}

		.titleBox {
			.title {
				padding-left: 20rpx;
				color: $font-color-base;
				font-size: $font-base;
			}
		}
	}

	.container {
		height: 100%;
		background-color: $page-color-base;
	}

	.content-box {
		height: 100%;
	}

	.user-section {
		padding: 15rpx 30rpx 0;
		position: relative;
		background: url('https://api.myjie.cn/resource/appimage/userbg.png');
		background-size: 100% 100%;
		padding-top: 100rpx;
		height: 350rpx;
	}

	.user-info-box {
		height: 180rpx;
		color: white;
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: relative;
		z-index: 1;

		.detail {
			height: 130rpx;
			flex-grow: 1;
			overflow: hidden;

			.portrait-box {
				height: 100%;

				.portrait {
					width: 130rpx;
					height: 100%;
					border: 5rpx solid #fff;
					border-radius: 50%;
				}
			}

			.info-box {
				margin-left: 20rpx;
				line-height: 1.5;
				flex-grow: 1;
				overflow: hidden;

				.tipLevel {
					height: 36rpx;
					margin-right: 20rpx;
				}

				.username {
					font-size: 34rpx;
					color: #FFF;
					font-weight: bold;
					height: 100%;
				}

				.authentication {
					font-size: 24rpx;
					color: #FFF;
					float: left;
				}
			}

			.righ-tbox {
				padding: 10rpx 20rpx;
				border-radius: 12rpx;
				font-size: 25rpx;
				line-height: 1;
				color: $base-color;
				background-color: #FFF;

				.right-tip {
					width: 25rpx;
					height: 33rpx;
					margin-right: 10rpx;
				}
			}
		}
	}

	.nav-model-rz {
		background-color: #FFD7E3;
		border-radius: 20rpx;
		margin: 0 auto;
		padding: 30rpx;
		padding-bottom: 15rpx;
		padding-top: 50rpx;
		line-height: 1;
		width: 690rpx;
		margin-top: -38rpx;

		.tiptext {
			color: #F65486;
			font-size: 26rpx;
			font-weight: bold;
		}

		.rztext {
			color: #FFF;
			background-color: #F65486;
			border-radius: 100rpx;
			padding: 15rpx 20rpx;
			font-size: 22rpx;
		}
	}

	.nav-model {
		background: url('https://api.myjie.cn/resource/appimage/uservip.png');
		background-size: 100% 100%;
		color: #FFF;
		border-radius: 20rpx;
		width: 690rpx;
		height: 157rpx;
		margin: 0 auto;
		margin-top: -80rpx;
		font-weight: bold;
		z-index: 1;
		position: relative;

		.next {
			width: 26rpx;
			height: 28rpx;
			margin-right: 40rpx;
		}

		.right-card {
			padding-left: 170rpx;
		}

		.title {
			font-size: 35rpx;
		}

		.tip {
			font-size: 26rpx;
		}

	}

	.cover-container {
		padding: 0 30rpx;
		position: relative;
		padding-bottom: 20rpx;
	}

	.alertBox {

		width: 479rpx;
		height: 832rpx;

		.alertImage {
			border-radius: 20rpx;
			width: 479rpx;
			height: 832rpx;
		}
	}
</style>