<template>
	<view>
		<view class="tabs-view">
			<view class="keyword-view clearfix">
				<u-search :clearabled="true" @custom="searchData" @search="searchData" @clear="searchData" placeholder="客户名称" v-model="keyword"></u-search>
			</view>
			<u-tabs-swiper ref="tabs" font-size="28" :current="tabs_current" :list="status_list" @change="statusChange" :is-scroll="false"></u-tabs-swiper>
		</view>

		<view class="list-ul">
			<view
				class="list-li"
				v-for="(item, index) in receipt_list"
				:key="index"
				@click="goPage('/pagesT/Finance/ApplyReceiptDetail?id=' + item.id + '&time=' + item.createTime)"
			>
				<view class="title clearfix">
					<view class="float_left">{{ item.customerName }}</view>
					<view class="float_right">
						<text class="success-status" v-if="item.auditStatus === 2">已审核</text>
						<text class="warning-status" v-else>待审核</text>
						<text class="custom-icon custom-icon-jinru"></text>
					</view>
				</view>
				<view class="list-cont">
					<view class="list-cont-li" @click.stop="copy(item.no)">
						<text style="margin-right: 20rpx;">{{ item.no }}</text>
						<u-icon name="copy" custom-prefix="custom-icon" size="22"></u-icon>
					</view>
					<view class="list-cont-li clearfix">
						<view class="float_left">{{ $u.timeFormat(item.createTime, 'yyyy-mm-dd') }}</view>
						<view class="float_right price">{{ $utils.formattedNumber(item.totalActualAmount) }}</view>
					</view>
				</view>
			</view>
			<view v-if="!receipt_list.length" class="empty-view"><u-empty text="暂无数据" mode="list"></u-empty></view>
			<u-loadmore v-if="receipt_list.length" :status="load_status" />
		</view>
		<addBtn v-if="$accessCheck($Access.addApplyReceipt)" url="/pagesT/Finance/AddApplyReceipt"></addBtn>
	</view>
</template>

<script>
export default {
	data() {
		return {
			receipt_list: [],
			load_status: 'nomore',
			page: 1,
			pageSize: 10,
			total: 0,
			tabs_current: 0,
			keyword: '',
			search_show: false,
			status_list: [
				{
					value: '',
					name: '全部'
				},
				{
					value: 1,
					name: '待审核'
				},
				{
					value: 2,
					name: '已审核'
				}
			],
			billStatus: '',
			customerName: '',
			customerId: '',
			customerData: ''
		};
	},
	onShow() {
		this.page = 1;
		this.getAllReceiptRequisition();
	},
	onReachBottom() {
		if (this.tab_current === 0) {
			if (this.total / this.pageSize > this.page) {
				this.page += 1;
				this.getAllReceiptRequisition();
			}
		}
	},
	onPullDownRefresh() {
		this.getAllReceiptRequisition();
	},
	methods: {
		getAllReceiptRequisition() {
			this.load_status = 'loading';
			this.$u.api
				.getAllReceiptRequisition({
					page: this.page,
					pageSize: this.pageSize,
					operatorName: '',
					custormerName: this.keyword,
					auditStatus: this.billStatus
				})
				.then(res => {
					uni.stopPullDownRefresh();
					if (this.page === 1) {
						this.receipt_list = res.data;
					} else {
						this.receipt_list = this.receipt_list.concat(res.data);
					}
					this.total = res.pageTotal;
					this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
				})
				.catch(err => {
					uni.stopPullDownRefresh();
				});
		},
		statusChange(index) {
			this.tabs_current = index;
			this.billStatus = this.status_list[index].value;
			this.searchData();
		},
		searchData() {
			this.page = 1;
			this.getAllReceiptRequisition();
		}
	}
};
</script>

<style lang="scss" scoped>
.tabs-view {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	background-color: #ffffff;
	z-index: 99;
	.keyword-view {
		padding: 20rpx 24rpx 0;

		.float_left {
			width: 640rpx;
		}

		.float_right {
			line-height: 64rpx;
			width: 50rpx;
			text-align: center;
			color: #666666;
		}
	}
}

.list-ul {
	padding-top: 160rpx;

	.list-li {
		width: 710rpx;
		border-radius: 20rpx;
		margin: 20rpx auto;
		padding: 10rpx 24rpx 30rpx;
		margin-top: 20rpx;
		background-color: #ffffff;

		.title {
			line-height: 80rpx;
			border-bottom: 1px solid #eeeeee;

			.float_left {
				font-weight: bold;
			}

			.float_rigth {
				.custom-icon-jinru {
					margin-left: 10rpx;
					font-size: 28rpx;
				}
			}
		}

		.list-cont {
			margin-top: 10rpx;

			.list-cont-li {
				color: #6c6c6c;
				line-height: 40rpx;
				font-size: 24rpx;

				.price {
					font-weight: bold;
					font-size: 26rpx;
					color: $uni-color-error;
				}
			}
		}
	}
}
</style>
