gongchunyi
11 小时以前 3ebd5fca130c2f9a5a4afc3dce185acff752b941
src/views/productionManagement/productStructure/Detail/index.vue
@@ -2,10 +2,6 @@
  <div class="app-container">
    <PageHeader content="产品结构详情">
      <template #right-button>
        <el-button v-if="dataValue.isEdit && !isOrderPage"
                   type="primary"
                   @click="addItem">添加
        </el-button>
        <el-button v-if="!dataValue.isEdit && !isOrderPage"
                   type="primary"
                   @click="dataValue.isEdit = true">编辑
@@ -127,7 +123,7 @@
                               fixed="right"
                               width="200">
                <template #default="{ row, $index }">
                  <el-button v-if="dataValue.isEdit"
                  <el-button v-if="dataValue.isEdit && !dataValue.dataList.some(item => (item as any).tempId === row.tempId)"
                             type="danger"
                             text
                             @click="removeItem(row.tempId)">删除
@@ -267,13 +263,21 @@
    }
    const productData = row[0];
    // 校验:不能在最外层选择跟当前产品一样的产品
    const isTopLevel = dataValue.dataList.some(item => item.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) {
        ElMessage.warning("不能在最外层选择跟当前产品一样的产品");
        //  查找是否已经有其他顶层行已经是这个产品
        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("最外层和当前产品一样的一级只能有一个");
        return;
        }
      }
    }
    // dataValue.dataList[dataValue.currentRowIndex].productName =
@@ -386,22 +390,7 @@
    }
  };
  const addItem = () => {
    dataValue.dataList.push({
      productName: "",
      productId: "",
      model: undefined,
      productModelId: undefined,
      processId: "",
      processName: "",
      unitQuantity: 0,
      demandedQuantity: 0,
      unit: "",
      children: [],
      tempId: new Date().getTime(),
    });
  };
  const removeItem = tempId => {
  const removeItem = (tempId:string) => {
    // 先尝试从顶层删除
    const topIndex = dataValue.dataList.findIndex(item => item.tempId === tempId);
    if (topIndex !== -1) {