<template>
	<view>
		<u-navbar placeholder :title="$t('ENU_ASS_T_0')" :bgColor="'#FB3024'" titleStyle="color:#fff" leftIconColor="#fff"
			leftIcon="arrow-left" @leftClick="goBack">
			<button class="nav-right-btn" slot="right" @click="showPop = true">{{$t('MY_ORD_50')}}</button>
		</u-navbar>
		<!-- <view class="top-head pb20">
			<view class="top-tabbar">
				<view class="tab-item" :class="{ active: type == 0 }" @click="changeType(0)">复购考核</view>
				<view class="tab-item" :class="{ active: type == 1 }" @click="changeType(1)">分红考核</view>
			</view>
			<view class="d-b-c search-data f26">
				<view class="flex-1 gray9">日期筛选</view>
				<view class="picker-item-data">{{ '2000-22-12' }}</view>
				<template v-if="type == 1">
					<view style="margin: 0 60rpx;">类型</view>
					<view class="picker-item-data">{{ '2000-22-12' }}</view>
				</template>
				<template v-if="type == 0">
					<view style="margin: 0 60rpx;">考核状态</view>
					<view class="picker-item-data">{{ '2000-22 -12' }}</view>
				</template>
				<view class="search-radio"><text class="icon iconfont icon-sousuo"></text></view>
			</view>
		</view> -->
		<view class="wallet-list">
			<!-- <view class="tips-box d-b-c" v-if="type == 1">
				<view>分红考核积分</view>
				<view class="fb f36">1000.00</view>
			</view> -->
			<view class="tips-box d-b-c mb20">
				<view>{{$t('N_I_158')}}</view>
				<view class="fb f36">{{points}}</view>
			</view>
			<view v-for="(item, index) in listData" class="product-item" :key="index">
				<view class="f26 gray9 mb20 d-b-c">
					<view>{{$t('N_I_163')}}</view>
					<view class="gray3">{{item.changeTypeVal}}</view>
				</view>
				<view class="f26 gray9 mb20 d-b-c">
					<view>{{$t('N_I_162')}}</view>
					<view class="gray3">{{formatNum(item.tradeAchieveSign)}}</view>
				</view>
				<view class="f26 gray9 mb20 d-b-c">
					<view>{{$t('N_I_160')}}</view>
					<view class="gray3">{{item.tradeTime}}</view>
				</view>
				<view class="f26 gray9 mb20 d-b-c">
					<view>{{$t('CK_KS_12')}}</view>
					<view class="gray3">{{item.assessStatusVal}}</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>
		<!-- 筛选 -->
		<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('N_I_163')}}</view>
				<view class="checkbox-list">
					<view v-for="(item, index) in changeData" :key="index" class="checkbox-item"
						:class="{ active: form.changeType === item.value }" v-if="item.value<2"
						@click="bindChange(item)">{{item.label}}
					</view>
				</view>
				<view class="right-item-title">{{$t('CK_KS_12')}}</view>
				<view class="checkbox-list">
					<view v-for="(item, index) in statusData" :key="index" class="checkbox-item"
						:class="{ active: form.assessStatus === item.value }" @click="bindStatus(item)">{{item.label}}
					</view>
				</view>
				<view class="right-item-title">{{$t('N_I_160')}}</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('CK_KS_9') }}</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 {
				showPop: false,
				date1: '',
				date2: '',
				/*有没有等多*/
				no_more: false,
				/*是否正在加载*/
				loading: true,
				listData: [],
				form: {
					assessType: 0,
					pageNum: 1,
					pageSize: 10,
					startDate: '',
					endDate: '',
					assessStatus: '',
					changeType: ''
				},
				total: 0,
				statusData: [],
				points: 0,
				changeData: []
			};
		},
		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');
			}
		},
		onLoad(e) {
			this.getStatusData();
			this.getPointsData();
			this.getChangeData();
		},
		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;
		},
		methods: {
			goBack(){
				uni.navigateBack();
			},
			getChangeData() {
				let self = this;
				// self.loading = true;
				var formdata = self.form;
				self._get(
					'system/pub/enums/change-type', {},
					function(res) {
						self.changeData = res.data;

					}, {},
					() => {
						// self.loading = false;
					}
				);
			},
			getPointsData() {
				let self = this;
				// self.loading = true;
				var formdata = self.form;
				self._get(
					'member/api/assess/assAchieve', {
						assessType: self.form.assessType
					},
					function(res) {
						self.points = res.data;

					}, {},
					() => {
						// self.loading = false;
					}
				);
			},
			getStatusData() {
				let self = this;
				// self.loading = true;
				var formdata = self.form;
				self._get(
					'system/pub/enums/member-assess-status', {},
					function(res) {
						self.statusData = res.data;

					}, {},
					() => {
						// self.loading = false;
					}
				);
			},
			getData() {
				let self = this;
				self.loading = true;
				var formdata = self.form;
				self._get(
					'member/api/assess/assessList', 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;
					}
				);
			},
			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.startDate = e.detail.value;
			},
			bindDateChange2: function(e) {
				this.form.endDate = e.detail.value;
			},
			resetSubmit: function() {
				this.form.assessStatus = "";
				this.form.changeType = "";
				this.form.startDate = "";
				this.form.endDate = "";
			},
			searchSubmit: function() {
				this.showPop = false;
				/*获取数据*/
				this.listData = [];
				this.form.pageNum = 1;
				this.getData();
			},
			bindStatus: function(e) {
				this.form.assessStatus = e.value;
				// console.log(e);
			},
			bindChange: function(e) {
				this.form.changeType = e.value;
			}
		}
	};
</script>

<style lang="scss">
	.top-tabbar {
		border-bottom: 1rpx solid #eee;

		.tab-item {
			color: #666;
		}

		.tab-item.active {
			font-weight: 400;
			color: #333;
		}
	}

	.product-item {
		background: #ffffff;
		margin-bottom: 24rpx;
		padding: 26rpx 22rpx 29rpx 22rpx;
	}

	.log-img {
		width: 76rpx;
		height: 48rpx;
		margin-right: 12rpx;
	}

	.nav-right-btn {
		background: none;
		color: #fff;
		font-size: 28rpx;
	}

	.tips-box {
		width: 750rpx;
		height: 123rpx;
		padding: 0 24rpx 0 28rpx;
		box-sizing: border-box;
		background-color:#ffffff;
		font-size: 26rpx;
		color: #222222;
	}
</style>