textUtil.wxs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var StirngUtils = {
  2. /**切割价格字符串 */
  3. priceSplit: function (text){
  4. if(!text){
  5. return [];
  6. }
  7. return (text.toString()).split('.')
  8. },
  9. /**175****7179 */
  10. phoneSplit: function (text){
  11. if(!text){
  12. return "";
  13. }
  14. // var newText = text.replace(text.substring(3,7), "****");
  15. var newText = text.substring(0,3) + "****" + text.substring(7)
  16. return newText;
  17. },
  18. parseInt: function (text){
  19. if(!text){
  20. return 0;
  21. }
  22. return parseInt(text);
  23. },
  24. parseFloat: function (text){
  25. if(!text){
  26. return 0.00;
  27. }
  28. return parseFloat(text).toFixed(2);
  29. },
  30. numberFixed: function (num){
  31. if(!num){
  32. return 0;
  33. }
  34. if(num > 99999){
  35. return "10w+";
  36. }
  37. return num > 9999 ? (Math.floor(num/1000)/10) + 'w' : num;
  38. },
  39. numberFloor: function (num){
  40. if(!num){
  41. return 0;
  42. }
  43. num = isNaN(num)?num:parseFloat(num)
  44. console.log(num)
  45. if(num < 10000){
  46. return num/10000;
  47. }
  48. return (Math.floor(num/1000)/10);
  49. },
  50. //计算金额
  51. priceFixed: function (num){
  52. if(!num){
  53. return 0;
  54. }
  55. return num > 9999 ? (Math.floor(num/1000)/10) : num;
  56. },
  57. //计算金额单位
  58. priceStringUnit: function (num){
  59. if(!num){
  60. return "元";
  61. }
  62. return parseFloat(num) > 9999? '万':'元';
  63. },
  64. //商品详情计算优惠价 商品原价 , 优惠力度
  65. ratePrice: function (goodsPrice,ratePrice){
  66. var newPrice = parseFloat(((parseFloat(goodsPrice)*100) - (parseFloat(ratePrice)*100)) /100).toFixed(2);
  67. return newPrice.toString()
  68. },
  69. //砍价活动计算成功砍掉 还可以继续砍
  70. ratePrice2: function (goodsPrice,lowPrice){
  71. var newPrice = parseFloat(((parseFloat(goodsPrice)*100) - (parseFloat(lowPrice)*100)) /100).toFixed(2);
  72. return newPrice.toString()
  73. },
  74. //是否显示划线价 市场价 划线价
  75. isShowLinePrice: function (goodsPrice,linePrice){
  76. if(!linePrice){
  77. return false;
  78. }
  79. if((parseFloat(goodsPrice)*100) >= (parseFloat(linePrice)*100)){
  80. return false;
  81. }
  82. return true
  83. },
  84. //截取字符串
  85. subString: function (str,number){
  86. if(!str){
  87. return "";
  88. }
  89. if(str.length < number){
  90. return str;
  91. }
  92. return str.substring(str.length-number);
  93. },
  94. getGoldRiceValue: function (gold_rice,number){
  95. if(!gold_rice){
  96. return "0.00";
  97. }
  98. return parseFloat(gold_rice/number).toFixed(2)
  99. },
  100. imageMax: function (){
  101. return "?x-oss-process=image/resize,w_800/format,png";
  102. },
  103. imageMin: function (){
  104. return "?x-oss-process=image/resize,w_400/format,png";
  105. },
  106. imageMiddle: function (){
  107. return "?x-oss-process=image/resize,w_600/format,png";
  108. },
  109. imageSmall: function (){
  110. return "?x-oss-process=image/resize,w_300/format,png";
  111. },
  112. image200: function (){
  113. return "?x-oss-process=image/resize,w_200/format,png";
  114. },
  115. }
  116. module.exports = {
  117. priceSplit: StirngUtils.priceSplit,
  118. phoneSplit: StirngUtils.phoneSplit,
  119. parseInt: StirngUtils.parseInt,
  120. parseFloat: StirngUtils.parseFloat,
  121. numberFixed: StirngUtils.numberFixed,
  122. subString: StirngUtils.subString,
  123. priceFixed: StirngUtils.priceFixed,
  124. priceStringUnit: StirngUtils.priceStringUnit,
  125. numberFloor: StirngUtils.numberFloor,
  126. imageMax: StirngUtils.imageMax,
  127. imageMin: StirngUtils.imageMin,
  128. imageMiddle: StirngUtils.imageMiddle,
  129. imageSmall: StirngUtils.imageSmall,
  130. image200: StirngUtils.image200,
  131. ratePrice: StirngUtils.ratePrice,
  132. ratePrice2:StirngUtils.ratePrice2,
  133. isShowLinePrice:StirngUtils.isShowLinePrice,
  134. getGoldRiceValue:StirngUtils.getGoldRiceValue
  135. }