| | |
| | | <el-tag type="" size="small" effect="dark">成品</el-tag> |
| | | <span style="margin:0 4px">← 最上层(产出物)</span> |
| | | <el-divider direction="vertical" /> |
| | | <el-tag type="warning" size="small" effect="dark">半成品</el-tag> |
| | | <span style="margin:0 4px">(可继续展开)</span> |
| | | <el-divider direction="vertical" /> |
| | | <span style="margin:0 4px">最下层(投入物)→</span> |
| | | <el-tag type="success" size="small" effect="dark">原料</el-tag> |
| | | </div> |
| | |
| | | :editable="dataValue.isEdit" |
| | | :process-options="dataValue.processOptions" |
| | | @remove="(id: string) => removeItem(id)" |
| | | @add="(id: string) => addChildItem(id)" |
| | | @add="(id: string, nodeType: string) => addChildItem(id, nodeType)" |
| | | @select-product="(tempId: string, _data: any) => { dataValue.currentRowName = tempId; dataValue.showProductDialog = true }" |
| | | @process-change="(row: any, v: any) => handleProcessChange(row, v)" |
| | | @quantity-change="handleUnitQuantityChange" |
| | |
| | | item.operationName = processName; |
| | | }; |
| | | |
| | | const normalizeTreeData = (items: any[]) => { |
| | | const normalizeTreeData = (items: any[], depth: number = 0) => { |
| | | items.forEach((item: any) => { |
| | | item.tempId = item.tempId || item.id || `${Date.now()}_${Math.random()}`; |
| | | syncProcessOperationFields(item); |
| | | if (depth > 0 && !item.nodeType) { |
| | | item.nodeType = Array.isArray(item.children) && item.children.length > 0 |
| | | ? 'semiFinished' |
| | | : 'rawMaterial'; |
| | | } |
| | | if (Array.isArray(item.children) && item.children.length > 0) { |
| | | normalizeTreeData(item.children); |
| | | normalizeTreeData(item.children, depth + 1); |
| | | } |
| | | }); |
| | | }; |
| | |
| | | }); |
| | | }; |
| | | |
| | | const newChildNode = (parentItem: any) => ({ |
| | | const newChildNode = (parentItem: any, nodeType: string = 'rawMaterial') => ({ |
| | | parentId: parentItem.id || "", |
| | | parentTempId: parentItem.tempId || "", |
| | | productName: "", |
| | |
| | | unitQuantity: 1, |
| | | demandedQuantity: 0, |
| | | unit: "", |
| | | nodeType, |
| | | children: [], |
| | | tempId: new Date().getTime(), |
| | | }); |
| | |
| | | dataValue.dataList.push(newChildNode({ id: "", tempId: "" })); |
| | | }; |
| | | |
| | | const addChildItem = (parentTempId: string) => { |
| | | const addChildItem = (parentTempId: string, nodeType: string = 'rawMaterial') => { |
| | | const addToItem = (items: any[]): boolean => { |
| | | for (const item of items) { |
| | | if (item.tempId === parentTempId) { |
| | | if (!item.children) item.children = []; |
| | | item.children.push(newChildNode(item)); |
| | | item.children.push(newChildNode(item, nodeType)); |
| | | recalculateDemandedQuantities(); |
| | | return true; |
| | | } |