<template>
	<view class="sales-content">
		<!--销售数据统计 -->
		<view class="content-data">
			<view class="date-type">
				<text :class="['type',timeType=='day' ? 'active_day' : '']" @click="seleteTime(0)">今日</text>
				<text :class="['type',timeType=='week' ? 'active_day' : '']" @click="seleteTime(1)">本周</text>
				<text :class="['type',timeType=='mounth' ? 'active_day' : '']" @click="seleteTime(2)">本月</text>
			</view>
			<view class="total">
				<view class="item-box">
					<u-count-to  :end-val="salesCount" separator=","></u-count-to>
					<view>销售总单量(个)</view>
				</view>
				<view class="item-box">
					<u-count-to :end-val="salesAmount" separator="," :decimals="2"></u-count-to>
					<view>销售总金额(￥)</view>
				</view>
			</view>
		</view>
		<!-- 销售报价及销售单创建 -->
		<view class="sales-box">
			 <view class="sales-box-1" @click="toPage('/pages/sales/productPricing')">
				 <view class="title">产品报价</view>
			 </view>
			 <view class="sales-box-1" @click="toPage('/pages/latePlay/chooseBulk')">
				 <view class="title">新增销售单</view>
			 </view>
		</view>
		<!-- 销售单 -->
		<view class="sales-list">
			<view class="title">
				<text class="title-name">销售单</text>
				<text class="title-all">查看全部<u-icon name="arrow-right" color="#999" size="28"></u-icon></text>
			</view>
		</view>
		<scroll-view class="st-detailList-con" scroll-y @scrolltolower="onreachBottom">
			<view class="st-detailList-main">
				<!-- <view class="st-detailList-main-item" v-for="(item, index) in listData" :key="item.id" @click="getDetail(item)">
					<view class="st-detailList-tit">
						<view class="u-line" :style="{backgroundColor: $config('primaryColor')}"></view>{{item.productName}}
					</view>
					<view class="st-detailList-item-con flex align_center">
						<view class="pimgs">
							<u-image :src="item.product&&item.product.productMsg?item.product.productMsg:`../../static/${theme}/def_img@2x.png`" width="128" height="128" border-radius="10"></u-image>
						</view>
						<view class="flex_1">
							<view>产品编码：{{item.productCode}}</view>
							<view class="padding_3">原厂编码：{{item.productOrigCode}}</view>
							<view class="flex align_center justify_between">
								<view class="font_13">
									可用数量：
									<u-count-to :end-val="item.currentStockQty ? item.currentStockQty : 0" separator="," font-size="26"></u-count-to>个
								</view>
								<view class="font_13">
									库存成本：
									￥<u-count-to :end-val="item.currentStockCost ? item.currentStockCost : 0" separator="," font-size="26" :decimals="2"></u-count-to>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view v-if="listData && listData.length == 0">
					<u-empty :text="noDataText" mode="list" :img-width="200" :margin-top="30"></u-empty>
				</view> -->
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {bizData,salesList} from '@/api/sales'
	export default{
		data(){
			return{
				timeType:'day',
				bizData:null, // 销售数据统计
				salesCount:0, // 销售总单数
				salesAmount:0, // 销售总金额
			}
		},
		onLoad() {
			this.getBizData()
		},
		methods:{
			seleteTime(val){
				if(val==0){
					this.timeType='day'
					// this.salesCount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.dayTotalQty || this.bizData.purchaseBill.dayTotalQty==0) ? this.bizData.purchaseBill.dayTotalQty : 0
					// this.salesAmount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.dayDiscountedAmount || this.bizData.purchaseBill.dayDiscountedAmount==0) ? this.bizData.purchaseBill.dayDiscountedAmount : 0
				}else if(val==1){
					this.timeType='week'
					// this.salesCount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.weekPurchaseQty || this.bizData.purchaseBill.weekPurchaseQty==0) ? this.bizData.purchaseBill.weekPurchaseQty : 0
					// this.salesAmount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.weekDiscountedAmount || this.bizData.purchaseBill.weekDiscountedAmount==0) ? this.bizData.purchaseBill.weekDiscountedAmount : 0
				}else{
					this.timeType='mounth'
					// this.salesCount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.monthPurchaseQty || this.bizData.purchaseBill.monthPurchaseQty==0) ? this.bizData.purchaseBill.monthPurchaseQty : 0
					// this.salesAmount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.monthDiscountedAmount || this.bizData.purchaseBill.monthDiscountedAmount==0) ? this.bizData.purchaseBill.monthDiscountedAmount : 0
				}
				this.getBizData()
				console.log(val,this.salesCount,this.salesAmount,'this.salesAmount')
			},
			toPage(url){
				uni.navigateTo({
					url:url
				})
			},
			getBizData () {
			  bizData({}).then(res => {
			    if (res.status == 200) {
			      this.bizData = res.data
				  if(this.timeType=='day'){
				  	this.salesCount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.dayTotalQty || this.bizData.purchaseBill.dayTotalQty==0) ? this.bizData.purchaseBill.dayTotalQty : 0
				  	this.salesAmount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.dayDiscountedAmount || this.bizData.purchaseBill.dayDiscountedAmount==0) ? this.bizData.purchaseBill.dayDiscountedAmount : 0
				  }else if(this.timeType=='week'){
				  	this.salesCount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.weekPurchaseQty || this.bizData.purchaseBill.weekPurchaseQty==0) ? this.bizData.purchaseBill.weekPurchaseQty : 0
				  	this.salesAmount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.weekDiscountedAmount || this.bizData.purchaseBill.weekDiscountedAmount==0) ? this.bizData.purchaseBill.weekDiscountedAmount : 0
				  }else{
				  	this.salesCount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.monthPurchaseQty || this.bizData.purchaseBill.monthPurchaseQty==0) ? this.bizData.purchaseBill.monthPurchaseQty : 0
				  	this.salesAmount=this.bizData&&this.bizData.purchaseBill&&(this.bizData.purchaseBill.monthDiscountedAmount || this.bizData.purchaseBill.monthDiscountedAmount==0) ? this.bizData.purchaseBill.monthDiscountedAmount : 0
				  }
			    } else {
			      this.bizData = null
			    }
			  })
			},
		}
	}
