ZN
4 天以前 0453b4d1e92d7a4779ad70857891b17ced6abe2e
同步华玺砂浆 同步
已修改2个文件
491 ■■■■ 文件已修改
src/views/procurementManagement/advancedPriceManagement/index.vue 225 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/procurementLedger/index.vue 266 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/advancedPriceManagement/index.vue
@@ -8,7 +8,7 @@
        </el-form-item>
        <el-form-item label="供应商:">
          <el-select v-model="searchForm.supplierId" placeholder="请选择供应商" clearable style="width: 200px">
            <el-option v-for="supplier in supplierList" :key="supplier.id" :label="supplier.name" :value="supplier.id" />
            <el-option v-for="supplier in supplierList" :key="supplier.id" :label="supplier.supplierName" :value="supplier.id" />
          </el-select>
        </el-form-item>
        <el-form-item>
@@ -31,10 +31,10 @@
          <el-icon><Plus /></el-icon>
          新增价格
        </el-button>
        <el-button type="success" @click="openBatchDiscountDialog">
        <!-- <el-button type="success" @click="openBatchDiscountDialog">
          <el-icon><Discount /></el-icon>
          批量折扣
        </el-button>
        </el-button> -->
        <el-button type="info" @click="exportData">
          <el-icon><Download /></el-icon>
          导出数据
