account.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. 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. if (seleced.taaccounttype !== 2) {
  34. const list = getAccountTypeList([2])
  35. if (list.length) {
  36. result = list[0].accountid
  37. } else {
  38. throw new Error('未获取到内部资金账号,请确认!')
  39. } ''
  40. }
  41. return result
  42. }
  43. /**
  44. * 获取第一个资金账号
  45. * @rerurn long型 | null
  46. */
  47. export const getAccount_longType = (): LongType | null => {
  48. const accountList = APP.get('accountList');
  49. if (accountList.length > 0) {
  50. return accountList[0].accountid;
  51. }
  52. return null;
  53. };
  54. /**
  55. * 获取用户id
  56. */
  57. export const getUserId = (): number => {
  58. const loginData = getLoginData();
  59. if (loginData) {
  60. return loginData.UserID;
  61. } else {
  62. console.warn('没有获取到用户id');
  63. return 0;
  64. }
  65. };
  66. export function getQuoteDayInfo(): Ref<QueryQuoteDayRsp[]> {
  67. return APP.getRef('quoteDayInfo');
  68. }
  69. /**
  70. * 计算浮动盈亏
  71. */
  72. function calcHolderSumDynProfit() {
  73. // const holds = APP.get('quoteDayInfo');
  74. // const HsbyListingGoods = APP.get('HsbyListingGoods');
  75. // for (let i = 0; i < holds.length; i++) {
  76. // const itemHold = holds[i];
  77. // const goodsInfo = HsbyListingGoods.find((e: any) => e.goodsid === itemHold.goodsid);
  78. // if (goodsInfo) {
  79. // }
  80. // }
  81. }
  82. /**
  83. * 获取可用余额
  84. */
  85. export function getCanUserMoney() {
  86. const list = APP.get('accountList');
  87. let result = 0;
  88. if (list && list.length) {
  89. const { CurrentBalance, FreezeMargin, UsedMargin, OtherFreezeMargin, FreezeCharge } = list[0];
  90. result = CurrentBalance - FreezeMargin - UsedMargin - OtherFreezeMargin - FreezeCharge;
  91. result = +result.toFixed(2);
  92. } else {
  93. console.error('获取资金列表错误');
  94. }
  95. return result;
  96. }
  97. // 获取选中的资金账号信息
  98. export function getSelectedAccount(): AccountListItem {
  99. return APP.get('selectedAccount')
  100. }
  101. // 设置当前中的资金账号
  102. export function setSelectedAccount(value: AccountListItem) {
  103. APP.set('selectedAccount', value)
  104. }
  105. /**
  106. * 获取选中的资金账号
  107. */
  108. export function getSelectedAccountId(): number {
  109. return getSelectedAccount().accountid
  110. }