<template>
	<view class="page1">
		<view v-if="dataType == 'xiaoshou'" v-for="(item,index) in dataList" :key="index">
			<view style="width: 100%;height: 160rpx;line-height: 80rpx;">
				<view style="width: 100%;text-align: center;font-weight: bold;font-size: 30rpx;">
					日期:{{item.saleDate | removeStr}}
				</view>
				<view style="width: 100%;text-align: center;border-left: 1px solid #eee;">
					操作人:{{item.createByName}}
				</view>
			</view>
			<uni-table border stripe emptyText="暂无更多数据">
				<uni-tr style="background: #eee;">
					<uni-th align="center" width="100">客户</uni-th>
					<uni-th align="center" width="50">销售额</uni-th>
					<uni-th align="center" width="70">利润</uni-th>
					<uni-th align="center" width="70">总成本</uni-th>
				</uni-tr>
				<uni-tr @tap="gotoDetail(item.saleId)">
					<uni-td align="center">{{item.userName}}</uni-td>
					<uni-td align="center">{{item.totalAmount}}</uni-td>
					<uni-td align="center">{{userType== 0?item.profit:'0'}}</uni-td>
					<uni-td align="center">{{userType== 0?item.totalCost:'0'}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		<view v-if="dataType == 'shishou'" v-for="(item,index) in dataList" :key="index">
			<view style="width: 100%;height: 80rpx;line-height: 80rpx;">
				<view style="width: 100%;text-align: center;font-weight: bold;font-size: 30rpx;">
					日期:{{item.paymentDay | removeStr}}
				</view>
			</view>
			<uni-table border stripe emptyText="暂无更多数据">
				<uni-tr style="background: #eee;">
					<uni-th align="center" width="85">微信</uni-th>
					<uni-th align="center" width="50">支付宝</uni-th>
					<uni-th align="center" width="70">现金</uni-th>
					<uni-th align="center" width="70">扫码</uni-th>
					<uni-th align="center" width="70">银行卡</uni-th>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">{{item.weixin}}</uni-td>
					<uni-td align="center">{{item.zhifubao}}</uni-td>
					<uni-td align="center">{{item.xianjin}}</uni-td>
					<uni-td align="center">{{item.shouhuanma}}</uni-td>
					<uni-td align="center">{{item.yihangzhuanzhang}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
	
					<view v-if="dataType == 'lirun'" v-for="(item,index) in dataList" :key="index">
						<view style="width: 100%;height: 160rpx;line-height: 80rpx;">
							<view style="width: 100%;text-align: center;font-weight: bold;font-size: 30rpx;">
								日期:{{item.saleDate | removeStr}}
							</view>
							<view style="width: 100%;text-align: center;border-left: 1px solid #eee;">
								操作人:{{item.createByName}}
							</view>
						</view>
						<uni-table border stripe emptyText="暂无更多数据">
							<uni-tr style="background: #eee;">
								<uni-th align="center" width="85">客户</uni-th>
								<uni-th align="center" width="50">销售额</uni-th>
								<uni-th align="center" width="70">利润</uni-th>
								<uni-th align="center" width="70">总成本</uni-th>
							</uni-tr>
							<uni-tr @tap="gotoDetail(item.saleId)">
								<uni-td align="center">{{item.userName}}</uni-td>
								<uni-td align="center">{{item.totalAmount}}</uni-td>
								<uni-td align="center">{{userType == 0?item.profit:'0'}}</uni-td>
								<uni-td align="center">{{userType == 0?item.totalCost:'0'}}</uni-td>
							</uni-tr>
						</uni-table>
					</view>
				
		<view v-if="dataType == 'jinhuo'" v-for="(item,index) in dataList" :key="index">
			<view style="width: 100%;height: 160rpx;line-height: 80rpx;">
				<view style="width: 100%;text-align: center;font-weight: bold;font-size: 30rpx;">
					日期:{{item.purchaseDate | removeStr}}
				</view>
				<view style="width: 100%;text-align: center;border-left: 1px solid #eee;">
					操作人:{{item.createByName}}
				</view>
			</view>
			<uni-table border stripe emptyText="暂无更多数据">
				<uni-tr style="background: #eee;">
					<uni-th align="center" width="85">供应商</uni-th>
					<uni-th align="center" width="50">数量</uni-th>
					<uni-th align="center" width="70">总成本</uni-th>
					<uni-th align="center" width="70">商品款数</uni-th>
				</uni-tr>
				<uni-tr @tap="gotoDetail(item.purchaseId)">
					<uni-td align="center">{{item.supplierName}}</uni-td>
					<uni-td align="center">{{item.productCount}}</uni-td>
					<uni-td align="center">{{userType == 0?item.totalCost:'0'}}</uni-td>
					<uni-td align="center">{{item.productNum}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		<view v-if="dataType == 'tuihuo'" v-for="(item,index) in dataList" :key="index">
			<view style="width: 100%;height: 160rpx;line-height: 80rpx;">
				<view style="width: 100%;text-align: center;font-weight: bold;font-size: 30rpx;">
					日期:{{item.returnSaleDate | removeStr}}
				</view>
				<view style="width: 100%;text-align: center;border-left: 1px solid #eee;">
					操作人:{{item.createByName}}
				</view>
			</view>
			<uni-table border stripe emptyText="暂无更多数据">
				<uni-tr style="background: #eee;">
					<uni-th align="center" width="85">客户</uni-th>
					<uni-th align="center" width="50">数量</uni-th>
					<uni-th align="center" width="70">退货金额</uni-th>
					<uni-th align="center" width="70">总成本</uni-th>
				</uni-tr>
				<uni-tr @tap="gotoDetail(item.saleId)">
					<uni-td align="center">{{item.userName}}</uni-td>
					<uni-td align="center">{{item.productCount}}</uni-td>
					<uni-td align="center">{{item.totalAmount}}</uni-td>
					<uni-td align="center">{{userType == 0?item.totalCost:'0'}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		<view v-if="dataType == 'xiadankehu'" v-for="(item,index) in dataList" :key="index">
			<view style="width: 100%;height: 80rpx;line-height: 80rpx;">
				<view style="width: 100%;text-align: center;font-weight: bold;font-size: 30rpx;">
					客户:{{item.userName}}
				</view>
			</view>
			<uni-table border stripe emptyText="暂无更多数据">
				<uni-tr style="background: #eee;">
					<uni-th align="center" width="100">拿货总数</uni-th>
					<uni-th align="center" width="100">拿货总额</uni-th>
					<uni-th align="center" width="70">成本</uni-th>
					<uni-th align="center" width="70">利润</uni-th>
				</uni-tr>
				<uni-tr>
					<uni-td align="center">{{item.productCount}}</uni-td>
					<uni-td align="center">{{item.realAmount}}</uni-td>
					<uni-td align="center">{{userType == 0?item.totalCost:'0'}}</uni-td>
					<uni-td align="center">{{userType == 0?item.profit:'0'}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		<u-loadmore :status="status" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataType:'',
				dataList:[],
				range:[],
				items: ['拿货(按订单)', '拿货(按商品)', '拿货(按客户)'],
				status: 'loadmore',
				userType:uni.getStorageSync('type'),
				pageNum:1,
				pages:1
			}
		},
		filters: {
			removeStr(val) {
				
				if(val == null){
					return "";
				}else{
					var dotIndex = val.indexOf('.');
					if (dotIndex !== -1) {
					    return val.substring(0, dotIndex);
					}
					return val;
				}
			}
		},
		onReachBottom() {
			if (this.pageNum >= this.pages) return;
			this.status = 'loading';
			this.pageNum ++;
			this.getDetailList();
		},
		onLoad(option) {
			this.dataType = option.value
			this.range = JSON.parse(option.range)
		},
		onShow(){
			if(uni.getStorageSync('noLoad') == true){
				uni.removeStorageSync('noLoad')
			}else{
				this.getDetailList()
			}
			
		},
		methods: {
			getDetailList(){
				this.status = 'loading';
				let url,data
				if(this.dataType == 'xiaoshou'){
					url = '/app/sale/totalAmountDetail'
					data = {
						startDate:this.range[0],
						endDate:this.range[1],
						pageNum:this.pageNum,
						pageSize:"10"
					}
				}else if(this.dataType == 'shishou'){
					url = '/app/sale/totalAlreadyEarnDetail'
					data = {
						startDate:this.range[0],
						endDate:this.range[1],
						pageNum:this.pageNum,
						pageSize:"10"
					}
				}else if(this.dataType == 'lirun'){
					url = '/app/sale/totalAmountDetail'
					data = {
						startDate:this.range[0],
						endDate:this.range[1],
						pageNum:this.pageNum,
						pageSize:"10"
					}
				}else if(this.dataType == 'jinhuo'){
					url = '/app/purchase/purchasingCostDetail'
					data = {
						startDate:this.range[0],
						endDate:this.range[1],
						pageNum:this.pageNum,
						pageSize:"10"
					}
				}else if(this.dataType == 'tuihuo'){
					url = '/app/return/returnTotalAmountDetail'
					data = {
						startDate:this.range[0],
						endDate:this.range[1],
						pageNum:this.pageNum,
						pageSize:"10"
					}
				}else if(this.dataType == 'xiadankehu'){
					url = '/app/sale/customerSaleDetail'
					data = {
						startDate:this.range[0],
						endDate:this.range[1],
						pageNum:this.pageNum,
						pageSize:"10"
					}
				}
				this.tui.request(url, "POST", data, false, false).then((res) => {
					this.status = 'nomore';
					if (res.code == 200) {
						
						
						if (this.pages == 1) {
							this.dataList = res.result.records
						} else {
							this.dataList = [...this.dataList, ...res.result.records]
						}
						this.pages = res.result.pages
					} else {
						this.tui.toast(res.message)
					}
							
				})
			},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
				if (e.currentIndex == 0) {
					this.duizhangList = []
					this.pageNum = 1
					this.pages = 1
					this.duizhangdan()
				} else if (e.currentIndex == 1) {
					this.list = []
					this.pageNum = 1
					this.getList()
				} else if (e.currentIndex == 2) {
					this.list = []
					this.pageNum = 1
					this.getList()
				}
			},
			gotoDetail(id) {
				this.page = 1
				uni.setStorageSync('noLoad',true)
				if(this.dataType == 'jinhuo'){
					uni.navigateTo({
						url: '/package1/index/waitStorageDetail?id=' + id
					})
				}else{
					uni.navigateTo({
						url: '/package1/index/orderDetail?id=' + id
					})
				}
				
			},
		}
	}
</script>

<style lang="scss">
	.page1{
		background: #fff;
		font-size: 28rpx;
	}
</style>