index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <!-- 合约 - 合约明细 -->
  2. <template>
  3. <app-view class="contract-detail g-form">
  4. <template #header>
  5. <app-navbar :title="t('digital.contractdetails')" />
  6. </template>
  7. <app-block class="g-account-total" v-if="accountItem">
  8. <div class="g-account-total__inner">
  9. <div class="g-account-total__header">
  10. <div class="g-account-total__title">
  11. <span>
  12. {{ `${t('digital.currencydecimalplace')}
  13. (${getGoodsCurrencyItemName(accountItem.currencyid)})` }}
  14. </span>
  15. <img :src="`./img/icons/${isAmountVisible ? 'eye' : 'eye-hidden'}.svg`"
  16. @click="isAmountVisible = !isAmountVisible" />
  17. </div>
  18. <div class="g-account-total__info" v-if="isAmountVisible">
  19. <span :class="handlePriceColor(accountItem.profitLoss)">
  20. {{ formatNumber(accountItem.profitLoss, accountItem.currencydecimalplace) }}
  21. </span>
  22. <span :class="accountItem.hazardRatioColor">
  23. {{ parsePercent(accountItem.hazardRatio) }}
  24. </span>
  25. </div>
  26. </div>
  27. <div class="g-account-total__balance">
  28. {{ getAccountAmount(accountItem.currentbalance) }}
  29. </div>
  30. <div class="g-account-total__footer">
  31. <ul>
  32. <li>
  33. <span>
  34. {{ `${t('mine.availableFunds')} (${getGoodsCurrencyItemName(accountItem.currencyid)})`
  35. }}
  36. </span>
  37. <span>{{ getAccountAmount(accountItem.avaiableBalance) }}</span>
  38. </li>
  39. <li>
  40. <span>
  41. {{ `${t('account.usedMargin')} (${getGoodsCurrencyItemName(accountItem.currencyid)})` }}
  42. </span>
  43. <span>{{ getAccountAmount(accountItem.usedmargin) }}</span>
  44. </li>
  45. <li>
  46. <span>
  47. {{ `${t('account.freeze')} (${getGoodsCurrencyItemName(accountItem.currencyid)})` }}
  48. </span>
  49. <span>{{ getAccountAmount(accountItem.freezeMargin) }}</span>
  50. </li>
  51. </ul>
  52. </div>
  53. </div>
  54. </app-block>
  55. <app-grid :items="gridItems" @click="() => navigateToContractDetail()" />
  56. <Tabs class="g-tabs" type="card" v-model:active="activeTab" shrink>
  57. <Tab :title="t('digital.position')">
  58. <contract-position :params="{ accids: accountid.toString() }" v-if="activeTab === 0" />
  59. </Tab>
  60. <Tab :title="t('digital.order')">
  61. <contract-order v-bind="{ accountid }" v-if="activeTab === 1" />
  62. </Tab>
  63. <Tab :title="t('digital.trade')">
  64. <contract-trade v-bind="{ accountid }" v-if="activeTab === 2" />
  65. </Tab>
  66. <Tab :title="t('digital.funds')">
  67. <contract-statement v-bind="{ accountid }" v-if="activeTab === 3" />
  68. </Tab>
  69. </Tabs>
  70. <ActionSheet v-model:show="showSheet" :title="t('common.choice')">
  71. <CellGroup style="min-height: 200px;">
  72. <template v-for="(item, index) in quotes" :key="index">
  73. <Cell :title="goodsname(item.goodscode)" :value="item.goodscode" :border="false" is-link clickable
  74. @click="navigateToContractDetail(item.goodsid)" />
  75. </template>
  76. </CellGroup>
  77. </ActionSheet>
  78. </app-view>
  79. </template>
  80. <script lang="ts" setup>
  81. import { shallowRef, computed, watch, onActivated } from 'vue'
  82. import { Cell, CellGroup, Tab, Tabs, ActionSheet } from 'vant'
  83. import { handlePriceColor, parsePercent, formatNumber } from '@/filters'
  84. import { useNavigation } from '@mobile/router/navigation'
  85. import { i18n, useAccountStore, useFuturesStore } from '@/stores'
  86. import { GridItem } from '@/packages/digital/components/grid/types'
  87. import AppGrid from '@/packages/digital/components/grid/index.vue'
  88. import ContractOrder from '../components/order/index.vue'
  89. import ContractTrade from '../components/trade/index.vue'
  90. import ContractPosition from '../components/position/detail/index.vue'
  91. import ContractStatement from '../components/statement/index.vue'
  92. import { getGoodsCurrencyItemName } from '@/constants/order'
  93. const { router, getQueryStringToNumber } = useNavigation()
  94. const { global: { t } } = i18n
  95. const futuresStore = useFuturesStore()
  96. const accountStore = useAccountStore()
  97. const accountid = getQueryStringToNumber('id')
  98. const activeTab = shallowRef(0)
  99. const showSheet = shallowRef(false)
  100. const isAmountVisible = shallowRef(true)
  101. // 合约账户
  102. const accountItem = computed(() => accountStore.getAccountItem({ accountid }))
  103. const quotes = computed(() => futuresStore.quotationList.filter((e) => e.trademode === 10 && (e.goodscurrencyid === accountItem.value?.currencyid || e.currencyid === accountItem.value?.currencyid)))
  104. const gridItems = computed(() => {
  105. const items: GridItem[] = [
  106. {
  107. text: t('digital.wallet-transfer'),
  108. icon: './img/icons/transfer.svg',
  109. to: { name: 'wallet-transfer' }
  110. }
  111. ]
  112. if (quotes.value.length) {
  113. items.push({
  114. text: t('digital.spot-goods-detail'),
  115. icon: './img/icons/trade.svg'
  116. })
  117. }
  118. return items
  119. })
  120. const goodsname = (code: string) => {
  121. return futuresStore.getI18nGoodsName(code)
  122. }
  123. // 获取金额
  124. const getAccountAmount = (value: number) => {
  125. if (isAmountVisible.value) {
  126. return value.toFixed(accountItem.value?.currencydecimalplace)
  127. }
  128. return '**********'
  129. }
  130. const navigateToContractDetail = (goodsid?: number) => {
  131. showSheet.value = false
  132. // 多个商品弹出列表选择,单个商品直接跳转
  133. if (quotes.value.length > 1 && !goodsid) {
  134. showSheet.value = true
  135. } else {
  136. router.push({
  137. name: 'contract-goods-detail',
  138. query: {
  139. id: goodsid ?? quotes.value[0].goodsid
  140. }
  141. })
  142. }
  143. }
  144. watch(isAmountVisible, (val) => {
  145. localStorage.setItem('isAmountVisible', JSON.stringify(val))
  146. })
  147. onActivated(() => {
  148. const visible = localStorage.getItem('isAmountVisible') || 'true'
  149. isAmountVisible.value = JSON.parse(visible)
  150. })
  151. </script>