<template>
	<view class="">
		<view class="lable-title" v-if="list.length > 0">
			<view class=""></view>
			<text class="lable-title-icon iconfont">&#xe611;</text>
		</view>
		<u-list class="swiper-list" :style="{'height': scrollHeight ? `${scrollHeight}px` : '' }" @scrolltolower="scrolltolower">

			<template v-for="item in list">
				<view class="content-box" :rise-fall="stocksColor">
					<view class="content-top">
						<view class="top-left">
							<view class="top-left-title">
								<text>{{ item.symbol }}</text>
								<!-- <text>{{ item.type_name }}</text> -->
								<text class="top-left-b-tag">{{ item.type_name }}</text>
							</view>
						 
						</view>
 
					</view>
					<view class="content-info">
						<view class="info-item">
							<text class="info-item-lable">数量(张)</text>
							<text class="info-item-val">{{ item.number }}</text>
						</view>
						<view class="info-item">
							<text class="info-item-lable">成交价格(USDT)</text>
							<text class="info-item-val">{{ item.origin_price }}</text>
						</view>
						<view class="info-item">
							<text class="info-item-lable">成交额(USDT)</text>
							<text class="info-item-val">{{ item.number }}</text>
						</view>


						<view class="info-item">
							<text class="info-item-lable">手续费(USDT)</text>
							<text class="info-item-val">{{ item.trade_fee || '--' }}</text>
						</view>
						<view class="info-item">
							<text class="info-item-lable">订单号</text>
							<text class="info-item-val">{{ item.id }}</text>
						</view>
						<view class="info-item">
							<text class="info-item-lable">成交时间</text>
							<text class="info-item-val">{{ $getData_(item.create_time ) }}</text>
						</view>
					</view>
				</view>
				<gap />
			</template>
			<view class="loadmore-box" v-show="loadStatus !== 'nomore' || list.length > 0">
				<u-loadmore :status="loadStatus" nomoreText="没有更多数据" :fontSize='28' :icon="false"/>
			</view>
			<empty class="empty-content" v-show="loadStatus === 'nomore' && list.length <= 0" />
		</u-list>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import {
		Api_getRegister
	} from "@/api/index.js"
	export default {
		name: 'login',
		props: {
			listHeight: {
				type: Number,
				default: 0
			},
			
			status: {
				type: Number,
				default: ''
			},
		},
		data() {
			return {
				scrollHeight:0,
				list: [],
				loadStatus: '', // loading / nomore / loadmore
				limit: 10,
				page: 1,
			};
		},
		// 80rpx
		watch:{
			listHeight:{
				handler(newH){
					if(newH){
						this.scrollHeight = newH - uni.upx2px(80);
					}
				},
				immediate:true
			},
			status: {
				handler(newSatus, oldStatus) {
					if (newSatus === 3 && newSatus !== oldStatus) {
						this.limit = 10;
						this.page = 1;
						this.getRegister()
					}
				},
				immediate: true
			},
		},
		computed: {
			...mapGetters([
				"stocksColor",
			])
		},
		mounted() {
			// this.getRegister()
		},
		methods: {
			scrolltolower() {
				if (this.loadStatus === 'loadmore') {
					this.page ++;
					this.getRegister()
				}
			},
			getRegister() {
				if (this.loadStatus === 'loading') {
					return false
				};
				this.loadStatus = 'loading'
				Api_getRegister({
					status: this.status,
					page: this.page,
					limit: this.limit,
				}).then(res => {
					const data = res.message;
					this.list = this.list.concat(data.data)
					this.page = data.current_page;
					if (this.list.length >= data.total) {
						this.loadStatus = 'nomore'
					} else {
						this.loadStatus = 'loadmore' 
					}
				}).catch(err => {
					if (this.page >= 2) {
						this.page -= 1;
						this.loadStatus = 'loadmore'
					} else {
						this.loadStatus = 'nomore'
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "~../sustainability/index.scss";
	.top-left-b-tag{
		padding-left: 30rpx !important;
		padding-right: 30rpx !important;
		line-height: 1;
	}
</style>