<template>
	<view class="mine">
		<view class="index-bg"></view>
		<view class="mine-tips" v-if="userinfo.certification_type != 0">
			<u-notice-bar mode="horizontal" bg-color="rgba(0,0,0,0)"
				:list="[`${userinfo.certification_type == 1 ? config.intermediary_explain : config.people_explain}`]"
				padding="0" :volume-icon="false" color="#fff" font-size="22"></u-notice-bar>
		</view>
		<view class="user-box u-flex">
			<image v-if="userinfo.headimg" :src="userinfo.headimg" class="user-head" mode=""></image>
			<image v-else src="../../static/images/head.png" class="user-head" mode=""></image>
			<view class="user-center u-flex-1 u-flex-col u-col-top">
				<text class="text1" v-if="userinfo.name">{{userinfo.name}}</text>
				<button class="text1" @getphonenumber="login" v-else @click="tologin">点击进行登录</button>
				<text class="text2" v-if="userinfo.certification_type == 0">未认证</text>
				<text class="text2" v-if="userinfo.certification_type == 1">中介经纪人</text>
				<text class="text2" v-if="userinfo.certification_type == 2">全民经纪人</text>
			</view>
			<u-icon name="edit-pen-fill" color="#fff" @click="toinfo" size="36"></u-icon>
		</view>

		<!-- 		<view class="yongjin-box">
			<view class="price u-flex u-row-center">
				<image src="../../static/images/qianbao.png" class="img" mode=""></image>
				<view class="text u-flex-col">
					<text>{{userinfo.balance || '0.00'}}</text>
					<text>积分总额（元）</text>
				</view>
			</view>
			<view class="mingxi u-flex u-row-between">
				<text class="u-flex-1" style="border-right: 2rpx solid #F5F5F5;" @click="toyongjin">积分明细</text>
				<text class="u-flex-1" @click="toxieyi">积分说明</text>
			</view>
		</view> -->

		<view class="yongjin-box">
			<view class="price">
				<view class="" style="display:flex;justify-content: space-between;">
					<view class="" style="display:flex;">
						<image style="width: 36rpx;height:36rpx;" src="../../static/images/jifen.png" mode=""></image>
						<view class="">
							<text class="yongjin-box">我的积分</text>
						</view>
						<image style="width: 36rpx;height:36rpx;" src="../../static/images/explain.png" mode=""></image>
					</view>
					<view class="">
						<text class="jffont" @click="tojifen">积分明细</text>
						<image style="width: 24rpx;height: 24rpx;margin-right: 10rpx;"
							src="../../static/images/nextto.png" mode=""></image>
					</view>
				</view>
				<view class="" style="margin-top: 40rpx;display: flex;justify-content: space-around;">
					<view class="">
						<text style="font-size: 48rpx;font-weight: 800;">{{userinfo.integral || '0.00'}}</text>
						<view class="font">
							<text>积分总额</text>
						</view>
					</view>
					<view class="" style="margin-left: 200rpx;">
						<text style="font-size: 48rpx;font-weight: 800;">{{userinfo.now_month_integral|| '0.00'}}</text>
						<view class="font">
							<text>本月积分</text>
						</view>
					</view>

				</view>
				
				<view v-if="userinfo.is_integral_hint==1" class="forward"
					style="margin-top: 20rpx;border-top: 2rpx solid #F6F6F6;padding: 24rpx 20rpx 0;">
					<view class="u-flex">
						<image style="width: 32rpx;height: 32rpx;margin-right: 12rpx;"
							src="../../static/images/index-img2.png" mode=""></image>
						<!-- <view class="" style="width: 500rpx;height: 34rpx;margin-top: -50rpx;"> -->
						<uni-notice-bar background-color="#fff" font-size="12" color="#000" style="width: 500rpx;"
							scrollable single text="您当月积分0，若本月无积分入账，历史积分将全部清零"></uni-notice-bar>
						<!-- </view> -->
						<button class="btn" open-type="share">
							转发赚积分
						</button>
					</view>
				</view>
			</view>
		</view>
		<!-- 佣金总额 -->
		<view class="yongjin-box" style="margin-top: 20rpx;">
			<view class="price">
				<view class="" style="display:flex;justify-content: space-between;">
					<view class="" style="display:flex;">
						<image style="width: 36rpx;height:36rpx;" src="../../static/images/qianbao.png" mode=""></image>
						<view class="">
							<text class="yongjin-box">佣金总额(元)</text>
						</view>
						<image @click='toxieyi' style="width: 36rpx;height:36rpx;" src="../../static/images/explain.png"
							mode=""></image>
					</view>
					<view class="">
						<text class="jffont" @click='toyongjin'>佣金明细</text>
						<image style="width: 24rpx;height: 24rpx;margin-right: 10rpx;"
							src="../../static/images/nextto.png" mode=""></image>
					</view>
				</view>
				<view class="" style="margin-top: 40rpx;margin-left: 50rpx;">
					<view class="">
						<text style="font-size: 30rpx;font-weight: 800;">￥</text>
						<text style="font-size: 48rpx;font-weight: 800;">{{userinfo.balance || '0.00'}}</text>
					</view>
				</view>
			</view>
		</view>

		<!-- 		<view class="yongjin-box " style="display: flex;">
			<view class="" style="width: 350rpx; border-right: 2px solid #F5F5F5;">
				<view class="" style="display:flex;">
					<image style="width: 36rpx;height:36rpx;"  src="../../static/images/jifen.png"  mode=""></image>
					<view class="">
						<text class="yongjin-box font">积分总额(元)</text>
					</view>
					<image   style="width: 36rpx;height:36rpx;" src="../../static/images/explain.png" mode=""></image>
				</view>
				<view class="" style="margin-top: 40rpx;display: flex;justify-content: space-between;">
					<view class="">
						<text style="font-size: 48rpx;font-weight: 800;">{{userinfo.balance || '0.00'}}</text>
					</view>
					<view class="" style="margin-top: 20rpx;">
						<text class="jffont" >积分明细</text>
						<image style="width: 24rpx;height: 24rpx;margin-right: 10rpx;" src="../../static/images/nextto.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="" style="width: 350rpx;margin-left: 30rpx;">
				<view class="" style="display:flex;">
					<image style="width: 36rpx;height:36rpx;"  src="../../static/images/qianbao.png"  mode=""></image>
					<view class="">
						<text class="yongjin-box font">佣金总额(元)</text>
					</view>
					<image @click="toxieyi" style="width: 36rpx;height:36rpx;" src="../../static/images/explain.png" mode=""></image>
				</view>
				<view class="" style="margin-top: 40rpx;display: flex;justify-content: space-between;">
					<view class="">
						<text style="font-size: 48rpx;font-weight: 800;">{{userinfo.balance || '0.00'}}</text>
					</view>
					<view class="" style="margin-top: 20rpx;">
						<text class="jffont" @click="toyongjin" >佣金明细</text>
						<image style="width: 24rpx;height: 24rpx;margin-right: 10rpx;" src="../../static/images/nextto.png" mode=""></image>
					</view>
				</view>
			</view>
		</view> -->
		<view class="tabs-box u-flex">
			<view class="tabs-item u-flex-col u-col-center" @click="tourl(1)"
				v-if="(userinfo.certification_type == 1 || userinfo.certification_type == 0) ">
				<image src="../../static/images/mine-tabs1.png" mode=""></image>
				<text>中介经纪人</text>
			</view>
			<view class="tabs-item u-flex-col u-col-center" @click="tourl(2)"
				v-if="(userinfo.certification_type == 2 || userinfo.certification_type == 0) ">
				<image src="../../static/images/mine-tabs2.png" mode=""></image>
				<text>全民经纪人</text>
			</view>
			<view class="tabs-item u-flex-col u-col-center" @click="tobaobei" v-if="config.report_switch == 1">
				<image src="../../static/images/mine-tabs3.png" mode=""></image>
				<text>我的报备</text>
			</view>
			<!-- 			<navigator target="miniProgram" app-id="wx43a84d2ad51cf509" class="tabs-item u-flex-col u-col-center">
				<image src="../../static/images/yewu.png" mode=""></image>
				<text>业务端</text>
			</navigator> -->

			<view @click="openmin" class="tabs-item u-flex-col u-col-center">
				<image src="../../static/images/yewu.png" mode=""></image>
				<text>业务端</text>
			</view>
		</view>
		<view class="setting-box u-flex u-row-between" @click="tosetting">
			<text>系统设置</text>
			<u-icon name="arrow-right"></u-icon>
		</view>
		<gf-tabbar></gf-tabbar>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex"
	export default {
		//分享
		onShareAppMessage(res) {
			this.$u.get('/api/Member/transmit').then(res => {
				this.getuser()
			})
			return {
				title: '晨照选房',//分享时标题名字
				path: 'pages/index/index', // 全局分享的路径，比如 首页
				imageUrl: '../../static/logo.jpg', 
			}
		},
		//分享朋友圈
		onShareTimeline(res) {
			this.$u.get('/api/Member/transmit').then(res => {
				this.getuser()
			})
			return {
				title: '晨照选房',//分享时标题名字
				path: 'pages/index/index', // 全局分享的路径，比如 首页
				imageUrl: '../../static/logo.jpg', 
			}
		},

		data() {
			return {
				userinfo: {
					certification_type: 0
				}
			}
		},
		onLoad() {
			
		},
		computed: {
			...mapState(['config', 'defaultcity'])
		},
		onShow() {
			console.log(this.config);
			if (uni.getStorageSync("token")) {
				this.getuser()
			} else {
				this.userinfo = {
					certification_type: 0,
				}
			}
		},
		methods: {
			openmin() {
				//#ifdef  MP-WEIXIN
				uni.navigateToMiniProgram({
					appId: 'wx43a84d2ad51cf509', //跳转的小程序的aooId
					path: '', //如果这里不填，默认是跳转到对方小程序的主页面
					extraData: { //需要传给对方小程序的数据
						'data1': 'test'
					},
					success(res) {
						console.log(111);
					}
				})
				// #endif


				//#ifdef  MP-TOUTIAO 
				tt.navigateToMiniProgram({
					appId: "wx43a84d2ad51cf509",
					success: function() {
						
					},
					fail: function(e) {
						console.log(e);
					},
				});

				//#endif
			},
			tologin() {
				uni.navigateTo({
					url: "/pages/mine/login"
				})
			},
			toxieyi() {
				uni.navigateTo({
					url: "./xieyi?type=4"
				})
			},
			tourl(type) {
				if (this.$islogin()) return
				uni.navigateTo({
					url: "/pages/index/broker?type=" + type
				})
			},
			login(e) {
				if (e.detail.code) {
					var phoneCode = e.detail.code
					uni.login({
						success: (code) => {
							this.$u.post('/api/Login/login', {
								code: code.code
							}).then(res => {
								if (res.code == 1) {
									uni.setStorageSync("token", res.data.token)
									if (!res.data.phone || 1) {
										this.$u.post('/api/Member/bind_Phone', {
											code: phoneCode
										}).then(res => {
											if (res.code == 1) {
												this.$u.toast("登录成功")
												this.$u.post('/api/Member/member_info').then(
													res => {
														uni.setStorageSync("hx_username",
															res.data.hx_username)
														this.$WebIM.conn.open({
															user: res.data.hx_username,
															pwd: "888888",
														}).then(() => {
															console.log(
																"login success"
															);
														}).catch((reason) => {
															console.log(
																"login fail",
																reason);
														});
													})
												this.setcity()
												this.getuser()
											} else {
												this.$u.toast(res.msg)
												uni.removeStorageSync('token')
											}
										})
									} else {
										this.$u.toast("登录成功")
										this.getuser()
									}
								} else {
									this.$u.toast(res.msg)
								}
							})
						}
					})
				}
			},
			setcity() {
				this.$u.post('/api/Index/location', {
					longitude: this.defaultcity.userLocation.split(',')[0],
					latitude: this.defaultcity.userLocation.split(',')[1],
					city_name: this.defaultcity.city
				})
			},
			getuser() {
				this.$u.post('/api/Member/member_info').then(res => {
					uni.setStorageSync("name", res.data.name)
					uni.setStorageSync("headimg", res.data.headimg)
					this.userinfo = res.data
				})
			},
			tosetting() {
				if (this.$islogin()) return
				uni.navigateTo({
					url: "./setting"
				})
			},
			tobaobei() {
				if (this.$islogin()) return
				uni.navigateTo({
					url: "./baobei-list"
				})
			},
			toyongjin() {
				if (this.$islogin()) return
				uni.navigateTo({
					url: "./yongjin"
				})
			},
			tojifen() {
				if (this.$islogin()) return
				uni.navigateTo({
					url: "./jifen"
				})
			},
			toinfo() {
				if (this.$islogin()) return
				uni.navigateTo({
					url: "./userinfo"
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F6F6F6;
	}

	.mine {
		position: relative;
		z-index: 1;

		.setting-box {
			width: 702rpx;
			height: 82rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 0 auto;
			padding: 0 24rpx;
			font-size: 24rpx;
			font-weight: 400;
			color: #333333;
		}

		.tabs-box {
			width: 702rpx;
			height: 218rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 20rpx auto;

			.tabs-item {
				width: 25%;

				image {
					width: 84rpx;
					height: 84rpx;
					margin-bottom: 20rpx;
					border-radius: 20rpx;
				}

				text {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #131415;
				}
			}
		}


		.yongjin-box {
			width: 702rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin: 0 auto;
			// padding: 0 50rpx;

			.btn {
				width: 132rpx;
				height: 52rpx;
				background: #1F7EFF;
				border-radius: 10rpx;
				color: #fff;
				line-height: 52rpx;
				padding: 0;
				font-size: 22rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
			}

			.mingxi {
				height: 82rpx;
				text-align: center;
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;

				text {
					text-align: center;
					line-height: 82rpx;
				}
			}
			.price {
				min-height: 226rpx;
				border-bottom: 2rpx solid rgba(245, 245, 245, 1);
				padding: 34rpx 20rpx;

				.forward {
					::v-deep .uni-noticebar {
						padding-top: 0 !important;
						padding-bottom: 0 !important;
						margin: 0 !important;
					}
				}

				.font {
					width: 96rpx;
					height: 34rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #888888;
					line-height: 34rpx;
				}

				.jffont {
					width: 112rpx;
					height: 40rpx;
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
					line-height: 40rpx;
				}

				.img {
					width: 94rpx;
					height: 94rpx;
					margin-right: 34rpx;
				}

				.text {
					text:first-child {
						font-size: 48rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #333333;
					}

					text:last-child {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
					}
				}
			}
		}

		.user-box {
			padding: 48rpx 24rpx 82rpx 24rpx;

			.user-center {
				margin: 0 32rpx;

				.text1 {
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					margin: 0 0 20rpx 0;
					padding: 0;
					border: none;
					background-color: rgba(0, 0, 0, 0);
					line-height: 1.5;
					text-align: left;
				}

				.text1::after {
					margin: 0;
					padding: 0;
					border: none;
				}

				.text2 {
					padding: 0 20rpx;
					min-width: 102rpx;
					line-height: 40rpx;
					border-radius: 24rpx;
					border: 2rpx solid #FFFFFF;
					text-align: center;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}
			}

			.user-head {
				width: 120rpx;
				height: 120rpx;
				border-radius: 100rpx;
			}
		}

		.mine-tips {
			width: 750rpx;
			line-height: 56rpx;
			background: rgba(255, 255, 255, 0.1);
			padding: 0 24rpx;
			font-size: 22rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
		}

		.index-bg {
			width: 750rpx;
			height: 556rpx;
			background: linear-gradient(180deg, #1E7DFF 0%, #F6F6F6 100%);
			position: absolute;
			top: 1;
			left: 0;
			z-index: -1;
		}
	}
</style>
