<template>
	<!-- 商家中心 -->
	<view class="page1">
		<view class="title">
			<view class="title-sreach">
				<view class="back-btn" @tap="back" :style="{'top': menuButtonInfo.top +'px'}">
					<uni-icons type="left" size="28"></uni-icons>
				</view>
				<view class="title-name" :style="{'padding-top': menuButtonInfo.top +'px'}">
					商家中心
				</view>
			</view>
		</view>
		<view class="shop-title">
			<view class="title1">
				<img :src="shop.shopIcon" alt="" />
			</view>
			<view class="title2">
				<view class="title22">
					{{shop.shopName == undefined ?"":shop.shopName}}
				</view>
				<view class="title33" @tap="updateStatus">
					{{businessStatus == '1'?'暂停营业':'正常营业'}}
					<uni-icons type="right" size="12"></uni-icons>
				</view>
			</view>
		</view>
		<view class="shop-order">
			<view class="order1">
				待办事项
			</view>
			<view class="order2">
				<view class="order22">
					<view class="order33" @tap="goDetail('db',3)">
						<view class="order44" style="color: red;">
							{{daipeisongjiedan}}
						</view>
						<view class="order55">
							待配送接单
						</view>
					</view>
					<view class="order33" @tap="goDetail('db',13)">
						<view class="order44" style="color: red;">
							{{daichucan}}
						</view>
						<view class="order55">
							待出餐
						</view>
					</view>
					<view class="order33" @tap="goDetail('db',4)">
						<view class="order44">
							{{daiquhuo}}
						</view>
						<view class="order55">
							待取货
						</view>
					</view>
					<view class="order33" @tap="goDetail('db',5)">
						<view class="order44">
							{{daisongda}}
						</view>
						<view class="order55">
							待送达
						</view>
					</view>
				</view>
				<view class="order22">
					<view class="order33" @tap="goDetail('db',2)">
						<view class="order44">
							{{daixiaofei}}
						</view>
						<view class="order55">
							待消费
						</view>
					</view>
					<view class="order33" @tap="goDetail('tui',11)">
						<view class="order44" style="color: red;">
							{{shopData.refundCount == undefined?0:shopData.refundCount}}
						</view>
						<view class="order55">
							待退款/售后
						</view>
					</view>
					<view class="order33" @tap="goDetail('pj','cha')">
						<view class="order44">
							{{shopData.pendingBadReviewCount == undefined?0:shopData.pendingBadReviewCount}}
						</view>
						<view class="order55">
							待回复差评
						</view>
					</view>
					<view class="order33" v-if="shopConfig.supportShopDelivery == 1" @tap="goDetail('selfDelivery')">
						<view class="order44" style="color: red;">
							{{shopData.shopDeliveryPendingCount == undefined?0:shopData.shopDeliveryPendingCount}}
						</view>
						<view class="order55">
							自配送订单
						</view>
					</view>
					<view class="order33" v-if="shopConfig.supportTransferDelivery == 1" @tap="goDetail('transferDelivery')">
						<view class="order44" style="color: red;">
							{{shopData.transferDeliveryPendingCount == undefined?0:shopData.transferDeliveryPendingCount}}
						</view>
						<view class="order55">
							中转配送
						</view>
					</view>
				</view>
				<!-- <view class="order22">
					
				</view> -->
			</view>
		</view>
		<view class="shop-order">
			<view class="order1" style="display: flex;">
				<view style="flex: 1;">
					今日实时数据
				</view>
				<!-- <view @tap="goDetail('tj')">
					更多
					<uni-icons type="right" size="12"></uni-icons>
				</view> -->
			</view>
			<view class="data2">
				<view class="data22">
					<view class="data222">
						{{shopData.orderRevenueAndCount.count == undefined?0:shopData.orderRevenueAndCount.count}}
					</view>
					<view class="data333">
						今日订单
					</view>
				</view>
				<view class="data22">
					<view class="data222">
						{{shopData.orderRevenueAndCount.amount == undefined?0:shopData.orderRevenueAndCount.amount}}
					</view>
					<view class="data333">
						营业额
					</view>
				</view>
				<view class="data22">
					<view class="data222">
						{{shopData.orderRevenueAndCount.afterSaleCount == undefined?0:shopData.orderRevenueAndCount.afterSaleCount}}
					</view>
					<view class="data333">
						售后笔数
					</view>
				</view>
				<view class="data22">
					<view class="data222">
						{{shopData.orderRevenueAndCount.afterSaleAmount == undefined?0:shopData.orderRevenueAndCount.afterSaleAmount}}
					</view>
					<view class="data333">
						售后金额
					</view>
				</view>
			</view>
		</view>
		<view class="shop-order">
			<view class="order1">
				必备工具
			</view>
			<view class="menu2">
				<view class="menu22" @tap="goDetail('sp')">
					<view class="menu33">
						<img src="/static/images/dingdan/dd0.png" alt="" />
					</view>
					<view class="menu44">
						商品管理
					</view>
				</view>
				<view class="menu22" @tap="goDetail('yy')">
					<view class="menu33">
						<img src="/static/images/dingdan/dd1.png" alt="" />
					</view>
					<view class="menu44">
						营业信息
					</view>
				</view>
				<view class="menu22" @tap="goDetail('dd')">
					<view class="menu33">
						<img src="/static/images/dingdan/dd2.png" alt="" />
					</view>
					<view class="menu44">
						订单管理
					</view>
				</view>
				<view class="menu22" @tap="goDetail('zd')">
					<view class="menu33">
						<img src="/static/images/dingdan/dd3.png" alt="" />
					</view>
					<view class="menu44">
						账单结算
					</view>
				</view>
				<view class="menu22" @tap="goDetail('pj','pj')">
					<view class="menu33">
						<img src="/static/images/dingdan/dd4.png" alt="" />
					</view>
					<view class="menu44">
						顾客评价
					</view>
				</view>
				<view class="menu22" @tap="goDetail('sjxx')">
					<view class="menu33">
						<img src="/static/images/dingdan/dd2.png" alt="" />
					</view>
					<view class="menu44">
						商家信息
					</view>
				</view>
				<view class="menu22" @tap="goDetail('hx')">
					<view class="menu33">
						<uni-icons type="scan" size="25"></uni-icons>
					</view>
					<view class="menu44">
						扫码核销
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import base from '@/utils/ossUploadFile/base64.js';
	export default {
		data() {
			return {
				menuButtonInfo: {},
				businessStatus:1,
				shop:{},
				shopConfig:{},
				shopData:{
					orderStatusCount:[],
					orderRevenueAndCount:{}
				},
				daixiaofei:0,
				daipeisongjiedan:0,
				daichucan:0,
				daiquhuo:0,
				daisongda:0
			}
		},
		onShow() {
			this.refreshPage()
		},
		onLoad(option) {
			
		},
		onPullDownRefresh() {
			this.refreshPage(true)
		},
		methods: {
			refreshPage(isPullDown){
				this.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
				const tasks = [
					this.getBusinessStatus(),
					this.getData()
				]
				if (isPullDown) {
					Promise.all(tasks).finally(() => {
						uni.stopPullDownRefresh()
					})
				}
			},
			getData(){
				this.refreshShopConfig()
				this.daixiaofei = 0
				this.daipeisongjiedan = 0
				this.daichucan = 0
				this.daiquhuo = 0
				this.daisongda = 0
				return this.tui.request("/mall/order/countByShop/"+uni.getStorageSync('shopId'), "GET", {}, false, true).then((res) => {
					if (res.code == 200) {
						this.shopData = res.result || {}
						this.shopData.orderStatusCount = this.shopData.orderStatusCount || []
						this.shopData.orderRevenueAndCount = this.shopData.orderRevenueAndCount || {}
						for(let i=0;i<this.shopData.orderStatusCount.length;i++){
							if(this.shopData.orderStatusCount[i].counttype){
								if(this.shopData.orderStatusCount[i].counttype == 'daipeisongjiedan'){
									this.daipeisongjiedan = this.shopData.orderStatusCount[i].count
								}else if(this.shopData.orderStatusCount[i].counttype == 'daisong'){
									this.daisongda = this.shopData.orderStatusCount[i].count
								}else if(this.shopData.orderStatusCount[i].counttype == 'daiqu'){
									this.daiquhuo = this.shopData.orderStatusCount[i].count
								}else if(this.shopData.orderStatusCount[i].counttype == 'daixiaofei'){
									this.daixiaofei = this.shopData.orderStatusCount[i].count
								}else if(this.shopData.orderStatusCount[i].counttype == 'daichucan'){
									this.daichucan = this.shopData.orderStatusCount[i].count
								}
							}
						}
						this.$forceUpdate()
					} else {
						this.tui.toast(res.message)
					}
					uni.hideLoading()
				}).catch((res) => {})
			},
			refreshShopConfig(){
				const shopList = uni.getStorageSync('schoolShop') || []
				if(Array.isArray(shopList)){
					this.shopConfig = shopList.find(item => item.id == uni.getStorageSync('shopId')) || {}
				}
			},
			//获取营业状态
			getBusinessStatus(){
				return this.tui.request("/app/shoptakeaway/getByShopId", "GET", {
					shopId: uni.getStorageSync('shopId')
				}, false, true).then((res) => {
					if (res.code == 200) {
						this.shop = res.result
						this.shop.shopIcon = uni.getStorageSync('shopIcon')
						this.businessStatus = res.result.status
					} else {
						this.tui.toast(res.message)
					}
					uni.hideLoading()
				}).catch((res) => {})
			},
			//更改营业状态
			updateStatus(){
				let that = this;
				uni.showModal({
					title: '提示',
					content: '要更改营业状态吗？',
					success: function (res1) {
						if (res1.confirm) {
							that.tui.request("/app/shoptakeaway/update", "post", {
								shopId: uni.getStorageSync('shopId'),
								status:that.businessStatus == "1"?'0':that.businessStatus == "0"?'1':'2'
							}, false, true).then((res) => {
								if (res.code == 200) {
									uni.showToast("更改成功")
									that.businessStatus = that.businessStatus == "1"?'0':that.businessStatus == "0"?'1':'2'
								} else {
									that.tui.toast(res.message)
								}
								uni.hideLoading()
							}).catch((res) => {})
						}
					}
				});
				
			},
			goDetail(type,index) {
				let url = ''
				switch (type) {
					case 'tj':
						url = '/package2/myCenter/dataStatistics'
						break;
					case 'db':
						url = '/package2/shop/shopOrderList?index=' + index
						break;
					case 'sp':
						url = '/package2/myCenter/goodsList'
						break;
					case 'yy':
						url = '/package2/shop/businessInfo'
						break;
					case 'sjxx':
						url = '/package2/shop/shopInfo'
						break;
					case 'selfDelivery':
						url = '/package2/shop/selfDeliveryOrderList'
						break;
					case 'transferDelivery':
						url = '/package2/shop/transferDeliveryOrderList'
						break;
					case 'dd':
						url = '/package2/shop/shopOrderList'
						break;
					case 'tui':	
						uni.navigateTo({
							url: '/package2/shop/afterService?type=shop'
						})
						break;
					case 'zd':
						url = '/package2/shop/shopBill'
						break;
					case 'pj':
						let item = {
							shopScore:uni.getStorageSync('shopScore'),
							id:uni.getStorageSync('shopId')
						}
						url = '/package2/group/shopEvaluate?item=' + JSON.stringify(item) + '&isMerchant=1&isCha=' + (index =='cha'?1:0)
						break;
					case 'hx':
						this.scanCodeAdd()
						break;
					default:
				}
				uni.navigateTo({
					url: url
				})
			},
			//扫一扫功能
			scanCodeAdd() {
				let that = this;
				uni.scanCode({
					success: (res) => {
						if (res.scanType == "QR_CODE") { //二维码
							let shopId = res.result.split('@@')[1]
							if (shopId == uni.getStorageSync('shopId')) {
								let productId = res.result.split('@@')[0]
								uni.showModal({
									title: '提示',
									content: '确定要核销该订单吗？',
									success: function (res1) {
										if (res1.confirm) {
											that.tui.request("/mall/order/complete", "post", {
												orderId: productId
											}, false, true).then((res) => {
												uni.hideLoading()
												if (res.code == 200) {
													that.tui.toast("核销成功",1500)
												} else {
													that.tui.toast(res.message)
												}
												//
											}).catch((res) => {})
										}
									}
								});
								
								
							} else {
								that.tui.toast('未查询到此订单信息，请核实！')
							}
						}
					},
					fail: (res) => {
						uni.showToast({
							title: '扫描失败',
							icon: 'none'
						})
					}
				})
			},
			back() {
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		min-height: 100%;
		font-size: 24rpx;
		background: #F6FBF8;
		color: #00231C;
	}

	.page1 {
		width: 100%;
		min-height: 100vh;
		padding-bottom: 60rpx;
		box-sizing: border-box;
		position: relative;
		overflow: hidden;
		background:
			radial-gradient(circle at 18% 210rpx, rgba(227, 255, 150, 0.58), rgba(227, 255, 150, 0) 260rpx),
			radial-gradient(circle at 90% 160rpx, rgba(166, 255, 234, 0.68), rgba(166, 255, 234, 0) 280rpx),
			linear-gradient(180deg, #f1ffe7 0%, #f4fff9 360rpx, #f6fbf8 100%);
	}

	.title {
		width: 100%;
		height: 252rpx;
		background: linear-gradient(135deg, rgba(227, 255, 150, 0.92), rgba(166, 255, 234, 0.86));
		position: relative;
	}

	.title::after {
		content: '';
		position: absolute;
		left: -90rpx;
		right: -90rpx;
		bottom: -70rpx;
		height: 150rpx;
		border-radius: 0 0 50% 50%;
		background: rgba(255, 255, 255, 0.28);
	}

	.title-sreach {
		width: 100%;
		display: flex;
		height: 188rpx;
		position: relative;
		z-index: 1;
	}

	.back-btn {
		position: absolute;
		left: 20rpx;
		width: 68rpx;
		height: 68rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 50%;
		background: rgba(255, 255, 255, 0.34);
	}

	.title-name {
		padding-top: 110rpx;
		font-size: 38rpx;
		font-weight: 900;
		flex: 1;
		text-align: center;
		color: #153b35;
		letter-spacing: 2rpx;
	}

	.shop-title {
		width: 92%;
		margin: -86rpx auto 0;
		padding: 26rpx;
		background:
			radial-gradient(circle at 92% 14%, rgba(166, 255, 234, 0.5), rgba(166, 255, 234, 0) 150rpx),
			linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(250, 255, 248, 0.94));
		border: 1px solid rgba(255, 255, 255, 0.78);
		border-radius: 34rpx;
		display: flex;
		align-items: center;
		font-size: 28rpx;
		font-weight: 800;
		box-shadow: 0 18rpx 42rpx rgba(0, 55, 44, 0.1);
		position: relative;
		z-index: 2;
		box-sizing: border-box;
	}

	.title1 {
		width: 92rpx;
		height: 92rpx;
		padding: 8rpx;
		border-radius: 28rpx;
		background: linear-gradient(135deg, #e3ff96, #a6ffea);
		box-sizing: border-box;
		box-shadow: 0 10rpx 24rpx rgba(32, 190, 154, 0.16);

		img {
			width: 100%;
			height: 100%;
			border-radius: 22rpx;
			display: block;
			object-fit: cover;
		}
	}

	.title2 {
		flex: 1;
		min-width: 0;
		display: flex;
		align-items: center;
		margin-left: 18rpx;
	}

	.title22 {
		flex: 1;
		min-width: 0;
		color: #153b35;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.title33 {
		flex-shrink: 0;
		height: 58rpx;
		line-height: 58rpx;
		padding: 0 18rpx;
		border-radius: 999rpx;
		background: rgba(255, 255, 255, 0.72);
		color: #08735d;
		font-size: 24rpx;
		font-weight: 800;
		box-shadow: inset 0 0 0 1px rgba(88, 220, 190, 0.32);
	}

	.shop-order {
		width: 92%;
		margin: 22rpx auto 0;
		background: rgba(255, 255, 255, 0.94);
		border-radius: 30rpx;
		padding: 0 24rpx 24rpx;
		box-shadow: 0 14rpx 34rpx rgba(0, 35, 28, 0.07);
		box-sizing: border-box;
	}

	.shop-title + .shop-order {
		background:
			radial-gradient(circle at 94% 12%, rgba(255, 220, 140, 0.32), rgba(255, 220, 140, 0) 150rpx),
			linear-gradient(160deg, #ffffff 0%, #fffdf7 54%, #f2fff7 100%);
		border: 1px solid rgba(255, 219, 145, 0.34);
	}

	.shop-title + .shop-order + .shop-order {
		background:
			radial-gradient(circle at 8% 16%, rgba(166, 255, 234, 0.38), rgba(166, 255, 234, 0) 170rpx),
			linear-gradient(145deg, #ffffff 0%, #f4fffb 52%, #eef8ff 100%);
		border: 1px solid rgba(132, 232, 205, 0.28);
	}

	.shop-title + .shop-order {
		background:
			radial-gradient(circle at 94% 12%, rgba(255, 220, 140, 0.32), rgba(255, 220, 140, 0) 150rpx),
			linear-gradient(160deg, #ffffff 0%, #fffdf7 54%, #f2fff7 100%);
		border: 1px solid rgba(255, 219, 145, 0.34);
	}

	.shop-title + .shop-order + .shop-order {
		background:
			radial-gradient(circle at 8% 16%, rgba(166, 255, 234, 0.38), rgba(166, 255, 234, 0) 170rpx),
			linear-gradient(145deg, #ffffff 0%, #f4fffb 52%, #eef8ff 100%);
		border: 1px solid rgba(132, 232, 205, 0.28);
	}

	.order1 {
		height: 78rpx;
		line-height: 78rpx;
		font-size: 30rpx;
		font-weight: 900;
		color: #153b35;
		border-bottom: 1px solid rgba(0, 35, 28, 0.06);
		display: flex;
		align-items: center;
	}

	.order1::before {
		content: '';
		width: 10rpx;
		height: 30rpx;
		margin-right: 12rpx;
		border-radius: 999rpx;
		background: linear-gradient(180deg, #e3ff96, #35d6a6);
	}

	.order22 {
		display: flex;
		min-height: 112rpx;
		padding-top: 22rpx;
		gap: 12rpx;
	}

	.order33 {
		flex: 1;
		text-align: center;
		padding: 12rpx 4rpx;
		border-radius: 24rpx;
		box-sizing: border-box;
		background: rgba(255, 255, 255, 0.6);
		box-shadow: inset 0 0 0 1px rgba(0, 35, 28, 0.04);
	}

	.order33:active,
	.menu22:active {
		transform: scale(0.96);
	}

	.order44 {
		display: inline-flex;
		min-width: 52rpx;
		height: 46rpx;
		align-items: center;
		justify-content: center;
		padding: 0 8rpx;
		border-radius: 999rpx;
		background: linear-gradient(135deg, rgba(227, 255, 150, 0.82), rgba(166, 255, 234, 0.82));
		font-size: 32rpx;
		line-height: 46rpx;
		font-weight: 900;
		color: #08735d;
		box-shadow: 0 8rpx 18rpx rgba(56, 196, 160, 0.12);
	}

	.shop-title + .shop-order .order44 {
		background: linear-gradient(135deg, #fff1bf, #ffd6a2);
		color: #9a5412;
		box-shadow: 0 8rpx 18rpx rgba(255, 163, 79, 0.14);
	}

	.shop-title + .shop-order + .shop-order .order1::before {
		background: linear-gradient(180deg, #a6ffea, #60b8ff);
	}

	.order55,
	.data333,
	.menu44 {
		color: #415c56;
		font-size: 22rpx;
	}

	.data2 {
		display: flex;
		min-height: 150rpx;
		text-align: center;
		padding-top: 26rpx;
		gap: 12rpx;
	}

	.data22 {
		flex: 1;
		position: relative;
		padding: 18rpx 6rpx;
		border-radius: 26rpx;
		background: rgba(255, 255, 255, 0.66);
		box-shadow: inset 0 0 0 1px rgba(68, 202, 185, 0.08);
	}

	.data22 + .data22::before {
		display: none;
	}

	.data222 {
		font-size: 38rpx;
		line-height: 52rpx;
		font-weight: 900;
		color: #0b6b5a;
		padding-bottom: 12rpx;
	}

	.menu2 {
		display: flex;
		flex-wrap: wrap;
		text-align: center;
		padding-top: 24rpx;
	}

	.menu22 {
		width: 25%;
		height: 142rpx;
	}

	.menu33 {
		width: 72rpx;
		height: 72rpx;
		margin: 0 auto 10rpx;
		border-radius: 24rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: linear-gradient(135deg, #fff3d7, #ffd7b0);
		box-shadow: 0 10rpx 22rpx rgba(255, 151, 97, 0.14);

		img {
			width: 46rpx;
			height: 46rpx;
			background-size: 100%;
			display: block;
		}
	}

	.menu22:nth-child(2n) .menu33 {
		background: linear-gradient(135deg, #e4f4ff, #b9ddff);
	}

	.menu22:nth-child(3n) .menu33 {
		background: linear-gradient(135deg, #e3ff96, #a6ffea);
	}

	.menu22:nth-child(4n) .menu33 {
		background: linear-gradient(135deg, #fff2b8, #ffd98b);
	}

	.menu44 {
		height: 40rpx;
		line-height: 40rpx;
		font-weight: 700;
	}
</style>