Browse Source

2022-11-23

cmy 3 years ago
parent
commit
80eb38c8fe
2 changed files with 307 additions and 69 deletions
  1. 16 0
      api/heyue.js
  2. 291 69
      pages/heyue/heyue.vue

+ 16 - 0
api/heyue.js

@@ -23,5 +23,21 @@ export function clearorder(data,id) {
 		data
 	});
 }
+//創建訂單
+export function UpOrderHandle(data,id) {
+	return request({
+		url: '/api/Levertade/UpOrderHandle',
+		method: 'get',
+		data
+	});
+}
+//保證金
+export function bond(data,id) {
+	return request({
+		url: '/api/Levertade/bond',
+		method: 'get',
+		data
+	});
+}
 
 

+ 291 - 69
pages/heyue/heyue.vue

@@ -2,12 +2,13 @@
 	<view class="content">
 		<view class="usdtTitle flex">
 			<view class="left flex">
-				<image class="img margin-r-10" src="../../static/icon/hy02.png" mode="widthFix"></image>
+				<image @click="alertShow=true" class="img margin-r-10" src="../../static/icon/hy02.png" mode="widthFix">
+				</image>
 				<view class="margin-r-10">
-					BTC/USDT
+					{{listOBj[actionList].name}}
 				</view>
-				<view class="font-color-green">
-					10086
+				<view :class="{'font-color-green':listOBj[actionList].bool,'font-color-red':!listOBj[actionList].bool}">
+					{{listOBj[actionList].dcf}}
 				</view>
 			</view>
 			<view class="right">
@@ -16,6 +17,42 @@
 		</view>
 		<view class="box  flex padding-t-20 padding-b-30">
 			<view class="item">
+				<view class="itemName flex">
+					<view class="itemMinName">
+						当前價格
+					</view>
+					<view class="itemMinName">
+						開盤價
+					</view>
+					<view class="itemMinName">
+						最高價
+					</view>
+					<view class="itemMinName">
+						最低價
+					</view>
+					<view class="itemMinName">
+						成交數量
+					</view>
+				</view>
+				<view class="itemList">
+					<view class="list flex font-color-green">
+						<view class="li top">
+							{{listOBj[actionList].last}}
+						</view>
+						<view class="li top">
+							{{listOBj[actionList].sodUtc0}}
+						</view>
+						<view class="li top">
+							{{listOBj[actionList].high24h}}
+						</view>
+						<view class="li top">
+							{{listOBj[actionList].low24h}}
+						</view>
+						<view class="li top">
+							{{listOBj[actionList].volCcy24h|actionMoney}}
+						</view>
+					</view>
+				</view>
 				<view class="itemTitle margin-b-20">
 					交易方向
 				</view>
@@ -35,8 +72,11 @@
 						市價委託
 					</view>
 				</view>
-				<view class="inputBox margin-b-20" v-if="jyType==1">
+				<view class="inputBox margin-b-20 flex" v-if="jyType==1">
 					<input v-model="xzMoney" class="input" placeholder="請輸入價格" type="number">
+					<view @click="xzMoney=listOBj[actionList].last" class="buttomZd font-color-yellow">
+						點擊獲取
+					</view>
 				</view>
 				<view class="itemTitle  margin-b-20">
 					交易個數
@@ -85,7 +125,7 @@
 						保證金
 					</view>
 					<view class="itemTitle">
-						0
+						{{bzjMoney}}
 					</view>
 				</view>
 				<view class="flex margin-b-20">
@@ -93,7 +133,7 @@
 						可用合約餘額
 					</view>
 					<view class="itemTitle">
-						0
+						{{userInfo.money}}
 					</view>
 				</view>
 				<view class="flex margin-b-20">
@@ -101,44 +141,14 @@
 						手續費
 					</view>
 					<view class="itemTitle">
-						0
+						{{sxfMoney}}
 					</view>
 				</view>
 				<view class="buttomSubmit" :class="{'bg-success':typeIndex==1,'bg-danger':typeIndex==2}">
 					{{typeIndex==1?'做多':'做空'}}
 				</view>
 			</view>
-			<view class="item padding-l-20">
-				<view class="itemName flex">
-					<view class="itemMinName">
-						價格
-					</view>
-					<view class="itemMinName">
-						數量
-					</view>
-				</view>
-				<view class="itemList">
-					<view class="list flex font-color-green">
-						<view class="li top">
-							166666
-						</view>
-						<view class="li top">
-							0000.00
-						</view>
-					</view>
-					<view class="llMax font-color-green">
-						10086
-					</view>
-					<view class="list flex font-color-red">
-						<view class="li bottom">
-							166666
-						</view>
-						<view class="li bottom">
-							0000.00
-						</view>
-					</view>
-				</view>
-			</view>
+			
 		</view>
 		<view class="box margin-t-30 padding-t-30 padding-b-30">
 			<view class="flex listTitleBox">
@@ -234,20 +244,66 @@
 				</view>
 			</view>
 		</view>
