exchangeRate.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { getRateList, bcurrencyGetExrate, standardCurrency, obtainRate } from "@/api/iosBasicData/rateManagement";
  2. import { getCurrentDate } from "@/util/date";
  3. //本地存储币别信息
  4. export async function setRateData() {
  5. let obj = {
  6. current: 1,
  7. size: 20
  8. }
  9. let res = await getRateList(obj)
  10. localStorage.setItem("币别信息", JSON.stringify(res.data.data.records));
  11. return res
  12. }
  13. //本地获取币别信息
  14. export function getRateData() {
  15. if (localStorage.getItem("币别信息")) {
  16. return JSON.parse(localStorage.getItem("币别信息"))
  17. } else {
  18. this.$confirm('本地暂无汇率信息,请刷新页面?', '提示', {
  19. confirmButtonText: '确定',
  20. cancelButtonText: '取消',
  21. type: 'error'
  22. }).then(() => {
  23. this.setRateData()
  24. })
  25. }
  26. }
  27. //获取本币币别
  28. export function getLocalCurrency() {
  29. return localStorage.getItem("本币");
  30. }
  31. //获取本币币别
  32. export function getCheckRate() {
  33. return JSON.parse(localStorage.getItem("所有币别以汇率")) ? JSON.parse(localStorage.getItem("所有币别以汇率")) : []
  34. }
  35. // 查本币
  36. export async function saveLocalCurrency(deptId) {
  37. let obj = {
  38. deptId: deptId
  39. }
  40. let res = await standardCurrency(obj)
  41. localStorage.setItem("本币", res.data.data);
  42. return res.data.data ? true : false
  43. }
  44. //查所有币别以汇率
  45. export async function checkRate(curCode, date, dc, type, deptId) {
  46. let obj = {
  47. deptId: deptId,
  48. date: date ? date : getCurrentDate(),
  49. type: type ? type : 1
  50. }
  51. let res = await obtainRate(obj)
  52. localStorage.setItem("所有币别以汇率", JSON.stringify(res.data.data));
  53. if (curCode) {
  54. for (let item of res.data.data) {
  55. if (item.code == curCode) {
  56. if (type == 1 && dc == 'D') return item.exrateReceivable
  57. if (type == 1 && dc == 'C') return item.exratePayable
  58. if (type == 2 && dc == 'D') return item.exrateReceipts
  59. if (type == 2 && dc == 'C') return item.exratePayment
  60. }
  61. }
  62. }
  63. }
  64. //查汇率
  65. export function getExchangeRate(curCode, dc, type) {
  66. for (let item of this.getCheckRate()) {
  67. if (item.code == curCode) {
  68. if (type == 1 && dc == 'D') return item.exrateReceivable
  69. if (type == 1 && dc == 'C') return item.exratePayable
  70. if (type == 2 && dc == 'D') return item.exrateReceipts
  71. if (type == 2 && dc == 'C') return item.exratePayment
  72. }
  73. }
  74. }