<template>
	<view>
		<view class="d-b-c search-data border-b f26 mb20">
				<view class="f26 gray9">{{$t('S_C_7')}}:$</view>
			<picker mode="date" :value="form.settleDate" @change="bindDateChange1">
				<view class="picker-small">
					<text>{{ form.settleDate || $t('w_0429') }}</text>
					<u-icon name="arrow-down-fill" size="28rpx" color="#333"></u-icon>
				</view>

			</picker>
		</view>
		<view class="wallet-list mb20">
			<view class="bonus-item" v-for="(item, index) in listData" :key="index">
				<view class="bonus-item-item border-b">
				<view class="bonus-item-name f26 gray3 fb" v-if="item.cuMemberSettleCountryExtList[0].placeDept >= 4">
           				 {{ item.cuMemberSettleCountryExtList[0].placeDept}}<span v-if="languages==='en-US'">th  </span> {{ '' }} {{ $t("fn_011") }}
           		 </view>
           		 <view class="bonus-item-name f26 gray3 fb" v-else>
            			  {{ item.cuMemberSettleCountryExtList[0].placeDept}}{{ $t("fn_011") }}
           		 </view>
					<!-- <view class="bonus-item-name f26 gray3 fb">{{ $t('fn_010') + item.cuMemberSettleCountryExtList[0].placeDept + $t('fn_011') }}</view> -->
				</view>
				<view class="bonus-item-item">
					<view class="bonus-item-name f26 gray9">{{ $t('MN_F_T_866') }}</view>
					<view class="bonus-item-content f26 gray3">{{ item.cuMemberSettleCountryExtList[0].countryName }}</view>
				</view>
				<view class="bonus-item-item">
					<view class="bonus-item-name f26 gray9">{{ $t('fn_116') }}</view>
					<view class="bonus-item-content f26 gray3">{{ formatNum(item.cuMemberSettleCountryExtList[0].newPv) }}</view>
				</view>
				<view class="bonus-item-item" style="margin-bottom: 0;">
					<view class="bonus-item-name f26 gray9">{{ $t('MN_F_T_47') }}</view>
					<view class="bonus-item-content f26 gray3">{{ formatNum(item.cuMemberSettleCountryExtList[0].sumPv) }}</view>
				</view>
			</view>
		</view>
		<view class="d-c-c p30" v-if="listData.length == 0 && !loading">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">{{$t('w_0405')}}</text>
		</view>
		<uni-load-more v-else :loadingType="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			const currentDate = this.getDate({
				format: true
			});
			return {
				showPop: false,
				date1: '',
				date2: '',
				/*有没有等多*/
				no_more: false,
				/*是否正在加载*/
				loading: true,
				membercode: '',
				listData: [],
				languages:'',
				cuMemberSettleCountryExtLists: [],
				form: {
					pageNum: 1,
					pageSize: 10,
					settleDate: ''
				},
				total: 0,
				registerType: []
			};
		},
		onLoad(e) {
			this.languages= uni.getLocale();
			// this.getRegisterData();
			uni.setNavigationBarTitle({
				title: this.$t('fn_119')
			});
		},
		onShow() {
			/*获取数据*/
			this.listData = [];
			this.form.pageNum = 1;
			this.getData();
		},
		onReachBottom() {
			let self = this;
			if (self.form.pageNum * self.form.pageSize < self.total) {
				self.form.pageNum++;
				self.getData();
			}
			self.no_more = true;
		},
		computed: {
			/*加载中状态*/
			loadingType() {
				if (this.loading) {
					return 1;
				} else {
					if (this.listData.length != 0 && this.no_more) {
						return 2;
					} else {
						return 0;
					}
				}
			},
			startCreationTime() {
				return this.getDate('start');
			},
			endCreationTime() {
				return this.getDate('end');
			}
		},
		methods: {
			getRegisterData() {
				let self = this;
				// self.loading = true;
				self._get(
					'system/api/grade/list', {},
					function(res) {
						self.registerType = res.data;
					}, {},
					() => {
						// self.loading = false;
					}
				);
			},
			getData() {
				let self = this;
				self.loading = true;
				var formdata = self.form;
				self._post(
					'bonus/api/bonus/query-country-achieve', formdata,
					function(res) {
						console.log('Response rows:', res.rows);
						self.listData = res.rows;
						self.total = res.total;
						if (self.total < (self.form.pageNum * self.form.pageSize)) {
							self.no_more = true;
						}
					}, {},
					() => {
						self.loading = false;
					}
				);
			},
			closePop() {
				this.showPop = false;
			},
			openPop() {
				this.showPop = true;
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			bindDateChange1: function(e) {
				this.form.settleDate = e.detail.value;
				this.getData();
			},
			bindDateChange2: function(e) {
				this.form.endCreationTime = e.detail.value;
			},
			bindregister: function(e) {
				this.form.pkRegisterGrade = e.pkId;
				// console.log(e);
			},
			resetSubmit: function() {
				this.form.pkRegisterGrade = "";
				this.form.startCreationTime = "";
				this.form.endCreationTime = "";
				this.form.memberCode = "";
				this.form.memberName = "";
			},
			searchSubmit: function() {
				this.showPop = false;
				/*获取数据*/
				this.listData = [];
				this.form.pageNum = 1;
				this.getData();
			},
			searchName: function() {
				/*获取数据*/
				this.listData = [];
				this.form.pageNum = 1;
				this.getData();
			}
		}
	};
</script>

<style lang="scss">
	.picker-small {
		min-width: 232rpx;
		height: 72rpx;
		border: 1rpx solid #eeeeee;
		border-radius: 15rpx;
		font-size: 28rpx;
		padding: 0 28rpx 0 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		background-color: #fff;
	}

	.top-box {
		width: 750rpx;
		padding: 0 30rpx 0 23rpx;
		box-sizing: border-box;
		height: 102rpx;
		background: #ffffff;
		display: flex;
		justify-content: center;
		align-items: center;
		border-bottom: 1rpx solid #eee;
		margin-bottom: 24rpx;
	}

	.search-box {
		flex: 1;
		height: 65rpx;
		background: #f5f6f8;
		border-radius: 33rpx;
		padding: 0 52rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: center;
		align-items: center;

		.search-input {
			font-size: 26rpx;
			color: #333;
			margin-left: 14rpx;
			flex: 1;
		}
	}

	.bonus-item {
		padding: 20rpx 25rpx 20rpx 23rpx;
		background-color: #fff;
		margin-bottom: 20rpx;
		.bonus-bottom {
			height: 104rpx;

			.order-btn {
				box-sizing: border-box;
				padding: 0 26rpx;
				min-width: 146rpx;
				height: 52rpx;
				line-height: 52rpx;
				text-align: center;
				border-radius: 26rpx;
				font-size: 24rpx;
				color: #fff;
				border: 1rpx solid #eee;
				margin-left: 18rpx;
				background: #fb3024;
				border: 1rpx solid #fb3024;
				flex-shrink: 0;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}

	.bonus-item-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
	}
	.bonus-item-item.border-b{
		padding-bottom: 26rpx;
		
		.bonus-item-name{
			font-size: 28rpx;
		}
	}
	.bonus-item-name {
		width: 30%;
		flex-shrink: 0;
	}

	.bonus-item-content {
		flex: 1;
		flex-shrink: 0;
		text-align: right;
	}

	.title-box {
		background-color: #fff;
		height: 98rpx;
		line-height: 98rpx;
		padding: 0 20rpx;
		border-bottom: 1px solid #eee;
	}
</style>