<template>
	<view>
		<view class="keyword-view clearfix">
			<u-search @clear="searchData()" @search="searchData()" :show-action="false" :clearabled="true" placeholder="采购单号" v-model="search_form.no"></u-search>
		</view>
		<view class="list-ul">
			<block v-for="(item, index) in purchase_list" :key="index">
				<view class="list-li" @click="selData(item)">
					<view class="top clearfix">
						<view class="ellipsis float_left">{{ item.supplierName }}</view>
						<view class="float_right">
							<text v-if="item.auditStatus === 2" class="success-status">已审核</text>
							<text v-else class="warning-status">待审核</text>
							<u-icon name="arrow-right" size="28" color="#999999"></u-icon>
						</view>
					</view>
					<view class="list-cont">
						<view class="total-money">{{ $utils.formattedNumber(item.purchaseAmount) }}</view>
						<view class="info-li" style="font-size: 28rpx; color: #111111;">{{ item.warehouseName }}</view>
						<view class="info-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="info-li clearfix">
							<text class="float_left">{{ $u.timeFormat(item.createTime, 'yyyy-mm-dd hh:MM:ss') }}</text>
							<text class="float_right">采购员：{{ item.buyerName }}</text>
						</view>
					</view>
				</view>
			</block>
		</view>
		<u-loadmore v-if="purchase_list.length" :status="load_status" />
		<view v-else class="empty-view"><u-empty text="暂无数据" mode="list"></u-empty></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			page: 1,
			pageSize: 10,
			total: 0,
			load_status: 'nomore',
			purchase_list: [],
			search_form: {
				no: '',
			}
		};
	},
	onShow() {
		this.searchData();
	},
	onReachBottom() {
		if (this.total / this.pageSize > this.page) {
			this.page += 1;
			this.getAllPurchase();
		}
	},
	onPullDownRefresh() {
		this.searchData();
	},
	methods: {
		selData(item) {
			// 选择返回上一页
			this._prePage().purchaseData = item;
			uni.navigateBack();
		},
		getAllPurchase() {
			this.load_status = 'loading';
			this.$u.api
				.getAllPurchase({
					returnStatus: '0,1',
					inStatus: '5,6',
					auditStatus: 2,
					deleteStatus: 5,
					no: this.search_form.no,
					page: this.page,
					pageSize: this.pageSize
				})
				.then(res => {
					if (this.page === 1) {
						this.purchase_list = res.data;
					} else {
						this.purchase_list = this.purchase_list.concat(res.data);
					}
					this.total = res.pageTotal;
					this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
				});
		},
		searchData() {
			this.page = 1;
			this.getAllPurchase();
		}
	}
};
</script>

<style lang="scss" scoped>
.keyword-view {
	position: fixed;
	width: 100%;
	top: 0;
	left: 0;
	padding: 20rpx 24rpx;
	background-color: #ffffff;
	z-index: 9;
	.float_left {
		width: 640rpx;
	}
	.float_right {
		line-height: 64rpx;
		width: 50rpx;
		text-align: center;
		color: #666666;
	}
}
.list-ul {
	padding-top: 100rpx;
	.list-li {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		padding: 30rpx 24rpx;
		.top {
			padding-bottom: 20rpx;
			border-bottom: 1px solid #eeeeee;
			.float_left {
				width: 400rpx;
				font-weight: bold;
			}
		}
		.list-cont {
			padding-top: 20rpx;
			position: relative;
			.total-money {
				position: absolute;
				top: 45%;
				right: 0;
				transform: translateY(-50%);
				color: $uni-color-error;
				font-weight: bold;
			}
			.info-li {
				color: #6c6c6c;
				font-size: 24rpx;
				padding-bottom: 10rpx;
			}
		}
	}
}
</style>
