glj.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { GljType, IBaseGlj, IInfoPriceItem, TaxType } from '@sc/types';
  2. import { roundForObj } from '@sc/util';
  3. export const getInfoMarketPrice = (info: IInfoPriceItem, taxType: TaxType) => {
  4. // 1: 一般计税 2: 简易计税
  5. const fieldArray = ['noTaxPrice']; // 一般计税 - 不含税价 || 简易计税 - 含税价
  6. if (taxType === TaxType.GENERAL) {
  7. fieldArray.push('taxPrice');
  8. } else {
  9. fieldArray.unshift('taxPrice');
  10. }
  11. // 一个放后面,一个放前面
  12. let infoPrice = (info as any)[fieldArray[0]];
  13. if (infoPrice === null || infoPrice === undefined) infoPrice = (info as any)[fieldArray[1]]; // 信息价只有一个价格(含税价/不含税价),则不分计税方式,套用仅有的价格。
  14. return parseFloat(infoPrice);
  15. };
  16. // 计算采保费率后的市场价
  17. export const calcMarketPriceByInfoPrice = (infoPrice: number, purchaseFeeRate: number, decimal: number) => {
  18. if (!purchaseFeeRate) return infoPrice;
  19. return roundForObj(infoPrice * (1 + purchaseFeeRate / 100), decimal);
  20. };
  21. // roundForObj()
  22. // 返回五大项组成的索引
  23. export const getIndex = (obj: IBaseGlj, pops = ['code', 'name', 'specs', 'unit', 'type']): string => {
  24. let index = '';
  25. const arr = [];
  26. for (const p of pops) {
  27. const tmpK = obj[p] === undefined || obj[p] === null || obj[p] === '' ? 'null' : obj[p];
  28. arr.push(tmpK);
  29. }
  30. index = arr.join('|-|');
  31. return index;
  32. };
  33. // 是否是人工
  34. export const isLabour = (type: GljType) => {
  35. return type === GljType.LABOUR;
  36. };
  37. // 是否是材料
  38. export const isMaterial = (type: GljType) => {
  39. const rootType = +String(type).charAt(0);
  40. return rootType === 2;
  41. };
  42. // 是否是机械
  43. export const isMachine = (type: GljType) => {
  44. const rootType = +String(type).charAt(0);
  45. return rootType === 3;
  46. };