<template>
	<view :rise-fall="stocksColor">
		<headContent borderBottom>
			<template #left>
				<reverse-back>
					<template #extend>
						<view class="details-nav">
							<view class="title-iocn">
								<text class="title-iocn-item"></text>
								<text class="title-iocn-item"></text>
								<text class="title-iocn-item"></text>
							</view>
							<text class="nav-name">
								{{ currencyVal.currency_name }}/ {{ currencyVal.legal_name }}
							</text>
						</view>
					</template>
				</reverse-back>
			</template>
			<template #right>
				<headCollect />
			</template>
		</headContent>

		<view class="top-index fixed-top-index" :style="{'top': navBarHeight + 'px'}">
			<view :class="['index-val' , $setColor(daymarket.open)]">
				<text class="index-val-num color">{{ daymarket.open }}</text>
				<text class="index-val-percent color">{{ daymarket.change }}%</text>
			</view>
			<view class="index-type">
				标记价格 <text class="iconfont">&#xeb6d;</text>
			</view>
		</view>
		<view style="width:100%;height:90rpx;"></view>
		<view class="info-content">
			<view class="info-item">
				<text class="info-lable">标记价格</text>
				<text class="info-val">{{ daymarket.now_price }}</text>
			</view>
			<view class="info-item">
				<text class="info-lable">24H高</text>
				<text class="info-val">{{ daymarket.high }}</text>
			</view>
			<view class="info-item">
				<text class="info-lable">24H低</text>
				<text class="info-val">{{ daymarket.low }}</text>
			</view>
			<view class="info-item">
				<text class="info-lable">24H额(BTC)</text>
				<text class="info-val">{{ daymarket.volume }}</text>
			</view>
			<view class="info-item">
				<text class="info-lable">24H量(BTC)</text>
				<text class="info-val">{{ daymarket.volume * daymarket.open }}</text>
			</view>
		</view>

		<view class="iframe-content">
			<template v-if="currencyVal.legal_id">
				<k-line></k-line>
			</template>
		</view>
		<gap />
		<view class="val-content">
			<view class="val-content-lable">
				<text @click.stop="valLableIndex = 0"
					:class="['lable-text' , valLableIndex === 0 ? 'active-lable-text' : '']">交易深度</text>
				<text @click.stop="valLableIndex = 1"
					:class="['lable-text' , valLableIndex === 1 ? 'active-lable-text' : '']">实时成交</text>
			</view>
			<swiper class="swiper-content" :current="valLableIndex"
				:style="{'height': swiperHeight ? `${swiperHeight}px` : '' }" disable-touch>
				<swiper-item class="swiper-item-box">
					<view class="val-content-type">
						<text class="left-type">买</text>
						<text class="right-type">卖</text>
					</view>
					<view class="val-content-list">
						<text>数量(张)</text>
						<text>价格(USDT)</text>
						<text>数量(张)</text>
					</view>
					<u-list class="swiper-list" :style="{'height': scrollLeftHeight ? `${scrollLeftHeight}px` : '' }">
						<view class="depth-content">
							<view class="depth-val">
								<template v-for="(item , index) in asks">
									<market-depth :type="2" :val="item" height="80rpx"></market-depth>
									<!-- <view class="depth-item depth-item-left">
										<text class="depth-item-bg" :style="{'width': item[2] + '%' }"></text>
										<view class="depth-item-val">
											<text>{{ item[1] }}</text>
											<text class="item-val-price">{{ item[0] }}</text>
										</view>
									</view> -->
								</template>
							</view>
							<view class="depth-val">
								<template v-for="(item , index) in bids">
									<market-depth :type="1" :val="item" height="80rpx" leftbg></market-depth>
								</template>

							</view>
						</view>
					</u-list>
				</swiper-item>
				<swiper-item>
					<view class="val-content-list">
						<text>时间</text>
						<text>价格(USDT)</text>
						<text>数量(张)</text>
					</view>
					<u-list class="swiper-list" :style="{'height': scrollRightHeight ? `${scrollRightHeight}px` : '' }">
						<empty />
					</u-list>
				</swiper-item>
			</swiper>


		</view>
		<view class="details-footer">
			<view class="footer-btn" @click.stop="consumeBtn">买入/做多</view>
			<view class="footer-btn" @click.stop="consumeBtn">卖出/做空</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import {
		startSocket,
		closeSocket
	} from "@/utils/websocket.js"
	export default {
		data() {
			return {
				valLableIndex: 0,
				swiperHeight: 0,
				scrollLeftHeight: 0,
				scrollRightHeight: 0
			};
		},
		computed: {
			...mapGetters([
				"currencyVal",
				"stocksColor",
				'bids',
				'asks',
				'daymarket',
				'tabBarHeight',
				'PageContentHeight',
				'navBarHeight',
				'contractAccount'
			])
		},
		watch: {
			PageContentHeight: {
				handler(newH) {
					this.swiperHeight = newH - uni.upx2px(90) - uni.upx2px(94)
					this.scrollLeftHeight = this.swiperHeight - uni.upx2px(66) - uni.upx2px(60) - uni.upx2px(96)
					this.scrollRightHeight = this.swiperHeight - uni.upx2px(60) - uni.upx2px(96)
				},
				immediate: true
			}
		},
		onShow() {
			this.setSocket();
		},
		onHide() {
			closeSocket()
		},
		mounted() {

		},
		methods: {
			setSocket() {
				startSocket();
			},
			consumeBtn() {
				const pages = getCurrentPages();
				console.log('pages = ', pages)
				if (pages.length >= 2 && pages[pages.length - 2].route === 'pages/contract/index') {
					uni.navigateBack({
						delta: 1
					});
				} else {
					uni.reLaunch({
						url: '/pages/contract/index'
					})
				}
			}
		}

	}
