<template>
	<view class="container">
		<view class="userinfo-card">
			<view class="card-box">
				<view class="user-section">
					<view class="left">
						<view class="avatar-wrap">
							<image class="avatar" :src="storeInfo.avatar"></image>
						</view>
						<view class="portrait-box">
							<view class="info-box">
								<text class="username"
									@click="goLogin">{{ storeInfo.storeName ? storeInfo.storeName : '游客' }}</text>
							</view>
							<!-- <view class="tuan" v-if="storeInfo.consortiaContent">
								<view class="ma">{{storeInfo.consortiaContent}}</view>
							</view> -->
						</view>
					</view>
					<!-- <view class="right">
						<view class="btn" @tap="editStoreInfo">
							修改店铺信息
						</view>
					</view> -->
				</view>
				<view class="balance-card-wrap">
					<view class="balance-card">
						<view class="left">
							<view class="tit">可提现金额(元)</view>
							<view class="num">
								<text>￥</text>{{ storeInfo.moneys }}
							</view>
						</view>
						<view class="right">
							<view @click="withdrawNow()" class="withdraw-btn">立即提现</view>
						</view>
					</view>
					<view class="shouyi-card">
						<view class="show-content">
							<view class="view-category" @click="navToLogin('/my/wallet/teammoneydetail')">
								<view class="num">￥{{ storeInfo.moneys }}</view>
								<view class="text">总收益额</view>
							</view>
							<view class="line"></view>
							<view class="view-category">
								<view class="num">{{ storeInfo.counts }}</view>
								<view class="text">总订单数</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="tool-card">
				<view class="tool-item" @click="navToLogin('/my/gonghui/therapist?consortiaId=' + consortiaId)">
					<view class="item-right">
						<view class="view-text">商家</view>
						<image src="/static/images/index/right.png" class="view-image-right"></image>
					</view>
				</view>
				<view class="tool-item" @click="navToLogin('/my/wallet/teammoneydetail')">
					<view class="item-right">
						<view class="view-text">商家收益</view>
						<image src="/static/images/index/right.png" class="view-image-right"></image>
					</view>
				</view>
				<!-- <view class="tool-item" @click="navToLogin('/pages/merchant/walletList')">
					<view class="item-right">
						<view class="view-text">钱包明细</view>
						<image src="/static/images/index/right.png" class="view-image-right"></image>
					</view>
				</view> -->
				<!-- <view class="tool-item" @click="goChat">
					<view class="item-right">
						<view class="view-text">联系客服</view>
						<image src="/static/images/index/right.png" class="view-image-right"></image>
					</view>
				</view> -->
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				orderList: [],
				top: 0,
				storeStatus: null,
				storeInfo: {
					storeName: "游客",
					avatar: "../../static/logo.png",
					consortiaContent: '',
					moneys: "0",
					counts: 0,
					todayEarnings: "0", //今日收益
					earningsThisMonth: "0", //本月收益
					NumWriteOffPieces: "0", //核销件数
				},
				wxWithdrawal: "否",
				aliWithdrawal: "否",
				modal4: false,
				button4: [{
						text: '微信',
						type: 'green',
						plain: true
					},
					{
						text: '支付宝',
						plain: true
					},
				],
			};
		},
		onLoad() {
			let that = this;
			this.getUserInfo();
		},
		onShow() {
			let that = this;
			this.getUserInfo();
		},
		methods: {
			goChat() {
				let kefu = this.$queue.getData('kefu'); // 用户端联系方式 1 手机号 2企业微信 
				let kefuPhone = this.$queue.getData('kefuPhone');
				let userId = this.$queue.getData('userId');
				if (userId) {
					if (kefu == 1) {
						uni.makePhoneCall({
							phoneNumber: kefuPhone //仅为示例
						});
					} else if (kefu == 3) {
						uni.navigateTo({
							url: '/my/setting/customer'
						});
					} else {
						// #ifdef MP-WEIXIN
						let that = this
						try {
							wx.openCustomerServiceChat({
								extInfo: {
									url: that.$queue.getData('kefuUrl')
								},
								corpId: that.$queue.getData('kefuAppId'),
								success(res) {},
								fail(res) {
									console.error(res)
								}
							})
						} catch (error) {
							console.error("catchcatch" + error)
							uni.showToast({
								title: '请更新至微信最新版本'
							});
						}
						// #endif
						// #ifndef MP-WEIXIN
						let url = this.$queue.getData('kefuUrl');
						if (url.indexOf('/pages/') !== -1 || url.indexOf('/my/') !== -1) {
							uni.navigateTo({
								url
							});
						} else {
							//#ifndef H5
							uni.navigateTo({
								url: '/pages/index/webView?url=' + url
							});
							//#endif
							//#ifdef H5
							window.location.href = url;
							//#endif
						}
						// #endif
					}
				} else {
					uni.showModal({
						title: '提示',
						content: '您还未登录,请先登录',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/pages/public/login'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			saveImgss(imgs, index) {
				console.log(imgs, index)
				// let that = this
				let imgArr = imgs
				// this.imgArr.push(imgs);
				// console.log(this.imgArr)
				// //预览图片
				uni.previewImage({
					urls: imgArr,
					current: imgArr[index]
				});
			},
			saveImgs(imgs) {
				let imgArr = [];
				imgArr.push(imgs);
				// //预览图片
				uni.previewImage({
					urls: imgArr,
					current: 0
				});
			},
			getlist() {
				let userId = this.$queue.getData('userId');
				let index = 2
				let data = {
					page: this.page,
					limit: this.limit,
					consortiaId: this.consortiaId,
					shopId: userId
				}
				// console.log(data)
				this.$Request.get("/app/consortia/selectUserListByConsortiaId", data).then(res => {
					if (res.code == 0) {
						if (this.page == 1) {
							this.orderList = res.data.list
						} else {
							this.orderList = [...this.orderList, ...res.data.list]
						}
					}
					uni.stopPullDownRefresh();
				})
			},
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.consortiaId = res.data.consortiaId
						uni.setStorageSync('avatar', res.data.avatar)
						uni.setStorageSync('userName', res.data.userName)
						uni.setStorageSync('invitationCode', res.data.invitationCode)
						uni.setStorageSync('zhiFuBao', res.data.zhiFuBao)
						uni.setStorageSync('zhiFuBaoName', res.data.zhiFuBaoName)
						this.initStoreInfo();
						this.getlist();
					}
				});
			},
			initNavigation(e) {
				this.top = e.top;
			},
			back() {
				uni.navigateBack();
			},
			//获取商户信息
			initStoreInfo() {
				let that = this;
				let userId = that.$queue.getData('userId');
				this.$Request.getT('/app/consortia/selectConsortiaByUserId?consortiaId=' + this.consortiaId).then(res => {
					if (res.code == 0) {
						this.storeInfo.avatar = res.data.logo;
						this.storeInfo.storeName = res.data.consortiaName;
						this.storeInfo.consortiaContent = res.data.consortiaContent;
					}
				});
				this.$Request.getT('/app/consortia/selectConsortiaMoney?shopId=' + userId).then(res => {
					if (res.code == 0) {
						this.storeInfo.moneys = res.data ? res.data : 0;
					}
				});
				this.$Request.getT('/app/artificer/selectOrdersLists?page=1&limit=10&shopId=' + userId).then(res => {
					if (res.code == 0) {
						this.storeInfo.counts = res.data.totalCount ? res.data.totalCount : 0;
					}
				});
			},
			/** 
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navToLogin(urlPath) {
				let that = this,
					url,
					userId = that.$queue.getData('userId');
				if (userId) {
					url = urlPath;
				} else {
					url = '/pages/member/login';
				}
				uni.navigateTo({
					url
				});
			},
			navTo(index) {
				uni.navigateTo({
					url: "/pages/merchant/order?index=" + index
				});
			},
			// 是否绑定支付宝账号，未绑定跳转绑定，已绑定可发起提现
			withdrawNow() {
				uni.navigateTo({
					url: '/my/wallet/index?tabIndex=1'
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	page {
		background: #F2F3F7;
	}

	page {
		background-color: #F7F7F7;
	}

	.zz_view {
		// width: 220upx;
		background: #e8fdf6;
		color: #73c2a2;
		font-size: 24rpx;
		padding: 6rpx 10rpx;
		border-radius: 10rpx;
	}

	.zpmore_view {
		background: #2FB57A;
		width: 120upx;
		text-align: center;
		border-radius: 10rpx;
		height: 42rpx;
		line-height: 42rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		margin-left: 10rpx;
	}

	.byy_view {
		// background: #2FB57A;
		width: 120upx;
		text-align: center;
		border-radius: 50rpx;
		height: 46rpx;
		line-height: 46rpx;
		font-size: 24rpx;
		color: #999999;
		border: 3upx solid #999999;
		margin-top: 6rpx;
	}

	.kyy_view {
		background: #2FB57A;
		width: 120upx;
		text-align: center;
		border-radius: 50rpx;
		height: 46rpx;
		line-height: 46rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		margin-top: 6rpx;
	}

	.bg {
		background: #FFFFFF;
	}

	.container {
		.header-box {
			width: 100%;
			position: fixed;
			top: 0;
			padding: 0 30rpx;
			display: flex;
			align-items: center;
			height: 32px;
			transform: translateZ(0);
			z-index: 99999;
			box-sizing: border-box;

			.header-title {
				display: flex;
				font-size: 38upx;
			}
		}

		.userinfo-card {
			.card-box {
				width: 100%;
				/* #ifdef H5 */
				height: 476upx;
				/* #endif */
				/* #ifdef MP-WEIXIN */
				height: 406upx;
				/* #endif */
				position: relative;
				z-index: 0;

				.user-section {
					position: absolute;
					top: 0;
					z-index: 10;
					width: 100%;
					/* #ifdef H5 */
					padding: 50upx 30upx 210upx;
					/* #endif */
					/* #ifdef MP-WEIXIN */
					padding: 0 30upx 140upx;
					/* #endif */
					background-color: #05C25C;
					display: flex;
					justify-content: space-between;

					.left {
						display: flex;

						.avatar-wrap {
							width: 100upx;
							height: 100upx;
							border-radius: 10upx;
							overflow: hidden;

							.avatar {
								width: 100%;
								height: 100%;
							}
						}

						.portrait-box {
							margin-left: 18upx;
							display: flex;
							flex-direction: column;
							justify-content: space-between;

							.info-box {
								font-size: 38upx;
								font-family: PingFang SC;
								font-weight: bold;
								color: #FFF;
								margin-top: 20rpx;
							}

							.tuan {
								display: flex;
								align-items: center;
								width: 560rpx;

								.ma {
									font-size: 24upx;
									font-family: PingFang SC;
									font-weight: 500;
									color: #FFF;
								}
							}
						}
					}

					.right {
						display: flex;
						align-items: center;
						justify-content: center;

						.btn {
							width: 180upx;
							height: 58upx;
							background: #FFFFFF;
							text-align: center;
							font-size: 24upx;
							color: #333;
							line-height: 58upx;
							border-radius: 29upx 0upx 0upx 29upx;
							margin-right: -30upx;
						}
					}

				}

				.balance-card-wrap {
					width: 100%;
					height: 276upx;
					padding: 0 20upx;
					position: absolute;
					bottom: 0;
					z-index: 10;
					display: flex;
					flex-direction: column;

					.balance-card {
						width: 100%;
						height: 140upx;
						background-color: #fff;
						border-radius: 20upx 20upx 0 0;
						padding: 30upx 30upx 0 30upx;
						border-bottom: 1upx solid #f2f2f2;
						display: flex;
						justify-content: space-between;

						.left {
							.tit {
								font-size: 24upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #999999;
							}

							.num {
								font-size: 40upx;
								font-family: DINPro;
								font-weight: 500;
								color: #333333;

								text {
									font-size: 36upx;
								}
							}
						}

						.right {
							.withdraw-btn {
								background: #05C25C;
								border-radius: 25px;
								width: 150upx;
								height: 50upx;
								line-height: 50upx;
								text-align: center;
								font-size: 24upx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #FFF;
							}
						}



					}

					.shouyi-card {
						width: 100%;
						flex: 1;
						background-color: #fff;
						border-radius: 0 0 20upx 20upx;
						display: flex;
						align-items: center;

						.show-content {
							width: 100%;
							display: flex;
							justify-content: space-around;
							align-items: center;

							.view-category {
								display: flex;
								flex-direction: column;
								align-items: center;
								justify-content: center;

								.num {
									font-size: 38upx;
									font-family: PingFang SC;
									font-weight: 800;
									color: #333333;
								}

								.text {
									font-size: 24upx;
									font-family: PingFang SC;
									font-weight: 500;
									color: #999999;
								}
							}

							.line {
								width: 1px;
								height: 65upx;
								background-color: #E6E6E6;
							}
						}
					}
				}
			}

		}


		.main {
			padding: 20upx;

			.income-card {
				width: 100%;
				background-color: #fff;
				border-radius: 20upx;
				padding: 30upx;
				margin-top: 20upx;

				.tit {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 32upx;
					line-height: 32upx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;

					image {
						width: 10upx;
						height: 21upx;
					}
				}

				.show-content {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 40upx;
					padding: 0 10upx;

					.view-category {
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;

						image {
							width: 48upx;
						}

						.text {
							font-size: 24upx;
							font-family: PingFang SC;
							font-weight: 500;
							color: #999999;
							margin-top: 15upx;
						}
					}
				}
			}

			.tool-card {
				background-color: #ffffff;
				width: 100%;
				padding: 0 30upx;
				border-radius: 20upx;

				.tool-item {
					display: flex;
					flex-direction: row;
					width: 100%;
					height: 100upx;
					align-items: center;
					justify-content: space-between;

					.view-image-left {
						width: 44upx;
					}

					.item-right {
						flex: 1;
						display: flex;
						flex-direction: row;
						align-items: center;
						justify-content: space-between;

						button {
							flex: 1;
							padding: 0;
							margin: 0;
							border: none;
							background: transparent;
							text-align: left;
						}

						button::after {
							border: none;
						}

						button::before {
							border: none;
						}

						.view-text {
							font-size: 28upx;
							font-family: PingFang SC;
							font-weight: bold;
							color: #1A1A1A;
						}

						.view-image-right {
							width: 10upx;
							height: 21upx;
						}
					}
				}
			}
		}

		.back-user {
			width: 100upx;
			height: 100upx;
			border-radius: 50%;
			background: #FFF;
			color: #000000;
			line-height: 100upx;
			text-align: center;
			position: fixed;
			right: 30upx;
			bottom: 5%;
		}
	}
</style>
