<template>
	<view class="body">
		<view class="wrapper wrap">
			<view class="u-tabs-box">
				<u-subsection :list="list" :current="current" @change="sectionChange" fontSize='23'></u-subsection>
			</view>
			<view v-if="orderList.length" class="main-box">
				<view class="page-box">
					<view class="order" v-for="(res, index) in orderList" :key="res.id" v-if="res.applyno"
						@click="redirectToDetail(res)">
						<view class="item">
							<view class="content">
								<view class="title">
									<nobr>编号：{{ res.applyno }}</nobr>
								</view>
								<view class="type all-reckon">
									<text style="padding-right: 100rpx;">结算金额: {{ res.finalprice }}</text>
									<text>订单金额: {{ res.orderprice }}</text>
								</view>
								<view class="type detail-reckon-tr">
									<view class="detail-reckon-tr-td" v-if="res.wechat_price > 0">
										微信订单结算:{{ res.wechat_price }}元</view>
									<view class="detail-reckon-tr-td" v-if="res.alipay_price > 0">
										支付宝订单结算:{{ res.alipay_price }}元</view>
									<view class="detail-reckon-tr-td" v-if="res.passcreditmoney > 0">
										金豆抵扣结算:{{ res.passcreditmoney }}元
										<text style="font-size:23rpx;color:#999999;">(通过支付宝转账)</text>
									</view>
									<view class="detail-reckon-tr-td" v-if="res.deduct_recharge > 0">
										储值抵扣:{{ res.deduct_recharge }}元
									</view>
									<view v-if="res.offline_fee > 0">第三方支付服务费:-{{ res.offline_fee }}元</view>
									<view v-if="res.all_creditadd_fee > 0">金豆赠送费:-{{ res.all_creditadd_fee }}元
										<text style="font-size:23rpx;color:#999999;"></text>
									</view>
								</view>
								<view class="time">
									<text>结算订单日:{{ res.ordertime ? res.ordertime : res.applyOrderDate }}</text>
									<text class="applay-status">{{ res.statusstr }}</text>
								</view>
							</view>
							<view class="right">
								<view @click="showPopupMenu(res.id)">
									<view class="dots">
									</view>
								</view>
							</view>
						</view>
					</view>
					<u-loadmore status="加载更多..." bgColor="#f2f2f2"></u-loadmore>
				</view>
			</view>

			<u-empty v-if="!orderList.length" text="数据为空" mode="list"></u-empty>
		</view>

	</view>
</template>

<script>
	let that = {}
	export default {
		data() {
			return {
				orderList: [],
				list: ['待结算','已结算'],
				current: 0,
				currentId: 0,
				form: {
					page: 1,
					limit: 15,
					keyword: '',
					status: 3
				},
			}
		},
		onLoad() {
			that = this
			// that.init()
		},
		onPullDownRefresh() {
			that.getList()
			setTimeout(function() {
				uni.showToast({
					title: '刷新成功',
					icon: 'none'
				})
				uni.stopPullDownRefresh({
					success: (result) => {},
					fail: (error) => {}
				})
			}, 688)

		},
		onReachBottom() {
			this.form.page += 1
			that.getList()
		},
		methods: {
			init() {
				let now = new Date()
				this.startDate = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + 1
				this.endDate = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate()
				this.getList()
			},
			getList() {
				uni.showLoading({
					title: '加载中...'
				})
			},
			redirectToCheckout() {
				uni.switchTab({
					url: '/pages/fiance/checkout/checkout',
					success(res) {
						//console.log(res);
					},
					fail(res) {
						//console.log(res);
					}
				})
			},
			redirectToDetail(item) {
				let url = '/pages/fiance/ledger/ledger?type=withdraw_history'
				uni.setStorage({
					key: 'withdraw_history_show_by_ledger',
					data: item,
					success: function() {
						uni.navigateTo({
							url: url,
							success: function(res) {
								res.eventChannel.emit('withdraw_history', item)
							}
						})
					}
				})
			},
			// tab栏切换
			sectionChange(index) {
				console.log(index);
				this.current = index
				that.form.status = index + 1
				that.form.page = 1
				that.orderList = []
				// that.getList()
			},
			showPopupMenu(id) {
				if (this.currentId === id) {
					this.currentId = 0;
					return;
				}
				this.currentId = id;

			}
		}
	}
</script>


<style lang="scss" scoped>
	@import "./withdraw.scss";
</style>