<template>
	<view class="container">
		<view class="vheigh"></view>
		<scroll-view class="content-box" scroll-y="true">
			<view class="user-section">
				<view class="user-info-box ">
					<view class="detail flex" @click="navTo('/pages/set/userinfo')">
						<view class="portrait-box">
							<image class="portrait" :src="shopAction.image || '/static/error/shopErroe.png'"></image>
						</view>
						<view class="info-box">
							<view class="username">{{ shopAction.name?shopAction.name:'载入中'}}</view>
							<view class="authentication success">已认证</view>
						</view>
					</view>
				</view>
			</view>
			<view class="cover-container">
				<view class="tj-sction" v-if="type==1">
					<view class="tj-item" @click="navTo('./money/wallet')">
						<text>支付金额</text>
						<text class="num">{{ orderNum.todayPrice || '0' }}</text>
						<text>昨日：{{orderNum.proPrice}}</text>
					</view>
					<!-- <view class="tj-item" @click="navTo('/pages/user/award/award')">
						<text>会员数</text>
						<text class="num">{{ orderNum.proPrice || '0' }}</text>
						<text>昨日：{{orderNum.proPrice}}</text>
					</view> -->
					<view class="tj-item" @click="navTo('/pages/user/scoreAccumulate')">
						<text>支付订单数</text>
						<text class="num">{{ orderNum.todayCount || '0' }}</text>
						<text>昨日：{{orderNum.proCount}}</text>
					</view>
				</view>
				<!-- 订单 -->
				<view class="item-box">
					<view class="box-title flex">
						<view class="title"><text>店铺订单</text></view>
						<!-- <view class="link" @click="navTo('/pages/shop/shopOrder?state=0')" hover-class="common-hover">
							<text>全部</text>
							<text class="iconfont iconenter"></text>
						</view> -->
					</view>
					<view class="order-section">
						<view class="order-item" @click="navTo('/pages/shop/shopOrder?state=0')"
							hover-class="common-hover" :hover-stay-time="50">
							<view class=" icon position-relative">
								<view class="numOrderItem font-color-gray">
									{{orderNum.unpaid_count}}
								</view>
							</view>
							<text>待付款</text>
						</view>
						<view class="order-item" @click="navTo('/pages/shop/shopOrder?state=1')"
							hover-class="common-hover" :hover-stay-time="50">
							<view class=" icon position-relative">
								<view class="numOrderItem font-color-red">
									{{orderNum.unshipped_count}}
								</view>
							</view>
							<text>待发货</text>
						</view>
						<view class="order-item" @click="navTo('/pages/shop/shopOrder?state=2')"
							hover-class="common-hover" :hover-stay-time="50">
							<view class="icon position-relative">
								<view class="numOrderItem font-color-gray">
									{{orderNum.received_count}}
								</view>
							</view>
							<text>已发货</text>
						</view>
						<!-- <view class="order-item" @click="navTo('/pages/shop/shopOrderAfter?state=3')"
							hover-class="common-hover" :hover-stay-time="50">
							<view class="icon position-relative">
								<view class="numOrderItem font-color-yellow">
									{{orderNum.refund_count}}
								</view>
							</view>
							<text>待售后</text>
						</view> -->
					</view>
				</view>
				<view class="listBox">
					<view class="list">
						<view class="flex listItem" @click="navTo('/pages/shop/repair/clientRepair')" v-if="type==1">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myWx.png" mode="widthFix"></image>
								<text class="title">客户报修</text>
							</view>
							<view class="right flex" v-if="question>0">
								<text class="numbox">{{question}}</text>
								<!-- <image class="img" src="../../static/icon/next1.png" mode="widthFix"></image> -->
							</view>
						</view>
						<view class="flex listItem" @click="navTo('/pages/shop/repair/repairHistory')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myWx.png" mode="widthFix"></image>
								<text class="title">维修历史</text>
							</view>
							<!-- <view class="right flex" v-if="question>0">
								<text class="numbox">{{question}}</text>
							</view> -->
						</view>
						<!-- <view class="flex listItem" @click="navTo('/pages/set/set')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/shopMoney.png" mode="widthFix">
								</image>
								<text class="title">店铺钱包</text>
							</view>
							<view class="right flex">
								<text></text>
							</view>
						</view> -->
						<view class="flex listItem" @click="navTo('/pages/shop/repair/taskClientRepair')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myWx.png" mode="widthFix"></image>
								<text class="title">维修任务</text>
							</view>
							<view class="right flex" v-if="tesk>0">
								<text class="numbox">{{tesk}}</text>
								<!-- <image class="img" src="../../static/icon/next1.png" mode="widthFix"></image> -->
							</view>
						</view>
						<!-- <view class="flex listItem" @click="navTo('/pages/set/set')">
							<view class="flex titleBox">
								<image class="listIconImg" src="../../static/icon/myServer.png" mode="widthFix"></image>
								<text class="title">联系平台</text>
							</view>
							<view class="right flex">
								<text></text>
							</view>
						</view> -->
						<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 class="tapBottom" @click="changeTab">
					前往用户界面
				</view>
			</view>
		</scroll-view>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		statistics,
		funds,
		question,
		adminStore,
		task
	} from '@/api/shop.js';
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	export default {
		data() {
			return {
				type: 0, //0为数据未加载,1为门店2为店员
				orderNum: {
					unpaid_count: 0, //待支付
					unshipped_count: 0, //待发货
					received_count: 0, //待收获
					refund_count: 0, //待售后
					todayPrice: 0, //今日成交额
					todayCount: 0, //今日订单数
					proPrice: 0, //昨日成交额
					proCount: 0, //昨日订单数
				},
				question: 0, //维修数量
				tesk: 0, //维修任务数量
			};
		},
		computed: {
			...mapState('user', ['hasLogin']),
			...mapState('shop', ['shopAction'])
		},
		created() {
			this.type = this.shopAction.type
		},
		methods: {
			...mapMutations('shop', ['setShopAction']),
			// 重新加载数据
			getInit() {
				const that = this;
				// 订单数
				statistics().then((e) => {
					that.orderNum = e.data
				})
				// 门店资金
				funds().then((e) => {
					that.name = e.data.name;
					that.logo = e.data.image;
					// 保存商店数据
					if (e.data.address) {
						e.data.type = 1;
						that.setShopAction(e.data);
					} else {
						e.data.type = 2;
						adminStore().then((ar) => {
							that.setShopAction(ar.data);
						}).catch((e) => {
							console.log(e);
						})
					}
					that.type = e.data.type;
				})
				// 查询店长客户报修数量
				question().then((e) => {
					that.question = e.data.count
				})
				// 查询维修任务数量
				task().then((e) => {
					that.tesk = e.data.count;
				}).catch((e) => {
					console.log(e);
				})

			},
			// 界面切换
			changeTab() {
				this.$emit('tab', false)
			},
			navTo(url) {
				if (!this.hasLogin) {
					// 保存地址
					saveUrl();
					// 登录拦截
					interceptor();
				} else {
					uni.navigateTo({
						url
					});
				}
			},
		}
	};
