filter.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * 公共方法的封装
  3. */
  4. import Vue from 'vue'
  5. // 性别
  6. Vue.filter("filterSex", function(val) {
  7. if(val == 0){
  8. return '男';
  9. }else if(val == 1){
  10. return '女';
  11. }else {
  12. return '未知';
  13. }
  14. });
  15. // 链接加时间戳
  16. Vue.filter("timestamp", function(link) {
  17. return link + '?t=' + new Date().getTime();
  18. });
  19. // 时间去掉时分秒
  20. Vue.filter("timeSplit", function(time) {
  21. if(time) {
  22. return time.indexOf(" ") > -1 ? time.split(" ")[0] : time
  23. } else {
  24. return ""
  25. }
  26. });
  27. // 结账方式
  28. Vue.filter("filterPayWay", function(val) {
  29. if(val == 0){
  30. return '现销';
  31. }else if(val == 1){
  32. return '赊销';
  33. }else {
  34. return '未知';
  35. }
  36. });
  37. // 订单类型
  38. Vue.filter("filterOrderType", function(val) {
  39. if(val == 0){
  40. return '普通';
  41. }else if(val == 1){
  42. return '换货销售';
  43. }else {
  44. return '未知';
  45. }
  46. });
  47. // 收货方式
  48. Vue.filter("filterReceiveWay", function(val) {
  49. if(val == 0){
  50. return '物流';
  51. }else if(val == 1){
  52. return '自提';
  53. }else if(val == 2){
  54. return '顺丰直发';
  55. }else {
  56. return '未知';
  57. }
  58. });
  59. // 保留两位小数,自动补充零
  60. Vue.filter("filterToFixed", function(val) {
  61. var value=Math.round(parseFloat(val)*100)/100;
  62. if(!value){return '0'}
  63. var xsd=value.toString().split(".");
  64. if(xsd.length==1){
  65. value=value.toString()+".00";
  66. return value;
  67. }
  68. if(xsd.length>1){
  69. if(xsd[1].length<2){
  70. value=value.toString()+"0";
  71. }
  72. return value;
  73. }
  74. })
  75. // 订单状态
  76. Vue.filter("filterOrderState", function(val) {
  77. let orderList = ['审核中', '待付款', '待发货', '待收货', '已完成', '售后', '已关闭', '酒业出库', '物流出库']
  78. return orderList[val]
  79. });