index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. <template>
  2. <view>
  3. <view class="contract-title" :rise-fall="stocksColor">
  4. <view class="contract-item" @click.stop="openDrawer">
  5. <view class="title-iocn">
  6. <text class="title-iocn-item"></text>
  7. <text class="title-iocn-item"></text>
  8. <text class="title-iocn-item"></text>
  9. </view>
  10. <!-- <image class="title-iocn" src="../../../static/logo.png" mode="aspectFit"></image> -->
  11. <text class="title-text">{{currencyVal.currency_name}}/{{currencyVal.legal_name}}</text>
  12. </view>
  13. <view class="contract-price" :class="$setColor(daymarket.now_price)">
  14. <text class="color">{{ daymarket.now_price }}</text>
  15. <text class="color" v-show="daymarket.change">{{ daymarket.change }}%</text>
  16. </view>
  17. <view class="contract-item">
  18. <text class="iconfont">&#xe625;</text>
  19. </view>
  20. </view>
  21. <view class="iframe-box">
  22. <template v-if="currencyVal.legal_id">
  23. <iframe
  24. :src="`https://doc.okenx.com/biking/kline.html?legal_id=${currencyVal.legal_id}&currency_id=${currencyVal.currency_id}&symbol=${currencyVal.currency_name}/${currencyVal.legal_name}`"
  25. frameborder="0"></iframe>
  26. </template>
  27. </view>
  28. <gap />
  29. <view class="swiper-title">
  30. <template v-for="(item , index) in lableList">
  31. <text @click.stop="lableIndex = index"
  32. :class="['swiper-item', lableIndex === index ? 'active-swiper-item' : '' ]">{{ item }}</text>
  33. </template>
  34. </view>
  35. <!-- {{ pagesInfo }} -->
  36. <view class="shortcut">
  37. <swiper class="swiper-content" :current="lableIndex"
  38. :style="{'height': scrollHeight ? `${scrollHeight}px` : '' }">
  39. <swiper-item class="swiper-item-box">
  40. <u-list>
  41. <view class="shortcut-open">
  42. <view class="shortcut-type">
  43. <view class="type-box">
  44. <text class="type-item active-type-item">市价委托</text>
  45. <text class="type-item">计划委托</text>
  46. </view>
  47. <view class="type-times" @click.stop="adjustLever()">
  48. {{leverName}}{{ multiple }}x
  49. <text class="iconfont">&#xeb6d;</text>
  50. </view>
  51. </view>
  52. <view class="shortcut-price">
  53. <view class="price-box">
  54. <text class="price-lable">价格</text>
  55. <view class="price-info">
  56. <text class="price-num">{{ daymarket.now_price }}</text>
  57. <text class="price-tag">USDT</text>
  58. </view>
  59. </view>
  60. <view class="price-box">
  61. <text class="price-lable">保证金</text>
  62. <input class="price-inp" type="number" v-model="caution_money">
  63. <view class="price-info">
  64. USDT
  65. </view>
  66. </view>
  67. </view>
  68. <view class="shortcut-usable">
  69. <view class="usable-info">
  70. 可用:{{ pagesInfo.user_lever }} USDT
  71. </view>
  72. <view class="usable-btn">
  73. 充值
  74. </view>
  75. </view>
  76. <view class="shortcut-btns">
  77. <view class="shortcut-btn" @click.stop="setSubmitLever(2)">
  78. 买入/做多
  79. </view>
  80. <view class="shortcut-btn" @click.stop="setSubmitLever(1)">
  81. 卖出/做空
  82. </view>
  83. </view>
  84. </view>
  85. </u-list>
  86. </swiper-item>
  87. <swiper-item>
  88. <u-list class="swiper-list" :style="{'height': scrollHeight ? `${scrollHeight}px` : '' }">
  89. <template v-if="leverTransaction && leverTransaction.length > 0">
  90. <view class="lable-title">
  91. <text class="lable-title-text">仓位信息</text>
  92. <text class="lable-title-btn" @click.stop="setCloseLeverAll()">全部平仓</text>
  93. </view>
  94. <template v-for="item in leverTransaction">
  95. <view class="content-box" :rise-fall="stocksColor">
  96. <view class="content-top">
  97. <view class="top-left">
  98. <view class="top-left-title">
  99. <text>{{ item.symbol }}</text>
  100. <text v-if="item.settled == 0">永续</text>
  101. <text v-else-if="item.settled == 9">快捷合约</text>
  102. </view>
  103. <view class="top-left-b">
  104. <text>{{ item.multiple }}倍杠杆</text>
  105. <text class="top-left-b-tag">{{ item.type_name }}</text>
  106. </view>
  107. </view>
  108. <view class="top-right">
  109. <text>{{ item.profits }}</text>
  110. <text
  111. class="top-right-float"><text>浮动盈亏</text>{{ item.fact_profits }}%</text>
  112. </view>
  113. </view>
  114. <view class="content-info">
  115. <view class="info-item">
  116. <text class="info-item-lable">保证金(USDT)</text>
  117. <text class="info-item-val">{{ item.caution_money }}</text>
  118. </view>
  119. <view class="info-item">
  120. <text class="info-item-lable">开仓价格(USDT)</text>
  121. <text class="info-item-val">{{ item.price }}</text>
  122. </view>
  123. <view class="info-item">
  124. <text class="info-item-lable">预估平仓价格(USDT)</text>
  125. <text class="info-item-val">{{item.update_price}}</text>
  126. </view>
  127. <view class="info-item">
  128. <text class="info-item-lable">过夜费</text>
  129. <text class="info-item-val">{{item.overnight_money}}</text>
  130. </view>
  131. <view class="info-item">
  132. <text class="info-item-lable">风险率(%)</text>
  133. <text class="info-item-val">0%</text>
  134. <!-- {{ item.caution_money }} -->
  135. </view>
  136. <!-- <view class="info-item">
  137. <text class="info-item-lable">预计止损(USDT)</text>
  138. <text class="info-item-val"
  139. @click.stop="setRestrict(item)">{{ item.stop_loss_price || '--' }} <text
  140. class="iconfont">&#xe610;</text></text>
  141. </view>
  142. <view class="info-item">
  143. <text class="info-item-lable">预计止盈(USDT)</text>
  144. <text class="info-item-val"
  145. @click.stop="setRestrict(item)">{{ item.target_profit_price || '--' }} <text
  146. class="iconfont">&#xe610;</text> </text>
  147. </view> -->
  148. <view class="info-item">
  149. <text class="info-item-lable">创建时间</text>
  150. <text class="info-item-val">{{ $getData_(item.create_time , false) }}</text>
  151. </view>
  152. </view>
  153. <view class="content-btns">
  154. <view class="content-btn-item" @click.stop="setCloseLever(item)">
  155. 平仓
  156. </view>
  157. <view class="content-btn-item" @click.stop="setInversion(item)">
  158. 反向开仓
  159. </view>
  160. <!-- <view class="content-btn-item">
  161. 加仓
  162. </view> -->
  163. </view>
  164. <view class="set-stop">
  165. <view class="stop-left" @click.stop="setRestrict(item)">
  166. <text>止盈/止损</text>
  167. <text
  168. class="stop-num">{{ item.target_profit_price || '--' }}/{{ item.stop_loss_price || '--'}}</text>
  169. <text class="iconfont">&#xe610;</text>
  170. </view>
  171. <view class="stop-right">
  172. <text class="icon-size iconfont">&#xe8b0;</text>
  173. <text class="icon-size">分享</text>
  174. </view>
  175. </view>
  176. </view>
  177. <gap />
  178. </template>
  179. </template>
  180. </u-list>
  181. </swiper-item>
  182. </swiper>
  183. </view>
  184. <drawer ref="drawerRef" />
  185. <restrictPopup ref="restrictRef" @setSuccess="setSuccess" />
  186. <lever ref="leverRef" :leverNum.sync="multiple" :leverName.sync="leverName" />
  187. <unopen ref="placeOrderRef" @confirm="confirmPlaceOrder" title="下单确认" cancelBtn content="确定要下单吗?" />
  188. <unopen ref="unopenRef" @confirm="confirm" textAlign="left" :title="unopenSolt.title" cancelBtn
  189. :content="unopenSolt.closeLeverContent" />
  190. </view>
  191. </template>
  192. <script>
  193. import {
  194. mapGetters
  195. } from 'vuex'
  196. import {
  197. Api_setSubmitLever,
  198. Api_getLeverDeal,
  199. Api_getRegister,
  200. Api_setBatchClose,
  201. Api_setCloseLever
  202. } from "@/api/index.js"
  203. import lever from "../sustainability/lever.vue"
  204. import drawer from "./../modules/drawer.vue"
  205. import {
  206. startWebSocket
  207. } from "@/utils/websock.js"
  208. import restrictPopup from "./../modules/restrict.vue"
  209. export default {
  210. name: 'shortcut',
  211. components: {
  212. lever,
  213. drawer,
  214. restrictPopup
  215. },
  216. data() {
  217. return {
  218. closeLeverItem: null,
  219. lableList: [
  220. '开仓',
  221. '当前持仓'
  222. ],
  223. lableIndex: 1,
  224. leverName: '逐仓',
  225. multiple: 100, // 逐仓倍数
  226. caution_money: '',
  227. status: 1, // 状态,填1. 1市价交易,为0则是挂单交易
  228. scrollHeight: 0,
  229. unopenSolt: {
  230. title: '',
  231. content: ''
  232. }
  233. };
  234. },
  235. props: {
  236. leverTransaction: {
  237. type: Array,
  238. default: () => {
  239. return []
  240. }
  241. },
  242. pagesInfo: {
  243. type: Object,
  244. default: () => {
  245. return {}
  246. }
  247. }
  248. },
  249. computed: {
  250. ...mapGetters([
  251. 'currencyVal',
  252. 'daymarket',
  253. 'stocksColor',
  254. 'PageContentHeight',
  255. 'tabBarHeight'
  256. ]),
  257. },
  258. mounted() {
  259. // startWebSocket()
  260. },
  261. watch: {
  262. currencyVal: {
  263. handler(newCurrency) {
  264. if (newCurrency && newCurrency?.legal_id) {
  265. }
  266. },
  267. deep: true,
  268. immediate: true
  269. },
  270. PageContentHeight: {
  271. handler(newHeigth) {
  272. if (newHeigth) {
  273. console.log('newHeigth = ', newHeigth)
  274. this.scrollHeight = newHeigth - uni.upx2px(100) - this.tabBarHeight;
  275. }
  276. },
  277. deep: true,
  278. immediate: true
  279. },
  280. },
  281. methods: {
  282. init() {
  283. this.getLeverDeal()
  284. this.getRegister()
  285. },
  286. getRegister() {
  287. Api_getRegister({
  288. status: 1,
  289. legal_id: this.currencyVal.legal_id,
  290. currency_id: this.currencyVal.currency_id,
  291. settled: 9,
  292. limit: 1000
  293. }).then(res => {
  294. console.log('Api_getRegister = ', res)
  295. })
  296. },
  297. openDrawer() {
  298. this.$nextTick(() => {
  299. this.$refs.drawerRef.open();
  300. })
  301. },
  302. setSubmitLever() {
  303. this.$nextTick(() => {
  304. this.$refs.placeOrderRef.open()
  305. })
  306. },
  307. // 确认下单
  308. confirmPlaceOrder(type) {
  309. const obj = {
  310. legal_id: this.currencyVal.legal_id,
  311. currency_id: this.currencyVal.currency_id,
  312. multiple: this.multiple,
  313. caution_money: this.caution_money,
  314. status: this.status
  315. }
  316. Api_setSubmitLever(obj).then(res => {
  317. this.setSuccess()
  318. })
  319. },
  320. // 设置止盈止损
  321. setRestrict(item) {
  322. this.$nextTick(() => {
  323. this.$refs.restrictRef.open(item)
  324. })
  325. },
  326. setSuccess() {
  327. this.$emit('refreshData')
  328. },
  329. setCloseLever(item) {
  330. this.closeLeverItem = item;
  331. this.unopenSolt = {
  332. title: '平仓',
  333. closeLeverContent: '如果存在平仓挂单(限价止盈止损),将会在全平前被撤单,确定平仓吗?'
  334. }
  335. this.setDepot();
  336. },
  337. setInversion() {
  338. this.closeLeverItem = -1;
  339. this.unopenSolt = {
  340. title: '反向开仓',
  341. closeLeverContent: '如果存在平仓挂单(限价止盈止损),将会在全平前被撤单,确定反向开仓吗?',
  342. }
  343. this.setDepot();
  344. },
  345. setCloseLeverAll() {
  346. this.closeLeverItem = null;
  347. this.unopenSolt = {
  348. title: '全部平仓',
  349. closeLeverContent: '如果存在平仓挂单(限价止盈止损),将会在全平前被撤单,确定全部平仓吗?',
  350. }
  351. this.setDepot();
  352. // this.title = '全部平仓';
  353. // this.closeLeverContent = '';
  354. // this.closeLeverItem = null;
  355. // this.$refs.unopenRef.open();
  356. },
  357. // 平仓 - 反向开仓
  358. setDepot(obj) {
  359. this.$nextTick(() => {
  360. this.$refs.unopenRef.open()
  361. })
  362. },
  363. confirm() {
  364. if (this.leverTransaction.length > 0) {
  365. if (this.closeLeverItem && this.closeLeverItem !== -1) {
  366. // 平仓
  367. Api_setCloseLever({
  368. id: this.closeLeverItem.id
  369. }).then(res => {
  370. this.setSuccess()
  371. })
  372. } else if (this.closeLeverItem == -1) {
  373. // 反向开仓
  374. } else {
  375. // 全部平仓
  376. Api_setBatchClose({
  377. type: 0,
  378. currency_id: this.currencyVal.currency_id
  379. }).then(res => {
  380. this.setSuccess()
  381. })
  382. }
  383. }
  384. },
  385. adjustLever() {
  386. this.$nextTick(() => {
  387. this.$refs.leverRef.open()
  388. })
  389. },
  390. }
  391. }
  392. </script>
  393. <style lang="scss" scoped>
  394. @import "~../sustainability/index.scss";
  395. .contract-title {
  396. padding: 5rpx $pages-padding 0;
  397. min-height: 90rpx;
  398. display: flex;
  399. align-items: center;
  400. justify-content: space-between;
  401. border-bottom: 1rpx solid $border-color;
  402. .contract-price {
  403. flex: 1;
  404. display: flex;
  405. justify-content: space-between;
  406. align-items: center;
  407. padding: 0 30rpx 0 20rpx;
  408. font-size: 28rpx;
  409. }
  410. .contract-item {
  411. flex-shrink: 0;
  412. display: flex;
  413. align-items: center;
  414. .title-iocn {
  415. width: 28rpx;
  416. height: 24rpx;
  417. display: flex;
  418. flex-direction: column;
  419. // align-items: center;
  420. justify-content: space-between;
  421. .title-iocn-item {
  422. width: 100%;
  423. height: 5rpx;
  424. border-radius: 3rpx;
  425. background: #111111;
  426. &:first-child {
  427. width: 50%;
  428. }
  429. }
  430. }
  431. .title-text {
  432. font-size: 34rpx;
  433. font-family: PingFang SC, PingFang SC-Bold;
  434. font-weight: 700;
  435. text-align: left;
  436. color: #141213;
  437. line-height: 1.2;
  438. letter-spacing: 0.74rpx;
  439. padding-left: 19rpx;
  440. }
  441. .title-ratio {
  442. font-size: 24rpx;
  443. font-family: PingFang SC, PingFang SC-Regular;
  444. font-weight: 400;
  445. color: #808080;
  446. line-height: 33rpx;
  447. }
  448. .ratio-icon {
  449. width: 31rpx;
  450. height: 33rpx;
  451. margin-left: 22rpx;
  452. }
  453. }
  454. }
  455. // <view class="lable-title">
  456. // <template v-for="(item , index) in lableList">
  457. // <text class="lable-item">{{ item }}</text>
  458. // </template>
  459. // </view>
  460. .swiper-title {
  461. padding: 0 $pages-padding;
  462. width: 100%;
  463. height: 100rpx;
  464. border-bottom: 1rpx solid $border-color;
  465. display: flex;
  466. align-items: stretch;
  467. .swiper-item {
  468. font-size: 28rpx;
  469. display: flex;
  470. align-items: center;
  471. &:nth-child(n + 2) {
  472. margin-left: 60rpx;
  473. }
  474. }
  475. .active-swiper-item {
  476. font-size: 34rpx;
  477. color: $Theme-Color;
  478. position: relative;
  479. &::before {
  480. content: '';
  481. position: absolute;
  482. left: 50%;
  483. bottom: 0;
  484. width: 30rpx;
  485. height: 5rpx;
  486. background-color: $Theme-Color;
  487. border-radius: 3rpx;
  488. transform: translateX(-50%);
  489. }
  490. }
  491. }
  492. .shortcut {
  493. .shortcut-open {
  494. padding: 30rpx $pages-padding;
  495. }
  496. .shortcut-type {
  497. width: 100%;
  498. display: flex;
  499. align-items: stretch;
  500. justify-content: space-between;
  501. .type-box {
  502. flex: 1;
  503. display: flex;
  504. align-items: stretch;
  505. border-radius: 6rpx;
  506. overflow: hidden;
  507. .type-item {
  508. font-size: 24rpx;
  509. flex-shrink: 0;
  510. flex: 1;
  511. text-align: center;
  512. display: flex;
  513. align-items: center;
  514. justify-content: center;
  515. border: 1rpx solid $border-color6;
  516. color: $SizeColor;
  517. }
  518. .active-type-item {
  519. color: #fff;
  520. background-color: $Theme-Color;
  521. border: 1rpx solid $Theme-Color;
  522. }
  523. }
  524. .type-times {
  525. margin-left: 20rpx;
  526. width: 230rpx;
  527. height: 50rpx;
  528. line-height: 50rpx;
  529. border: 1rpx solid red;
  530. text-align: center;
  531. font-size: 26rpx;
  532. position: relative;
  533. color: $SizeColor;
  534. border: 1rpx solid $border-color6;
  535. border-radius: 6rpx;
  536. .iconfont {
  537. position: absolute;
  538. right: 10rpx;
  539. top: 50%;
  540. transform: translateY(-50%);
  541. font-size: 20rpx;
  542. color: $Theme-Color;
  543. }
  544. }
  545. }
  546. }
  547. .shortcut-price {
  548. width: 100%;
  549. padding-top: 60rpx;
  550. .price-box {
  551. width: 100%;
  552. height: 80rpx;
  553. border-radius: 10rpx;
  554. display: flex;
  555. justify-content: space-between;
  556. align-items: center;
  557. padding: 0 20rpx;
  558. background-color: $box-bg;
  559. font-size: 24rpx;
  560. color: $SizeColor2;
  561. .price-lable,
  562. .price-info {
  563. flex-shrink: 0;
  564. }
  565. .price-info {
  566. .price-num {
  567. color: #000;
  568. padding-right: 20rpx;
  569. }
  570. }
  571. .price-inp {
  572. flex: 1;
  573. height: 100%;
  574. padding: 0 10rpx;
  575. font-size: 24rpx;
  576. color: #000;
  577. text-align: right;
  578. }
  579. // <view class="price-box">
  580. // <text class="price-lable">价格</text>
  581. // <input class="price-inp" type="number">
  582. // <view class="price-info">
  583. // USDT
  584. // </view>
  585. // </view>
  586. }
  587. .price-box+.price-box {
  588. background-color: #fff;
  589. margin-top: 20rpx;
  590. border: 1rpx solid $box-bg;
  591. }
  592. }
  593. // <view class="shortcut-usable">
  594. // <view class="usable-info">
  595. // 可用:2927.81 USDT
  596. // </view>
  597. // <view class="usable-btn">
  598. // 充值
  599. // </view>
  600. // </view>
  601. .shortcut-usable {
  602. width: 100%;
  603. display: flex;
  604. justify-content: space-between;
  605. align-items: center;
  606. font-size: 24rpx;
  607. color: $SizeColor2;
  608. padding: 20rpx 0 40rpx;
  609. .usable-btn {
  610. color: $Theme-Color;
  611. }
  612. }
  613. // <view class="shortcut-btns">
  614. // <view class="shortcut-btn">
  615. // 买入/做多
  616. // </view>
  617. // <view class="shortcut-btn">
  618. // 卖出做空
  619. // </view>
  620. // </view>
  621. .shortcut-btns {
  622. display: flex;
  623. align-items: center;
  624. .shortcut-btn {
  625. flex: 1;
  626. height: 70rpx;
  627. line-height: 70rpx;
  628. text-align: center;
  629. font-size: 28rpx;
  630. color: #fff;
  631. background-color: $Theme-Color;
  632. &:nth-child(n + 2) {
  633. margin-left: 30rpx;
  634. background-color: $Theme-Color2;
  635. }
  636. }
  637. }
  638. .iframe-box {
  639. width: 100%;
  640. height: 50vh;
  641. iframe {
  642. width: 100%;
  643. height: 100%;
  644. }
  645. }
  646. // <view class="set-stop">
  647. // <view class="stop-left">
  648. // <text>止盈/止损</text>
  649. // <text class="stop-num">{{ item.target_profit_price || '--' }}/{{ item.stop_loss_price || '--'}}</text>
  650. // <text class="iconfont">&#xe610;</text>
  651. // </view>
  652. // <view class="stop-right">
  653. // <text class="icon-size iconfont">&#xe8b0;</text>
  654. // <text class="icon-size">分享</text>
  655. // </view>
  656. // </view>
  657. .set-stop {
  658. width: 100%;
  659. display: flex;
  660. align-items: center;
  661. justify-content: space-between;
  662. font-size: 26rpx;
  663. padding: 30rpx $pages-padding 0;
  664. .stop-left {
  665. font-size: 24rpx;
  666. color: $SizeColor2;
  667. .stop-num {
  668. padding: 0 10rpx;
  669. }
  670. .iconfont {
  671. color: $Theme-Color;
  672. }
  673. }
  674. .stop-right {
  675. color: $Theme-Color;
  676. font-size: 26rpx;
  677. .iconfont {
  678. margin-right: 6rpx;
  679. }
  680. }
  681. }
  682. </style>