<template>
	<view class="page1">
		<uni-datetime-picker style="margin-bottom:20rpx;" v-model="range" type="daterange" @change="searchList" />
		<view style="width: 100%;margin: 20rpx auto;background: #fff;">
			<view class="box" @tap="goDetail('xiaoshou')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="cart" size="24" color="red"></uni-icons>
					</view>
					销售金额
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.totalAmount}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="goDetail('xiaoshou')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="cart" size="24" color="red"></uni-icons>
					</view>
					销售总件数
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.totalJCount}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view style="width: 100%;height: 10rpx;background: #eee;"></view>
			<view class="box" @tap="goDetail('xiaoshoulirun')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="wallet" size="24" color="red"></uni-icons>
					</view>
					销售利润
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.totalProfit==null?0:shopInfo.totalProfit}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="showDayPrice = true">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="wallet" size="24" color="red"></uni-icons>
					</view>
					实际利润
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{((shopInfo.totalProfit == null?0:shopInfo.totalProfit)-shopInfo.returnTotalAmount+shopInfo.saleReturnCost).toFixed(2)}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view style="width: 100%;height: 10rpx;background: #eee;"></view>
			<view class="box" @tap="goDetail('jinhuo')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="home" size="24" color="red"></uni-icons>
					</view>
					进货金额
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.purchasingCost}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="goDetail('jinhuo')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="home" size="24" color="red"></uni-icons>
					</view>
					进货总件数
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.purchasingCount}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view style="width: 100%;height: 10rpx;background: #eee;"></view>
			<view class="box" @tap="goDetail('tuihuo')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="refreshempty" size="24" color="red"></uni-icons>
					</view>
					退货金额
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.returnTotalAmount}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="goDetail('tuihuo')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="refreshempty" size="24" color="red"></uni-icons>
					</view>
					退货总件数
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.returnTotalCount}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view style="width: 100%;height: 10rpx;background: #eee;"></view>
			<view class="box" @tap="goDetail('shishou')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="auth" size="24" color="red"></uni-icons>
					</view>
					实收金额
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.totalAlreadyEarn}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="goDetail('xiadankehu')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="staff" size="24" color="red"></uni-icons>
					</view>
					下单客户
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;">{{shopInfo.totalCCount}}</text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="goDetail('gongyingshang')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="staff" size="24" color="red"></uni-icons>
					</view>
					按供应商查看库存
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;"></text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="goDetail('fenleitongji')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="fire" size="24" color="red"></uni-icons>
					</view>
					按商品分类统计
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;"></text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
			<view class="box" @tap="goDetail('rexiao')">
				<view style="width: 69%;">
					<view style="width: 50rpx;height: 50rpx;float: left;margin-right: 20rpx;">
						<uni-icons type="fire" size="24" color="red"></uni-icons>
					</view>
					热销商品
				</view>
				<view style="width: 30%;">
					<text style="display: inline-block;width: 150rpx;text-align: center;"></text>
					<uni-icons type="right" size="24" color="#777"></uni-icons>
				</view>
			</view>
		</view>
		<view v-if="showDayPrice" style="width:100%;height:100%;position: fixed;top: 0;background: rgba(0,0,0,0.7);">
			<view
				style="position: fixed;margin:auto;height:660rpx;left:0;right:0;top:0;bottom:0;width:600rpx;background:#fff;border-radius: 10px;color: #000;">
				<view style="width:100%;height:80rpx;font-size: 30rpx;text-align: center;line-height: 80rpx;font-weight: bold;">
					利润明细
				</view>
				<view style="display: flex;">
					<view style="width: 25%;display: flex;flex-direction: column;text-align: center;">
						<text style="font-weight: bold;">{{shopInfo.totalAmount}}</text>
						<text>销售金额</text>
					</view>
					<view style="width: 25%;display: flex;flex-direction: column;text-align: center;">
						<text style="font-weight: bold;">{{(shopInfo.totalAmount - shopInfo.totalProfit).toFixed(2)}}</text>
						<text>销售成本</text>
					</view>
					<view style="width: 25%;display: flex;flex-direction: column;text-align: center;">
						<text style="font-weight: bold;">{{shopInfo.returnTotalAmount}}</text>
						<text>退货金额</text>
					</view>
					<view style="width: 25%;display: flex;flex-direction: column;text-align: center;">
						<text style="font-weight: bold;">{{shopInfo.saleReturnCost}}</text>
						<text>退货成本</text>
					</view>
				</view>
				<view style="width: 95%;height:380rpx;margin: 0 auto;margin-top: 20rpx;border-top: 1px solid #eee;">
					<view style="background: #ecf5ff;width: 100%;color: #5fd9ee;height: 80rpx;line-height: 80rpx;padding-left: 20rpx;">
						点击↓↓↓可查看计算公式
					</view>
					<view class="tan-lirun" @tap="changeFormula('0')">
						<text style="font-weight: bold;margin-top: 20rpx;">{{shopInfo.totalProfit}}</text>
						<text>销售利润</text>
					</view>
					
					<view @tap="changeFormula('1')" class="tan-lirun" style="float: right;" >
						<text style="font-weight: bold;margin-top: 20rpx;">{{(shopInfo.totalAmount-(shopInfo.totalAmount-shopInfo.totalProfit)-shopInfo.returnTotalAmount+shopInfo.saleReturnCost).toFixed(2)}}</text>
						<text>实际利润</text>
					</view>
					<view @tap="changeFormula('3')" class="tan-lirun">
						<text style="font-weight: bold;margin-top: 20rpx;">{{(shopInfo.totalProfit == 0 || shopInfo.totalProfit ==null)?0:(shopInfo.totalAmount == 0 || shopInfo.totalAmount == null)?0:((shopInfo.totalProfit/shopInfo.totalAmount)*100).toFixed(2)}}%</text>
						<text>销售利润率</text>
					</view>
					<view @tap="changeFormula('2')" class="tan-lirun" style="float: right;">
						<text style="font-weight: bold;margin-top: 20rpx;">{{((shopInfo.totalProfit-shopInfo.returnTotalAmount+shopInfo.saleReturnCost)==0 || (shopInfo.totalProfit-shopInfo.returnTotalAmount+shopInfo.saleReturnCost)==null)?0:((shopInfo.totalAmount-shopInfo.returnTotalAmount)== 0 || (shopInfo.totalAmount-shopInfo.returnTotalAmount)== null) ?0:(((shopInfo.totalProfit-shopInfo.returnTotalAmount+shopInfo.saleReturnCost)/(shopInfo.totalAmount-shopInfo.returnTotalAmount))*100).toFixed(2)}}%</text>
						<text>实际利润率</text>
					</view>
					
					
				</view>
				
				<view @tap="showDayPrice = false" style="height: 100rpx;width: 100%;line-height: 100rpx;text-align: center;border-top: 1px solid #eee;font-size: 40rpx;">
					确定
				</view>
			</view>
		</view>
		<view v-if="showFormula"
			style="height:230rpx;position: fixed;z-index:999;margin:auto;left:0;right:0;top:0;bottom:0;width:400rpx;background: rgba(0,0,0,0.7);border-radius: 10px;color: #eee;">
			<view style="width:100%;height:80rpx;font-size: 30rpx;text-align: center;line-height: 80rpx;">
				{{showDan == 0?'销售利润':showDan == 1?'实际利润':showDan == 2?'实际利润率':showDan == 3?'销售利润率':''}}计算公式
			</view>
			<view style="text-align: center;line-height: 40rpx;">
				<view v-if="showDan == 3" style="margin-top: 20rpx;">
					<view>公式：销售利润/销售金额*100</view>
					<view>{{shopInfo.totalProfit}}/{{shopInfo.totalAmount}}*100={{(shopInfo.totalProfit == 0 && shopInfo.totalAmount == 0)?0:((shopInfo.totalProfit/shopInfo.totalAmount)*100).toFixed(2)}}%</view>
				</view>
				<view v-if="showDan == 2" style="margin-top: 20rpx;">
					<view>公式：实际利润/(销售金额-退货金额)</view>
					<view>{{(shopInfo.totalAmount-(shopInfo.totalAmount-shopInfo.totalProfit)-shopInfo.returnTotalAmount+shopInfo.saleReturnCost).toFixed(2)}}/{{shopInfo.totalAmount - shopInfo.returnTotalAmount}} * 100={{(shopInfo.totalProfit-shopInfo.returnTotalAmount+shopInfo.saleReturnCost)==0?0:(((shopInfo.totalProfit-shopInfo.returnTotalAmount+shopInfo.saleReturnCost)/(shopInfo.totalAmount-shopInfo.returnTotalAmount))*100).toFixed(2)}}%</view>
				</view>
				<view v-if="showDan == 1" style="margin-top: 20rpx;">
					<view>公式：销售利润-(退货金额-退货成本)</view>
					<view>{{shopInfo.totalProfit}}-({{shopInfo.returnTotalAmount}}-{{shopInfo.saleReturnCost}})={{(shopInfo.totalAmount-(shopInfo.totalAmount-shopInfo.totalProfit)-shopInfo.returnTotalAmount+shopInfo.saleReturnCost).toFixed(2)}}</view>
				</view>
				<view v-if="showDan == 0" style="margin-top: 20rpx;">
					<view>公式：销售金额-销售成本</view>
					<view>{{shopInfo.totalAmount}}-{{shopInfo.totalAmount - shopInfo.totalProfit}}={{shopInfo.totalProfit}}</view>
				</view>
				
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showDan:'',
				showFormula: false, 
				range:[],
				shopInfo:{
					totalProfit:0,
					returnTotalAmount:0,
					saleReturnCost:0
				},
				showDayPrice: false,
				type:uni.getStorageSync('type')
			};
		},
		onShow(){
			if(this.range ==''){
				this.getMonth();
			}
			this.getSaleInfo();
		},
		methods: {
			goDetail(item){
				if(item == 'xiaoshoulirun'){
					uni.navigateTo({
						url:'/package1/index/lirun?value='+ item + '&range=' + JSON.stringify(this.range)
					})
				}else if(item == 'shijilirun'){
					this.showDayPrice = true
				}else if(item == 'rexiao'){
					uni.navigateTo({
						url:'/package1/index/fireGoods'
					})
				}else if(item == 'gongyingshang'){
					uni.navigateTo({
						url:'/package1/index/calculatedBySupplier'
					})
				}else if(item == 'fenleitongji'){
					uni.navigateTo({
						url:'/package2/index/classifiedStatistics'
					})
				}else{
					uni.navigateTo({
						url:'/package1/index/statisticsDetail?value='+ item + '&range=' + JSON.stringify(this.range)
					})
				}
				
			},
			changeFormula(type){
				
				this.showFormula = true
				this.showDan = type
				setTimeout(res=>{
					this.showFormula = false
				},2000)
			},
			getSaleInfo() {
				this.shopInfo = {
					totalProfit:0,
					returnTotalAmount:0,
					saleReturnCost:0
				}
				this.tui.request("/app/sale/getShopAll", "POST", {
					pageVo: {
						pageSize: 5,
						pageNumber: 1
					},
					startTime:this.range[0],
					endTime:this.range[1]
				}, false, false).then((res) => {
					if (res.code == 200) {
						this.shopInfo = res.result
					} else {
						this.tui.toast(res.message)
					}
			
				})
			},
			//获取当月1日到当前时间
			getMonth() {
				let date = new Date()
				let year = date.getFullYear().toString()   //'年'
				let month = date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1).toString():(date.getMonth()+1).toString()  //'月'
				let da = date.getDate() < 10 ? '0'+date.getDate().toString():date.getDate().toString()  //'日'
				let end = year + '-' + month + '-' + da  //当天
				let beg = year + '-' + month + '-01'    //当月第一天
				this.range = [beg,end]
			},
			searchList() {
				this.priceList = [];
				this.getSaleInfo()
			},
		}
	}