+		<view class="alertBox" v-show="alertShow">
+			<view class="list flex">
+				<view class="type">
+					产品
+				</view>
+				<view class="type">
+					實時價格
+				</view>
+				<view class="type">
+					营收
+				</view>
+			</view>
+			<view class="itemlist flex" @click="changeData(ls)"  v-for="ls in listOBj">
+				<view class="type name">
+					{{ls.name}}
+				</view>
+				<view class="type money"
+					:class="{'font-color-green':ls.bool,'font-color-red':!ls.bool}">
+					{{ls.last}}
+				</view>
+				<view class="type bfb"
+					:class="{'font-color-green':ls.bool,'font-color-red':!ls.bool}">
+					{{ls.dcf}}
+				</view>
+			</view>
+		</view>
 	</view>
 </template>
 
 <script>
+	import { mapState } from 'vuex';
 	import {
 		levertadeLaverorder,
 		closeorder,
-		clearorder
+		clearorder,
+		UpOrderHandle,
+		bond
 	} from '@/api/heyue.js';
+	import {
+		scoketNew,
+		scoketOpen
+	} from '@/utils/socket.js';
+	import {
+		geLevertade
+	} from '@/api/index.js';
 	export default {
 		data() {
 			return {
+				// 是否显示弹窗
+				alertShow: false,
 				//保存幣種類型
-				moneytypeList:[],
+				spList: [],
+				// 右侧允许的最长长度
+				listLength: 20,
+				// 当前选中的对象数据列表
+				actionList: 'BCH-USDT',
+				// 價格列表
+				listOBj: {
+					"BCH-USDT": {}
+				},
 				// 当前选中的杠杆倍数
 				ggIndex: 0,
 				ggList: [{
@@ -275,6 +331,10 @@
 				zsMoney: 0,
 				// 止盈价格
 				zyMoney: 0,
+				// 保證金
+				bzjMoney:0,
+				// 手續費
+				sxfMoney:0,
 				ddType: 1, //1委托订单2持仓订单3成交订单
 				loadData: [{
 						state: 1,
@@ -292,22 +352,144 @@
 						page: 1, //当前页数
 						limit: 10 //每次信息条数
 					}
-				]
+				],
+				setTimeoutObj:'',
+			}
+		},
+		watch: {
+			ggBs(newValue, oldValue) {
+				this.ggBs = newValue;
+				this.bond();
+			},
+			payNum(newValue, oldValue){
+				this.payNum = newValue;
+				this.bond();
+			}
+		},
+		filters: {
+			actionMoney: function(value) {
+				let num = 0;
+				if(+value>10000000){
+					num = (+(value/10000000).toFixed(2))+'千萬'
+				}else if(+value>10000){
+					num = (+(value/10000).toFixed(2))+'萬'
+				}
+				
+				return num;
 			}
 		},
 		onLoad() {
+			// 初始化保存BCH对象
 			this.levertadeLaverorder();
 		},
-		onShow() {
-
+		onShow: function() {
+			this.geLevertade()
+			this.initListData()
+		},
+		onHide() {
+			this.closeScoket()
+			clearInterval(this.setTimeoutObj)
+			
 		},
 		onReachBottom() {
 			this.levertadeLaverorder();
 		},
 		onReady() {
-
+			console.log(this.userInfo);
+		},
+		computed: {
+			...mapState('user', ['userInfo'])
 		},
 		methods: {
+			// 提交訂單
+			UpOrderHandle(){
+				UpOrderHandle()
+			},
+			// 修改当前选中的数据对象
+			changeData(item) {
+				console.log(item,'qh');
+				this.actionList = item.instId;
+				this.alertShow = false;
+			},
+			// 獲取保證金
+			bond(){
+				bond({
+					name:this.actionList.split('-')[0],
+					'num':this.payNum,
+					'gann':this.ggBs
+				}).then((e)=>{
+					this.sxfMoney = e.data.fee
+					this.bzjMoney = e.data.bong? e.data.bong:0
+					console.log(e)
+				}).catch(()=>{
+					console.log(e)
+				})
+			},
+			//循環獲取數據
+			initListData(){
+				this.setTimeoutObj = setInterval(()=>{
+					this.levertadeLaverorder();
+				},2000)
+			},
+			// 獲取幣種列表
+			geLevertade() {
+				const that = this;
+				geLevertade().then((e) => {
+					that.spList = e.list;
+					// 开启长连接
+					that.onScoket()
+
+				})
+			},
+			// 开始请求长连接
+			onScoket() {
+				const that = this;
+				uni.showLoading({
+					title: '數據加載中...',
+					mask: true
+				});
+				that.scoket = scoketNew("wss://wsaws.okx.com:8443/ws/v5/public");
+				that.scoket.scoketOpen().then((res) => {
+					const requestList = that.spList.map((e) => {
+						return {
+							"channel": "tickers",
+							"instId": e.coinname.toUpperCase() + "-USDT"
+						}
+					})
+					that.scoket.scoketSend({
+						"op": "subscribe",
+						"args": requestList
+					}).then((res) => {
+						console.log(res, '发送成功');
+					})
+					that.scoket.scoketMessage((res) => {
+						try {
+							if (res.data) {
+								// 判断是否已经有这个对象
+								// console.log(res.arg.instId, 'id', that.listOBj);
+								that.listOBj[res.arg.instId] = res.data[0];
+								const item = that.listOBj[res.arg.instId];
+								// 转为数字
+								item.last = +item.last;
+								item.sodUtc0 = +item.sodUtc0;
+								// 保存收益情况
+								item.bool = item.last - item.sodUtc0>0?true:false;
+								// 算出收益率
+								item.dcf = (+((item.last - item.sodUtc0) / item.sodUtc0 * 100).toFixed(
+									2)) + '%'
+								item.name = item.instId.replace('-', '/')
+								that.listOBj = Object.assign({}, that.listOBj);
+
+							}
+						} catch (e) {
+							console.log(res, res.data, '报错');
+						}
+					})
+				})
+			},
+			closeScoket() {
+				this.scoket.scoketClose();
+			},
 			// 平倉
 			closeorder(item) {
 				const that = this;
@@ -382,16 +564,16 @@
 					//防止重复加载
 					return;
 				}
-				if (navItem.loadingType === 'noMore') {
-					//防止重复加载
-					return;
-				}
+				// if (navItem.loadingType === 'noMore') {
+				// 	//防止重复加载
+				// 	return;
+				// }
 				// 修改当前对象状态为加载中
 				navItem.loadingType = 'loading';
-				uni.showLoading({
-					title: '數據加載中',
-					mask: true
-				});
+				// uni.showLoading({
+				// 	title: '數據加載中',
+				// 	mask: true
+				// });
 				levertadeLaverorder({
 						type: state,
 						page: navItem.page,
@@ -400,7 +582,7 @@
 					.then(({
 						list
 					}) => {
-						uni.hideLoading()
+						// uni.hideLoading()
 						let arr = list.map(e => {
 							e.direction = +e.direction;
 							e.bond = +e.bond
@@ -408,20 +590,21 @@
 							e.wt_price = +e.wt_price
 							return e;
 						});
-						navItem.list = navItem.list.concat(arr);
-						navItem.page++;
-						if (navItem.limit == list.length) {
-							//判断是否还有数据, 有改为 more, 没有改为noMore
-							navItem.loadingType = 'more';
-							return;
-						} else {
-							//判断是否还有数据, 有改为 more, 没有改为noMore
-							navItem.loadingType = 'noMore';
-						}
+						navItem.list = arr;
+						// navItem.list = navItem.list.concat(arr);
+						// navItem.page++;
+						// if (navItem.limit == list.length) {
+						// 	//判断是否还有数据, 有改为 more, 没有改为noMore
+						// 	navItem.loadingType = 'more';
+						// 	return;
+						// } else {
+						// 	//判断是否还有数据, 有改为 more, 没有改为noMore
+						// 	navItem.loadingType = 'noMore';
+						// }
 						this.$set(navItem, 'loaded', true);
 					})
 					.catch(e => {
-						uni.hideLoading()
+						// uni.hideLoading()
 						console.log(e);
 					});
 
@@ -501,7 +684,7 @@
 			font-size: $font-sm;
 
 			.buttom {
-				width: 200rpx;
+				width: 350rpx;
 				padding: 20rpx 0;
 				text-align: center;
 				border-radius: 10rpx;
@@ -537,7 +720,9 @@
 			display: flex;
 			align-items: center;
 			border: 1px solid $border-color-light;
-
+			.buttomZd{
+				font-size: $font-sm;
+			}
 			.input {
 				font-size: $font-sm;
 				flex-grow: 1;
@@ -585,9 +770,8 @@
 		}
 
 		.itemName {
-			padding-bottom: 20rpx;
-
 			.itemMinName {
+				width: 20%;
 				font-size: 22rpx;
 				color: #5D6677;
 			}
@@ -598,6 +782,9 @@
 			.list {
 				font-size: 20rpx;
 				padding: 10rpx 0;
+				.li{
+					width: 20%;
+				}
 			}
 
 			.llMax {
@@ -669,4 +856,39 @@
 			}
 		}
 	}
+
+	.alertBox {
+		position: fixed;
+		top: 0;
+		left: 0;
+		right: 0;
+		bottom: 0;
+		background-color: #FFFFFF;
+		text-align: center;
+		color: #707A8A;
+
+		.type {
+			width: 30%;
+			flex-grow: 1;
+		}
+
+		.itemlist {
+			padding-top: 20rpx;
+
+			.name {
+				padding-left: 20rpx;
+				text-align: left;
+			}
+		}
+
+		.list {
+			padding: 30rpx 0;
+			border-bottom: 1px solid $border-color-light;
+
+			.type {
+				font-size: $font-lg;
+				font-weight: bold;
+			}
+		}
+	}
 </style>