tradlist.vue 12 KB

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