table 合计功能
countTotal(arr, keyName) {
let $total = 0;
$total = arr.reduce(function (total, currentValue, currentIndex, arr){
return currentValue[keyName] ? (total + currentValue[keyName]) : total;
}, 0);
return $total.toFixed(2);
},
通过调用这个方法 第一个急需要处理的数组,第二个参数为需要合计的属性
getlist () {
var userToken = this.$cookie.get('token')
this.$http({
url: this.$http.adornUrl('/generator/laborworker/list2'),
method: 'post',
headers: {
'token': userToken
},
data: JSON.stringify({
'page': this.page,
'limit': this.pageSize,
"name": this.keyword,
"status":this.status
})
}).then(({data}) => {
this.list=data.page.list
this.gz=this.countTotal(this.list,'salary') //工资
this.yfgz=this.countTotal(this.list,'yfSalary') //应发工资
this.qjkc=this.countTotal(this.list,'subMoney') //请假扣除工资
this.sfgz=this.countTotal(this.list,'sfSalary') //实发工资
this.wfgz= this.yfgz-this.sfgz-this.qjkc //实发工资
console.log( this.list,789789)
this.total=data.page.totalCount
if (this.total <= 10) {
this.show = false
} else {
this.show = true
}
})
},