123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- var StirngUtils = {
- /**切割价格字符串 */
- priceSplit: function (text){
- if(!text){
- return [];
- }
- return (text.toString()).split('.')
- },
- /**175****7179 */
- phoneSplit: function (text){
- if(!text){
- return "";
- }
- // var newText = text.replace(text.substring(3,7), "****");
- var newText = text.substring(0,3) + "****" + text.substring(7)
- return newText;
- },
- parseInt: function (text){
- if(!text){
- return 0;
- }
- return parseInt(text);
- },
- parseFloat: function (text){
- if(!text){
- return 0.00;
- }
- return parseFloat(text).toFixed(2);
- },
- numberFixed: function (num){
- if(!num){
- return 0;
- }
- if(num > 99999){
- return "10w+";
- }
- return num > 9999 ? (Math.floor(num/1000)/10) + 'w' : num;
- },
- numberFloor: function (num){
- if(!num){
- return 0;
- }
- num = isNaN(num)?num:parseFloat(num)
- console.log(num)
- if(num < 10000){
- return num/10000;
- }
- return (Math.floor(num/1000)/10);
- },
- //计算金额
- priceFixed: function (num){
- if(!num){
- return 0;
- }
- return num > 9999 ? (Math.floor(num/1000)/10) : num;
- },
- //计算金额单位
- priceStringUnit: function (num){
- if(!num){
- return "元";
- }
- return parseFloat(num) > 9999? '万':'元';
- },
- //商品详情计算优惠价 商品原价 , 优惠力度
- ratePrice: function (goodsPrice,ratePrice){
- var newPrice = parseFloat(((parseFloat(goodsPrice)*100) - (parseFloat(ratePrice)*100)) /100).toFixed(2);
- return newPrice.toString()
- },
- //砍价活动计算成功砍掉 还可以继续砍
- ratePrice2: function (goodsPrice,lowPrice){
- var newPrice = parseFloat(((parseFloat(goodsPrice)*100) - (parseFloat(lowPrice)*100)) /100).toFixed(2);
- return newPrice.toString()
- },
- //是否显示划线价 市场价 划线价
- isShowLinePrice: function (goodsPrice,linePrice){
- if(!linePrice){
- return false;
- }
- if((parseFloat(goodsPrice)*100) >= (parseFloat(linePrice)*100)){
- return false;
- }
- return true
- },
- //截取字符串
- subString: function (str,number){
- if(!str){
- return "";
- }
- if(str.length < number){
- return str;
- }
- return str.substring(str.length-number);
- },
- getGoldRiceValue: function (gold_rice,number){
- if(!gold_rice){
- return "0.00";
- }
- return parseFloat(gold_rice/number).toFixed(2)
- },
- imageMax: function (){
- return "?x-oss-process=image/resize,w_800/format,png";
- },
- imageMin: function (){
- return "?x-oss-process=image/resize,w_400/format,png";
- },
- imageMiddle: function (){
- return "?x-oss-process=image/resize,w_600/format,png";
- },
- imageSmall: function (){
- return "?x-oss-process=image/resize,w_300/format,png";
- },
- image200: function (){
- return "?x-oss-process=image/resize,w_200/format,png";
- },
- }
- module.exports = {
- priceSplit: StirngUtils.priceSplit,
- phoneSplit: StirngUtils.phoneSplit,
- parseInt: StirngUtils.parseInt,
- parseFloat: StirngUtils.parseFloat,
- numberFixed: StirngUtils.numberFixed,
- subString: StirngUtils.subString,
- priceFixed: StirngUtils.priceFixed,
- priceStringUnit: StirngUtils.priceStringUnit,
- numberFloor: StirngUtils.numberFloor,
- imageMax: StirngUtils.imageMax,
- imageMin: StirngUtils.imageMin,
- imageMiddle: StirngUtils.imageMiddle,
- imageSmall: StirngUtils.imageSmall,
- image200: StirngUtils.image200,
- ratePrice: StirngUtils.ratePrice,
- ratePrice2:StirngUtils.ratePrice2,
- isShowLinePrice:StirngUtils.isShowLinePrice,
- getGoldRiceValue:StirngUtils.getGoldRiceValue
- }
|