This commit is contained in:
zjf committed 2025-08-04 15:48:29 +08:00
commit de4edb8f86
1 file changed
+38 -4
@@ -81,6 +81,7 @@
border
:loading="loading"
show-overflow
show-footer
max-height="410"
:edit-config="{
trigger: 'click',
@@ -99,13 +100,14 @@
:resizable-config="{ dragMode: 'fixed' }"
:data="vxeTableData"
:edit-rules="validRules"
:footer-data="footerData"
@checkbox-all=""
@checkbox-change=""
size="mini"
align="center"
>
<vxe-column type="checkbox" width="40" fixed="left" />
<vxe-column type="seq" width="50" fixed="left" />
<vxe-column field="seq" type="seq" width="50" fixed="left" />
<vxe-column field="productName" title="库存商品">
<template #default="{ row }">
<span v-if="row.productName">{{ row.productName }}</span>
@@ -167,7 +169,13 @@
</span> -->
</template>
<template #edit="{ row }">
<el-input-number v-if="row.selectedUnitObj" v-model="row.selectedUnitObj.totalAmount" :min="0" :precision="2" />
<el-input-number
v-if="row.selectedUnitObj"
v-model="row.selectedUnitObj.totalAmount"
:min="0"
:precision="2"
@change="updateFootEvent"
/>
</template>
</vxe-column>
<vxe-column field="remark" title="备注" :edit-render="{ autoFocus: 'input', placeholder: '请输入' }">
@@ -249,6 +257,7 @@ const baseDataForm = reactive<any>({
})
const vxeTableData = ref<any>([])
const erpSpuSimpleAll = ref<any>([])
const footerData = ref([{ seq: "合计", totalAmount: "0" }])
// 基本信息表单校验规则
const dataRules = ref({
@@ -263,8 +272,9 @@ const validRules = ref<VxeTablePropTypes.EditRules<any>>({
quantity: [{ required: true, type: "number", min: 1, message: "必需大于等于0" }],
})
onMounted(() => {
getInitData()
onMounted(async () => {
await getInitData()
updateFootCount(vxeTableData.value)
})
// 初始化数据
@@ -361,6 +371,8 @@ const getSelectedRows = (selectionRows: any) => {
// vxeTableData.value = vxeTableData.value.filter(
// (item: any) => !removedItems.some((removeItem: any) => removeItem.erpSpuId === item.erpSpuId),
// )
updateFootCount(vxeTableData.value)
console.log("vxeTableData.value", vxeTableData.value)
}
@@ -371,6 +383,7 @@ const removeRow = () => {
const selectRecords = $table.getCheckboxRecords()
if (selectRecords.length > 0) {
vxeTableData.value = vxeTableData.value.filter((item: any) => !selectRecords.some((row) => row.erpSpuId === item.erpSpuId))
updateFootEvent()
}
}
}
@@ -378,6 +391,27 @@ const removeRow = () => {
// 重新计算累计总金额
const reComputeTotalAmount = (row: any, index: number) => {
vxeTableData.value[index].selectedUnitObj.totalAmount = Number((row.quantity * parseFloat(row.selectedUnitObj.realPrice || 0)).toFixed(2))
updateFootEvent()
}
// 更新尾行合计
const updateFootEvent = () => {
const $table = vxeTableRef.value
if ($table) {
const fullData = $table.getFullData()
updateFootCount(fullData)
}
}
const updateFootCount = (list: any[]) => {
const [sumNObj] = footerData.value
sumNObj.totalAmount = sumNum(list, "totalAmount")
}
const sumNum = (list: any[], field: string) => {
let count = 0
list.forEach((item) => {
count += Number(item.selectedUnitObj[field])
})
return count.toFixed(2)
}
// 整理table数据