index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="contract">
  3. <headContent :showleftRight="false">
  4. <template #content>
  5. <view class="navigation-box">
  6. <view :class="['navigation-item hide_1' , contractIndex === index ? 'active-navigation-item' : '']"
  7. v-for="(item , index) in contractArr" :key="`navigation_${index}`"
  8. @click.stop="contractIndex = index">
  9. {{ item }}
  10. </view>
  11. </view>
  12. </template>
  13. </headContent>
  14. <!-- 永续合约 -->
  15. <template v-if="contractIndex === 0">
  16. <sustainability ref="sustainabilityRef" :currency-info="currencyVal" :myTransaction="my_transaction"
  17. :pagesInfo="pagesInfo" :my-peding-transaction="my_peding_transaction" @refreshData="init"
  18. @setContract="setContract" @setProfitLoss="setProfitLoss" @setHighInfo="setHighInfo"
  19. @shareContent="val => $refs.shareRef.openShare(val)" @setCloseLever="e => $refs.closeoutRef.open(e)" />
  20. </template>
  21. <!-- 永续合约 -->
  22. <template v-if="contractIndex === 1">
  23. <shortcut :myFast="my_fast" :rate-profits-total="rate_profits_total" :pagesInfo="pagesInfo"
  24. @refreshData="init" @shareContent="val => $refs.shareRef.openShare(val)" @setCloseLever="e => $refs.closeoutRef.open(e)" />
  25. </template>
  26. <!-- 赠金交易 -->
  27. <template v-if="contractIndex === 2">
  28. <grants />
  29. </template>
  30. <notarize />
  31. <!-- 永续合约设置 -->
  32. <contract-set ref="contractSetRef" @confirm="openSet" />
  33. <!-- 偏好设置 -->
  34. <preference ref="preferenceRef" />
  35. <!-- 设置盈亏 -->
  36. <restrictPopup ref="restrictPopupRef" @setSuccess="setRestrictSuccess" />
  37. <!-- 分享 -->
  38. <sharePage ref="shareRef" :shareType="2"></sharePage>
  39. <!-- 平仓 -->
  40. <close-out ref="closeoutRef" @setCloseLeverAll="setCloseLeverAll" @refreshData="init"></close-out>
  41. <!-- 平仓提示 -->
  42. <unopen ref="unopenRef" @confirm="$refs.closeoutRef.confirm()" textAlign="left" :title="unopenInfo.title"
  43. cancelBtn :content="unopenInfo.content" />
  44. </view>
  45. </template>
  46. <script>
  47. import notarize from "./modules/notarize.vue"
  48. import sustainability from "./sustainability/index.vue"
  49. import grants from "./grants/index.vue"
  50. import shortcut from "./shortcut/index.vue"
  51. import preference from "@/components/contract-set/preference.vue"
  52. import {
  53. Api_getLeverDeal,
  54. Api_getRegister
  55. } from "@/api/index.js"
  56. import {
  57. Way_getUserInfo
  58. } from "@/utils/common-request.js"
  59. import {
  60. mapGetters
  61. } from 'vuex'
  62. import {
  63. startSocket,
  64. closeSocket
  65. } from "@/utils/websocket.js"
  66. import restrictPopup from "./modules/restrict.vue"
  67. import closeOut from "./modules/close-out.vue"
  68. import {
  69. getCurrencyMarket
  70. } from "@/utils/currency-market.js"
  71. export default {
  72. name: 'contract',
  73. components: {
  74. notarize,
  75. sustainability,
  76. grants,
  77. shortcut,
  78. preference,
  79. restrictPopup,
  80. closeOut
  81. },
  82. data() {
  83. return {
  84. contractIndex: 0,
  85. contractArr: [
  86. '永续合约',
  87. '快捷合约',
  88. '赠金交易'
  89. ],
  90. currency: {},
  91. UserInfo: {},
  92. pagesInfo: {},
  93. my_transaction: [], // 永续 当前持仓
  94. my_peding_transaction: [], // 永续 限价持仓
  95. my_fast: [], // 快捷合约 持仓
  96. rate_profits_total: {},
  97. unopenInfo: {
  98. title: '平仓',
  99. content: '如果存在平仓挂单(限价止盈止损),将会在全平前被撤单,确定平仓吗?'
  100. }
  101. };
  102. },
  103. onLoad() {
  104. },
  105. computed: {
  106. ...mapGetters([
  107. 'currencyVal'
  108. ]),
  109. },
  110. watch: {
  111. currencyVal: {
  112. handler(newCurrency) {
  113. if (newCurrency && newCurrency?.legal_id) {
  114. this.init();
  115. }
  116. },
  117. deep: true,
  118. immediate: true
  119. },
  120. },
  121. onShow() {
  122. const nu = this.$getStorageSync('contractIndex');
  123. this.contractIndex = [0, 1, 2].includes(nu) ? nu : this.contractIndex
  124. this.$removeStorageSync('contractIndex')
  125. this.init()
  126. // this.setSocket();
  127. },
  128. onHide() {
  129. this.close()
  130. },
  131. mounted() {
  132. // 设置盈亏
  133. // setProfitLoss(item) {
  134. // console.log('setProfitLoss')
  135. // this.$nextTick(() => {
  136. // this.$refs.restrictPopupRef.open(item)
  137. // })
  138. // },
  139. // this.$on('setProfitLoss', (val) => {
  140. // console.log('setProfitLoss' , val);
  141. // });
  142. },
  143. methods: {
  144. // 平仓 - 单个订单的平仓(全平)
  145. setCloseLeverAll(obj) {
  146. this.unopenInfo = obj;
  147. this.$nextTick(() => {
  148. this.$refs.unopenRef.open();
  149. })
  150. },
  151. close() {
  152. closeSocket() // 停止 Socket
  153. this.$store.commit('websocket/set_currencySuspend', false) // 停止币种刷新
  154. },
  155. init() {
  156. console.log('99')
  157. // if ([0, 1].includes(this.contractIndex)) {
  158. // // 永续 / 快捷 需要获取持仓信息
  159. // this.getRegister()
  160. // }
  161. this.getAccountInfo();
  162. getCurrencyMarket('contract', {
  163. onceRefresh: true
  164. })
  165. // this.$store.dispatch('websocket/getQuotationNew', {
  166. // noRefresh: true
  167. // })
  168. // 运行 socket 实时更新
  169. // this.$store.commit('websocket/set_socket_update_status', true)
  170. if (this.currencyVal && this.currencyVal?.legal_id) {
  171. this.getLeverDeal();
  172. this.setSocket();
  173. }
  174. },
  175. setSocket() {
  176. startSocket();
  177. },
  178. getLeverDeal() {
  179. Api_getLeverDeal({
  180. legal_id: this.currencyVal.legal_id,
  181. currency_id: this.currencyVal.currency_id
  182. }).then(res => {
  183. this.pagesInfo = res
  184. this.my_transaction = res.my_transaction || []; // 永续合约 - 持仓信息
  185. this.my_peding_transaction = res.my_peding_transaction || []; // 永续合约 - 限价委托
  186. this.my_fast = res.my_fast || []; // 快捷合约 - 持仓信息
  187. console.log('my_transaction', this.my_transaction)
  188. }).catch(err => {
  189. // this.getLeverDeal()
  190. })
  191. },
  192. getAccountInfo() {
  193. this.$store.dispatch('possession/getPossession').then(res => {
  194. console.log('获取成功')
  195. }).catch(err => {
  196. console.log('获取shibai ')
  197. })
  198. },
  199. setContract() {
  200. // setContract
  201. this.$nextTick(() => {
  202. this.$refs.contractSetRef.open()
  203. })
  204. },
  205. // 设置盈亏
  206. setProfitLoss(item) {
  207. this.$nextTick(() => {
  208. this.$refs.restrictPopupRef.open(item)
  209. })
  210. },
  211. // 设置盈亏成功
  212. setRestrictSuccess() {
  213. this.getRegister();
  214. this.getLeverDeal();
  215. },
  216. // 永续合约 设置
  217. openSet(type) {
  218. return false
  219. switch (type) {
  220. case 1:
  221. // 偏好设置
  222. this.$nextTick(() => {
  223. this.$refs.preferenceRef.open()
  224. })
  225. break;
  226. case 2:
  227. // 合约计算器
  228. uni.navigateTo({
  229. url: '/pages/contract/calculator'
  230. })
  231. break;
  232. //
  233. }
  234. },
  235. setHighInfo() {
  236. this.$refs.restrictPopupRef.open()
  237. }
  238. }
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .navigation-box {
  243. width: 100%;
  244. height: 100%;
  245. padding: 0 $pages-padding 11rpx;
  246. display: flex;
  247. align-items: flex-end;
  248. .navigation-item {
  249. // width: 25%;
  250. flex: 1;
  251. flex-shrink: 0;
  252. text-align: center;
  253. height: 60rpx;
  254. border: 2rpx solid #27ae83;
  255. line-height: 60rpx;
  256. font-size: 28rpx;
  257. font-family: PingFang SC, PingFang SC-Regular;
  258. font-weight: 400;
  259. color: #05c175;
  260. &:nth-child(n + 2) {
  261. border-left: none;
  262. }
  263. &:last-child {
  264. border-radius: 0 6rpx 6rpx 0;
  265. }
  266. &:first-child {
  267. border-radius: 6rpx 0 0 6rpx;
  268. }
  269. }
  270. .active-navigation-item {
  271. background-color: #05C175;
  272. color: #FFFFFF;
  273. }
  274. }
  275. </style>