<template>
	<!-- 奖励明细页面 -->
	<view class="header">

		<view class="header-one">
		</view>

		<view class="content">
			<view style="width: 100%;">
				<view style="width: 340rpx;height: 80rpx;text-align: center;padding-top: 25rpx;padding-left: 20rpx;float: left;margin-top: 0;margin-left: 30rpx;">
					<view style="float: left;">
						<text @tap="$u.throttle(whole, 500)">{{ $t('awardDetail.all') }}</text>
						<view v-if="bottoma == true" style="width: 100%;height: 1rpx;background-color: #FFFFFF;border-radius: 10rpx;"></view>
						<view v-else></view>
					</view>
					<view style="float: left;margin-left: 70rpx;">
						<text @click="brand">{{ $t('awardDetail.brand') }}</text>
						<view v-if="bottomb == true" style="width: 100%;height: 1rpx;background-color: #FFFFFF;border-radius: 10rpx;"></view>
						<view v-else></view>
					</view>
					<view style="float: left;margin-left: 70rpx;">
						<text @click="time_s">{{ $t('awardDetail.time') }}</text>
						<view v-if="bottomc == true" style="width: 100%;height: 1rpx;background-color: #FFFFFF;border-radius: 10rpx;"></view>
						<view v-else></view>
					</view>
				</view>
			</view>
			<!-- <u-tabs style="width: 500rpx;" bg-color="#0095ff" inactive-color="#FFFFFF" active-color="#fff" :list="list"
						 :is-scroll="false" :current="current" @change="change"></u-tabs> -->
			<!-- <u-select :mask-close-able="false" @cancel="clear" style=" color: #fff;" @confirm="confirm" v-model="showBrand"
			 value-name="brandId" label-name="brandName" :list="brandList"></u-select> -->
			 <u-action-sheet 
				:mask-close-able="false" 
				:list="list_a"
				:cancel-text="$t('unified.cancel')" 
				@click="click"
				@close="close"
				v-model="showBrand"
			></u-action-sheet>
			<u-calendar 
				:mask-close-able="false" 
				:toolTip="$t('uView.choiceDate')"
				:start-text="$t('uView.startTime')"
				:end-text="$t('uView.endTime')"
				style=" color: #fff;" 
				@click="calendar" 
				@change="changetime" 
				v-model="showDate" 
				:mode="mode"
			>
			</u-calendar>
			<view>
				<u-search style="width: 320rpx;" :placeholder="$t('awardDetail.placeholder')" v-model="input" :clearabled="true" @change="handleSearch"
				 :show-action="false" :animation="true"></u-search>
			</view>
		</view>
		<view v-if="count!=0">
			<view class="content-one" v-for="(item,index) in datalist" :key="index">
				<view class="content-one-view">
				</view>
				<view class="content-one-text">{{ $t('awardDetail.rewarded') }}：{{item.money}}元</view>
				<view class="content-two">
					<view class="">
						{{ $t('awardDetail.tireType') }}
					</view>
					<view class="">
						{{item.tireModel}}
					</view>
				</view>
				<view class="content-two">
					<view class="">
						{{ $t('awardDetail.tireCode') }}
					</view>
					<view class="">
						{{item.tyreNum}}
					</view>
				</view>
				<view class="content-two">
					<view class="">
						{{ $t('awardDetail.rewardType') }}
					</view>
					<view class="">
						{{getWay}}
					</view>
				</view>
				<view class="content-two">
					<view class="">
						{{ $t('awardDetail.time') }}
					</view>
					<view class="">
						{{item.createTime}}
					</view>
				</view>

			</view>


		</view>
		<view v-else style="margin-top: 400rpx;">
			<u-empty :text="$t('unified.nodata')" mode="list"></u-empty>
		</view>
		<u-loadmore v-if="datalist.length>3" :status="status" />
	</view>
</template>

