<template>
	<view class="main_con">

		<navigation :showBack="false" :bgnum="true" class="head">
			{{i18n.Market}}
		</navigation>
		<view class="main">
			<view class="title_item flex">
				<view class="text1 pairs">{{i18n.TrandingPairs}}</view>
				<view class="text1 price">{{i18n.PriceVol}}</view>
				<view class="text1  chang">
					{{i18n.Chang}}
				</view>
			</view>
			<view class="scroll">
				<view class="item flex" v-for="(item,index) in recordInfo">
					<view class="text2 pairs">
						<strong>{{item.symbol}}</strong><span class="t1">/USDT</span>
					</view>
					<view class="text2 price">
						<view class="">
							<strong>${{item.last}}</strong>
						</view>
						<view class="t1">
							{{item.priceCny}}
						</view>

					</view>
					<view class="btn " :class="item.rose>0?'red':'green'">

						{{item.rose>0?'+':''}}{{item.rose}}%
					</view>
				</view>
			</view>
		</view>

		<tab-bar :selectActive="3"></tab-bar>
	</view>




</template>

<script>
	import cont from "@/components/navigation/navigation.vue"
	export default {
		data() {
			return {
				recordInfo: []
			}
		},


		computed: {
			i18n() {
				return this.$t('index')
			},
		},
		methods: {
			async getHomeSlideFunc() {
				const response = await this.$api.getCoinTickerList()
				// this.collectinInfo=response.data
				this.recordInfo = response.data.value
			},


		},
		onLoad() {
			this.getHomeSlideFunc();
			let that=this
			uni.onSocketOpen(function (res) {
			 
			});
			uni.connectSocket({
				url: that.$SystemConfiguration.constant.coinTickerWs
			});
			
			
			
			uni.sendSocketMessage({
				data: '{"type":"add_ticker"}'
			});
			uni.onSocketMessage(function(res) {
				let data=JSON.parse(res.data);
				console.log(data,11111)
				that.recordInfo = data.value
				
			});
		},onUnload: function() {
			
			uni.onSocketClose(function (res) {
			  console.log('WebSocket 已关闭！');
			});
		},onHide:function(){
			uni.onSocketClose(function (res) {
			  console.log('WebSocket 已关闭！');
			});
		}
	};
</script>
<style scoped>
	page {
		background-color: #FAFAFA;
	}
</style>

<style>
	@import './index.css';
</style>
