number.wxs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. function toPrice(val) {
  2. if(!val){
  3. val = 0;
  4. }
  5. return (val.toFixed(2))
  6. };
  7. function parsePrice(val){
  8. if (!val) {
  9. val = 0;
  10. }
  11. return val.toFixed(2).split(".");
  12. }
  13. // 取整
  14. function rounding(val) {
  15. if (!val) {
  16. val = 0;
  17. }
  18. return parseInt(val);
  19. }
  20. /**
  21. * <分销员等级>根据index动态添加样式
  22. */
  23. var indexof = function (index) {
  24. switch (index) {
  25. case 1:
  26. return 'width2';
  27. break;
  28. case 2:
  29. return 'width3';
  30. break;
  31. case 3:
  32. return 'width4';
  33. break;
  34. case 4:
  35. return 'width5';
  36. break;
  37. }
  38. };
  39. function array_contain(array, obj) {
  40. for (var i = 0; i < array.length; i++) {
  41. if (array[i] == obj)//如果要求数据类型也一致,这里可使用恒等号===
  42. return true;
  43. }
  44. return false;
  45. }
  46. //判断当前的规格值 是否可以选,即其他
  47. function props_contain(allProperties, selectedPropObj, key, item, propKeys){
  48. var properties = "";
  49. selectedPropObj[key] = item;
  50. for (var j = 0; j < propKeys.length; j++){
  51. properties += propKeys[j] + ":" + selectedPropObj[propKeys[j]] + ";";
  52. }
  53. properties = properties.substring(0, properties.length - 1);
  54. var find = false;
  55. for (var i = 0; i < allProperties.length; i++){
  56. if (properties == allProperties[i]){
  57. find = true;
  58. break;
  59. }
  60. }
  61. return find;
  62. }
  63. /**
  64. * 当前属性是否可以选择
  65. *
  66. * 参数说明:
  67. * @param allProperties ['颜色:金色;内存:64GB','颜色:金色;内存:256GB']
  68. * @param selectedPropObj {'颜色':'金色','内存':'64GB'}
  69. * @param propKeys ['颜色','内存']
  70. * @param key 颜色
  71. * @param item 金色
  72. *
  73. * @return 0 不可选 1 可选 2 可选但跟其他值不匹配
  74. */
  75. function props_contain2(allProperties, selectedPropObj, key, item, propKeys) {
  76. var properties = "";
  77. selectedPropObj[key] = item;
  78. for (var j = 0; j < propKeys.length; j++) {
  79. properties += propKeys[j] + ":" + selectedPropObj[propKeys[j]] + ";";
  80. }
  81. properties = properties.substring(0, properties.length - 1);
  82. var find = false;
  83. for (var i = 0; i < allProperties.length; i++) {
  84. if (properties == allProperties[i]) {
  85. find = true;
  86. return 1;
  87. break;
  88. }
  89. }
  90. if(!find){
  91. for (var i = 0; i < allProperties.length; i++) {
  92. if (allProperties[i].indexOf(item)>=0) {
  93. return 2;
  94. break;
  95. }
  96. }
  97. }
  98. return 0;
  99. }
  100. function parseDiscount(discountRule){
  101. if (discountRule == 0){
  102. return '满额减';
  103. } else if(discountRule == 1){
  104. return '满件减';
  105. } else if (discountRule == 2) {
  106. return '满额折';
  107. } else if (discountRule == 3) {
  108. return '满件折';
  109. }else{
  110. return '';
  111. }
  112. }
  113. function parseDiscountMsg(discountRule, needAmount,discount){
  114. if (discountRule == 0) {
  115. return '购满' + needAmount + '元减' + discount + '元';
  116. } else if (discountRule == 1) {
  117. return '购满' + needAmount + '件减' + discount + '元';
  118. } else if (discountRule == 2) {
  119. return '购满' + needAmount + '元打' + discount + '折';
  120. } else if (discountRule == 3) {
  121. return '购满' + needAmount + '件打' + discount + '折';
  122. } else {
  123. return '';
  124. }
  125. }
  126. function getCurrDiscountName(discountId, discounts) {
  127. for (var i = 0; i < discounts.length; i++) {
  128. if (discounts[i].discountId == discountId) {
  129. return discounts[i].discountName
  130. }
  131. }
  132. return '不参与促销'
  133. }
  134. /**
  135. * 裁剪日期 2020-03-20 15:04:40 -> 2020-03-20
  136. */
  137. function spliceDate(dateStr){
  138. if (!dateStr) return
  139. return dateStr.split(' ')[0]
  140. }
  141. // function trim(str) {
  142. // return str.replace(/^\s+|\s+$/g, '');
  143. // }
  144. module.exports = ({
  145. spliceDate: spliceDate,
  146. toPrice: toPrice,
  147. parsePrice: parsePrice,
  148. array_contain: array_contain,
  149. props_contain: props_contain,
  150. props_contain2: props_contain2,
  151. parseDiscount: parseDiscount,
  152. parseDiscountMsg: parseDiscountMsg,
  153. getCurrDiscountName: getCurrDiscountName,
  154. indexof: indexof,
  155. rounding: rounding
  156. });