You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

569 lines
20 KiB

<template>
<el-dialog v-model="dialogTableVisible" title="标签" width="1100">
<el-table
:data="showTableData()"
border
row-key="id"
style="width: 1050px; max-height: 70vh; overflow-y: auto"
9 months ago
v-if="tableData.length > 0 && dialogTableVisible == true"
v-loading="isLoading"
>
<el-table-column type="expand" width="50">
<template #default="scope">
<div
style="margin-left: 400px; margin-top: -8px; margin-bottom: -8px"
9 months ago
v-if="scope.row.packUnit && scope.row.packQty && scope.row.secondPackUnit && scope.row.secondPackQty"
>
<el-table
9 months ago
:data="scope.row.packageList"
border
style="width: 550px"
row-key="id"
:row-class-name="getRowClass"
>
<el-table-column type="expand" width="50">
<template #default="scope1">
<div style="margin-left: 150px; margin-top: -8px; margin-bottom: -8px">
10 months ago
<el-table :data="scope1.row.children" border style="width: 300px" row-key="id">
9 months ago
<el-table-column label="箱行号" width="100" prop="xPoNumber" align="center">
<template #default="scope2">
{{ scope2.$index + 1 }}
</template>
</el-table-column>
10 months ago
<el-table-column label="数量" width="100" prop="qtyTwo" align="center">
<template #default="scope2">
<el-input
10 months ago
v-model="scope2.row.qtyTwo"
@blur="blurTwo(scope.row, scope1.row, scope2.row)"
/>
</template>
</el-table-column>
<el-table-column label="添加箱" width="100" prop="add" align="center">
<template #header>
<el-button
type="primary"
link
10 months ago
@click="addX(scope.row, scope.$index, scope1.row, scope1.$index, 1)"
>添加箱</el-button
>
</template>
<template #default="scope2">
<el-button
type="warning"
link
@click="
removeX(
scope.row,
scope.$index,
scope1.row,
scope1.$index,
scope2.row,
scope2.$index,
1
)
"
>移出</el-button
>
</template>
</el-table-column>
</el-table>
</div>
</template>
9 months ago
</el-table-column>
9 months ago
<el-table-column label="托行号" width="100" prop="tPoNumber" align="center">
<template #default="scope">
{{ scope.$index + 1 }}
</template>
</el-table-column>
<el-table-column label="箱个数" width="100" prop="xNumber" align="center">
<template #default="scope1">
9 months ago
<el-input
v-model="scope1.row.xNumber"
@blur="blurOne(scope.row, scope1.row)"
onkeyup="value=value.replace(/\D/g,'')"
/>
</template>
</el-table-column>
10 months ago
<el-table-column label="数量" width="100" prop="qtyOne" align="center" />
<el-table-column label="操作" width="100" prop="action" align="center">
<template #default="scope1">
<el-button
type="warning"
link
@click="removeT(scope.row, scope.$index, scope1.row, scope1.$index)"
>移出</el-button
>
</template>
</el-table-column>
<el-table-column label="添加托" width="100" prop="add" align="center">
<template #header>
<el-button type="primary" link @click="addT(scope.row)">添加托</el-button>
</template>
</el-table-column>
</el-table>
</div>
9 months ago
<div style="margin-left: 550px; margin-top: -8px; margin-bottom: -8px" v-if="scope.row.packUnit && scope.row.packQty && !scope.row.secondPackUnit">
<div v-for="(item, index) in scope.row.packageList" :key="index">
<el-table :data="item.children" border style="width: 300px" row-key="id">
9 months ago
<el-table-column label="箱行号" width="100" prop="xPoNumber" align="center" > <template #default="scope1">
{{ scope1.$index + 1 }}
</template>
</el-table-column>
<el-table-column label="数量" width="100" prop="qtyOne" align="center">
<template #default="scope1">
<el-input
v-model="scope1.row.qtyTwo"
@blur="blurThree(scope.row, item, scope1.row)"
/>
</template>
</el-table-column>
<el-table-column label="添加箱" width="100" prop="add" align="center">
<template #header>
<el-button
type="primary"
link
@click="addX(scope.row, scope.$index, item, index)"
>添加箱</el-button
>
</template>
<template #default="scope1">
<el-button
type="warning"
link
@click="removeX(scope.row, scope.$index, item, index)"
>移出</el-button
>
</template>
</el-table-column>
</el-table>
</div>
9 months ago
</div>
</template>
</el-table-column>
<el-table-column label="物料代码" width="150" prop="itemCode" align="center" />
<el-table-column label="批次" width="150" prop="batch" align="center" />
9 months ago
<el-table-column label="数量" width="100" prop="qty" align="center" />
<el-table-column label="计量单位" width="100" prop="uom" align="center" />
9 months ago
<el-table-column label="托个数" width="100" prop="allTuoQty" align="center" />
<el-table-column label="托规格" width="100" prop="secondPackUnit" align="center" />
<el-table-column label="托数量" width="100" prop="secondPackQty" align="center" />
<el-table-column label="箱规格" width="100" prop="packUnit" align="center" />
<el-table-column label="箱数量" width="100" prop="packQty" align="center" />
</el-table>
<el-pagination
v-show="tableData.length > 10"
style="margin-top: 10px"
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:small="true"
:background="false"
layout="total, prev, pager, next, jumper"
:total="tableData.length"
/>
<template #footer>
<slot name="foorter"></slot>
<ButtonBase :Butttondata="Butttondata" @button-base-click="buttonBaseClick" />
</template>
</el-dialog>
</template>
<script setup lang="ts">
import * as defaultButtons from '@/utils/disposition/defaultButtons'
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
const props = defineProps({
// 列表 相关信息
tableAllSchemas: {
type: Array,
required: true,
default: null
}
})
const dialogTableVisible = ref(false)
9 months ago
const defaultExpandAll = ref(false)
const tableData = ref([])
const isLoading = ref(false)
const oneId = ref(0) //每托的id
const twoId = ref(0) //每箱的id
9 months ago
const openLabel = async (tableList) => {
dialogTableVisible.value = true
tableData.value = tableList
9 months ago
defaultExpandAll.value = false
await intData()
}
const currentPage = ref(1)
const pageSize = ref(10)
const showTableData = () => {
if (tableData.value.length > 10) {
return tableData.value.slice(
(currentPage.value - 1) * pageSize.value,
currentPage.value * pageSize.value
)
} else {
return tableData.value
}
}
9 months ago
const intData = async () => {
9 months ago
tableData.value.forEach((row) => {
9 months ago
expandChange(row)
9 months ago
})
}
const expandChange = (row: any, expandedRows: any[]) => {
9 months ago
// 判断托信息和箱信息是否都存在
if (row.secondPackUnit && row.secondPackQty&&row.packUnit && row.packQty) {
// 总共需要多少箱
row.allXiangQty = Math.ceil(parseFloat(row.qty) / parseFloat(row.packQty))
9 months ago
// 放满的多少箱
row.manXiangQty = Math.floor(parseFloat(row.qty) / parseFloat(row.packQty))
9 months ago
// 托数量/箱数量 一托可以放几箱
9 months ago
row.otherNumber = Math.floor(parseFloat(row.secondPackQty) / parseFloat(row.packQty))
// 数量%托数量 获取总共几托
row.allTuoQty = Math.ceil(parseFloat(row.allXiangQty) / parseFloat(row.otherNumber))
9 months ago
// 放满的托数量
row.manTuoQty = Math.floor(parseFloat(row.manXiangQty) / parseFloat(row.otherNumber))
// 放满的托数量*一托的箱数量*一箱的数量 获取放满的托一共多少数量
row.tuoInManNumber =
parseFloat(row.manTuoQty) * parseFloat(row.otherNumber) * parseFloat(row.packQty)
// 数量除以托数量获取余数
row.lastNumber =
parseFloat(row.qty) > parseFloat(row.tuoInManNumber)
? parseFloat(row.qty) - parseFloat(row.tuoInManNumber)
: parseFloat(row.qty)
9 months ago
// 循环托
9 months ago
row.packageList =[]
9 months ago
for (let i = 0; i < row.allTuoQty; i++) {
oneId.value++
// 先给所有托一个默认对象值
9 months ago
row.packageList[i] = {
9 months ago
id: oneId.value,
9 months ago
// tPoNumber: i + 1,
9 months ago
xNumber: '',
9 months ago
qtyOne: '',
isTuo: 1 //有托
9 months ago
}
9 months ago
9 months ago
// 如果有余数
if (row.lastNumber) {
// 最后一条信息直接展示余数的信息
if (i == row.allTuoQty - 1) {
9 months ago
row.packageList[i].xNumber = Math.ceil(row.lastNumber / parseFloat(row.packQty))
row.packageList[i].qtyOne = row.lastNumber
9 months ago
} else {
// 其他数据展示一托的全部箱数和全部数量
9 months ago
row.packageList[i].xNumber = row.otherNumber
9 months ago
row.packageList[i].qtyOne = parseFloat(row.otherNumber) * parseFloat(row.packQty)
9 months ago
}
} else {
// 如果沒有余数,直接展示一托的全部箱数和全部数量
9 months ago
row.packageList[i].xNumber = row.otherNumber
row.packageList[i].qtyOne = parseFloat(row.otherNumber) * parseFloat(row.packQty)
9 months ago
}
}
// 判断箱信息是否存在
if (row.packUnit && row.packQty) {
9 months ago
row.packageList.forEach((cur, key) => {
9 months ago
cur.children = []
// 数量除以箱数量获取余数
cur.xLastNumber = parseFloat(cur.qtyOne) % parseFloat(row.packQty)
// cur.xiangNumber = Math.ceil(parseFloat(cur.qtyOne) / parseFloat(item.secondPackQty))
for (let j = 0; j < cur.xNumber; j++) {
9 months ago
twoId.value++
cur.children[j] = {
9 months ago
id: twoId.value,
9 months ago
// xPoNumber: j + 1
9 months ago
}
// 如果有余数
if (cur.xLastNumber) {
// 最后一条信息直接展示余数的信息
if (j == cur.xNumber - 1) {
cur.children[j].qtyTwo = cur.xLastNumber
9 months ago
} else {
// 其他数据展示一托的全部箱数和全部数量
cur.children[j].qtyTwo = row.packQty
9 months ago
}
} else {
// 如果沒有余数,直接展示一托的全部箱数和全部数量
cur.children[j].qtyTwo = row.packQty
9 months ago
}
}
})
}
9 months ago
}
// 只有箱规格
if(!row.secondPackUnit && row.packUnit && row.packQty){
9 months ago
// 数量%每箱数量 获取总共几箱
row.allXiangQty = Math.ceil(parseFloat(row.qty) / parseFloat(row.packQty))
9 months ago
row.packageList = []
9 months ago
row.allTuoQty = ''
row.allTuoQty1 = 1
9 months ago
// 循环箱
9 months ago
for (let i = 0; i < row.allTuoQty1; i++) {
9 months ago
oneId.value++
// 先给所有托一个默认对象值
9 months ago
row.packageList[i] = {
9 months ago
id: oneId.value,
9 months ago
// xPoNumber: i + 1,
qtyOne: row.qty,
isTuo: 0 //无托
9 months ago
}
}
row.packageList.forEach((cur) => {
cur.children = []
for (let j = 0; j < row.allXiangQty; j++) {
twoId.value++
cur.children[j] = {
id: twoId.value,
9 months ago
// xPoNumber: j + 1
}
// 数量除以箱数量获取余数
cur.lastNumber = parseFloat(row.qty) % parseFloat(row.packQty)
// 如果有余数
if (cur.lastNumber) {
// 最后一条信息直接展示余数的信息
if (j == row.allXiangQty - 1) {
cur.children[j].qtyTwo = cur.lastNumber
} else {
// 其他数据展示一托的全部箱数和全部数量
cur.children[j].qtyTwo = row.packQty
}
9 months ago
} else {
// 如果沒有余数,直接展示一托的全部箱数和全部数量
cur.children[j].qtyTwo = row.packQty
9 months ago
}
}
})
9 months ago
}
}
10 months ago
/** 弹窗按钮 */
let Butttondata: any = []
Butttondata = [
defaultButtons.formSaveBtn(null), // 保存
defaultButtons.formCloseBtn(null) // 关闭
]
/** 按钮事件 */
const buttonBaseClick = (val) => {
// 保存
if (val == 'save') {
submitForm()
}
// 关闭
else if (val == 'close') {
dialogTableVisible.value = false
}
}
10 months ago
// 保存
const submitForm = () => {
9 months ago
let isZ = false
console.log(tableData.value)
setTimeout(() => {
tableData.value.forEach((item) => {
item.packageList.forEach((cur, key) => {
cur.tPoNumber = key + 1
if (cur.qtyOne == '' || cur.qtyOne == 0) {
isZ = true
}
cur?.children?.forEach((ele,i) => {
ele.xPoNumber = i+1
if (ele.qtyTwo == '' || ele.qtyTwo == 0) {
isZ = true
}
})
})
10 months ago
})
9 months ago
if (isZ) {
message.warning('有数量为0或空,请重新填写')
return
10 months ago
}
9 months ago
let obj = tableData.value.find((item) => {
item.allNumber = 0
item.packageList.forEach((cur) => {
item.allNumber += parseFloat(cur.qtyOne) || 0
})
return item.allNumber != parseFloat(item.qty)
})
console.log(222, obj)
// return
// const isBol = arr.some((item) => item == false)
if (obj) {
message.warning(
`物料【${obj.itemCode}】,批次【${obj.batch}】,${obj.packageList.length}托的总和数量【${obj.allNumber}】不等于发货总数量【${obj.qty}`
9 months ago
)
return
}
emit('submitForm', tableData.value)
}, 300)
10 months ago
}
// 添加托
const addT = (oneRow) => {
oneId.value++
9 months ago
oneRow.packageList.push({
id: oneId.value,
9 months ago
// tPoNumber:oneRow.packageList.length+1 || 1,
// tPoNumber:
// oneRow?.packageList?.length > 0
// ? oneRow.packageList[oneRow.packageList.length - 1]?.tPoNumber + 1
// : 1, //行号是上一行的行号加1
xNumber: '',
9 months ago
qtyOne: '',
isTuo: 1 //有托
})
9 months ago
oneRow.allTuoQty = oneRow.packageList.length
}
// 移出托
const removeT = (oneRow, oneIndex, twoRow, twoIndex) => {
9 months ago
oneRow.packageList.splice(twoIndex, 1)
oneRow.allTuoQty = oneRow.packageList.length
}
10 months ago
// 添加箱
const addX = (oneRow, oneIndex, twoRow, twoIndex, type) => {
twoId.value++
// 有父级托的时候
if (type == 1) {
// 在托下添加箱
twoRow.children.push({
10 months ago
id: twoId.value,
9 months ago
// xPoNumber:
// twoRow?.children?.length > 0
// ? twoRow?.children[twoRow.children.length - 1]?.xPoNumber + 1
// : 1,
qtyTwo: oneRow.packQty
10 months ago
})
twoRow.xNumber = twoRow.children.length
9 months ago
let num = 0
twoRow.children.forEach((item) => {
num += parseFloat(item.qtyTwo) || 0
})
twoRow.qtyOne = num
10 months ago
} else {
// 直接添加箱
9 months ago
oneRow.isTuo= 1 //无托
twoRow.children.push({
id: twoId.value,
9 months ago
// xPoNumber:
// twoRow.children.length > 0 ? twoRow.children[twoRow.children.length - 1].xPoNumber + 1 : 1,
// qtyTwo: oneRow.packQty
10 months ago
})
oneRow.allTuoQty = twoRow.children.length
}
}
10 months ago
// 移除箱
const removeX = (oneRow, oneIndex, twoRow, twoIndex, threeRow, threeIndex, type) => {
// 有父级托的时候
if (type == 1) {
// 在托下移除箱
twoRow.children.splice(threeIndex, 1)
let num = 0
twoRow.children.forEach((item) => {
10 months ago
num += parseFloat(item.qtyTwo) || 0
})
10 months ago
twoRow.qtyOne = num
twoRow.xNumber = twoRow.children.length
10 months ago
} else {
twoRow.children.splice(twoIndex, 1)
oneRow.allTuoQty = twoRow.children.length
}
}
10 months ago
// 是否显示展开图标
const getRowClass = (row) => {
if (!row.row.children || row.row.children.length == 0) {
return 'row-expand-cover'
}
}
10 months ago
// 托失去焦点
const blurOne = (oneRow, twoRow) => {
9 months ago
if (!twoRow.xNumber) {
twoRow.qtyOne = ''
}
// if (parseFloat(twoRow.xNumber) > parseFloat(oneRow.otherNumber)) {
// message.warning('每托箱个数最多' + oneRow.otherNumber + '箱')
// twoRow.xNumber = oneRow.otherNumber
// twoRow.children = []
// twoRow.qtyOne = parseFloat(twoRow.xNumber) * parseFloat(oneRow.packQty)
// }
9 months ago
twoRow.qtyOne = parseFloat(twoRow.xNumber) * parseFloat(oneRow.packQty)
// let num = 0
// oneRow.packageList.forEach((item) => {
// num += parseFloat(item.xNumber) || 0
// })
// if (num > oneRow.allPackQty) {
// message.warning('总箱数不可以大于' + oneRow.allPackQty)
// twoRow.xNumber = ''
// twoRow.qtyOne = ''
// return
// }
10 months ago
// 托信息修改的時候箱数据自动排列
// 判断箱信息是否存在
9 months ago
if (oneRow.packUnit && oneRow.packQty) {
// oneRow.packageList.forEach((cur, key) => {
9 months ago
twoRow.children = []
// 数量除以托数量获取余数
twoRow.xLastNumber = parseFloat(twoRow.xNumber) % parseFloat(oneRow.packQty)
for (let j = 0; j < twoRow.xNumber; j++) {
twoId.value++
// 如果有余数
if (twoRow.xLastNumber) {
// 最后一条信息直接展示余数的信息
if (j == twoRow.xNumbery - 1) {
twoRow.children.push({
id: twoId.value,
// xPoNumber: j + 1,
qtyTwo: twoRow.xLastNumber
})
10 months ago
} else {
9 months ago
// 其他数据展示一托的全部箱数和全部数量
twoRow.children.push({
10 months ago
id: twoId.value,
9 months ago
// xPoNumber: j + 1,
9 months ago
qtyTwo: oneRow.packQty
10 months ago
})
}
9 months ago
} else {
// 如果沒有余数,直接展示一托的全部箱数和全部数量
twoRow.children.push({
id: twoId.value,
// xPoNumber: j + 1,
qtyTwo: oneRow.packQty
})
}
9 months ago
}
// })
10 months ago
}
}
10 months ago
//在托下方的箱数量失去焦点
const blurTwo = (oneRow, twoRow, threeRow) => {
// if (parseFloat(threeRow.qtyTwo) > parseFloat(oneRow.packQty)) {
// message.warning('数量最多为' + oneRow.packQty)
// threeRow.qtyTwo = oneRow.packQty
// return
// }
let num = 0
twoRow.children.forEach((item) => {
10 months ago
num += parseFloat(item.qtyTwo) || 0
})
10 months ago
twoRow.qtyOne = num
}
10 months ago
// 箱数量失去焦点
const blurThree = (oneRow, twoRow, thereeRow) => {
// if (parseFloat(thereeRow.qtyTwo) > parseFloat(oneRow.packQty)) {
// message.warning('每箱个数最多' + oneRow.packQty)
// thereeRow.qtyTwo = oneRow.packQty
// }
let num = 0
twoRow.children.forEach((item) => {
num += parseFloat(item.qtyTwo) || 0
})
twoRow.qtyOne = num
}
9 months ago
// 传递给父类
const emit = defineEmits(['submitForm'])
defineExpose({ openLabel, dialogTableVisible, isLoading }) // 提供 open 方法,用于打开弹窗
</script>
<style lang="scss" scoped>
::v-deep .row-expand-cover td .el-table__expand-icon {
visibility: hidden;
}
</style>