<template>
	<view>
		<view class="d-b-c search-data border-b f26 mb20" @click="openPop()">
			<view class="flex-1 gray9">{{ $t('w_0352') }}</view>
			<picker disabled 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 disabled 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"><text class="icon iconfont icon-sousuo"></text></view>
		</view>
		<view class="wallet-list">
			<view class="bonus-item" v-for="(item, index) in listData" :key="index">
				<view class="items-title d-e-c">
					<!-- <view class="items-title-name">{{item.memberCode}}</view> -->
					<view :class="`status${item.applicationStatus}`">{{item.applicationStatusVal}}</view>
				</view>
				<view class="f26 d-b-c p-20-0 line-h-15">
					<view>{{$t('MN_T_1')}}</view>
					<view class="flex-1 tr">{{item.memberCode}}</view>
				</view>
				<view class="f26 d-b-c p-20-0 line-h-15">
					<view>{{$t('fn_132')}}</view>
					<view class="flex-1 tr">{{item.remitter}}</view>
				</view>
				<view class="f26 d-b-c p-20-0 line-h-15">
					<view>{{$t('fn_133')}}</view>
					<view class="flex-1 tr">{{item.remittanceAmount}}</view>
				</view>
				<view class="f26 p-20-0 line-h-15">
					<view class="gray3 mb20">{{$t('fn_135')}}:</view>
					<u-read-more text-indent="0" show-height="78rpx" toggle>
						<view class="gray9 f26">
							{{item.remittanceInstructions}}
							<!-- {{pop_content}} -->
						</view>
					</u-read-more>
				</view>
				<view class="items-bottom d-b-c">
					<view>{{$t('fn_134')}}：{{item.remittanceDate}}</view>
					<view v-if="item.applicationStatus == 3 && item.rejectionStatement"
						@click="openContent(item.rejectionStatement)">
						{{$t('fn_122')}}
					</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>

		<button class="normal-sub-btn"
			@click="gotoPage('/pages/user/rechargeApplication/apply')">{{$t('fn_139')}}</button>
		<template v-if="isPop">
			<view class="pop-bg" @click.stop="isPop = false"></view>
			<view class="pop-content2" @click.stop="isPop = false">
				<view class="pop-content-box" @click.stop="isPop = true">
					<view class="d-e-c">
						<view @click.stop="isPop = false"><u-icon name="close" size="28rpx" color="#999999"></u-icon>
						</view>
					</view>
					<view class="tc fb f32 p20 border-b pt0">{{ $t('fn_121') }}</view>
					<view class="pop-list">
						<u-parse :content="pop_content"></u-parse>
					</view>
				</view>
			</view>
		</template>
		<!-- 筛选 -->
		<u-popup :show="showPop" mode="right" @close="closePop" @open="openPop">
			<view class="pop-content rightpop">
				<view class="pop-title d-b-c">
					<view class="f28 gray3">{{ $t('MY_ORD_50') }}</view>
					<view class="f28 domation" @click="closePop">{{ $t('N_I_241') }}</view>
				</view>
				<view class="right-item-title">{{ $t('fn_120') }}</view>
				<view class="checkbox-list">
					<view v-for="(item, index) in status" :key="index" class="checkbox-item"
						:class="{ active: form.applicationStatus == item.value }" @click="bindStatus(item)">
						{{ item.label }}
					</view>
				</view>
				<view class="right-item-title">{{ $t('w_0352') }}</view>
				<view class="d-c-c">
					<picker mode="date" :value="date1" :start="startDate" :end="endDate" @change="bindDateChange1">
						<view class="data-input">{{ form.startDate || $t('CK_KS_3') }}</view>
					</picker>
					<view style="width: 30rpx;height: 1rpx;background-color: #333;margin: 0 24rpx;"></view>
					<picker mode="date" :value="date2" :start="startDate" :end="endDate" @change="bindDateChange2">
						<view class="data-input">{{ form.endDate || $t('MN_T_7') }}</view>
					</picker>
				</view>
				<view class="pop-btns">
					<view class="pop-left-btn" @click="resetSubmit()">{{ $t('w_0257') }}</view>
					<view class="pop-right-btn" @click="searchSubmit()">{{ $t('w_0035') }}</view>
				</view>
			</view>
		</u-popup>
	</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: '',
					applicationStatus: ''
				},
				total: 0,
				showPop: false,
				isPop: false,
				date1: '',
				date2: '',
				status: [],
				pop_content: ''
			};
		},
		onShow() {
			/*获取数据*/
			this.listData = [];
			// this.form.pageNum = 1;
			this.getData();
			this.getType();
		},
		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');
			},
		},
		onReachBottom() {
			let self = this;
			if (self.form.pageNum * self.form.pageSize < self.total) {
				self.form.pageNum++;
				self.getData();
			}
			self.no_more = true;
		},
		methods: {
			bindStatus: function(e) {
				console.log(e);
				if (this.form.applicationStatus == e.value) {
					this.form.applicationStatus = ''
				} else {
					this.form.applicationStatus = e.value;
				}
				// console.log(e);
			},
			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}`;
			},
			openContent(e) {
				this.pop_content = e;
				this.isPop = true;
			},
			closePop() {
				this.showPop = false;
			},
			openPop() {
				this.showPop = true;
			},
			getType() {
				let self = this;
				// self.loading = true;
				self._get(
					'system/pub/enums/personal-status', {},
					function(res) {
						self.status = res.data;
						// self.total = res.total;
						// if (self.total < self.form.pageNum * self.form.pageSize) {
						// 	self.no_more = true;
						// }
					}, {},
					() => {
						// self.loading = false;
					}
				);

			},
			getData() {
				let self = this;
				self.loading = true;
				var formdata = self.form;
				self._post(
					'member/api/recharge/list?pageNum=' + self.form.pageNum + '&pageSize=' + self.form.pageSize,
					formdata,
					function(res) {
						self.loading = false;
						self.listData = self.listData.concat(res.rows);
						self.total = res.total;
						if (self.total < self.form.pageNum * self.form.pageSize) {
							self.no_more = true;
						}
					}, {},
					() => {
						self.loading = false;
					}
				);
			},
			bindDateChange1: function(e) {
				this.form.startDate = e.detail.value;
			},
			bindDateChange2: function(e) {
				this.form.endDate = e.detail.value;
			},
			resetSubmit: function() {
				this.form.applicationStatus = '';
				this.form.startDate = '';
				this.form.endDate = '';
			},
			searchSubmit: function() {
				/*获取数据*/
				this.listData = [];
				// this.form.pageNum = 1;
				this.showPop = false;
				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;
	}

	.items-title {
		padding: 20rpx 0;
		border-bottom: 1px solid #eee;
	}

	.items-title-name {
		font-size: 28rpx;
		font-weight: bold;
	}

	.items-bottom {
		color: #999;
		padding: 20rpx 0;
		border-top: 1px solid #eee;
	}

	.bonus-item {
		padding-top: 0;
		padding-bottom: 0;
	}

	.status1 {
		color: #FFAE36;
	}

	.status2 {
		color: #1AA90E;
	}

	.status3 {
		color: #FB3024;
	}

	.pop-bg {
		z-index: 101;
	}

	.pop-content2 {
		position: fixed;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 102;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
	}

	.pop-content-box {
		width: 90%;
		background-color: #ffffff;
		border-radius: 15rpx;
		padding: 20rpx;
		box-sizing: border-box;
		min-height: 400rpx;
	}

	.pop-list {
		padding-top: 20rpx;
		box-sizing: border-box;
		max-height: 60vh;
		overflow-y: auto;
	}

	.pt0 {
		padding-top: 0;
	}

	.rightpop.pop-content {
		padding-top: 0;
	}

	.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;
		}
	}

	.wallet-list {
		padding-bottom: 120rpx;
	}

	.normal-sub-btn {
		position: fixed;
		width: 690rpx;
		bottom: 20rpx;
		left: 30rpx;
		height: 90rpx;
		line-height: 1.5;
		display: flex;
		justify-content: center;
		align-items: center;
		word-break: break-all;
	}
</style>