tradlist.vue 12 KB

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