var data = [
{
OnTime: '12-16',
OnUserName: '小明',
OnType: '5G升级包',
OnNumber: 15
}, {
OnTime: '12-17',
OnUserName: '小明',
OnType: '5G升级包',
OnNumber: 15
}, {
OnTime: '12-18',
OnUserName: '小明',
OnType: '5G升级包',
OnNumber: 18
}, {
OnTime: '12-19',
OnUserName: '小明',
OnType: '5G升级包',
OnNumber: 15
}, {
OnTime: '12-21',
OnUserName: '小明',
OnType: '5G升级包',
OnNumber: 16
}
, {
OnTime: '12-22',
OnUserName: '小明',
OnType: '5G升级包',
OnNumber: 16
}
, {
OnTime: '12-23',
OnUserName: '小明',
OnType: '5G升级包',
OnNumber: 16
}
]
console.log('您好,小明的工作天数是:' + data.length)
// 临时存储总单量
var number = 0
// 计算总单量
for (var o = 0; o < data.length; o++) {
number = number + data[o].OnNumber
}
console.log('您好,小明的总单量是:' + number)
console.log('您好,小明的均单是:' + Math.floor((number / data.length)))
addTimeLi(data,'小明','5G级包',20)
// 添加一条工单记录
function addTimeLi(objectDate,UserName, Type, Number) {
var DateTime = new Date()
// 判断今天的数据是否已经存在
var onDay = (DateTime.getMonth()+1) + '-' + DateTime.getDate()
for(var i=0;i<data.length;i++){
if(onDay === data[i].OnTime && data[i].OnType === Type){
console.log('今日的数据已经存在,不可添加')
return
}
}
objectDate.push({
OnTime: onDay,
OnUserName: UserName,
OnType: Type,
OnNumber: Number
})
return objectDate.length
}
console