| | |
| | | const openProductForm = async (type, row, index) => { |
| | | productOperationType.value = type; |
| | | productForm.value = {}; |
| | | modelOptions.value = []; // 清空规格型号选项 |
| | | proxy.resetForm("productFormRef"); |
| | | |
| | | // 确保产品大类数据已加载 |
| | | const options = productOptions.value && productOptions.value.length > 0 |
| | | ? productOptions.value |
| | | : await getProductOptions(); |
| | | |
| | | if (type === "edit") { |
| | | productForm.value = { ...row }; |
| | | productIndex.value = index; |
| | | // 编辑时根据产品大类名称反查 tree 节点 id,并加载规格型号列表 |
| | | try { |
| | | const options = productOptions.value && productOptions.value.length > 0 |
| | | ? productOptions.value |
| | | : await getProductOptions(); |
| | | const categoryId = findNodeIdByLabel(options, productForm.value.productCategory); |
| | | if (categoryId) { |
| | | const models = await modelList({ id: categoryId }); |
| | |
| | | // 加载失败时保持可编辑,不中断弹窗 |
| | | console.error("加载产品规格型号失败", e); |
| | | } |
| | | } else { |
| | | getProductOptions() |
| | | } |
| | | productFormVisible.value = true; |
| | | }; |