tradlist.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <view class="content">
  3. <view class="flex navbar">
  4. <view class="" v-for="(item,index) in navList" :class="{'action':current == index}"
  5. @click="changetab(index)">
  6. {{item.name}}
  7. </view>
  8. </view>
  9. <swiper class="swiper" :style="{'height': height}" :current="current" disable-touch>
  10. <swiper-item v-for="navitem in navList">
  11. <scroll-view scroll-y="true" class="scroll" :style="{'height': height}">
  12. <view v-for="(item,ind) in navitem.list" class="usdtList padding-t-30 padding-b-30">
  13. <view class="flex">
  14. <view class="name">
  15. <text v-if="item.direction==1" class="font-color-green">
  16. 做多
  17. </text>
  18. <text v-if="item.direction==2" class="font-color-red">
  19. 做空
  20. </text>
  21. <text>
  22. {{item.symbol}}
  23. </text>
  24. <text v-if="current==1 && item.direction==2"
  25. :class="{'font-color-green':+((item.price - listOBj[item.symbol.replace('/','-')].last)/item.num)>=0,'font-color-red':+((item.price - listOBj[item.symbol.replace('/','-')].last)/item.num)<0}">
  26. <!-- {{+item.profit}} -->{{ ((item.price - listOBj[item.symbol.replace('/','-')].last)/item.num).toFixed(2)|| ''}}
  27. </text>
  28. <text v-if="current==1 && item.direction==1"
  29. :class="{'font-color-green':+(( listOBj[item.symbol.replace('/','-')].last- item.price )/item.num)>=0,'font-color-red':+(( listOBj[item.symbol.replace('/','-')].last- item.price )/item.num)<0}">
  30. <!-- {{+item.profit}} -->{{ (( listOBj[item.symbol.replace('/','-')].last- item.price )/item.num).toFixed(2) || ''}}
  31. </text>
  32. </view>
  33. <view @click="clearorder(item)" v-if="current==0" class="usdtListButtom">
  34. 撤銷
  35. </view>
  36. <view @click="closeorder(item)" v-if="current==1" class="usdtListButtom">
  37. 平倉
  38. </view>
  39. </view>
  40. <view class="tip ">
  41. <text v-if="item.direction==1">
  42. 委託時間:{{item.wttime}}
  43. </text>
  44. <text v-if="item.direction==2">
  45. 開倉時間:{{item.addtime}}
  46. </text>
  47. </view>
  48. <view class="flex" style="flex-wrap: wrap;justify-content: flex-start;">
  49. <view v-if="current == 0" class="tipList">
  50. <view class="nameTip">
  51. 委托價格
  52. </view>
  53. <view class="text">
  54. {{item.wt_price}}
  55. </view>
  56. </view>
  57. <view v-if="current != 0" class="tipList">
  58. <view class="nameTip">
  59. 開倉單價
  60. </view>
  61. <view class="text">
  62. {{item.price}}
  63. </view>
  64. </view>
  65. <view v-if="current != 0" class="tipList">
  66. <view class="nameTip">
  67. 當前價格
  68. </view>
  69. <view class="text">
  70. {{listOBj[item.symbol.replace('/','-')].last}}
  71. </view>
  72. </view>
  73. <view class="tipList">
  74. <view class="nameTip">
  75. 槓桿倍數
  76. </view>
  77. <view class="text">
  78. {{item.ggan}}
  79. </view>
  80. </view>
  81. <view class="tipList" v-if="current != 0">
  82. <view class="nameTip">
  83. 手續費
  84. </view>
  85. <view class="text">
  86. {{item.fee}}
  87. </view>
  88. </view>
  89. <view class="tipList" v-if="current == 2">
  90. <view class="nameTip">
  91. 平倉單價
  92. </view>
  93. <view class="text">
  94. {{item.pc_price}}
  95. </view>
  96. </view>
  97. <view class="tipList">
  98. <view class="nameTip">
  99. {{current == 0?'委托手數': '交易個數'}}
  100. </view>
  101. <view class="text">
  102. {{item.num}}
  103. </view>
  104. </view>
  105. <template v-if="current == 1">
  106. <view class="tipList">
  107. <view class="nameTip">
  108. 止盈單價
  109. </view>
  110. <view class="text">
  111. {{item.zyprice}}
  112. </view>
  113. </view>
  114. <view class="tipList">
  115. <view class="nameTip">
  116. 止損單價
  117. </view>
  118. <view class="text">
  119. {{item.zsprice}}
  120. </view>
  121. </view>
  122. </template>
  123. <template v-if="current == 2">
  124. <view class="tipList">
  125. <view class="nameTip">
  126. 盈虧狀態
  127. </view>
  128. <view class="text" :style="{'color': item.yk_status == 1?'#5DC887':'#dd524d'}">
  129. {{item.yk_status == 1?'盈利':'虧損'}}
  130. </view>
  131. </view>
  132. <view class="tipList">
  133. <view class="nameTip">
  134. 盈虧金額
  135. </view>
  136. <view class="text" :style="{'color': item.yk_status == 1?'#5DC887':'#dd524d'}">
  137. {{item.yk_status == 1?'+':'-'}}{{item.ylmoney}}
  138. </view>
  139. </view>
  140. </template>
  141. </view>
  142. </view>
  143. </scroll-view>
  144. </swiper-item>
  145. </swiper>
  146. </view>
  147. </template>
  148. <script>
  149. import {
  150. geLevertade
  151. } from '@/api/index.js';
  152. import {
  153. scoketNew,
  154. scoketOpen
  155. } from '@/utils/socket.js';
  156. import {
  157. levertadeLaverorder,
  158. closeorder,
  159. clearorder,
  160. UpOrderHandle,
  161. bond
  162. } from '@/api/heyue.js';
  163. export default {
  164. data() {
  165. return {
  166. listOBj: {}, //保存实际列表对象
  167. timer: '',
  168. height: '',
  169. current: 0,
  170. navList: [{
  171. status: 1,
  172. name: '全部委托',
  173. page: 1,
  174. limit: 10,
  175. loadingType: 'more',
  176. loded: false,
  177. list: []
  178. },
  179. {
  180. status: 2,
  181. name: '全部持倉',
  182. page: 1,
  183. limit: 10,
  184. loadingType: 'more',
  185. loded: false,
  186. list: []
  187. },
  188. {
  189. status: 3,
  190. name: '成交明細',
  191. page: 1,
  192. limit: 10,
  193. loadingType: 'more',
  194. loded: false,
  195. list: []
  196. }
  197. ]
  198. }
  199. },
  200. onLoad() {
  201. if (this.timer) {
  202. clearTimeout(this.timer);
  203. this.timer = null;
  204. }
  205. },
  206. onShow() {
  207. this.geLevertade()
  208. this.loadData()
  209. },
  210. onHide() {
  211. this.closeScoket()
  212. clearTimeout(this.timer);
  213. },
  214. // 监听页面卸载
  215. onUnload() {
  216. // 关闭倒计时
  217. clearTimeout(this.timer);
  218. },
  219. // 监听页面后退
  220. onBackPress() {
  221. // 关闭倒计时
  222. clearTimeout(this.timer);
  223. },
  224. onReachBottom() {
  225. },
  226. onReady(res) {
  227. var obj = this;
  228. uni.getSystemInfo({
  229. success: resu => {
  230. const query = uni.createSelectorQuery();
  231. query.select('.swiper').boundingClientRect();
  232. query.exec(function(res) {
  233. obj.height = resu.windowHeight - res[0].top + 'px';
  234. });
  235. },
  236. fail: res => {}
  237. });
  238. },
  239. methods: {
  240. changetab(index) {
  241. this.current = index
  242. this.loadData('tab')
  243. },
  244. loadData(tab) {
  245. let obj = this
  246. let index = obj.current
  247. let item = obj.navList[index]
  248. if (tab == 'tab' && item.loaded) {
  249. return
  250. }
  251. if (item.loadingType == 'loading') {
  252. return
  253. }
  254. levertadeLaverorder({
  255. type: item.status,
  256. page: item.page,
  257. limit: item.limit
  258. })
  259. .then(({
  260. list
  261. }) => {
  262. console.log(list, 'list+++++++')
  263. let arr = list.map(e => {
  264. e.direction = +e.direction;
  265. e.bond = +e.bond
  266. e.price = +e.price
  267. e.wt_price = +e.wt_price
  268. return e;
  269. });
  270. item.list = arr;
  271. this.$set(item, 'loaded', true);
  272. if (obj.timer) {
  273. clearTimeout(obj.timer);
  274. obj.timer = null;
  275. }
  276. obj.timer = setTimeout(() => {
  277. obj.loadData()
  278. }, 2000)
  279. })
  280. .catch(e => {
  281. console.log(e);
  282. });
  283. },
  284. // 平倉
  285. closeorder(item) {
  286. const that = this;
  287. uni.showModal({
  288. title: '平倉',
  289. content: '是否立即平倉,確認後不可修改',
  290. confirmText: '確認',
  291. cancelText: '取消',
  292. success: res => {
  293. if (res.confirm) {
  294. uni.showLoading({
  295. title: '請求中...',
  296. mask: true
  297. });
  298. closeorder({
  299. id: item.id
  300. }).then((e) => {
  301. uni.hideLoading()
  302. uni.showToast({
  303. title: '平倉成功',
  304. icon: 'success'
  305. });
  306. that.ddTypeInit()
  307. }).catch(() => {
  308. uni.hideLoading()
  309. })
  310. }
  311. },
  312. fail: () => {},
  313. complete: () => {}
  314. });
  315. },
  316. // 撤銷
  317. clearorder(item) {
  318. const that = this;
  319. uni.showModal({
  320. title: '撤銷',
  321. content: '是否立即撤銷,確認後不可修改',
  322. confirmText: '確認',
  323. success: res => {
  324. if (res.confirm) {
  325. uni.showLoading({
  326. title: '請求中...',
  327. mask: true
  328. });
  329. clearorder({
  330. id: item.id
  331. }).then((e) => {
  332. uni.hideLoading()
  333. uni.showToast({
  334. title: '撤銷成功',
  335. icon: 'success'
  336. });
  337. that.ddTypeInit()
  338. }).catch(() => {
  339. uni.hideLoading()
  340. })
  341. }
  342. },
  343. fail: () => {},
  344. complete: () => {}
  345. });
  346. },
  347. // 獲取幣種列表
  348. geLevertade() {
  349. uni.showLoading({
  350. title: '數據加載中...',
  351. mask: true
  352. });
  353. const that = this;
  354. geLevertade().then((e) => {
  355. that.spList = e.list;
  356. // 开启长连接
  357. that.onScoket()
  358. })
  359. },
  360. // 开始请求长连接
  361. onScoket() {
  362. const that = this;
  363. that.scoket = scoketNew("wss://wsaws.okx.com:8443/ws/v5/public");
  364. that.scoket.scoketOpen().then((res) => {
  365. uni.hideLoading()
  366. const requestList = that.spList.map((e) => {
  367. return {
  368. "channel": "tickers",
  369. "instId": e.coinname.toUpperCase() + "-USDT"
  370. }
  371. })
  372. that.scoket.scoketSend({
  373. "op": "subscribe",
  374. "args": requestList
  375. }).then((res) => {
  376. console.log(res, '发送成功');
  377. })
  378. that.scoket.scoketMessage((res) => {
  379. try {
  380. if (res.data) {
  381. // 判断是否已经有这个对象
  382. // console.log(res.arg.instId, 'id', that.listOBj);
  383. that.listOBj[res.arg.instId] = res.data[0];
  384. const item = that.listOBj[res.arg.instId];
  385. // 转为数字
  386. item.last = +item.last;
  387. item.sodUtc0 = +item.sodUtc0;
  388. // 保存收益情况
  389. item.bool = item.last - item.sodUtc0 > 0 ? true : false;
  390. // 算出收益率
  391. item.dcf = (+((item.last - item.sodUtc0) / item.sodUtc0 * 100).toFixed(
  392. 2)) + '%'
  393. item.name = item.instId.replace('-', '/')
  394. that.listOBj = Object.assign({}, that.listOBj);
  395. console.log(that.listOBj,'that.listOBj')
  396. }
  397. } catch (e) {
  398. console.log(res, res.data, '报错');
  399. }
  400. })
  401. })
  402. },
  403. closeScoket() {
  404. this.scoket.scoketClose();
  405. },
  406. }
  407. }
  408. </script>
  409. <style lang="scss">
  410. .swiper {
  411. background-color: #fff;
  412. }
  413. .scroll {
  414. padding: 0 20rpx;
  415. }
  416. .navbar {
  417. justify-content: flex-start;
  418. font-size: 40rpx;
  419. padding: 30rpx;
  420. view {
  421. width: 184rpx;
  422. height: 100rpx;
  423. line-height: 100rpx;
  424. }
  425. }
  426. .usdtList {
  427. color: #707A8A;
  428. border-bottom: 1px solid $border-color-light;
  429. .name {
  430. font-size: $font-lg;
  431. font-weight: bold;
  432. }
  433. .usdtListButtom {
  434. font-size: $font-base;
  435. background-color: #F5F5F5;
  436. color: $uni-color-warning;
  437. border-radius: 10rpx;
  438. padding: 10rpx 20rpx;
  439. }
  440. .tip {
  441. padding-top: 10rpx;
  442. padding-bottom: 30rpx;
  443. font-size: $font-base;
  444. }
  445. .tipList {
  446. font-size: $font-sm;
  447. text-align: center;
  448. width: 25%;
  449. max-width: 33%;
  450. padding-top: 20rpx;
  451. flex-grow: 1;
  452. .nameTip {
  453. padding-bottom: 20rpx;
  454. }
  455. }
  456. }
  457. .action {
  458. font-weight: bold;
  459. font-size: 44rpx;
  460. }
  461. </style>