filter.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import Vue from 'vue'
  2. //保留两位小数
  3. Vue.filter('keepTwoNum',function(val){
  4. let value = Number(val)
  5. return value.toFixed(2)
  6. });
  7. //格式化数字三位加一逗号
  8. Vue.filter('NumFormat', function(value) {
  9. if(!value) return '';
  10. /*原来用的是Number(value).toFixed(0),这样取整时有问题,例如0.51取整之后为1 */
  11. /*后来改成了 Number(value)|0,但是输入超过十一位就为负数了 */
  12. var intPart = Number(value) - Number(value)%1; //获取整数部分
  13. var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断
  14. return intPartFormat;
  15. });
  16. //链接加时间戳
  17. Vue.filter("timestamp", function(link) {
  18. return link + '?t=' + new Date().getTime();
  19. });
  20. //截取第一张照片且判断是否有图片,没有图片输入默认图片
  21. Vue.filter("firstImg",function(arr,sizeType,imgType){
  22. //图片类型判断
  23. if(arr){
  24. if(arr instanceof Array){
  25. img = arr[0]
  26. }else{
  27. img = arr.split(',')[0]
  28. }
  29. }else if(!arr){
  30. //如果没有图片则随机输出一张
  31. // if(imgType === 'farmer'){
  32. // const farmerList = ['carbon2/farmer/1.png','carbon2/farmer/2.png']
  33. // img = farmerList[Math.floor(Math.random() * farmerList.length)];
  34. // }
  35. // img = '/static/img/inbuild.png'
  36. }
  37. // return config.imgUrl + img;
  38. return img;
  39. });
  40. //七牛云压缩图片
  41. Vue.filter("miniImg",function(img,quality){
  42. return img+'?imageMogr2/quality/'+quality
  43. });
  44. //车辆颜色
  45. Vue.filter("filterCarColor",function(item){
  46. item = Number(item);
  47. switch (item){
  48. case 0:
  49. return '蓝色'
  50. break;
  51. case 1:
  52. return '黄色'
  53. break;
  54. case 2:
  55. return '黑色'
  56. break;
  57. case 3:
  58. return '白色'
  59. break;
  60. case 4:
  61. return '绿色'
  62. break;
  63. case 99:
  64. return '其他'
  65. break;
  66. default:
  67. return '其他'
  68. break;
  69. }
  70. });
  71. //车辆类型
  72. Vue.filter("filterCarType",function(item){
  73. // console.log(item)
  74. item = Number(item);
  75. switch (item){
  76. case 0:
  77. return '小车'
  78. break;
  79. case 1:
  80. return '大车'
  81. break;
  82. case 2:
  83. return '超大型车'
  84. break;
  85. case 3:
  86. return '摩托车'
  87. break;
  88. case 4:
  89. return '非机动车'
  90. break;
  91. case 5:
  92. return '其他'
  93. break;
  94. default:
  95. return '其他'
  96. break;
  97. }
  98. });
  99. // 订单状态
  100. Vue.filter("filterOrderStatus",function(status){
  101. status = Number(status);
  102. switch (status){
  103. case 1:
  104. return '停放中'
  105. break;
  106. case 2:
  107. return '出场中'
  108. break;
  109. case 3:
  110. return '欠费'
  111. break;
  112. case 4:
  113. return '完成'
  114. break;
  115. default:
  116. return '未知'
  117. break;
  118. }
  119. });
  120. // 支付状态
  121. Vue.filter("filterPayStatus",function(status){
  122. status = Number(status);
  123. switch (status){
  124. case 0:
  125. return '未支付'
  126. break;
  127. case 1:
  128. return '已支付'
  129. break;
  130. case 2:
  131. return '支付中'
  132. break;
  133. case 3:
  134. return '支付失败'
  135. break;
  136. default:
  137. return '未知'
  138. break;
  139. }
  140. });