<template>
	<view class="vinRecord flex flex_column">
		<!-- <view class="des">仅可查看最近7天的VIN查询记录</view> -->
		<swiper class="list-box">
			<swiper-item class="swiper-item" style="height: 100%;width: 100%;overflow: hidden;">
				<scroll-view scroll-y style="height: 100%;width: 100%;overflow: auto;" @scrolltolower="onreachBottom">
					<view class="list-item flex align_center justify_between" v-for="item in list" :key="item.id" @click="toChoosePart(item)">
						<view v-if="userInfo&&userInfo.sysUserFlag == '1'">
							<u-image shape="circle" :src="item.icon||'@/static/def_imgs.png'" width='90' height="90"></u-image>
						</view>
						<view>
							<view class="flex align_center justify_between">
								<text class="vin-text">{{item.vinCode}}</text>
								<text class="time-text">{{item.createDate}}</text>
							</view>
							<view v-if="userInfo&&userInfo.sysUserFlag == '1'">{{item.modelInfo}}</view>
						</view>
					</view>
					 <view style="padding: 20upx;">
						 <u-empty :src="`/static/nodata.png`" icon-size="180" :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
						 <u-loadmore v-if="(total>=list.length&&list.length)||status=='loading'" :status="status" />
					 </view>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import { getScanVinLogList }from '@/api/car.js'
	import moment from 'moment'
	export default {
		data() {
			return {
				status: 'loading',
				noDataText: '暂无数据',
				// 查询条件
				pageNo: 1,
				pageSize: 10,
				list: [],
				total: 0,
			}
		},
		onLoad() {
			this.pageInit()
		},
		computed: {
			hasShelf(){
				return this.$store.state.vuex_storeShelf
			},
			userInfo(){
				return this.$store.state.vuex_userInfo
			}
		},
		methods: {
			pageInit(){
				this.total = 0
				this.pageNo = 1
				this.getRow()
			},
			// 查询列表
			getRow (pageNo) {
			  let _this = this
			  if (pageNo) {
			    this.pageNo = pageNo
			  }
			  // 查询条件
			  let params = {
				// beginDate: moment().subtract('days', 6).format('YYYY-MM-DD 00:00:00'),
				// endDate: moment(moment().valueOf()).format('YYYY-MM-DD 23:59:59'),
			    pageNo: this.pageNo,
			    pageSize: this.pageSize,
				identifyType: this.userInfo ? this.userInfo.identifyType : ''
			  }
			  this.status = "loading"
			  getScanVinLogList(params).then(res => {
				if (res.code == 200 || res.status == 204 || res.status == 200) {
				  const retList = res.data.list.filter(item => item.vinCode)
				  if(_this.pageNo>1){
					  _this.list = _this.list.concat(retList || [])
				  }else{
					  _this.list = retList || []
				  }
				  _this.total = res.data.count || 0
				} else {
				  _this.list = []
				  _this.total = 0
				  _this.noDataText = '暂无数据'
				}
				_this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
			  })
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.list.length < this.total){
					this.pageNo += 1
					this.getRow()
				}else{
					this.status = "nomore"
				}
			},
			toChoosePart(item){
				item.text = item.modelInfo
				uni.navigateTo({
					url: "/pagesA/digitalShelf/choosePart?vinNumber="+item.vinCode+"&carList="+encodeURIComponent(JSON.stringify(item))
				})
			}
		}
	}
</script>

<style lang="less">
.vinRecord{
	width: 100%;
	height: 100vh;
	background: #f8f8f8;
	.des{
		text-align: center;
		color: #999;
		font-size: 12px;
		padding: 20rpx 15rpx;
	}
	.list-box{
		flex-grow: 1;
		overflow: auto;
	}
	.list-item{
		margin: 20rpx 30rpx;
		border:2rpx solid #f8f8f8;
		box-shadow: 2rpx 2rpx 6rpx #eee;
		border-radius: 20rpx;
		padding: 20rpx 15rpx;
		background: #ffffff;
		> view{
			padding: 0 10rpx;
			&:last-child{
				flex-grow: 1;
				>view{
					padding: 10rpx 0;
				}
			}
		}
		.time-text{
			font-size: 10px;
			color: #999;
		}
		&:first-child{
			margin-top: 10rpx;
		}
		&:active{
			opacity: 0.6;
			transform:scale(0.9);
		}
	}
}
</style>
