<template>
	<view class="video-pagesCons">
		<view class="tab-body">
			<scroll-view scroll-y style="height: 100%;width: 100%;overflow: auto;" @scrolltolower="onreachBottom">
				<view  
				class="check-order-list" 
				v-for="(item,index) in list" 
				:key="item.id" 
				 @click="viewRow(item)"
				>
					<view class="video-item">
						<view>
							<u-image :src="item.imageSet[0]" height="160px" width="100%"></u-image>
						</view>
						<view class="ellipsis-two">{{item.title}}</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>     
		</view>
		<u-tabbar :list="vuex_tabBarList" :before-switch="beforeSwitch" :midButton="vuex_tabBarList.length==5"></u-tabbar>
	</view>
</template>

<script>
	import {
	    mapState,
	    mapMutations,
	} from 'vuex'
	import { promoTerminalList } from '@/api/video.js'
	export default {
		data() {
			return {
				status: 'loading',
				noDataText: '暂无数据',
				// 查询条件
				pageNo: 1,
				pageSize: 10,
				list: [],
				total: 0,
			}
		},
		computed: {
			...mapState(['hasLogin','vuex_vinScanNums','vuex_scanMaxNums','vuex_tabBarList','vuex_videoTypeList']),
			userInfo(){
				return this.$store.state.vuex_userInfo
			},
			tabList(){
				return this.$store.state.vuex_videoTypeList
			}
		},
		onLoad() {
			this.pageInit()
		},
		onHide() {
			this.list.map(item => {
				item.showVideo = false
			})
		},
		methods: {
			pageInit(){
				this.total = 0
				this.pageNo = 1
				this.getRow()
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				if(this.list.length < this.total){
					this.pageNo += 1
					this.getRow()
				}else{
					this.status = "nomore"
				}
			},
			// 查询列表
			getRow (pageNo) {
			  let _this = this
			  if (pageNo) {
			    this.pageNo = pageNo
			  }
			  let params = {
			    pageNo: this.pageNo,
			    pageSize: this.pageSize,
			  }
			  const storeShelf = this.$store.state.vuex_storeShelf
			  this.status = "loading"
			  promoTerminalList({sn:storeShelf.dealerSn,contentType:'LINK'}).then(res => {
				if (res.code == 200 || res.status == 204 || res.status == 200) {
				  // const list = res.data.list || []
				  // if(_this.pageNo>1){
					 //  _this.list = _this.list.concat(list)
				  // }else{
					 //  _this.list = list
				  // }
				  // _this.total = res.data.count || 0
				  
				  _this.list = res.data.filter(item => item.content.indexOf("pages/promo/index") >= 0)
				  _this.total = _this.list.length
				} else {
				  _this.list = []
				  _this.total = 0
				  _this.noDataText = res.message
				}
				_this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
			  })
			},
			// 促销活动产品列表页
			viewRow(item){
				 uni.navigateTo({
				 	url: '/pagesB/promoDetail?id='+item.id+'&title='+item.title
				 })
			},
			// 扫描vin
			beforeSwitch(index){
				const row = this.$store.state.vuex_tabBarList[index]
				if(row.text == '扫描VIN'){
					this.openCamera()
				}else{
					return true
				}
			},
			// 去扫描
			openCamera(){
				if(this.hasLogin){
					if(this.userInfo.sysUserFlag == '0'){
						if(this.vuex_vinScanNums < this.vuex_scanMaxNums){
							uni.navigateTo({
								url: "/pages/scan-frame/scan-frame"
							})
						}else{
							uni.showModal({
								title: '提示',
								content: '个人用户扫描VIN仅限10次，您的次数已用完！',
								confirmText: '好的',
								showCancel: false,
								success(res) {}
							})
						}
					}else{
						uni.navigateTo({
							url: "/pages/scan-frame/scan-frame"
						})
					}
				}else{
					uni.navigateTo({
						url: '/pages/login/login'
					})
				}
			},
		}
	}
</script>

<style lang="less">
    page{
		height: 100vh;
	}
	.video-pagesCons{
		height: 100%;
		display: flex;
		flex-direction: column;
		.tab-body{
			height: 100vh;
			.check-order-list{
				background: #ffffff;
				padding: 20upx;
				margin: 25upx;
				border-radius: 10upx;
				box-shadow: 1px 1px 3px #EEEEEE;
				.video-item{
					> view{
						&:first-child{
							position: relative;
						}
						&:last-child{
							text-align: center;
							font-size: 36rpx;
							margin: 20rpx 0 0;
						}
					}
				}
			}
		}
	}
</style>