@@ -62,17 +62,16 @@
            <div class="product-info">
              <div class="product-name">{{ row.productName }}</div>
              <div class="product-spec">{{ row.specification }}</div>
              <div class="product-code">编码: {{ row.productCode }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="供应商" prop="supplierName" width="150" />
        <el-table-column label="基础价格" width="120" align="right">
        <el-table-column label="供应商" prop="supplierName" width="200" />
        <el-table-column label="基础价格(不含税)" width="150" align="right">
          <template #default="{ row }">
            <span class="price-text">¥{{ row.basePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column label="折扣信息" width="150">
        <el-table-column label="折扣信息" width="120" align="center">
          <template #default="{ row }">
            <div v-if="row.discountType">
              <el-tag :type="getDiscountTagType(row.discountType)" size="small">
@@ -83,9 +82,12 @@
            <span v-else class="no-discount">无折扣</span>
          </template>
        </el-table-column>
        <el-table-column label="实际价格" width="120" align="right">
        <!-- <el-table-column label="实际价格(不含税)" prop="actuallyPrice" width="150" align="right"> -->
        <!-- </el-table-column> -->
        <el-table-column label="实际价格(不含税)"  width="150" align="right">
          <template #default="{ row }">
            <span class="final-price">¥{{ calculateFinalPrice(row) }}</span>
            <!-- <span class="final-price">¥{{ calculateFinalPrice(row) }}</span> -->
            <span class="final-price" >¥{{ row.actuallyPrice?row.actuallyPrice:row.basePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column label="价格控制" width="120">
@@ -103,13 +105,14 @@
        <el-table-column label="状态" width="100" align="center">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)">{{ getStatusText(row.status) }}</el-tag>
            <div v-if="isPriceWarning(row)" class="warning-indicator">
            <!-- <div v-if="isPriceWarning(row)" class="warning-indicator">
              <el-icon color="#F56C6C"><Warning /></el-icon>
            </div>
            </div> -->
          </template>
        </el-table-column>
        <el-table-column label="生效时间" prop="effectiveTime" width="180" />
        <el-table-column label="更新时间" prop="updateTime" width="180" sortable />
        <el-table-column label="生效时间" prop="effectiveTime" width="100" align="center" />
        <el-table-column label="更新时间" prop="updateTime" width="160" sortable align="center" />
        <el-table-column label="备注" width="200" prop="remark" align="center" show-overflow-tooltip />
        <el-table-column label="操作" width="250" align="center" fixed="right">
          <template #default="{ row }">
            <el-button type="primary" link @click="openDialog('edit', row)">
@@ -143,38 +146,65 @@
      <el-form :model="formData" :rules="formRules" ref="formRef" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="商品名称" prop="productName">
              <el-select v-model="formData.productName" placeholder="请选择商品" style="width: 100%" filterable>
                <el-option v-for="product in productList" :key="product.id" :label="product.name" :value="product.name" />
              </el-select>
            <el-form-item label="商品名称" prop="productId">
              <el-tree-select
                v-model="formData.productId"
                placeholder="请选择商品"
                clearable
                filterable
                check-strictly
                @change="getModels"
                :data="productOptions"
                :props="{ label: 'productName', value: 'id', children: 'children' }"
                node-key="id"
                :render-after-expand="false"
                style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商品编码" prop="productCode">
              <el-input v-model="formData.productCode" placeholder="请输入商品编码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="规格型号" prop="specification">
              <el-input v-model="formData.specification" placeholder="请输入规格型号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商" prop="supplierName">
              <el-select v-model="formData.supplierName" placeholder="请选择供应商" style="width: 100%">
                <el-option v-for="supplier in supplierList" :key="supplier.id" :label="supplier.name" :value="supplier.name" />
              <el-select
                v-model="formData.specification"
                placeholder="请选择"
                clearable
                @change="getProductModel"
              >
                <el-option
                  v-for="item in modelOptions"
                  :key="item.id"
                  :label="item.model"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="供应商" prop="supplierId">
              <el-select
                v-model="formData.supplierId"
                placeholder="请选择供应商"
                clearable
                @change="handleSupplierChange"
              >
                <el-option
                  v-for="item in supplierList"
                  :key="item.id"
                  :label="item.supplierName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="基础价格" prop="basePrice">
              <el-input-number v-model="formData.basePrice" :min="0" :precision="2" placeholder="请输入基础价格" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="单位">
              <el-input v-model="formData.unit" placeholder="请输入单位" />
@@ -185,7 +215,7 @@
        <!-- 折扣设置 -->
        <el-divider content-position="left">折扣设置</el-divider>
        <el-row :gutter="20">
          <el-col :span="8">
          <el-col :span="12">
            <el-form-item label="折扣类型">
              <el-select v-model="formData.discountType" placeholder="请选择折扣类型" style="width: 100%">
                <el-option label="无折扣" value="" />
@@ -194,10 +224,11 @@
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="折扣值" v-if="formData.discountType && formData.discountType !== 'tiered'">
          <el-col :span="12">
            <el-form-item label="折扣值">
              <el-input-number 
                v-model="formData.discountValue" 
                :disabled="!(formData.discountType && formData.discountType !== 'tiered')"
                :min="0" 
                :max="formData.discountType === 'percentage' ? 100 : undefined"
                :precision="2" 
@@ -206,10 +237,11 @@
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
          <el-col :span="12">
            <el-form-item label="折扣有效期">
              <el-date-picker 
                v-model="formData.discountEndTime" 
                :disabled="!(formData.discountType && formData.discountType !== 'tiered')"
                type="datetime" 
                placeholder="选择结束时间" 
                style="width: 100%" 
@@ -221,19 +253,14 @@
        <!-- 价格控制 -->
        <el-divider content-position="left">价格控制</el-divider>
        <el-row :gutter="20">
          <el-col :span="8">
          <el-col :span="12">
            <el-form-item label="最低价格">
              <el-input-number v-model="formData.minPrice" :min="0" :precision="2" placeholder="最低价格" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
          <el-col :span="12">
            <el-form-item label="最高价格">
              <el-input-number v-model="formData.maxPrice" :min="0" :precision="2" placeholder="最高价格" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="预警阈值(%)">
              <el-input-number v-model="formData.warningThreshold" :min="0" :max="100" :precision="1" placeholder="预警阈值" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
@@ -334,12 +361,14 @@
<script setup>
import {ref, reactive, computed, onMounted, getCurrentInstance} from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { productTreeList, modelList } from "@/api/basicData/product.js";
import {
  Search, Refresh, Plus, Discount, Setting, Download, Delete, Edit, 
  Warning
} from '@element-plus/icons-vue'
import { listPage, update, del, add } from '@/api/procurementManagement/advancedPriceManagement'
import {
  getOptions,
} from "@/api/procurementManagement/procurementLedger.js";
// 响应式数据
const loading = ref(false)
const submitLoading = ref(false)
@@ -347,6 +376,8 @@
const batchDiscountVisible = ref(false)
const priceControlVisible = ref(false)
const dialogType = ref('add')
const productOptions = ref([]);
const modelOptions = ref([]);
const selectedRows = ref([])
const formRef = ref()
@@ -367,10 +398,12 @@
// 表单数据
const formData = reactive({
  productId: null,
  productName: '',
  productCode: '',
  specification: '',
  supplierId: null,
  supplierName: '',
  specificationId: null,
  basePrice: 0,
  unit: '',
  discountType: '',
@@ -405,24 +438,18 @@
// 表单验证规则
const formRules = {
  productName: [{ required: true, message: '请选择商品名称', trigger: 'change' }],
  productCode: [{ required: true, message: '请输入商品编码', trigger: 'blur' }],
  supplierName: [{ required: true, message: '请选择供应商', trigger: 'change' }],
  productId: [{ required: true, message: '请选择商品名称', trigger: 'change' }],
  supplierId: [{ required: true, message: '请选择供应商', trigger: 'change' }],
  basePrice: [{ required: true, message: '请输入基础价格', trigger: 'blur' }],
  effectiveTime: [{ required: true, message: '请选择生效时间', trigger: 'change' }],
  reason: [{ required: true, message: '请选择调价原因', trigger: 'change' }]
}
const supplierList = ref([
  { id: 1, name: '优质五金供应商' },
  { id: 2, name: '钢材贸易公司' },
  { id: 3, name: '建材批发商' }
])
getOptions().then((res) => {
    supplierList.value = res.data;
  });
const productList = ref([
  { id: 1, name: '高强度螺栓' },
  { id: 2, name: '不锈钢管' },
  { id: 3, name: '铝合金型材' }
const supplierList = ref([
])
@@ -434,7 +461,8 @@
  } else if (row.discountType === 'fixed') {
    finalPrice = row.basePrice - row.discountValue
  }
  return Math.max(finalPrice, 0)
  let man = Math.max(finalPrice, 0)
  return man.toFixed(2)
}
const getDiscountTagType = (discountType) => {
@@ -454,6 +482,39 @@
  return textMap[discountType] || '未知'
}
const getProductOptions = () => {
  productTreeList().then((res) => {
    productOptions.value = res;
  });
};
const findNodeById = (data, id) => {
  for (const item of data) {
    if (item.id === id) return item;
    if (item.children) {
      const found = findNodeById(item.children, id);
      if (found) return found;
    }
  }
  return null;
};
const getModels = (value) => {
  if (value) {
    const selectedProduct = findNodeById(productOptions.value, value);
    if (selectedProduct) {
      formData.productName = selectedProduct.productName;
    }
    modelList({ id: value }).then((res) => {
      modelOptions.value = res;
    });
    formData.specification = "";
  } else {
    formData.productName = "";
    modelOptions.value = [];
  }
};
const getStatusType = (status) => {
  const statusMap = {
    active: 'success',
@@ -461,6 +522,27 @@
    expired: 'info'
  }
  return statusMap[status] || 'info'
}
const getProductModel = (value) => {
  const index = modelOptions.value.findIndex((item) => item.id === value);
  if (index !== -1) {
    formData.specification = modelOptions.value[index].model;
    formData.specificationId = modelOptions.value[index].id;
    formData.unit = modelOptions.value[index].unit;
  } else {
    formData.specification = null;
    formData.specificationId = null;
    formData.unit = null;
  }
};
const handleSupplierChange = (value) => {
  const supplier = supplierList.value.find(supplier => supplier.id === value)
  if (supplier) {
      formData.supplierId = supplier.id
      formData.supplierName = supplier.supplierName
  }
}
const getStatusText = (status) => {
@@ -471,13 +553,6 @@
  }
  return statusMap[status] || '未知'
}
const isPriceWarning = (row) => {
  if (!row.priceControl) return false
  const finalPrice = calculateFinalPrice(row)
  return finalPrice < row.priceControl.minPrice || finalPrice > row.priceControl.maxPrice
}
const handleSearch = () => {
  loading.value = true
@@ -501,10 +576,14 @@
const openDialog = (type, row = {}) => {
  dialogType.value = type
  if (type === 'edit' && row.id) {
    // 复制行数据到表单
    Object.assign(formData, {
      ...row,
      minPrice: row.priceControl?.minPrice,
      maxPrice: row.priceControl?.maxPrice,
      // 兼容两种数据结构:平铺的字段或嵌套在 priceControl 中的字段
      minPrice: row.minPrice ?? row.priceControl?.minPrice,
      maxPrice: row.maxPrice ?? row.priceControl?.maxPrice,
      // 确保折扣有效期也被赋值 (如果 row.discountEndTime 存在的话)
      discountEndTime: row.discountEndTime || row.discountEndTime,
      tieredDiscount: row.tieredDiscount || []
    })
  } else {
@@ -515,9 +594,10 @@
const resetFormData = () => {
  Object.assign(formData, {
    productId: null,
    productName: '',
    productCode: '',
    specification: '',
    supplierId: null,
    supplierName: '',
    basePrice: 0,
    unit: '',
@@ -543,12 +623,12 @@
  })
}
const removeTieredRow = (index) => {
  formData.tieredDiscount.splice(index, 1)
}
const handleSubmit = async () => {
  if (!formRef.value) return
    formData.actuallyPrice = Number(calculateFinalPrice(formData))
    if( formData.discountType === ''){
      formData.discountEndTime = '2099-12-31 23:59:59'
    }
  
  try {
    await formRef.value.validate()
@@ -677,6 +757,7 @@
// 生命周期
onMounted(() => {
  handleSearch()
  getProductOptions()
})
</script>
src/views/procurementManagement/procurementLedger/index.vue
@@ -225,6 +225,7 @@
                v-model="form.supplierId"
                placeholder="请选择"
                clearable
                @change="handleSupplierChange"
              >
                <el-option
                  v-for="item in supplierList"
@@ -485,6 +486,11 @@
                            </el-select>
                        </el-form-item>
                    </el-col>
          <el-col :span="24">
            <el-form-item label=" ">
              <el-button type="warning" :disabled="!(productForm.productId && productForm.productModelId && productForm.taxRate)" @click="showPriceReference" icon="Search">查看历史采购价格参考</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="30">
          <el-col :span="12">
@@ -695,6 +701,83 @@
      </template>
    </el-dialog>
    <!-- 历史采购价格参考弹窗 -->
    <el-dialog
      v-model="priceReferenceVisible"
      :title="`历史采购价格参考 ${productForm.supplierName}-${productForm.productName}-${productForm.productModel}`"
      width="1000px"
      append-to-body
    >
      <el-table
        :data="priceReferenceData"
        border
        v-loading="priceReferenceLoading"
        :default-sort="{ prop: 'updateTime', order: 'descending' }"
      >
        <!-- <el-table-column label="商品信息" min-width="200">
          <template #default="{ row }">
            <div class="product-info">
              <div class="product-name">{{ row.productName }}</div>
              <div class="product-spec">{{ row.specification }}</div>
              <div class="product-code">编码: {{ row.productCode }}</div>
            </div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="供应商" prop="supplierName" width="200" /> -->
        <el-table-column label="基础价格(不含税)" width="150" align="right">
          <template #default="{ row }">
            <span class="price-text">¥{{ row.basePrice }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实际价格(不含税)" prop="actuallyPrice" width="150" align="right"/>
        <el-table-column label="折扣信息" width="120" align="center">
          <template #default="{ row }">
            <div v-if="row.discountType">
              <el-tag :type="getDiscountTagType(row.discountType)" size="small">
                {{ getDiscountText(row.discountType) }}
              </el-tag>
              <div class="discount-value">{{ row.discountValue }}{{ row.discountType === 'percentage' ? '%' : '元' }}</div>
            </div>
            <span v-else class="no-discount">无折扣</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="100" align="center">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)">{{ getStatusText(row.status) }}</el-tag>
            <!-- <div v-if="isPriceWarning(row)" class="warning-indicator">
              <el-icon color="#F56C6C"><Warning /></el-icon>
            </div> -->
          </template>
        </el-table-column>
        <el-table-column label="生效时间" prop="effectiveTime" width="100" align="center" />
        <el-table-column label="更新时间" prop="updateTime" width="160" sortable align="center" />
        <el-table-column label="备注" width="200" prop="remark" align="center" show-overflow-tooltip />
        <el-table-column label="操作" width="100" align="center" fixed="right">
          <template #default="{ row }">
            <el-button type="success" link @click="selectPriceReference(row)">
              <el-icon><Check /></el-icon>
              引用
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container" style="margin-top: 20px; display: flex; justify-content: flex-end;">
        <el-pagination
          v-model:current-page="priceReferencePagination.current"
          v-model:page-size="priceReferencePagination.size"
          :page-sizes="[10, 20, 50]"
          :total="priceReferenceTotal"
          layout="total, sizes, prev, pager, next"
          @size-change="handlePriceReferenceSizeChange"
          @current-change="handlePriceReferenceCurrentChange"
        />
      </div>
      <template #footer>
        <el-button @click="priceReferenceVisible = false">关闭</el-button>
      </template>
    </el-dialog>
    <!-- 扫码登记对话框 -->
    <el-dialog
      v-model="scanDialogVisible"
@@ -793,7 +876,7 @@
import { getToken } from "@/utils/auth";
import pagination from "@/components/PIMTable/Pagination.vue";
import { ref, onMounted, reactive, toRefs, getCurrentInstance, nextTick } from "vue";
import { Search } from "@element-plus/icons-vue";
import { Search, Check } from "@element-plus/icons-vue";
import { ElMessageBox } from "element-plus";
import { userListNoPage } from "@/api/system/user.js";
import {
@@ -834,6 +917,7 @@
const fileList = ref([]);
import useUserStore from "@/store/modules/user";
import { modelList, productTreeList } from "@/api/basicData/product.js";
import { listPage as listAdvancedPrice } from "@/api/procurementManagement/advancedPriceManagement.js";
import dayjs from "dayjs";
const userStore = useUserStore();
@@ -899,6 +983,9 @@
    taxExclusiveTotalPrice: "",
    invoiceType: "",
        warnNum: "",
    supplierName: "",
    productName: "",
    productModel: "",
  },
  productRules: {
    productId: [{ required: true, message: "请选择", trigger: "change" }],
@@ -920,6 +1007,139 @@
  },
});
const { productForm, productRules } = toRefs(productFormData);
// 采购价格管理参考弹窗
const priceReferenceVisible = ref(false);
const priceReferenceLoading = ref(false);
const priceReferenceData = ref([]);
const priceReferenceTotal = ref(0);
const priceReferencePagination = reactive({
  current: 1,
  size: 10
});
const calculateFinalPrice = (row) => {
  let finalPrice = row.basePrice;
  if (row.discountType === "percentage") {
    finalPrice = row.basePrice * (1 - row.discountValue / 100);
  } else if (row.discountType === "fixed") {
    finalPrice = row.basePrice - row.discountValue;
  }
  let man = Math.max(finalPrice, 0);
  return man.toFixed(2);
};
const getDiscountTagType = (discountType) => {
  const typeMap = {
    percentage: "success",
    fixed: "warning",
    tiered: "info",
  };
  return typeMap[discountType] || "info";
};
const getDiscountText = (discountType) => {
  const textMap = {
    percentage: "百分比",
    fixed: "固定金额",
  };
  return textMap[discountType] || "未知";
};
const getStatusType = (status) => {
  const statusMap = {
    active: "success",
    pending: "warning",
    expired: "info",
  };
  return statusMap[status] || "info";
};
const getStatusText = (status) => {
  const statusMap = {
    active: "有效",
    pending: "待生效",
    expired: "已过期",
  };
  return statusMap[status] || "未知";
};
const showPriceReference = () => {
  if (form.value.supplierId) {
    const supplier = supplierList.value.find((item) => item.id === form.value.supplierId);
    if (supplier) {
      productForm.value.supplierName = supplier.supplierName;
    }
  }
  priceReferenceVisible.value = true;
  handlePriceReferenceSearch();
};
const handlePriceReferenceSearch = () => {
  priceReferenceLoading.value = true;
  // 模拟搜索参数:productId 映射为 productName 或 ID,这里根据 advancedPriceManagement 的 API 确定参数
  // 假设高级价格管理的 listPage 接收 productId
  const query = {
    productId: productForm.value.productId,
    supplierId: form.value.supplierId,
    current: priceReferencePagination.current,
    size: priceReferencePagination.size
  };
  listAdvancedPrice(query).then(res => {
    console.log(res);
    priceReferenceData.value = res.data.records;
    priceReferenceTotal.value = res.data.total;
    priceReferenceLoading.value = false;
  }).catch(() => {
    priceReferenceLoading.value = false;
  });
};
const handlePriceReferenceSizeChange = (size) => {
  priceReferencePagination.size = size;
  handlePriceReferenceSearch();
};
const handlePriceReferenceCurrentChange = (page) => {
  priceReferencePagination.current = page;
  handlePriceReferenceSearch();
};
const selectPriceReference = (row) => {
  // 计算历史价格(作为不含税单价):基础价格 - 折扣
  let taxExclusivePrice = row.basePrice;
  if (row.discountType === "percentage") {
    taxExclusivePrice = row.basePrice * (1 - row.discountValue / 100);
  } else if (row.discountType === "fixed") {
    taxExclusivePrice = row.basePrice - row.discountValue;
  }
  taxExclusivePrice = Number(Math.max(taxExclusivePrice, 0));
  // 设置数量为 1
  if (!productForm.value.quantity) {
    productForm.value.quantity = 1;
  }
  // 如果已有税率,则计算含税单价
  if (productForm.value.taxRate) {
    const taxRate = Number(productForm.value.taxRate);
    productForm.value.taxInclusiveUnitPrice = (
      taxExclusivePrice *
      (1 + taxRate / 100)
    ).toFixed(2);
  } else {
    // 如果没有税率,暂时将含税单价设为不含税价格,提示用户选择税率
    productForm.value.taxInclusiveUnitPrice = taxExclusivePrice.toFixed(2);
    proxy.$modal.msgWarning("请选择税率以准确计算含税价格");
  }
  // 自动触发计算逻辑(计算总价等)
  mathNum();
  priceReferenceVisible.value = false;
  proxy.$modal.msgSuccess("已引用历史价格(不含税)");
};
const upload = reactive({
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/file/upload",
@@ -1135,13 +1355,38 @@
};
// 打开产品弹框
const openProductForm = (type, row, index) => {
  if(!form.value.supplierId){
    proxy.$modal.msgWarning("请选择供应商");
    return;
  }
  productOperationType.value = type;
  productOperationIndex.value = index;
  productForm.value = {};
  productForm.value = {
    supplierName: "",
    productName: "",
    productModel: "",
  };
  proxy.resetForm("productFormRef");
  if (type === "edit") {
    productForm.value = { ...row };
    productForm.value = {
      ...row,
      productName: row.productCategory || "",
      productModel: row.specificationModel || ""
    };
    // 编辑时,根据 productId 预加载规格型号列表,确保下拉框显示名称而非 ID
    if (productForm.value.productId) {
      modelList({ id: productForm.value.productId }).then((res) => {
        modelOptions.value = res;
      });
  }
  }
  // 确保供应商名称始终同步
  const supplier = supplierList.value.find((item) => item.id === form.value.supplierId);
  if (supplier) {
    productForm.value.supplierName = supplier.supplierName;
  }
  productFormVisible.value = true;
  getProductOptions();
};
@@ -1153,11 +1398,14 @@
const getModels = (value) => {
  if (value) {
    productForm.value.productCategory = findNodeById(productOptions.value, value) || "";
    productForm.value.productName = productForm.value.productCategory;
    productForm.value.productModelId = "";
    modelList({ id: value }).then((res) => {
      modelOptions.value = res;
    });
  } else {
    productForm.value.productCategory = "";
    productForm.value.productName = "";
    modelOptions.value = [];
  }
};
@@ -1165,12 +1413,24 @@
  const index = modelOptions.value.findIndex((item) => item.id === value);
  if (index !== -1) {
    productForm.value.specificationModel = modelOptions.value[index].model;
    productForm.value.productModel = modelOptions.value[index].model;
    productForm.value.unit = modelOptions.value[index].unit;
  } else {
    productForm.value.specificationModel = null;
    productForm.value.productModel = null;
    productForm.value.unit = null;
  }
};
const handleSupplierChange = (value) => {
  const supplier = supplierList.value.find((item) => item.id === value);
  if (supplier) {
    form.value.supplierName = supplier.supplierName;
    productForm.value.supplierName = supplier.supplierName;
  } else {
    form.value.supplierName = "";
    productForm.value.supplierName = "";
  }
};
const findNodeById = (nodes, productId) => {
  for (let i = 0; i < nodes.length; i++) {
    if (nodes[i].value === productId) {