<template>
	<!-- 采购入库 -->
	<view class="container">
		<u-navbar back-icon-color='#fff' :background="{ background: '#409eff'}" back-text="" title-color='#fff'
			title="采购入库">
		</u-navbar>
		<!-- <Search @search='search' @screen='screen' /> -->
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index" @click="openDetail(item)">
				<view class="title">
					<view class="title-txt">
						{{item.number}}
					</view>
					<view class="time">
						{{`${$time.formatDate(item.createTime)}`}}
					</view>
				</view>
				<view class="dec">
					采购人:<span>{{item.purchaser}}</span>
				</view>
				<view class="dec">
					采购时间:<span>{{item.date}}</span>
				</view>
				<view class="bottom">
					<view class="status">
						<u-tag text="未完成" v-if="item.status=='INCOMPLETE'" bg-color='rgba(255,255,255,0)' color='#e01f54'
							border-color='#e01f54' type="success" shape='circle' />
						<u-tag text="已完成" v-else-if="item.status=='COMPLETE'" bg-color='rgba(255,255,255,0)' color='#2ba471'
							border-color='#2ba471' type="info" shape='circle' />
					</view>

				</view>
			</view>
		</view>
		<view style="height: constant(safe-area-inset-bottom); height: env(safe-area-inset-bottom);"></view>
	</view>
</template>

<script>
	import * as inLocationApi from "@/api/inLocation.js"
	export default {
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 10,
				},
				status: 'loadmore', //是否显示没有更多了
				list: [],

			}
		},
		methods: {
			openDetail(item){
				this.$tab.navigateTo(`/pages/inLocation/addForm?data=${encodeURIComponent(JSON.stringify(item))}`)
			},
			// 获取备件领用列表
			async getList() {
				if (this.status == 'nomore') return;
				this.status = 'loading';
				this.$modal.loading('加载中')
				await inLocationApi.getInLocationPage(this.params).then((res) => {
					this.$modal.closeLoading()
					if (res.data.list.length > 0) {
						this.list = this.list.concat(res.data.list);
						console.log(this.list )
						this.params.pageNo++;
						this.status = 'loadmore'
					} else {
						this.status = 'nomore'
					}
				})
			},
			
		},
		onLoad(option) {
			if (option.type) this.params.type = option.type;
		},
		onShow() {
			this.params.pageNo = 1
			this.list = []
			this.status = 'loadmore'
			this.getList()

		},
		onReachBottom() {
			this.getList()
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		background: #f5f5f5;
		margin-top: 20rpx;

		.item {
			padding: 30rpx 30rpx 0px 30rpx;
			margin-top: 20rpx;
			background: white;
			position: relative;

			.title {
				display: flex;
				align-items: center;
				padding-bottom: 20rpx;

				.title-txt {
					color: #409eff;
					font-weight: bold;
					font-size: 36rpx;
					width: 0px;
					flex: 1;
				}

				.time {
					color: #919191;

				}
			}

			.dec {
				padding-bottom: 20rpx;

				span {
					color: #999999;
				}
			}

			.last {
				padding-bottom: 30rpx;
			}

			.bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-top: 1px solid #E4E4E4;
				padding: 20rpx 0px;
				height: 90rpx;

			}
		}
	}
</style>