</script>

<style lang="scss">
	.sales-content{
		width: 100%;
		padding: 30rpx;
		.content-data{
			background-color: #fff;
			padding: 20upx 20upx;
			border-radius: 20upx;
			box-shadow: 3upx 2upx 6upx #eee;
			margin-bottom: 30upx;
			.date-type{
				margin: 0 120upx 30upx 120upx;
				border-radius: 50upx;
				border: 1upx solid #eee;
				.type{
					display: inline-block;
					padding: 10upx 0;
					width: 33%;
					text-align: center;
				}
				.type:first-child{
					border-top-left-radius: 50upx;
					border-bottom-left-radius: 50upx;
				}
				.type:last-child{
					border-top-right-radius: 50upx;
					border-bottom-right-radius: 50upx;
				}
				.type:not(:last-child){
					border-right: 1upx solid #eee;
				}
				.active_day {
				  background: rgb(0, 122, 255);
				  color: #fff;
				}
			}
			.total{
				display: flex;
				.item-box{
					text-align: center;
					width: 50%;
					color:#999;
					
				}
				.item-box:first-child{
					border-right: 1px solid #e4e7ed;
				}
			}
		}
		.sales-box{
			display: flex;
			align-items: center;
			margin-bottom: 30upx;
			.sales-box-1{
				background-color: #ffffff;
				border-radius: 20upx;
				box-shadow: 3upx 2upx 6upx #eee;
				padding: 30rpx;
				width: 50%;
				color: #424D5E;
				text-align: center;
				.title{
					font-size: 32rpx;
					color: rgb(0, 122, 255);
					font-weight: bold;
				}
			}
			> view{
				&:first-child{
					margin-right: 15rpx;
				}
				&:last-child{
					margin-left: 15rpx;
				}
			}
		}
		.sales-list{
			.title{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.title-name{
					font-size: 32upx;
					color:#000 ;
					font-weight: 1000;
				}
				.title-all{
					color:#999;
				}
			}
		}
	}
</style>