</script>
<style lang="scss">
	page {
		height: 100%;
	}

	.tapBottom {
		margin: 0 50rpx;
		text-align: center;
		color: #FFFFFF;
		border: 1px solid $color-green;
		background-color:$color-green ;
		line-height: 1;
		padding: 25rpx;
		border-radius: 100rpx;
		margin-top: 50rpx;
	}

	.listBox {
		margin-top: 20rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
		overflow: hidden;
	}

	.list {
		.listItem {
			padding: 35rpx 40rpx;
			border-bottom: 1px solid $page-color-light;
		}

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

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

			.numbox {
				background-color: $color-red;
				color: #FFFFFF;
				font-size: 22rpx;
				border-radius: 100rpx;
				min-width: 36rpx;
				height: 36rpx;
				line-height: 36rpx;
				text-align: center;
				padding: 0 5rpx;
			}
		}

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

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		border-radius: 10rpx;
	}

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

	.content-box {
		height: 100%;
	}

	.vheigh {
		height: var(--status-bar-height);
	}

	.user-section {
		padding: 15rpx 30rpx 0;
		position: relative;
	}

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

		.detail {
			height: 130rpx;

			.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;

				.username {
					font-size: 40rpx;
					color: $font-color-dark;
					font-weight: bold;
					height: 100%;
				}

				.authentication {
					border: 2rpx solid #FF4241;
					border-radius: 20px;
					padding: 0 25rpx;
					font-size: 24rpx;
					color: #FF4241;
					float: left;

					&.success {
						border: 2rpx solid $color-green;
						color: $color-green;
					}
				}
			}
		}
	}

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

	.tj-sction {
		@extend %section;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 100rpx;
			font-size: $font-sm;
			color: $font-color-light;
		}

		.num {
			font-size: $font-base;
			color: $font-color-dark;
			margin-bottom: 8rpx;
			font-weight: bold;
		}
	}

	.item-box {
		border-radius: 20rpx;
		background-color: white;
		margin-top: 20rpx;

		.box-title {
			line-height: 1;
			padding: 30rpx;

			.title {
				font-size: $font-lg;
				font-weight: bold;
			}

			.link {
				font-size: $font-base - 2rpx;
				color: $font-color-light;
			}
		}

		.order-section {
			@extend %section;
			padding: 28rpx 0;
			padding-top: 0;

			.order-item {
				@extend %flex-center;
				width: 120rpx;
				height: 120rpx;
				border-radius: 10rpx;
				font-size: $font-sm;
				color: $font-color-dark;

				.numOrderItem {
					font-size: 36rpx;
					font-weight: bold;
					text-align: center;
				}
			}

			.iconfont {
				font-size: 48rpx;
				margin-bottom: 18rpx;
				color: #fa436a;
			}

			.icon-shouhoutuikuan {
				font-size: 44rpx;
			}

			.icon {
				height: 50rpx;
				width: 48rpx;
				margin-bottom: 18rpx;
				background-size: 100%;
				background-repeat: no-repeat;
				background-position: center;

				.icon-img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.history-section {
		// padding: 30rpx 0 0;
		margin-top: 20rpx;
		background: #fff;
		border-radius: 10rpx;

		.h-list {
			white-space: nowrap;
			padding: 30rpx 30rpx 0;

			.h-list-image {
				display: inline-block;
				width: 160rpx;
				height: 160rpx;
				margin-right: 20rpx;
				border-radius: 10rpx;
			}
		}
	}
</style>
