<template>
	<view class="my">
		<view class="login">
			<view class="head" v-if="isLogin">
				<view class="img">
					<image :src="info.cIcon" alt=""></image>
				</view>
				<view class="login_title">{{info.cNickName}}</view>
			</view>
			<view class="head" v-else>
				<view class="img" @click="login">
					<image
						src="https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132"
						alt=""></image>
				</view>
				<view class="login_title" @click="login">
					去登录
				</view>
			</view>
			<view class="balance">
				<view class="money_box">
					<view class="title">
						账户余额
					</view>
					<text>￥</text>
					{{dBalance}}

				</view>
				<view class="btn_box">
					<view class="btn" @click="goPay">
						去充值
					</view>
				</view>

			</view>
		</view>
		<view class="account">

			<view class="other">
				<view class="option" @click="gocollect">
					<view class="left">
						<image src="../../static/other/collect.png" mode=""></image>
					</view>
					<view class="right">
						<view class="top">
							我的收藏
						</view>
						<view class="bottom">
							<text>
								{{collectNum}}
							</text>人
						</view>
					</view>
				</view>
				<view class="option" @click="goCoupon">
					<view class="left">
						<image src="../../static/other/coupon.png" mode=""></image>
					</view>
					<view class="right">
						<view class="top">
							我的优惠券
						</view>
						<view class="bottom">
							<text>
								{{couponNum}}
							</text>张
						</view>
					</view>
				</view>
				<!-- <view class="option" @click="goCoupon">
					我的优惠券
					<text>
						{{couponNum}}
					</text>张
				</view> -->
			</view>
		</view>
		<view class="feature">
			<view class="title">
				通用功能
			</view>
			<view class="box">
				<view class="item" @click="goremamber">
					<image src="../../static/other/address.png" alt=""></image>
					<view>地址管理</view>
				</view>
				<view class="item" @click="goTeamwork">
					<image src="../../static/other/feedback.png" alt=""></image>
					<view>招商合作</view>
				</view>
				<!-- <view class="item" @click="goEngineer" v-if="check == 0 || check == 2 || check == -1"> -->
				<view class="item" @click="goEngineer">
					<image src="../../static/other/home.png" alt=""></image>
					<view>商户入驻</view>
				</view>
				<view class="item" @click="goEngineerCenter">
					<image src="../../static/other/personal.png" alt=""></image>
					<view>商户中心</view>
				</view>
				<view class="item" @click="goComplaint">
					<image src="../../static/other/complain.png" alt=""></image>
					<view>投诉举报</view>
				</view>
			</view>
		</view>
		<view class="popup">
			<u-mask :show="show" @click="show = false">
				<view class="refuse">
					<view class="title">
						退回提示
					</view>
					<view class="content">
						{{reasonRefusal}}
					</view>
					<view class="btn_box" @click="show = false">
						<view class="btn">
							取消
						</view>
						<view class="btn success" @click="update">
							去修改
						</view>
					</view>
				</view>
			</u-mask>
		</view>
	</view>

