|
@@ -336,6 +336,13 @@
|
|
|
<el-form class="-mb-15px" ref="queryFormRef" :inline="true" label-width="68px">
|
|
|
<el-form-item>
|
|
|
<el-button type="danger" @click="openMaterialForm()">
|
|
|
+ <Icon icon="ep:plus" class="mr-5px" />
|
|
|
+ {{ t('iotMaintain.selectMaterials') }}
|
|
|
+ </el-button>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="success" @click="addMaterial()">
|
|
|
+ <Icon icon="ep:plus" class="mr-5px" />
|
|
|
{{ t('iotMaintain.selectMaterials') }}
|
|
|
</el-button>
|
|
|
</el-form-item>
|
|
@@ -351,14 +358,25 @@
|
|
|
<el-table-column prop="materialCode" :label="t('workOrderMaterial.materialCode')" width="180" />
|
|
|
<el-table-column prop="unit" :label="t('workOrderMaterial.unit')" width="180" />
|
|
|
<el-table-column prop="unitPrice" :label="t('workOrderMaterial.unitPrice')" width="180" />
|
|
|
- <el-table-column prop="quantity" :label="t('workOrderMaterial.ConsumptionQuantity')" width="180" />
|
|
|
+ <el-table-column prop="quantity" :label="t('workOrderMaterial.ConsumptionQuantity')" width="180" >
|
|
|
+ <template #default="scope">
|
|
|
+ <el-input
|
|
|
+ type="number"
|
|
|
+ :controls="false"
|
|
|
+ v-model="scope.row.quantity"
|
|
|
+ @click.stop=""
|
|
|
+ @blur="(event) => handleQuantityBlur(event, scope.row)"
|
|
|
+ size="small"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
<el-table-column prop="materialSource" :label="t('bomList.type')" width="180" />
|
|
|
<el-table-column :label="t('workplace.operation')" align="right" v-if="true">
|
|
|
<template #default="scope">
|
|
|
<el-button
|
|
|
size="small"
|
|
|
type="danger"
|
|
|
- @click="handleDelete(scope.row)"
|
|
|
+ @click="materialDelete(scope.row)"
|
|
|
>{{ t('form.delete') }}</el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
@@ -491,13 +509,53 @@ const formRules = reactive({
|
|
|
// status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
|
|
|
})
|
|
|
const handleIfNeedChange = (row) =>{
|
|
|
- debugger
|
|
|
if (row.ifNeed) {
|
|
|
materialIfShow.value = true
|
|
|
} else {
|
|
|
materialIfShow.value = false
|
|
|
+ //关闭的同时清除该维修项的物料
|
|
|
+ debugger
|
|
|
+ materialList.value = materialList.value.filter(item => item.bomNodeId !== row.bomNodeId);
|
|
|
+ const targetItem = list.value.find(item => item.bomNodeId === row.bomNodeId);
|
|
|
+ if (targetItem) {
|
|
|
+ targetItem.materialCount = 0;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+const addMaterial = () =>{
|
|
|
+ // 向数组末尾添加新对象
|
|
|
+ filteredMaterials.value.push({
|
|
|
+ id: null,
|
|
|
+ factory: '',
|
|
|
+ costCenter: null,
|
|
|
+ projectDepartment: null,
|
|
|
+ materialName: null,
|
|
|
+ materialName:null
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+const handleQuantityBlur = (event: Event, row: any) => {
|
|
|
+ const inputValue = (event.target as HTMLInputElement).value;
|
|
|
+ let num = parseFloat(inputValue);
|
|
|
+ // 处理无效值
|
|
|
+ if (isNaN(num)) {
|
|
|
+ row.quantity = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 处理小于等于0的情况
|
|
|
+ if (num <= 0) {
|
|
|
+ row.quantity = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ totalFee.value = 0
|
|
|
+ // 保留两位小数
|
|
|
+ row.quantity = parseFloat(num.toFixed(4));
|
|
|
+ materialList.value.forEach((it) => {
|
|
|
+ totalFee.value = it.unitPrice * it.quantity + totalFee.value
|
|
|
+ })
|
|
|
+ formData.value.maintainFee = totalFee.value
|
|
|
+};
|
|
|
// 行点击事件处理函数
|
|
|
const handleRowClick = (row: any) => {
|
|
|
if (selectedRowId.value === row.bomNodeId) {
|
|
@@ -513,8 +571,9 @@ const handleRowClick = (row: any) => {
|
|
|
debugger
|
|
|
if (selectedRow.value === null) {
|
|
|
filteredMaterials.value = materialList.value;
|
|
|
+ } else {
|
|
|
+ filteredMaterials.value = materialList.value.filter((item) => item.bomNodeId === row.bomNodeId)
|
|
|
}
|
|
|
- filteredMaterials.value = materialList.value.filter((item) => item.bomNodeId === row.bomNodeId)
|
|
|
if (row.ifNeed) {
|
|
|
materialIfShow.value = true
|
|
|
} else {
|
|
@@ -662,15 +721,19 @@ const handleViewNew = (nodeId) => {
|
|
|
const materialDelete = (row) =>{
|
|
|
totalFee.value = 0
|
|
|
const index = materialList.value.findIndex((item) => item.bomNodeId === bomNodeId.value&&item.materialCode===row.materialCode)
|
|
|
+ const filterIndex = filteredMaterials.value.findIndex((item) => item.bomNodeId === bomNodeId.value&&item.materialCode===row.materialCode)
|
|
|
if (index>-1) {
|
|
|
materialList.value.splice(index,1)
|
|
|
}
|
|
|
+ if (filterIndex > -1) {
|
|
|
+ filteredMaterials.value.splice(filterIndex, 1)
|
|
|
+ }
|
|
|
list.value.forEach((item)=>{
|
|
|
if (item.bomNodeId === row.bomNodeId){
|
|
|
item.materials = materialList.value.filter((item)=>item.bomNodeId===row.bomNodeId)
|
|
|
- item.materialCount = item.materials.length;
|
|
|
- }
|
|
|
- })
|
|
|
+ item.materialCount = item.materials.length;
|
|
|
+ }
|
|
|
+ })
|
|
|
|
|
|
materialList.value.forEach((it) => {
|
|
|
totalFee.value = it.unitPrice * it.quantity + totalFee.value
|
|
@@ -724,6 +787,8 @@ const maintainChoose = (formData) => {
|
|
|
item.ifNeed= true
|
|
|
list.value.push(item)
|
|
|
if (item.deviceBomMaterials) {
|
|
|
+ item.materialCount = item.deviceBomMaterials.length
|
|
|
+ item.materials = item.deviceBomMaterials;
|
|
|
item.deviceBomMaterials.forEach((it) => {
|
|
|
it.bomNodeId = item.bomNodeId
|
|
|
it.materialCode = it.code;
|
|
@@ -775,6 +840,7 @@ const submitForm = async () => {
|
|
|
maintain: formData.value,
|
|
|
maintainMaterials: list.value
|
|
|
}
|
|
|
+ debugger
|
|
|
if (formType.value === 'create') {
|
|
|
await IotMaintainApi.createIotMaintain(data)
|
|
|
message.success(t('common.createSuccess'))
|
|
@@ -847,11 +913,17 @@ const handleDelete = async (id: number) => {
|
|
|
if (index !== -1) {
|
|
|
// 通过 splice 删除元素
|
|
|
list.value.splice(index, 1)
|
|
|
+ materialList.value = materialList.value.filter((item) => item.bomNodeId !== id)
|
|
|
totalFee.value = 0
|
|
|
- list.value.forEach(item => {
|
|
|
- item.materials.forEach((it) => {
|
|
|
- totalFee.value = it.unitPrice * it.quantity + totalFee.value
|
|
|
- })
|
|
|
+ debugger
|
|
|
+ // list.value.forEach(item => {
|
|
|
+ // // item.materials = item.materials.filter(item => item.bomNodeId !== id);
|
|
|
+ // item.materials.forEach((it) => {
|
|
|
+ // totalFee.value = it.unitPrice * it.quantity + totalFee.value
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ materialList.value.forEach((item) => {
|
|
|
+ totalFee.value = item.unitPrice * item.quantity + totalFee.value
|
|
|
})
|
|
|
formData.value.maintainFee = totalFee.value
|
|
|
}
|