<template>
	<u-cell-group>
	    <u-cell
	        center
			isLink
			v-for="item in list"
			:key="item.sparePartsPurchaseNo"
			@click="toEdit(item)"
	    >
		<view slot="label">
			<view class="u-kh">
				<view>
					{{item.sparePartsPurchaseNo}}
				</view>
				<view style="padding: 0 10rpx;" v-if="item.sourceType=='HAND'">
					<u-icon name="android-fill" size="16" color="#00aaff"></u-icon>
				</view>
			</view>
			<view class="u-time">创建时间：{{item.createDate}}</view>
		</view>
		<view slot="value">
			<text class="u-text" :style="{color: item.sourceType=='HAND'&&item.state == 'WAIT_SUBMIT' ? '#00aaff' : '#999'}">{{item.stateDictValue}}</text>
		</view>
		</u-cell>
		<view v-if="list.length==0&&status != 'loading'">
			<u-empty :iconSize="60" text="无入库记录" :marginTop="100" mode="history"></u-empty>
		</view>
		<view style="padding: 30rpx 0;">
			<u-loadmore :status="status" />
		</view>
	</u-cell-group>
</template>

<script>
	import { sparePartsPurList } from '@/config/api.js'
	export default{
		data(){
			return {
				list: [],
				pageSize: 10,
				pageNo: 1,
				total: 0,
				status: 'loadmore'
			}
		},
		onLoad() {
			var _this = this
			this.status = 'loading'
			this.getList()
			
			// 刷新
			uni.$on('refashList', function(content) {
				_this.status = 'loading'
				_this.getList()
			})
		},
		onUnload() {
			uni.$off("refashList")
		},
		methods:{
			getList(){
				sparePartsPurList({pageSize:this.pageSize,pageNo:this.pageNo}).then(res => {
					if(res.status == 200){
						const list = res.data.list
						this.total = res.data.count
						if(this.pageNo == 1){
							this.list = list
						}else{
							this.list = this.list.concat(list)
						}
						if(this.list.length < this.total){
							this.status = 'loadmore'
						}else{
							this.status = 'nomore'
						}
					}
				})
			},
			toEdit(item){
				// 待提交
				if(item.state == 'WAIT_SUBMIT' && item.sourceType == 'HAND'){
					uni.navigateTo({
						url:"/pages/stockIn/index?sn="+item.sparePartsPurchaseSn+"&id="+item.id
					})
				}else{
					// 查看详情
					uni.navigateTo({
						url:"/pages/stockIn/viewDetail?sn="+item.sparePartsPurchaseSn+"&id="+item.id
					})
				}
			},
			onReachBottom(){
				const pageNums = Math.ceil(this.total / this.pageSize)
				if(this.pageNo < pageNums){
					this.pageNo = this.pageNo + 1
					this.status = 'loading'
					this.getList()
				}else{
					this.status = 'nomore'
				}
			}
		}
	}
</script>

<style lang="scss">
	.u-time{
		color: $uni-text-color-grey;
		font-size: 30upx;
	}
	.u-kh{
		font-size: 34upx;
		display: flex;
	}
	.u-text{
		font-size: 30upx;
	}
</style>