</template>
<script>
	import {
		wxGetCode
	} from '../../api/my'
	import {
		getInfo,
		engineDetail,
		getCoupon,
		getwxQrCode,
		getCollect,
		logout
	} from '../../api/index.js'
	// import { wxLogin } from 'uni-login';
	export default {

		data() {
			return {
				show: false,
				info: [],
				check: -1,
				data: '',
				dBalance: 0,
				txShow: false,
				couponNum: 0, //优惠券数量
				isQrcodeShow: false,
				qrcodeImage: '',
				urlView: '',
				qqUrl: '',
				cnickName: '',
				wx_copenid: '', //微信返回openid
				token: '', //登录成功token
				isLogin: false,
				collectNum: 0,
				reasonRefusal: ''

			}
		},
		methods: {
			goTeamwork() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					uni.navigateTo({
						url: '../join/teamwork'
					})
				}
			},
			goComplaint() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					uni.navigateTo({
						url: '../join/feedback'
					})
				}
			},
			//获取收藏列表
			getcollectList() {
				var data = {
					cWxOpenId: uni.getStorageSync('wx_copenid')
				}
				getCollect(data).then(res => {
					if (res.data.code == 200) {
						this.collectNum = res.data.data.length
						// this.list = res.data.data
					}
				})
			},
			goWithdraw() {
				uni.navigateTo({
					url: './withdraw'
				})
			},
			goFeedBack() {

			},
			// },
			qrCodeShow() {
				this.isQrcodeShow = !this.isQrcodeShow
			},
			getwxQrCode() {
				var openId = {
					openId: uni.getStorageSync('wx_copenid')
				}
				getwxQrCode(openId).then(res => {
					let TICKET = res.data.ticket
					this.urlView = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' + TICKET
				})
			},
			//跳转至优惠券页
			goCoupon() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					uni.navigateTo({
						url: './coupon'
					})
				}
			},
			//跳转至商户中心页
			goEngineerCenter() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					uni.navigateTo({
						url: './engineerCenter'
					})
				}

			},
			//商户入驻
			goEngineer() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					if (this.check == 0 || this.check == 2 || this.check == 3) {
						uni.showToast({
							title: '正在审核中',
							icon: 'none'
						})
						return
					} else if (this.check == 1) {
						uni.showToast({
							title: '审核已通过',
							icon: 'none'
						})
						return
					} else {
						uni.navigateTo({
							url: '/pages/join/first_join'
						})
					}

				}
			},
			update() {
				uni.navigateTo({
					url: './indent?title=编辑资料'
				})
			},
			//跳转至充值
			goPay() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					uni.navigateTo({
						url: '../my/pay'
					})
				}
			},
			//跳转至我的收藏
			gocollect() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					uni.navigateTo({
						url: './collect'
					})
				}
			},
			login() {
				uni.navigateTo({
					url: '../login/wxLogin'
				})
			},
			goremamber() {
				if (!this.isLogin) {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					return
				} else {
					uni.navigateTo({
						url: './remember'
					})
				}
			},
			myCoupon() {
				var openId = {
					openid: uni.getStorageSync('wx_copenid')
				}
				getCoupon(openId).then(res => {
					if (res.data.data.length > 0) {
						this.couponNum = res.data.data.length
					} else {
						this.couponNum = 0
					}

				})
			},
			getinfo() {
				getInfo().then(res => {
					if (res.data.code == 200) {
						this.isLogin = true
						this.info = res.data.data,
							this.dBalance = res.data.data.dBalance.toFixed(2)
					} else {
						this.isLogin = true
					}
					// uni.setStorage({
					// 	key: 'wx_copenid',
					// 	data: res.data.data.cOpenid
					// })


					// this.check = res.data.data.role
					// if (res.data.data.role == 1) {
					// 	this.txShow = true
					// }

				})

			},
			getDetails() {
				var openid = {
					cOpenId: uni.getStorageSync('wx_copenid')
				}
				engineDetail(openid).then(res => {
					if (res.data.data) {
						this.check = res.data.data.nTong
						this.reasonRefusal = res.data.data.reasonRefusal
						this.data = res.data.data
						if (this.check == 1) {
							this.txShow = true
						}
					} else {
						this.check = -1
					}
				})
			},
			//退出登录
			logout() {
				uni.showModal({
					title: '确定退出登录吗',
					success: (res) => {
						if (res.confirm) {
							logout().then(res => {
								if (res.data.code == 200) {
									// this.getinfo()
									uni.removeStorageSync('access-token')
									this.$router.go(0)
									uni.showToast({
										title: '已退出登录',
										icon: 'none'
									})
								}
							})
						} else if (res.cancel) {
							return
						}
					}
				})
			}
		},
		onLoad() {
			this.wx_copenid = uni.getStorageSync('wx_copenid')
			uni.setStorageSync('access-token','eyJhbGciOiJIUzUxMiJ9.eyJ0ZjoiOiIwMTU2MTZiNS0xNjdmLTQ3YTEtODVmOC0xMWYxNzJiNzA5ZmUifQ._21anlHblpwT97QZ7t2c_aH3VD79CjnP4_LHjgXjF7-GqXVk1U9RtnZlGYAwhe91I_eqCB8ZWY1Gn3R5zk28jw')
			uni.setStorageSync('wx_copenid','o7Txd6poqpr0ZJUOsAudwJgoNutw')
		},
		onShow() {
			this.getinfo()
			this.myCoupon()
			this.getDetails()
			this.getcollectList()

			// this.getwxQrCode()
		}
	}
</script>

