index.vue 6.3 KB

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