<template>
	<view>
		<view class="d-e-c tips-box">
			<u-icon name="info-circle-fill" size="32rpx" color="#CCCCCC"></u-icon>
			<text class="f28 gray9 ml10">{{ $t('w_0157') }}</text>
			<text class="f32 ml20 fb">{{formatNum(queryBonusTotal)}}</text>
		</view>
		<view class="d-b-c search-data border-b f26 mb20">
			<view class="flex-1 gray9">{{ $t('w_0352') }}</view>
			<picker mode="date" :value="form.startDate" :start="startDate" :end="endDate" @change="bindDateChange1">
				<view class="picker-item-data">{{ form.startDate || $t('CK_KS_3') }}</view>
			</picker>
			<view style="margin: 0 60rpx;">{{ $t('w_0139') }}</view>
			<picker mode="date" :value="form.endDate" :start="startDate" :end="endDate" @change="bindDateChange2">
				<view class="picker-item-data">{{ form.endDate || $t('CK_KS_9') }}</view>
			</picker>
			<view class="search-radio" @click="searchSubmit"><text class="icon iconfont icon-sousuo"></text></view>
		</view>
		<!-- 	<view class="d-s-c tips-box">
			<u-icon name="info-circle-fill" size="32rpx" color="#CCCCCC"></u-icon>
			<text class="f24 gray9 ml10">SVIP会员享受3%报单服务补贴</text>
		</view> -->
		<view class="wallet-list">
			<view class="bonus-item" v-for="(item, index) in listData" :key="index">
				<view class="bonus-item-item">
					<view class="bonus-item-name f26 gray9">{{ $t('N_I_130') }}</view>
					<view class="bonus-item-content f26 gray3">{{ item.settleDate }}</view>
				</view>
				<view class="bonus-item-item">
					<view class="bonus-item-name f26 gray9">{{ $t('N_I_148') }}({{ currencyIcon() }})</view>
					<view class="bonus-item-content f26 gray3">{{ formatNum(item.makerDirectIncome) }}</view>
				</view>

				<view class="bonus-item-item">
					<view class="bonus-item-name f26 gray9">{{ $t('N_I_149') }}({{ currencyIcon() }})</view>
					<view class="bonus-item-content f26 gray3">{{ formatNum(item.makerShareIncome) }}</view>
				</view>
				<view class="bonus-item-item">
					<view class="bonus-item-name f26 gray9">{{ $t('N_I_137') }}({{ currencyIcon() }})</view>
					<view class="bonus-item-content f26 gray3">{{ formatNum(item.serviceSpend) }}</view>
				</view>
				<view class="bonus-item-item">
					<view class="bonus-item-name f26 gray9">{{ $t('N_I_138') }}({{ currencyIcon() }})</view>
					<view class="bonus-item-content f26 gray3">{{ formatNum(item.makerRealSubtotal) }}</view>
				</view>
				<!-- 		<view class="d-e-c bonus-bottom border-t">
					<view class="order-btn">查看详情</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 {
			/*有没有等多*/
			no_more: false,
			/*是否正在加载*/
			loading: true,
			listData: [],
			form: {
				pageNum: 1,
				pageSize: 10,
				startDate: '',
				endDate: '',
				gradeId: ''
			},
			total: 0,
			queryBonusTotal: 0
		};
	},
	onShow() {
		/*获取数据*/
		this.listData = [];
		this.form.pageNum = 1;
		this.getData();
		this.getQueryBonusTotal();
	},
	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;
				}
			}
		},
		startDate() {
			return this.getDate('start');
		},
		endDate() {
			return this.getDate('end');
		}
	},
	methods: {
		getQueryBonusTotal() {
			let self = this;
			self._post('bonus/api/bonus/query-bonus-total', {}, function(res) {
				self.queryBonusTotal = res.rows[0].realIncomeTotal;
			});
		},
		getData() {
			let self = this;
			self.loading = true;
			var formdata = self.form;
			self._post(
				'bonus/api/bonus/query-bonus-maker',
				formdata,
				function(res) {
					self.listData = res.rows;
					self.total = res.total;
					if (self.total < self.form.pageNum * self.form.pageSize) {
						self.no_more = true;
					}
				},
				{},
				() => {
					self.loading = false;
				}
			);
		},
		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.startDate = e.detail.value;
		},
		bindDateChange2: function(e) {
			this.form.endDate = e.detail.value;
		},
		resetSubmit: function() {
			this.form.gradeId = '';
			this.form.startDate = '';
			this.form.endDate = '';
		},
		searchSubmit: function() {
			/*获取数据*/
			this.listData = [];
			this.form.pageNum = 1;
			this.getData();
		}
	}
};
</script>

<style lang="scss">
.tips-box {
	padding: 30rpx 20rpx;
	background-color: #fff;
	border-bottom: 1rpx solid #eee;
}

.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: 20rpx;
}
</style>
