<template>
	<view class="common-page" style="padding:0">
		<PageScroll requestStr="/app/orderStat/afterOrderDailyStat" @updateList="updateList" ref="scrollRef"
			:otherParams="otherParams">
			<u-sticky :customNavHeight="0">
				<view class="search-area flex-d">
					<view class="flex-a">
						<view class="text-item flex-2">申请时段</view>
						<view class="text-item flex-1">售后订单数</view>
						<view class="text-item flex-1">发出订单数</view>
						<view class="text-item flex-1">未发订单数</view>
					</view>
				</view>
			</u-sticky>
			<view class="list-con">
				<view class="flex-a list-item stat-header" v-if="dataList.length > 0">
					<view class="text-item flex-2" style="flex:2">
						<view v-if="otherParams.startTime && otherParams.endTime">
							<view class="flex-d">
								<view class="text-item flex-1">{{otherParams.startTime}}</view>
								<view class="text-item flex-1">{{otherParams.endTime}}</view>
							</view>
						</view>
						<view v-else>合计</view>
					</view>
					<view class="text-item flex-1">{{total.refundOrderNum}}</view>
					<view class="text-item flex-1">{{total.sendOrderNum}}</view>
					<view class="text-item flex-1">{{total.notSendBookNum}}</view>
				</view>

				<view v-for="(item,index) in dataList" :key="index" class="flex-a list-item">
					<view class="text-item flex-2" style="flex:2">{{item.statDate}}</view>
					<view class="text-item flex-1">{{item.refundOrderNum}}</view>
					<view class="text-item flex-1">{{item.sendOrderNum}}</view>
					<view class="text-item flex-1">{{item.notSendBookNum}}</view>
				</view>
			</view>
		</PageScroll>
	</view>
</template>

<script setup>
import { reactive, ref, onMounted } from 'vue';
import PageScroll from '@/components/pageScroll/index.vue'
import { onLoad } from '@dcloudio/uni-app'

const otherParams = ref({
	startTime: '',
	endTime: ''
})

const scrollRef = ref(null)
const refreshList = () => {
	scrollRef.value?.resetUpScroll()
	getStatData()
}

let dataList = ref([])
const updateList = (data) => {
	dataList.value = data
}

const total = ref({
	refundOrderNum: 0,
	sendOrderNum: 0,
	notSendBookNum: 0
})

//获取时段统计数据
const getStatData = () => {
	uni.$u.http.get('/app/orderStat/afterOrderStat?startTime=' + otherParams.value.startTime + '&endTime=' + otherParams.value.endTime).then(res => {
		total.value = res.data
	})
}

onLoad((options) => {
	if (options.startTime && options.endTime) {
		otherParams.value.startTime = decodeURIComponent(options.startTime)
		otherParams.value.endTime = decodeURIComponent(options.endTime)
		getStatData()
	}else{
		otherParams.value.startTime = ''
		otherParams.value.endTime = ''
		getStatData()
	}
})
</script>

<style lang="scss">
.search-area {
	padding: 24rpx;
	background-color: #ffffff;
	z-index: 9;
}

.stat-header {
	background-color: #3bb54b;
}

.flex-2 {
	flex: 2;
}

.list-item {
	border-bottom: 1rpx solid #f5f5f5;
	font-size: 24rpx !important;
	padding: 10rpx 0;
}
</style> 