<style lang="scss" scoped>
	.my {
		background: #F7F8FA;
		width: 100vw;
		height: 100vh;
		position: relative;

		.popup {
			.refuse {
				width: 60%;
				height: 200px;
				background-color: #fff;
				border-radius: 10px;
				position: fixed;
				top: 50%;
				left: 50%;
				transform: translate(-50%, -50%);
				padding: 20px;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				align-items: center;

				.title {
					width: 100%;
					height: 10%;
					text-align: center;
					color: #808080;
				}

				.content {
					flex: 1;
					overflow-y: auto;
					margin-bottom: 10px;
					margin-top: 10px;
				}

				.btn_box {
					width: 100%;
					height: 10%;
					display: flex;
					justify-content: space-around;
					font-size: 24rpx;

					.btn {
						width: 30%;
						height: 25px;
						background-color: #c8c9cc;
						text-align: center;
						line-height: 25px;
						border-radius: 5px;
					}

					.success {
						background: linear-gradient(to right, #35c99d, #27aea7);
						color: #fff;
					}
				}
			}
		}
	}

	.title {
		width: 100%;
		padding-bottom: 20rpx;

		.titles {
			text-align: center;
			font-size: 36rpx;
			font-family: Georgia, 'Times New Roman', Times, serif;
			font-weight: bold;
			padding-top: 10rpx;
		}

		.back {
			position: absolute;
			left: 30rpx;
			width: 80rpx;
			height: 35rpx;

			image {
				width: 18rpx;
				height: 100%;
			}
		}
	}

	.login {
		width: 100%;
		height: 484rpx;
		box-sizing: border-box;
		// background-image: url(../../static/other/bgi.png);
		background-image: url(../../static/other/bgimg.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: relative;

		.head {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding-top: 52rpx;

			.img {
				width: 160rpx;
				height: 160rpx;
				border-radius: 100px;
				overflow: hidden;
				margin-bottom: 20rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.login_title {
				font-weight: 700;
				margin-left: 20rpx;
			}
		}

		.balance {
			width: 670rpx;
			height: 188rpx;
			position: absolute;
			bottom: -32rpx;
			left: 50%;
			transform: translateX(-50%);
			background: linear-gradient(292deg, #3A3532 0%, #222021 100%);
			border-radius: 24px 24px 24px 24px;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 48rpx;
			box-sizing: border-box;
			font-size: 48rpx;
			color: #FFE6CE;

			.money_box {
				color: #FFE6CE;

				.title {
					padding: 0;
					font-size: 24rpx;
					margin-bottom: 16rpx;
				}

				text {
					font-size: 28rpx;
				}
			}

			.btn_box {
				display: flex;
				align-items: center;

				.btn {
					color: #000;
					width: 148rpx;
					height: 72rpx;
					font-size: 28rpx;
					background: linear-gradient(to bottom, #ead3ba, #ddbe96);
					display: flex;
					justify-content: center;
					align-items: center;
					border-radius: 20px;
					// margin-left: 200rpx;
				}
			}

		}

		image {
			width: 108rpx;
			height: 108rpx;

		}

		.text {
			flex: 1;
			font-size: 36rpx;
			color: #1A1A1A;
			font-family: monospace;
			font-weight: bold;
			margin-left: 40rpx;
		}

		.login_out {
			// margin-left: 100;
			width: 50rpx;
			height: 50rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.my_list {
		// position: fixed;
		bottom: 0;
		width: calc(100% - 60rpx);
		height: 60vh;
		border-top-left-radius: 30rpx;
		border-top-right-radius: 30rpx;
		padding: 0 30rpx;
		padding-top: 50rpx;
		display: flex;
		justify-content: space-around;

		.item {
			height: 100rpx;
			line-height: 100rpx;
			position: relative;
			text-align: center;

			image {
				width: 80rpx;
				height: 80rpx;
			}

			view {
				font-size: 26rpx;
				color: #707678;
				height: 30rpx;
				line-height: 30rpx;
			}
		}
	}

	.account {
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin: 62rpx auto;



		.other {
			width: 100%;
			padding: 0px 40rpx;
			// border-radius: 20rpx 20rpx 0px 0px;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			// padding: 10rpx 0px 10rpx 0px;
			// background-color: #fff;

			.option {
				width: 319rpx;
				height: 136rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				display: flex;
				align-items: center;
				font-weight: 700;
				padding: 24rpx 32rpx;
				box-sizing: border-box;

				.left {
					image {
						width: 88rpx;
						height: 88rpx;
					}
				}

				.right {
					margin-left: 24rpx;

					.top {
						font-size: 28rpx;
						color: #2F3437;
						margin-bottom: 10rpx;
					}

					.bottom {
						font-size: 24rpx;
						color: #5E686E;

						text {
							font-size: 26rpx;
							color: #03C8BE;
						}
					}
				}
			}
		}

		.money {
			font-size: 40rpx;
		}

		.btn {
			color: #eddbc5;
		}
	}

	.feature {
		width: 670rpx;
		padding: 32rpx;
		background-color: #fff;
		border-radius: 10px;
		box-sizing: border-box;
		margin: 30rpx auto;

		.title {
			font-weight: 700;
			font-size: 28rpx;
			color: #2F3437;
		}

		.box {
			display: flex;
			flex-wrap: wrap;
			.item {
				width: 25%;
				margin: 20rpx 0px;
				display: flex;
				flex-direction: column;
				align-items: center;
				font-size: 24rpx;
				color: #2F3437;
				image {
					width: 60rpx;
					height: 60rpx;
					margin-bottom: 8rpx;
				}
			}
		}
	}

	.qr_code {
		width: 100vw;
		height: 100vh;
		background-color: rgba(0, 0, 0, 0.8);
		z-index: 999999;
		position: absolute;
		top: 0;
		left: 0;
		display: flex;
		justify-content: center;
		align-items: center;

		.img_box {
			background-color: #fff;
			// height: 800rpx;
			border-radius: 20rpx;
			overflow: hidden;

			image {
				width: 400rpx;
				height: 400rpx;
			}
		}
	}
</style>