赞
踩
import Vue from 'vue' //全局过滤器,金额千分位 Vue.filter('moneyFormat', function (value) { if (value != undefined) { return value.toFixed(2).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); } }) //全局过滤器,数量2位 Vue.filter('qtyFormat', function (value) { if (value != undefined) { return value.toFixed(2); } }) // bit小数位 Vue.filter('customFormat', function (value,bit) { if(!value){ value = 0 } if (value != undefined) { var valueCopy =Number(value).toFixed(bit).toString() // 截取小数点前的数据 var intNumber = valueCopy.substring(0,valueCopy.indexOf(".")); // 小数点前的数据使用千位分割 intNumber =intNumber.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); // 截取小数点后的数据 var laterNumber =valueCopy.replace(/\d+\.(\d*)/,"$1") //有负数的数据重截取 laterNumber =laterNumber.replace('-','') // return Number(value).toFixed(bit).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"); return intNumber+"."+laterNumber; } }) Vue.filter('timestampToTime' ,function(timestamp) { // 计算年月日时分的函数 var date = new Date(timestamp) var Y = date.getFullYear() + '-' var M = (date.getMonth() + 1) + '-' var D = date.getDate() + ' ' var h = date.getHours() + ':' var m = date.getMinutes() + ':' var s = date.getSeconds() return Y + M + D + h + m + s }) Vue.filter('deptLevel' ,function(value) { console.log(value) // 计算年月日时分的函数 var dept = [] for (let index = 0; index < value.length; index++) { if(value[index].deptLevel == "1"){ dept.push(value[index]) } } return dept; })
代码中使用
<el-table-column label="成本总价" align="center" prop="stockCost">
<template slot-scope="scope">
<p>{{form.detailList[scope.$index].stockCost | customFormat(2)}}</p>
</template>
</el-table-column>
<el-table-column label="总售价" align="center" prop="sellingSum">
<template slot-scope="scope">
<p>{{form.detailList[scope.$index].sellingSum | customFormat(2)}}</p>
</template>
</el-table-column>```
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。