| | |
| | | <el-input v-model="row.unit" |
| | | placeholder="请输入单位" |
| | | clearable |
| | | :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" /> |
| | | :disabled="!dataValue.isEdit || dataValue.dataList.some(item => (item as any).tempId === row.tempId)" /> |
| | | </el-form-item> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="操作" |
| | | fixed="right" |
| | | width="200"> |
| | | width="260"> |
| | | <template #default="{ row, $index }"> |
| | | <el-button v-if="dataValue.isEdit && !dataValue.dataList.some(item => (item as any).tempId === row.tempId)" |
| | | <el-button v-if="dataValue.isEdit" |
| | | type="danger" |
| | | text |
| | | @click="removeItem(row.tempId)">删除 |
| | | </el-button> |
| | | <el-button v-if="dataValue.isEdit" |
| | | type="primary" |
| | | text |
| | | @click="quoteItem(row.tempId)">引用 |
| | | </el-button> |
| | | <el-button v-if="dataValue.isEdit" |
| | | type="primary" |
| | |
| | | ]); |
| | | |
| | | const openDialog = (tempId: any) => { |
| | | console.log(tempId, "tempId"); |
| | | dataValue.currentRowName = tempId; |
| | | dataValue.showProductDialog = true; |
| | | }; |
| | |
| | | const { data } = await queryList(routeId.value); |
| | | dataValue.dataList = (data as any) || []; |
| | | // 为所有项及其子项设置name属性 |
| | | const setNameRecursively = (items: any[]) => { |
| | | const setNameRecursively = (items: any[], parent: any = null) => { |
| | | items.forEach((item: any) => { |
| | | item.tempId = item.id; |
| | | item.parentTempId = parent?.tempId || ""; |
| | | item.processName = |
| | | dataValue.processOptions.find(option => option.id === item.processId) |
| | | ?.name || ""; |
| | | if (item.children && item.children.length > 0) { |
| | | setNameRecursively(item.children); |
| | | setNameRecursively(item.children, item); |
| | | } |
| | | }); |
| | | }; |
| | |
| | | const productData = row[0]; |
| | | |
| | | // 最外层组件中,与当前产品相同的产品只能有一个 |
| | | const isTopLevel = dataValue.dataList.some(item => (item as any).tempId === dataValue.currentRowName); |
| | | const isTopLevel = dataValue.dataList.some( |
| | | item => (item as any).tempId === dataValue.currentRowName |
| | | ); |
| | | if (isTopLevel) { |
| | | if (productData.productName === tableData[0].productName && |
| | | productData.model === tableData[0].model) { |
| | | if ( |
| | | productData.productName === tableData[0].productName && |
| | | productData.model === tableData[0].model |
| | | ) { |
| | | // 查找是否已经有其他顶层行已经是这个产品 |
| | | const hasOther = dataValue.dataList.some(item => |
| | | (item as any).tempId !== dataValue.currentRowName && |
| | | (item as any).productName === tableData[0].productName && |
| | | (item as any).model === tableData[0].model |
| | | const hasOther = dataValue.dataList.some( |
| | | item => |
| | | (item as any).tempId !== dataValue.currentRowName && |
| | | (item as any).productName === tableData[0].productName && |
| | | (item as any).model === tableData[0].model |
| | | ); |
| | | if (hasOther) { |
| | | ElMessage.warning("最外层和当前产品一样的一级只能有一个"); |
| | |
| | | } |
| | | }; |
| | | |
| | | const removeItem = (tempId:string) => { |
| | | const removeItem = (tempId: string) => { |
| | | // 先尝试从顶层删除 |
| | | const topIndex = dataValue.dataList.findIndex(item => item.tempId === tempId); |
| | | if (topIndex !== -1) { |
| | |
| | | } |
| | | }); |
| | | }; |
| | | const createTempId = () => new Date().getTime() + Math.floor(Math.random() * 1000); |
| | | const cloneItem = (item: any, parentTempId = "", parentId = item.parentId || "") => { |
| | | const tempId = createTempId(); |
| | | return { |
| | | ...item, |
| | | id: undefined, |
| | | parentId, |
| | | tempId, |
| | | parentTempId, |
| | | children: [], |
| | | }; |
| | | }; |
| | | const quoteItem = (tempId: string) => { |
| | | const topIndex = dataValue.dataList.findIndex(item => item.tempId === tempId); |
| | | if (topIndex !== -1) { |
| | | const currentItem = dataValue.dataList[topIndex]; |
| | | dataValue.dataList.splice( |
| | | topIndex + 1, |
| | | 0, |
| | | cloneItem(currentItem, currentItem.parentTempId || "") |
| | | ); |
| | | return; |
| | | } |
| | | |
| | | const quoteChildItem = (items: any[], currentTempId: string) => { |
| | | for (let i = 0; i < items.length; i++) { |
| | | const item = items[i]; |
| | | if (item.tempId === currentTempId) { |
| | | items.splice(i + 1, 0, cloneItem(item, item.parentTempId || "")); |
| | | return true; |
| | | } |
| | | if (item.children && item.children.length > 0) { |
| | | if (quoteChildItem(item.children, currentTempId)) { |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | return false; |
| | | }; |
| | | |
| | | quoteChildItem(dataValue.dataList, tempId); |
| | | }; |
| | | const addItem2 = tempId => { |
| | | dataValue.dataList.map(item => { |
| | | if (item.tempId === tempId) { |
| | |
| | | productModelId: undefined, |
| | | processId: "", |
| | | processName: "", |
| | | unitQuantity: 0, |
| | | unitQuantity: 1, |
| | | demandedQuantity: 0, |
| | | unit: "", |
| | | children: [], |
| | |
| | | model: undefined, |
| | | productModelId: undefined, |
| | | processId: "", |
| | | unitQuantity: 0, |
| | | unitQuantity: 1, |
| | | demandedQuantity: 0, |
| | | children: [], |
| | | unit: "", |
| | |
| | | await fetchProcessOptions(); |
| | | await fetchData(); |
| | | }); |
| | | </script> |
| | | </script> |