<template>
	<view class="">

		<view class="box-pack-between header-hg100 flex-y-center ">
			<text class="ft32">展示时间</text>
			<view class="flex-y-center ft26 header-text">
				<text data-text="1" :class="act_index==1?'act':''" @click="bindDeta">近7日</text>
				<text data-text="2" :class="act_index==2?'act':''" @click="bindDeta">近30日</text>
				<view class="flex-y-center" data-text="3" :class="act_index==3?'act':''" @click="bindDeta">
					自定义
					<image class="sanjiao" :src="'../../static/images/'+(act_index==3?'sanjian2':'sanjian')+'.png'" mode=""></image>
				</view>
			</view>
		</view>


	<!-- <view class="model" @click="bindMedel" v-if="is_model">
			<view class="" @click.stop="bindMedes">
			<view class=" model-item ">
				<picker mode='date' :value="start" :start="startDate" 
				:end="endDate" @change="bindDateChange1">
					<view class="box-pack-between">
						<text>开始时间</text>
						<text :style="'color:'+(start=='请选择'?'#999':'')">{{start}}</text>
					</view>
				</picker>
			</view>
			<view class=" model-item ">
				<picker mode='date' :value="end" :start="startDate" :end="endDate" @change="bindDateChange2">
					<view class="box-pack-between">
						<text>结束时间</text>
						<text :style="'color:'+(end=='请选择'?'#999':'')">{{end}}</text>
					</view>
				</picker>
			</view>
			</view>
		</view> -->


		<uni-popup-top ref="popup" type="top" :top="top" :maskClass="maskClass">
			<view class="model">
				<view class="flex-y-center box-pack-between model-date">
					<view class="model-item" :class="time_index==1?'act':''">
						<picker mode='date' :value="start" :start="startDate" :end="endDate" @change="bindDateChange1" data-index="1">
							<view class="flex-center">
								<text>{{start}}</text>
							</view>
						</picker>
					</view>
					<text>至</text>
					<view class="model-item" :class="time_index2==2?'act':''">
						<picker mode='date' :value="end" :start="startDate" :end="endDate" @change="bindDateChange2" data-index="2">
							<view class="flex-center">
								<text>{{end}}</text>
							</view>
						</picker>
					</view>
				</view>
				<view class="model-btn flex-center" @click="sure">
					确定
				</view>
			</view>
		</uni-popup-top>
		
		<view style="height: 172rpx"></view>

		<view class="main-flow">
			<view class="row tab-h sticky">
				<view class="td">日期</view>
				<view class="td">曝光量</view>
				<view class="td">收入</view>
				<view class="td">eCPM</view>
			</view>

			<view class="row" v-for="(item,index) in list" :key="item.id">
				<view class="td">{{item.date}}</view>
				<view class="td">{{item.count}}</view>
				<view class="td">{{item.money}}</view>
				<view class="td">{{item.ecpm}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import uniPopupTop from '@/components/zx-uni-popup/uni-popup-top.vue'
	export default {
		components: {
			uniPopupTop,
		},
		data() {
			return {
				startDate: "2020-10-01",
				endDate: "2030-10-01",
				list: [
				],
				time_index: 0,
				time_index2: 0,
				act_index: 1,
				
				start: "开始时间",
				end: "结束时间",
				
				day:7,
				page:1,
				top:"100rpx",
				maskClass: {
					'position': 'fixed',
					'bottom': 0,
					'top': "100rpx",
					'left': 0,
					'right': 0,
					'backgroundColor': 'rgba(0, 0, 0, 0.4)'
				},
			}
		},
		onLoad() {
			this.AdvertiserLog();
		},
		onReachBottom(e) {
			this.AdvertiserLog();
		},
		methods: {
			
			bindDeta(e) {
				this.act_index = e.currentTarget.dataset.text;
				this.day=this.act_index==1?7:this.act_index==2?30:'';
				if (this.act_index == 3) {
					this.$refs.popup.open();
					return
				}
				this.start ="开始时间";
				this.end ="结束时间";
				this.time_index =0;
				this.time_index2 =0;
				this.clear();
				// this.AdvertiserLog();
			},
			
			// bindDateChange1(e) {
			// 	this.start = e.target.value;
			// 	this.page=1;
			// 	this.list =[];
			// 	this.AdvertiserLog();
			// },
			
			// bindDateChange2(e) {
			// 	this.end = e.target.value;
			// 	this.page=1;
			// 	this.list =[];
			// 	this.AdvertiserLog();
			// },
	
			bindDateChange1(e) {
				this.time_index = e.currentTarget.dataset.index;
				this.start = e.target.value;
			},
			
			bindDateChange2(e) {
				this.time_index2 = e.currentTarget.dataset.index;
				this.end = e.target.value;
			},
			
			sure(e) {
				
				// this.time = this.start + " - " + this.end;
				
				this.clear();
				this.$refs.popup.close();
			},
			
			clear() {
				this.page = 1;
				this.list = [];
		 	    this.AdvertiserLog();
			},
			
			AdvertiserLog() {
				this.request({
					url: "Advertiser/AdvertiserLog",
					data: {
						token: uni.getStorageSync("token"),
						day:this.day,
						start:this.start=='开始时间'?'':this.start,
						end:this.end=='结束时间'?'':this.end,
						page:this.page,
						limit:20,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === '200') {
						this.page=this.page+1;
			            this.list =this.list.concat(res.data);
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},
		}
	}
</script>
<style lang="scss">
	.model {
		width: 100%;
		z-index: 10;
		background: #FFFFFF;
		padding-bottom: 20rpx;

		.model-date {
			width: 100%;
			padding: 20rpx 80rpx;
			border-bottom: 1rpx solid #F1F1F1;

			.model-item {
				width: 225rpx;
				text-align: center;
				font-size: 28rpx;
				color: #999;
				position: relative;
				padding: 10rpx 0;
				text-align: center;
				border-radius: 8rpx;
				border: 1rpx solid #999;
			}

			.act {
				color: #FFFFFF;
				background: #FFBE2C;
				border: 1rpx solid #FFBE2C;
			}
		}

		.model-btn {
			text-align: center;
			color: #FFFFFF;
			height: 80rpx;
			border-radius: none;
			width: 80%;
			opacity: 1;
			background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
			border-radius: 8rpx;
			box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.20);
			margin: 0 auto;
			margin-top: 20rpx;
		}
	}


	.header-hg100 {
		height: 100rpx;
		padding: 0 40rpx;
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 999;
		background: #fff;
	}

	.header-text text {
		margin-left: 30rpx;
	}

	.header-text view {
		margin-left: 30rpx;
	}

	.header-text .act {
		color: #007AFF;
	}

	.main-flow {
		background-color: #fff;
		display: table;
		width: 100%;
		box-sizing: border-box;

	}

	.main-flow .row {
		display: flex;
		flex-flow: row nowrap;
		justify-content: flex-start;
		align-items: center;
		height: 72rpx;
		padding: 0 40rpx;
	}

	.sticky {
		background-color: #f5f5f5;
		color: #ccc;
		position: fixed;
		top: 100rpx;
		width: 100%;
		z-index: 2;
	}


	.main-flow .row .td {
		text-align: left;
		font-size: 30rpx;

	}

	.main-flow .row.tab-h .td {
		color: #999999;
		text-align: left;
	}

	.main-flow .row .td:nth-child(1) {
		width: 40%;
	}

	.main-flow .row .td:nth-child(2) {
		width: 20%;
	}

	.main-flow .row .td:nth-child(3) {
		width: 20%;
	}

	.main-flow .row .td:nth-child(4) {
		width: 20%;
	}

	.sanjiao {
		width: 40rpx;
		height: 40rpx;
	}
</style>
