tradlist.vue 12 KB

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