index.sjs 987 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // 获得最大可购买值
  2. const getMaxBuyNum = (goodsItem = {}) => {
  3. const {
  4. buyLimitType = '',
  5. stock = 0,
  6. buyLimitCount = 0,
  7. stockStatus = 'N',
  8. } = goodsItem;
  9. // 展示库存 && 限购
  10. if (stockStatus === 'Y' && buyLimitType === 'GENERAL') {
  11. return Math.min(stock, buyLimitCount);
  12. }
  13. if (buyLimitType === 'GENERAL') {
  14. return buyLimitCount;
  15. }
  16. if (stockStatus === 'Y') {
  17. return stock;
  18. }
  19. return 99;
  20. };
  21. // 获得最大可够类型
  22. const getNumType = (goodsItem = {}) => {
  23. const {
  24. buyLimitType = '',
  25. stock = 0,
  26. buyLimitCount = 0,
  27. stockStatus = 'N',
  28. } = goodsItem;
  29. // 展示库存 && 限购
  30. if (stockStatus === 'Y' && buyLimitType === 'GENERAL') {
  31. return Math.min(stock, buyLimitCount) === buyLimitCount ? 'limit' : 'stock';
  32. }
  33. if (buyLimitType === 'GENERAL') {
  34. return 'limit';
  35. }
  36. if (stockStatus === 'Y') {
  37. return 'stock';
  38. }
  39. return 'limit';
  40. };
  41. export default {
  42. getNumType,
  43. getMaxBuyNum,
  44. };