</script>

<style lang="scss">
	page,.page1{
		font-size: 28rpx;
	}
	.contentPadding {
		padding: 28rpx 20rpx;
		background-color: #fff;
		color: #909399;
	
		.title {
			padding-left: 20rpx;
			font-size: 32rpx;
			color: #303133;
			margin-bottom: 26rpx;
			line-height: 66rpx;
	
			image {
				display: inline-block;
				width: 40rpx;
				vertical-align: middle;
			}
	
			.btn {
				text-align: right;
				width: 24%;
				float: right;
				font-size: 26rpx;
				color: $u-primary;
			}
		}
		.grid-text {
			font-size: 28rpx;
			margin-bottom: 26rpx;
			text-align: center;
		}
	}
	.u-grid-item {
		width: 30% !important;
		height: 160rpx;
		background: linear-gradient(#84C1FF, #C4E1FF) !important;
		margin-left: 3%;
		border-radius: 30rpx;
		margin-top: 20rpx !important;
		color: #fff !important;
	
	}
	.cardText {
		font-size: 24rpx;
	}
	
	.priceText {
		color: $u-primary;
		font-size: 28rpx;
	}
	.u-grid-item:nth-child(2) {
		background: linear-gradient(#FFBB77, #FFDCB9) !important;
	}
	
	.u-grid-item:nth-child(3) {
		background: linear-gradient(#1AFD9C, #7AFEC6) !important;
	}
	
	.u-grid-item:nth-child(4) {
		background: linear-gradient(#1AFD9C, #7AFEC6) !important;
	}
	.u-grid-item:nth-child(5) {
		background: linear-gradient(#FFBB77, #FFDCB9) !important;
	}
	.u-grid-item:nth-child(6) {
		background: linear-gradient(#84C1FF, #C4E1FF) !important;
	}
	.u-count-num {
		color: #FFF !important;
		text-align:center;
	}
	.uni-date{
		background: #fff;
	}
	.uni-tooltip-popup{
		width: 180rpx;
	}
	.u-icon{
		padding: 0 0 0 16rpx !important;
	}
	.u-zidingyi{
		width: 22% !important;
		height: 160rpx;
		background: linear-gradient(#84C1FF, #C4E1FF) !important;
		margin-left: 3%;
		border-radius: 30rpx;
		margin-top: 20rpx !important;
		color: #fff !important;
		text-align: center;
		padding-top: 20rpx;
	}
	.u-zidingyi:nth-child(2) {
		background: linear-gradient(#FFBB77, #C4E1FF) !important;
	}
	.u-zidingyi:nth-child(3) {
		background: linear-gradient(#84C1FF, #7AFEC6) !important;
	}
	.u-zidingyi:nth-child(4) {
		background: linear-gradient(#84C1FF, #C4E1FF) !important;
	}
	.box{
		width: 100%;
		height: 100rpx;
		padding-left: 20rpx;
		display: flex;
		line-height: 100rpx;
		font-size: 34rpx;
		border-bottom: 1px solid #eee;
	}
	.tan-lirun{
		margin-top: 20rpx;
		width: 45%;
		height: 120rpx;
		display: flex;
		flex-direction: column;
		text-align: center;
		float: left;
		background-image: linear-gradient(#84C1FF, #C4E1FF) !important;
		color: #fff;
		border-radius: 10px;
	}
</style>