</script>

<style lang="scss" scoped>
	.details-nav {
		display: flex;
		align-items: center;
		border-left: 1rpx solid $border-color4;
		padding-left: 20rpx;

		.nav-name {
			padding-left: 10rpx;
			font-size: 38rpx;
			font-weight: bold;
		}
	}

	.title-iocn {
		width: 28rpx;
		height: 24rpx;
		display: flex;
		flex-direction: column;
		// align-items: center;
		justify-content: space-between;

		.title-iocn-item {
			width: 100%;
			height: 4rpx;
			border-radius: 2rpx;
			background: #111111;

			&:first-child {
				width: 50%;
			}
		}
	}

	// <view class="top-index fixed-top-index" :style="{'top': navBarHeight + 'px'}">
	// 			<view :class="['index-val' , $setColor(27)]">
	// 				<text class="index-val-num color">27</text>
	// 				<text class="index-val-percent color">0.29%</text>
	// 			</view>
	// 			<view class="index-type">
	// 				标记价格 <text class="iconfont">&#xeb6d;</text>
	// 			</view>
	// 		</view>
	.top-index {
		width: 100%;
		height: 94rpx;
		padding: 16rpx $pages-padding;
		border-bottom: 1rpx solid $border-color;
		display: flex;
		justify-content: space-between;
		background-color: #fff;

		.index-val-num {
			font-size: 30rpx;
			font-weight: bold;
		}

		.index-val-percent {
			font-size: 24rpx;
			padding-left: 10rpx;
		}

		.index-type {
			width: 240rpx;
			height: 100%;
			border: 1rpx solid $border-color6;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 24rpx;
			padding: 0 20rpx;
			border-radius: 10rpx;

			.iconfont {
				font-size: 20rpx;
				color: $Theme-Color;
			}
		}

	}

	.fixed-top-index {

		position: fixed;
		z-index: 1;
		left: 0;
	}

	.iframe-content {
		width: 100%;
		height: 660rpx;
	}

	.info-content {
		display: flex;
		align-items: stretch;
		flex-wrap: wrap;
		padding: 26rpx $pages-padding 0;
		border-bottom: 1rpx solid $border-color;

		.info-item {
			min-height: 70rpx;
			width: calc(100% / 3);
			flex-shrink: 0;
			display: flex;
			flex-direction: column;
			font-size: 20rpx;
			margin-bottom: 26rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			&:nth-child(3n),
			&:nth-child(3n - 1) {
				text-align: right;
			}

		}
	}

	.val-content {
		width: 100%;

		.val-content-lable {
			width: 100%;
			display: flex;
			align-items: stretch;
			padding: 0 $pages-padding;
			height: 96rpx;
			border-bottom: 1rpx solid $border-color;

			.lable-text {
				height: 100%;
				font-size: 28rpx;
				line-height: 90rpx;
				margin-right: 50rpx;
			}

			.active-lable-text {
				position: relative;
				color: $Theme-Color;

				&::before {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 40rpx;
					height: 7rpx;
					border-radius: 4rpx;
					background-color: $Theme-Color;
				}
			}
		}

		.val-content-type {
			width: 100%;
			height: 66rpx;
			border-bottom: 1rpx solid $border-color;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 $pages-padding;
			font-size: 28rpx;
			font-weight: bold;

			.left-type {
				color: $mai_01;
			}

			.right-type {
				color: $mai_02;
			}
		}

		.val-content-list {
			width: 100%;
			padding: 0 $pages-padding;
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 60rpx;
			font-size: 26rpx;
		}

		.depth-content {
			padding: 0 $pages-padding;
			width: 100%;
			display: flex;

			.depth-val {
				width: 50%;
				flex-shrink: 0;

				.depth-item {
					height: 80rpx;
					position: relative;

					.depth-item-bg {
						height: 100%;
						position: absolute;
						top: 0;
					}

					.depth-item-val {
						position: absolute;
						width: 100%;
						height: 100%;
						font-size: 26rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;
						font-weight: bold;
					}
				}

				.depth-item-left {
					.depth-item-val {
						padding-right: 10rpx;
					}

					.depth-item-bg {
						right: 0;
						background-color: $mai_03;
					}

					.item-val-price {
						color: $Theme-Color;
					}
				}

				.depth-item-right {
					.depth-item-val {
						padding-left: 10rpx;
					}

					.depth-item-bg {
						left: 0;
						background-color: $mai_04;
					}

					.item-val-price {
						color: $Theme-Color2;
					}
				}

			}
		}
	}

	.details-footer {
		position: fixed;
		left: 0;
		bottom: 0;
		height: 90rpx;
		width: 100%;
		padding: 5rpx 40rpx;
		display: flex;
		justify-content: space-between;
		align-items: stretch;

		background-color: #fff;

		.footer-btn {
			flex: 1;
			height: 80rpx;
			color: #fff;
			text-align: center;
			line-height: 80rpx;
			font-size: 30rpx;
			border-radius: 6rpx;

			&:first-child {
				background-color: $Theme-Color;
			}

			&:last-child {
				margin-left: 20rpx;
				background-color: $Theme-Color2;
			}
		}
	}
</style>