From d42363cc83fc811e5ba9812a9825201064eeb25b Mon Sep 17 00:00:00 2001 From: qb <1191961160@qq.com> Date: Thu, 21 Dec 2023 14:22:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=88=E8=AE=A1=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/tablecmt/tablecmt.vue | 51 ++++++++++++++++------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/components/tablecmt/tablecmt.vue b/src/components/tablecmt/tablecmt.vue index 78c6a1df..5088e19d 100644 --- a/src/components/tablecmt/tablecmt.vue +++ b/src/components/tablecmt/tablecmt.vue @@ -338,20 +338,20 @@ const isHaveSelection = ref(false); let selectarr = ref([]); /** 设置每行颜色 */ const tableRowClassName = ({ row, rowIndex }: { row: TableDataType; rowIndex: number }) => { - let sfcheck = false; - selectarr.value.forEach((val, index) => { - if (val == row) { - sfcheck = true; + // let sfcheck = false; + let item = ''; + + for (let value of selectarr.value) { + if (value == row) { + item = value; + break; } + } - selectCount.value.forEach(item => { - if (index === 0) item.value = 0; - item.value = computeNumber(item.value, '+', Number(val[item.prop] || 0)).result; - }); - }); - if (sfcheck) { + if (item) { return 'table-SelectedRow-bgcolor'; } + if (props.tableRowClassName) return props.tableRowClassName(row, rowIndex); return ''; @@ -483,19 +483,26 @@ function timechange(value, column: TableColumnType) { emit('timeCheck', value, column); } const handleSelectionChange = (param: TableDataType[]) => { - // 重置数据 - // selectCount.value.forEach(item => { - // item.value = 0; - // }); - selectarr.value = param; - // selectarr.value.forEach((val, index) => { - // selectCount.value.forEach(item => { - // if (index === 0) item.value = 0; - // item.value = computeNumber(item.value, '+', Number(val[item.prop] || 0)).result; - // }); - // }); - emit('selection', param); + try { + // 重置数据 + for (const iterator of selectCount.value) { + iterator.value = 0; + } + + for (let index = 0; index < selectarr.value.length; index++) { + const val = selectarr.value[index]; + + for (let item of selectCount.value) { + if (index === 0) item.value = 0; + item.value = computeNumber(item.value, '+', Number(val[item.prop] || 0)).result; + } + } + } catch (error) { + console.log('error :>> ', error); + } finally { + emit('selection', param); + } }; function inputclear(value, column: TableColumnType) { emit('inputTxt', '', column);