<script>
	import {
		request
	} from '../../../common/request/request'
	require("promise.prototype.finally").shim()
	export default {
		data() {
			return {
				datalist: [],
				status: 'loadmore',
				getWay: '',
				input: '',
				bottoma: true,
				bottomb: false,
				bottomc: false,
				list: [{
					name: '全部'
				}, {
					name: '品牌'
				}, {
					name: '时间',
				}],
				list_a: [],
				brandList: JSON.parse(JSON.stringify([])),
				current: 0,
				// 默认页数
				current1: 1,
				showBrand: false,
				showDate: false,
				mode: 'range',
				// 开始时间
				startTime: '',
				// 结束时间
				endTime: '',
				pages: '',
				count: '',
				datalength: '',
				label: '',
			};
		},
		created() {
			uni.setNavigationBarTitle({
			    title: this.$t('awardDetail.title')
			});
			
			this.whole()
			this.getBrandList()
		},
		methods: {
			// 获取奖励明细
			data() {
				uni.showLoading({
					title: '加载中...'
				});
				request({
						url: '/myPage/getPageScanRewordList',
						method: 'post',
						data: {
							storeId: this.$store.state.storeInfo.storeId,
							userId: this.$store.state.storeInfo.userId,
							searchKey: this.input,
							current: this.current1,
							size: '10',
							brandCode: this.label,
							startTime: this.startTime,
							endTime: this.endTime
						}
					}).then(res => {
						this.count = res.data.count
						this.datalist = this.datalist.concat(res.data.data)

						// 判断扫码类型
						for (var i = 0; i < res.data.data.length; i++) {
							if (res.data.data[i].getWay == 0) {
								this.getWay = this.$t('awardDetail.scanCodeType1')
							} else {
								this.getWay = this.$t('awardDetail.scanCodeType2')
							}
						}
					}).catch(err => {
						
					})
					.finally(() => {
						uni.hideLoading();
						this.loading = false;
					})
			},
			calendar() {
			},
			// 全部事件
			whole() {
				this.datalist = []
				this.label=null
				this.startTime =null
				this.endTime =null
				this.bottoma = true
				this.bottomb = false
				this.bottomc = false
				this.current1 = 1
				this.data()
			},
			// 品牌事件
			brand() {
				this.showBrand = true
				this.bottomb = true
				this.bottoma = false
				this.bottomc = false
			},
			// 时间事件
			time_s() {
				this.showDate = true
				this.bottoma = false
				this.bottomc = true
				this.bottomb = false
			},
			// 时间选择器获取时间
			changetime(e) {
				this.current1 = 1
				this.startTime = e.startDate + ' 00:00:00'
				this.endTime = e.endDate + ' 23:59:59'
				this.datalist = []
				uni.showLoading({
					title: this.$t('unified.Loading')
				});
				this.data()
			},
			// 获取品牌列表
			getBrandList() {
				request({
						url: '/baseReq/getBrandListByStoreId',
						method: 'post',
						data: {
							storeId: this.$store.state.storeInfo.storeId,
							userId: this.$store.state.storeInfo.userId
						}
					}).then(res => {
						this.brandList = JSON.parse(JSON.stringify(res.data.data))
						for (var i = 0; i < this.brandList.length; i++) {
							this.list_a.push({
								brandCode: this.brandList[i].brandCode,
								text: this.brandList[i].brandName,
								color: '#000',
								fontSize: 28
							})
						}
					}).catch(err => {
						
					})
					.finally(() => {
						setTimeout(() => {
							uni.hideLoading();
							this.loading = false;
						}, 1000)

					})
			},
			// 搜索框
			handleSearch(e) {
				this.datalist = []
				this.current1=1
				this.data()
			},
			// 点击获取品牌
			click(e) {
				this.datalist = []
				
				this.label = this.list_a[e].text
				this.data()
			},
			// 点击取消按钮


			close() {
				this.whole()
			},
			change(index) {
				this.current = index;
				if (this.current == 1) {
					this.showBrand = true
					this.datalist = []
				} else if (this.current == 2) {
					this.showDate = true
					this.datalist = []
				}
				this.current1 = 1
				this.datalist = []
				this.data()
			}
		},
		onReachBottom() {
			this.current1++
			this.status = 'loading';
			if (this.datalist.length >= this.count) {
				this.status = 'nomore';
			} else {
				this.data()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.header {
		height: 400rpx;
		width: 100%;
		background: #0094FE;
		color: #fff;
		font-size: 28rpx;
	}

	.header-one {
		text-align: center;
		padding-top: 10rpx;
	}

	.header-one>text {
		font-size: 52rpx;
	}

	.content {
		display: flex;
		justify-content: space-between;
		width: 700rpx;
		margin-top: 80rpx;
	}

	.content-one {
		width: 690rpx;
		height: 315rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 24px 0px rgba(101, 176, 249, 0.41);
		border-radius: 20rpx;
		margin: 0 auto;
		margin-top: 30rpx;
	}

	.content-one-view {
		width: 6rpx;
		height: 30rpx;
		background: #0292FD;
		position: relative;
		top: 20rpx;
		left: 30rpx;
	}

	.content-one-text {
		// position: relative;
		// top: -8rpx;
		// left: 60rpx;
		margin-left: 50rpx;
		margin-top: -14rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #000;
	}

	.content-one-time {
		position: relative;
		top: -40rpx;
		left: 530rpx;
		font-size: 13rpx;
		color: #626262;
	}

	.content-two {
		display: flex;
		justify-content: space-between;
		font-size: 26rpx;
		color: #6A6A6A;
		margin-top: 25rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}
</style>
