account.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import APP from '@/services';
  2. import { getLoginData } from '@/services/bus/login';
  3. import { QueryQuoteDayRsp } from '@/services/go/quote/interface';
  4. import { LongType } from '@/services/socket/login/interface/index';
  5. import { Ref } from 'vue';
  6. import { AccountListItem } from '../dataCenter/interafce/account';
  7. export function getAllTaAccount(): AccountListItem[] {
  8. return APP.get('accountList')
  9. }
  10. /**
  11. * 获取资金账号列表
  12. * @return string 拼接之后的字符串
  13. */
  14. export const getAccoutIdList = (): string => {
  15. const accountList = getAllTaAccount();
  16. return accountList.reduce((prev: string, cur: any, i: number) => {
  17. const id = String(cur.accountid);
  18. const temp = i ? `,${id}` : id;
  19. prev += temp;
  20. return prev;
  21. }, '');
  22. };
  23. // taaccounttype: number;//账号类型 - 1:外部账号 2:内部账号 3:内部做市自营账号 4:内部做市接单账号
  24. export type taaccounttype = 1 | 2 | 3 | 4
  25. export function getAccountTypeList(type: taaccounttype[]): AccountListItem[] {
  26. return APP.get('accountList').filter((e: AccountListItem) => type.includes(e.taaccounttype as taaccounttype))
  27. }
  28. // 获取内部资金账号
  29. // 先判断当前选中的资金账号是否为内部账号,是的话取当前的账号,不是的话,取内部账号列表里的第一个
  30. export function getInTaAccount(): number {
  31. const seleced = getSelectedAccount()
  32. let result: number = seleced?.accountid
  33. const list = getAccountTypeList([2])
  34. if (seleced) {
  35. if (seleced.taaccounttype !== 2) {
  36. if (list.length) {
  37. result = list[0].accountid
  38. } else {
  39. throw new Error('未获取到内部资金账号,请确认!')
  40. }
  41. }
  42. } else {
  43. if (list.length) {
  44. result = list[0].accountid
  45. } else {
  46. throw new Error('未获取到内部资金账号,请确认!')
  47. } ''
  48. }
  49. return result
  50. }
  51. /**
  52. * 获取第一个资金账号
  53. * @rerurn long型 | null
  54. */
  55. export const getAccount_longType = (): LongType | null => {
  56. const accountList = APP.get('accountList');
  57. if (accountList.length > 0) {
  58. return accountList[0].accountid;
  59. }
  60. return null;
  61. };
  62. /**
  63. * 获取用户id
  64. */
  65. export const getUserId = (): number => {
  66. const loginData = getLoginData();
  67. if (loginData) {
  68. return loginData.UserID;
  69. } else {
  70. console.warn('没有获取到用户id');
  71. return 0;
  72. }
  73. };
  74. export function getQuoteDayInfo(): Ref<QueryQuoteDayRsp[]> {
  75. return APP.getRef('quoteDayInfo');
  76. }
  77. /**
  78. * 计算浮动盈亏
  79. */
  80. function calcHolderSumDynProfit() {
  81. // const holds = APP.get('quoteDayInfo');
  82. // const HsbyListingGoods = APP.get('HsbyListingGoods');
  83. // for (let i = 0; i < holds.length; i++) {
  84. // const itemHold = holds[i];
  85. // const goodsInfo = HsbyListingGoods.find((e: any) => e.goodsid === itemHold.goodsid);
  86. // if (goodsInfo) {
  87. // }
  88. // }
  89. }
  90. /**
  91. * 获取可用余额
  92. */
  93. export function getCanUserMoney() {
  94. const list = APP.get('accountList');
  95. let result = 0;
  96. if (list && list.length) {
  97. const { CurrentBalance, FreezeMargin, UsedMargin, OtherFreezeMargin, FreezeCharge } = list[0];
  98. result = CurrentBalance - FreezeMargin - UsedMargin - OtherFreezeMargin - FreezeCharge;
  99. result = +result.toFixed(2);
  100. } else {
  101. console.error('获取资金列表错误');
  102. }
  103. return result;
  104. }
  105. // 获取选中的资金账号信息
  106. export function getSelectedAccount(): AccountListItem {
  107. return APP.get('selectedAccount')
  108. }
  109. // 设置当前中的资金账号
  110. export function setSelectedAccount(value: AccountListItem) {
  111. APP.set('selectedAccount', value)
  112. }
  113. /**
  114. * 获取选中的资金账号
  115. */
  116. export function getSelectedAccountId(): number {
  117. return getSelectedAccount().accountid
  118. }
  119. // 获取冻结资金
  120. export function getFreeze(value: AccountListItem, isFixed2 = false) {
  121. const { freezecharge, freezemargin, otherfreezemargin, outamountfreeze } = value;
  122. const freeze = freezecharge + freezemargin + otherfreezemargin + outamountfreeze;
  123. return isFixed2 ? freeze.toFixed(2) : freeze
  124. }
  125. // 获取可用资金
  126. export function getCanUseMoney(value: AccountListItem) {
  127. const freeze = getFreeze(value) as number
  128. return (value.currentbalance - freeze).toFixed(2)
  129. }