bblist.vue 10 KB

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