@@ -65,18 +65,44 @@
< right-toolbar :showSearch.sync = "showSearch" @queryTable ="getList" > < / right -toolbar >
< / el-row >
<!-- 修改 : 统计组件扩展为6列 , 展示有效 / 无效的6项统计 -- >
< el-descriptions size = "small" border class = "mb8" :column = "3 ">
< el-descriptions-item label = "堂食人数" > { { validDineIn + invalidDineIn } } < / el-descriptions-item >
< el-descriptions-item label = "打包人数" > { { validTakeout + invalidTakeout } } < / el-descriptions-item >
< el-descriptions-item label = "总人数" > { { validTotal + invalidTotal } } < / el-descriptions-item >
< el-descriptions-item label = "有效堂食人数" > { { validDineIn } } < / el-descriptions-item >
< el-descriptions-item label = "有效打包人数" > { { validTakeout } } < / el-descriptions-item >
< el-descriptions-item label = "有效总人数" > { { validTotal } } < / el-descriptions-item >
< el-descriptions-item label = "无效堂食人数" > { { invalidDineIn } } < / el-descriptions-item >
< el-descriptions-item label = "无效打包人数" > { { invalidTakeout } } < / el-descriptions-item >
< el-descriptions-item label = "无效总人数" > { { invalidTotal } } < / el-descriptions-item >
< / el-descriptions >
<!-- 三维交叉统计矩阵表 -- >
< div class = "stats-matrix mb8 ">
< table c lass = "matrix-table" >
< thead >
< tr >
< th rowspan = "2" class = "label-col" > < / th >
< th colspan = "3" class = "group-header group-valid" > 有效 < / th >
< th colspan = "3" class = "group-header group-invalid" > 无效 < / th >
< th colspan = "3" c lass = "group-header group-all" > 合计 < / th >
< / tr >
< tr >
< th > 堂食 < / th > < th > 打包 < / th > < th > 小计 < / th >
< th > 堂食 < / th > < th > 打包 < / th > < th > 小计 < / th >
< th > 堂食 < / th > < th > 打包 < / th > < th > 小计 < / th >
< / tr >
< / thead >
< tbody >
< tr >
< td class = "label-col" > 吃辣 < / td >
< td > { { matrix . spicy . validDine } } < / td > < td > { { matrix . spicy . validTake } } < / td > < td class = "subtotal" > { { matrix . spicy . validTotal } } < / td >
< td > { { matrix . spicy . invalidDine } } < / td > < td > { { matrix . spicy . invalidTake } } < / td > < td class = "subtotal" > { { matrix . spicy . invalidTotal } } < / td >
< td > { { matrix . spicy . dine } } < / td > < td > { { matrix . spicy . take } } < / td > < td class = "subtotal" > { { matrix . spicy . total } } < / td >
< / tr >
< tr >
< td class = "label-col" > 不吃辣 < / td >
< td > { { matrix . nonSpicy . validDine } } < / td > < td > { { matrix . nonSpicy . validTake } } < / td > < td class = "subtotal" > { { matrix . nonSpicy . validTotal } } < / td >
< td > { { matrix . nonSpicy . invalidDine } } < / td > < td > { { matrix . nonSpicy . invalidTake } } < / td > < td class = "subtotal" > { { matrix . nonSpicy . invalidTotal } } < / td >
< td > { { matrix . nonSpicy . dine } } < / td > < td > { { matrix . nonSpicy . take } } < / td > < td class = "subtotal" > { { matrix . nonSpicy . total } } < / td >
< / tr >
< tr class = "total-row" >
< td class = "label-col" > 合计 < / td >
< td > { { matrix . all . validDine } } < / td > < td > { { matrix . all . validTake } } < / td > < td class = "subtotal" > { { matrix . all . validTotal } } < / td >
< td > { { matrix . all . invalidDine } } < / td > < td > { { matrix . all . invalidTake } } < / td > < td class = "subtotal" > { { matrix . all . invalidTotal } } < / td >
< td > { { matrix . all . dine } } < / td > < td > { { matrix . all . take } } < / td > < td class = "subtotal" > { { matrix . all . total } } < / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- 修改 : 添加行样式判断 , 为无效报餐行加背景色 -- >
< el-table
@@ -196,6 +222,7 @@
< script >
import { listMealReport , getMealReport , delMealReport , addMealReport , updateMealReport } from "@/api/wms/mealReport" ;
import { listEmployeeInfo } from "@/api/wms/employeeInfo" ;
import DictSelect from "@/components/DictSelect" ;
import EmployeeSelector from "@/components/EmployeeSelector" ;
import { listDept } from "@/api/wms/dept"
@@ -254,13 +281,13 @@ export default {
updateTime : undefined ,
remark : undefined
} ,
// 替换原有统计变量, 新增6个有效/无效统计项
validDineIn : 0 , // 有效堂食人数
validTakeout : 0 , // 有效打包人数
validTotal : 0 , // 有效总人数
invalidDineIn : 0 , // 无效堂食人数
invalidTakeout : 0 , // 无效打包人数
invalidTotal : 0 , // 无效总人数
// 三维交叉统计矩阵
matrix : {
spicy : { validDine : 0 , validTake : 0 , validTotal : 0 , invalidDine : 0 , invalidTake : 0 , invalidTotal : 0 , dine : 0 , take : 0 , total : 0 } ,
nonSpicy : { validDine : 0 , validTake : 0 , validTotal : 0 , invalidDine : 0 , invalidTake : 0 , invalidTotal : 0 , dine : 0 , take : 0 , total : 0 } ,
all : { validDine : 0 , validTake : 0 , validTotal : 0 , invalidDine : 0 , invalidTake : 0 , invalidTotal : 0 , dine : 0 , take : 0 , total : 0 }
} ,
employeeSpicyMap : { } ,
// 表单校验规则
rules : {
reportDate : [ { required : true , message : '用餐日期不能为空' , trigger : 'change' } ] ,
@@ -278,6 +305,7 @@ export default {
this . getList ( ) ;
this . getDeptList ( ) ;
this . getDeadlineConfig ( ) ;
this . buildEmployeeMap ( ) ;
} ,
watch : {
'form.dineInPeople' : {
@@ -324,37 +352,78 @@ export default {
this . form . takeoutPeople = val ? . length || 0 ;
this . calcTotalPeople ( ) ;
} ,
/** 核心修改:区分有效/无效统计 */
/** 构建员工吃辣偏好映射( name -> isSpicyEater) */
buildEmployeeMap ( ) {
listEmployeeInfo ( { pageNum : 1 , pageSize : 9999 } ) . then ( response => {
const map = { } ;
( response . rows || [ ] ) . forEach ( emp => {
if ( emp . name && emp . isLeave !== 1 && emp . isSpicyEater !== undefined && emp . isSpicyEater !== null ) {
map [ emp . name ] = emp . isSpicyEater == 1 ? 1 : 0 ;
}
} ) ;
this . employeeSpicyMap = map ;
this . calcTableSum ( ) ;
} ) ;
} ,
/** 根据人员名单统计不吃辣人数 */
countNonSpicy ( nameList ) {
if ( ! nameList ) return 0 ;
const names = nameList . split ( ',' ) . map ( n => n . trim ( ) ) . filter ( n => n ) ;
let count = 0 ;
const counted = { } ;
names . forEach ( name => {
if ( ! counted [ name ] && this . employeeSpicyMap [ name ] === 0 ) {
count ++ ;
counted [ name ] = true ;
}
} ) ;
return count ;
} ,
/** 三维交叉统计:吃辣/不吃辣 × 堂食/打包 × 有效/无效 */
calcTableSum ( ) {
// 初始化统计变量
let validDine = 0 , validTake = 0 , validAll = 0 ;
let invalidDine = 0 , invalidTake = 0 , invalidAll = 0 ;
const m = {
spicy : { validDine : 0 , validTake : 0 , validTotal : 0 , in validDine: 0 , in validTake: 0 , in validTotal : 0 , dine : 0 , take : 0 , total : 0 } ,
nonSpicy : { validDine : 0 , validTake : 0 , validTotal : 0 , invalidDine : 0 , invalidTake : 0 , invalidTotal : 0 , dine : 0 , take : 0 , total : 0 } ,
all : { validDine : 0 , validTake : 0 , validTotal : 0 , invalidDine : 0 , invalidTake : 0 , invalidTotal : 0 , dine : 0 , take : 0 , total : 0 }
} ;
this . mealReportList . forEach ( item => {
// 处理空值,转为数字
const dine = item . dineInPeople ? Number ( item . dineInPeople ) : 0 ;
const take = item . takeoutPeople ? Number ( item . takeoutPeople ) : 0 ;
const total = item . totalPeople ? Number ( item . totalPeople ) : 0 ;
// 判断当前报餐是否有效
if ( this . isValidMealReport ( item . createTime ) ) {
valid Dine + = dine ;
valid Take + = take ;
validAll += total ;
} else {
invalidDine += dine ;
invalidTake += take ;
invalidAll += total ;
}
const nonSpicyDine = this . countNonSpicy ( item . dineInPeopleList ) ;
const nonSpicyTake = this . countNonSpicy ( item . takeoutPeopleList ) ;
const spicy Dine = dine - nonSpicyDine ;
const spicy Take = take - nonSpicyTake ;
const nonSpicyTotal = nonSpicyDine + nonSpicyTake ;
const spicyTotal = spicyDine + spicyTake ;
const v = this . isValidMealReport ( item . createTime ) ? 'valid' : 'invalid' ;
m . spicy [ v + 'Dine' ] += spicyDine ;
m . spicy [ v + 'Take' ] += spicyTake ;
m . spicy [ v + 'Total' ] += spicyTotal ;
m . spicy . dine += spicyDine ;
m . spicy . take += spicyTake ;
m . spicy . total += spicyTotal ;
m . nonSpicy [ v + 'Dine' ] += nonSpicyDine ;
m . nonSpicy [ v + 'Take' ] += nonSpicyTake ;
m . nonSpicy [ v + 'Total' ] += nonSpicyTotal ;
m . nonSpicy . dine += nonSpicyDine ;
m . nonSpicy . take += nonSpicyTake ;
m . nonSpicy . total += nonSpicyTotal ;
m . all [ v + 'Dine' ] += dine ;
m . all [ v + 'Take' ] += take ;
m . all [ v + 'Total' ] += total ;
m . all . dine += dine ;
m . all . take += take ;
m . all . total += total ;
} ) ;
// 赋值到统计变量
this . validDineIn = validDine ;
this . validTakeout = validTake ;
this . validTotal = validAll ;
this . invalidDineIn = invalidDine ;
this . invalidTakeout = invalidTake ;
this . invalidTotal = invalidAll ;
this . matrix = m ;
} ,
/** 新增:判断报餐是否有效(仅比较时分秒) */
isValidMealReport ( createTime ) {
@@ -504,12 +573,69 @@ export default {
< / script >
< style scoped >
/* 新增: 无效报餐行样式 */
/* 无效报餐行样式 */
. invalid - meal - row {
background - color : # fff0f0 ! important ; /* 浅红色背景,可根据需求调整 */
background - color : # fff0f0 ! important ;
}
/* 优化表格行hover样式 */
: : v - deep . el - table . invalid - meal - row : hover > td {
background - color : # ffe0e0 ! important ;
}
/* 三维交叉统计矩阵表 */
. matrix - table {
width : 100 % ;
border - collapse : collapse ;
font - size : 13 px ;
border : 1 px solid # EBEEF5 ;
}
. matrix - table th ,
. matrix - table td {
padding : 8 px 6 px ;
text - align : center ;
border : 1 px solid # EBEEF5 ;
min - width : 52 px ;
}
. matrix - table th {
background - color : # F5F7FA ;
color : # 909399 ;
font - weight : 500 ;
}
. matrix - table . label - col {
background - color : # F5F7FA ;
color : # 909399 ;
font - weight : 500 ;
text - align : center ;
min - width : 60 px ;
}
. matrix - table . group - header {
font - weight : 600 ;
color : # 303133 ;
}
. matrix - table . group - valid {
background - color : # F0F9EB ;
color : # 67 C23A ;
}
. matrix - table . group - invalid {
background - color : # FEF0F0 ;
color : # F56C6C ;
}
. matrix - table . group - all {
background - color : # ECF5FF ;
color : # 409 EFF ;
}
. matrix - table . subtotal {
font - weight : 600 ;
color : # 303133 ;
background - color : # FAFAFA ;
}
. matrix - table . total - row td {
font - weight : 700 ;
border - top : 2 px solid # DCDFE6 ;
}
. matrix - table . total - row . label - col {
font - weight : 700 ;
}
. matrix - table . total - row . subtotal {
font - weight : 700 ;
}
< / style >