From 221b524e39d5f60761445ccc9608cb975b4d6416 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 30 十月 2026 08:43:36 +0800
Subject: [PATCH] fix: 销售报价选择产品修改
---
src/views/salesManagement/salesQuotation/index.vue | 239 ++++++++++++++---------------------------------------------
1 files changed, 57 insertions(+), 182 deletions(-)
diff --git a/src/views/salesManagement/salesQuotation/index.vue b/src/views/salesManagement/salesQuotation/index.vue
index 455f686..61c9a18 100644
--- a/src/views/salesManagement/salesQuotation/index.vue
+++ b/src/views/salesManagement/salesQuotation/index.vue
@@ -161,58 +161,37 @@
<div class="card-header-wrapper">
<el-icon class="card-icon"><Box /></el-icon>
<span class="card-title">浜у搧淇℃伅</span>
- <el-button type="primary" size="small" @click="addProduct" class="header-btn">
+ <el-button type="primary" size="small" @click="openProductSelect" class="header-btn">
<el-icon><Plus /></el-icon>
- 娣诲姞浜у搧
+ 閫夋嫨浜у搧
</el-button>
</div>
</template>
<div class="form-content">
<el-table :data="form.products" border style="width: 100%" class="product-table" v-if="form.products.length > 0">
- <el-table-column prop="product" label="浜у搧鍚嶇О" width="200">
+ <el-table-column type="index" label="搴忓彿" width="60" align="center" />
+ <el-table-column prop="product" label="浜у搧鍚嶇О" min-width="180">
<template #default="scope">
<el-form-item :prop="`products.${scope.$index}.productId`" class="product-table-form-item">
- <el-tree-select
- v-model="scope.row.productId"
- placeholder="璇烽�夋嫨"
- clearable
- check-strictly
- @change="getModels($event, scope.row)"
- :data="productOptions"
- :render-after-expand="false"
- style="width: 100%"
- />
+ <span>{{ scope.row.product || '--' }}</span>
</el-form-item>
</template>
</el-table-column>
- <el-table-column prop="specification" label="瑙勬牸鍨嬪彿" width="200">
+ <el-table-column prop="specification" label="瑙勬牸鍨嬪彿" min-width="160">
<template #default="scope">
<el-form-item :prop="`products.${scope.$index}.productModelId`" class="product-table-form-item">
- <el-select
- v-model="scope.row.productModelId"
- placeholder="璇烽�夋嫨"
- clearable
- @change="getProductModel($event, scope.row)"
- style="width: 100%"
- >
- <el-option
- v-for="item in scope.row.modelOptions || []"
- :key="item.id"
- :label="item.model"
- :value="item.id"
- />
- </el-select>
+ <span>{{ scope.row.specification || '--' }}</span>
</el-form-item>
</template>
</el-table-column>
- <el-table-column prop="unit" label="鍗曚綅">
+ <el-table-column prop="unit" label="鍗曚綅" width="120">
<template #default="scope">
<el-form-item :prop="`products.${scope.$index}.unit`" class="product-table-form-item">
<el-input v-model="scope.row.unit" placeholder="鍗曚綅" clearable/>
</el-form-item>
</template>
</el-table-column>
- <el-table-column prop="unitPrice" label="鍗曚环">
+ <el-table-column prop="unitPrice" label="鍗曚环" min-width="180">
<template #default="scope">
<el-form-item :prop="`products.${scope.$index}.unitPrice`" class="product-table-form-item">
<el-input-number v-model="scope.row.unitPrice" :min="0" :precision="6" :step="0.000001" style="width: 100%" />
@@ -225,7 +204,7 @@
</template>
</el-table-column>
</el-table>
- <el-empty v-else description="鏆傛棤浜у搧锛岃鐐瑰嚮娣诲姞浜у搧" :image-size="80" />
+ <el-empty v-else description="鏆傛棤浜у搧锛岃鐐瑰嚮閫夋嫨浜у搧" :image-size="80" />
</div>
</el-card>
@@ -253,6 +232,9 @@
</el-form>
</div>
</FormDialog>
+
+ <!-- 閫夋嫨浜у搧寮圭獥 -->
+ <ProductSelectDialog v-model="productSelectVisible" @confirm="handleProductSelect" />
<!-- 鏌ョ湅璇︽儏瀵硅瘽妗� -->
<el-dialog v-model="viewDialogVisible" title="鎶ヤ环璇︽儏" width="800px">
@@ -294,13 +276,13 @@
</template>
<script setup>
-import { ref, reactive, computed, onMounted, markRaw, shallowRef } from 'vue'
+import { ref, reactive, computed, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Search, Document, Box, EditPen, Plus } from '@element-plus/icons-vue'
import Pagination from '@/components/PIMTable/Pagination.vue'
import FormDialog from '@/components/Dialog/FormDialog.vue'
+import ProductSelectDialog from '@/views/basicData/product/ProductSelectDialog.vue'
import {getQuotationList,addQuotation,updateQuotation,deleteQuotation} from '@/api/salesManagement/salesQuotation.js'
-import {modelList, productTreeList} from "@/api/basicData/product.js";
import {listCustomer} from "@/api/basicData/customer.js";
import { userListNoPage } from "@/api/system/user.js";
import { formatDecimal, roundAmount } from '@/utils/numberFormat';
@@ -315,8 +297,6 @@
const quotationList = ref([])
const userList = ref([])
-const productOptions = ref([]);
-const modelOptions = ref([]);
const pagination = reactive({
total: 3,
currentPage: 1,
@@ -325,6 +305,7 @@
const dialogVisible = ref(false)
const viewDialogVisible = ref(false)
+const productSelectVisible = ref(false)
const dialogTitle = ref('鏂板鎶ヤ环')
const form = reactive({
quotationNo: '',
@@ -408,7 +389,6 @@
isEdit.value = false
resetForm()
dialogVisible.value = true
- getProductOptions();
fetchCustomerOptions()
}
@@ -418,99 +398,39 @@
customerOption.value = res.data.records;
});
}
-const getProductOptions = () => {
- // 杩斿洖 Promise锛屼究浜庣紪杈戞椂 await 纭繚鑳藉弽鏄�
- return productTreeList().then((res) => {
- productOptions.value = convertIdToValue(res);
- return productOptions.value
- });
-};
-function convertIdToValue(data) {
- return data.map((item) => {
- const { id, children, ...rest } = item;
- const newItem = {
- ...rest,
- value: id, // 灏� id 鏀逛负 value
- };
- if (children && children.length > 0) {
- newItem.children = convertIdToValue(children);
- }
-
- return newItem;
- });
+// 鎵撳紑閫夋嫨浜у搧寮圭獥锛堟敮鎸佸閫夛級
+const openProductSelect = () => {
+ productSelectVisible.value = true
}
-// 鏍规嵁鍚嶇О鍙嶆煡鑺傜偣 id锛屼究浜庝粎瀛樺悕绉版椂鐨勫弽鏄�
-function findNodeIdByLabel(nodes, label) {
- if (!label) return null;
- for (let i = 0; i < nodes.length; i++) {
- const node = nodes[i];
- if (node.label === label) return node.value;
- if (node.children && node.children.length > 0) {
- const found = findNodeIdByLabel(node.children, label);
- if (found !== null && found !== undefined) return found;
- }
- }
- return null;
+// 閫夋嫨浜у搧寮圭獥纭鍥炶皟锛氭壒閲忚拷鍔犲埌浜у搧鏄庣粏
+const handleProductSelect = (rows) => {
+ if (!Array.isArray(rows) || rows.length === 0) return
+ const getRowKey = (row) => String(row.productModelId || `${row.productId || ''}-${row.specification || ''}`)
+ const existingKeys = new Set(form.products.map(getRowKey))
+ let addedCount = 0
+ rows.forEach((row) => {
+ const productModelId = row.id ?? row.productModelId ?? ''
+ const item = {
+ productId: row.productId ?? '',
+ product: row.productName || row.product || '',
+ productName: row.productName || row.product || '',
+ productModelId,
+ specification: row.model || row.specification || '',
+ quantity: 1,
+ unit: row.unit || '',
+ unitPrice: 0,
+ amount: 0
+ }
+ const key = getRowKey(item)
+ if (existingKeys.has(key)) return
+ existingKeys.add(key)
+ form.products.push(item)
+ addedCount++
+ })
+ if (addedCount === 0) {
+ ElMessage.warning('鎵�閫変骇鍝佸凡鍦ㄦ槑缁嗕腑锛岃鍕块噸澶嶉�夋嫨')
+ }
}
-const getModels = (value, row) => {
- if (!row) return;
- // 濡傛灉娓呯┖閫夋嫨锛屽垯娓呯┖鐩稿叧瀛楁
- if (!value) {
- row.productId = '';
- row.product = '';
- row.modelOptions = [];
- row.productModelId = '';
- row.specification = '';
- row.unit = '';
- return;
- }
- // 鏇存柊 productId锛坴-model 宸茬粡鑷姩鏇存柊锛岃繖閲岀‘淇濅竴鑷存�э級
- row.productId = value;
- // 鎵惧埌瀵瑰簲鐨� label 骞惰祴鍊肩粰 row.product
- const label = findNodeById(productOptions.value, value);
- if (label) {
- row.product = label;
- }
- // 鑾峰彇瑙勬牸鍨嬪彿鍒楄〃锛岃缃埌褰撳墠琛岀殑 modelOptions
- modelList({ id: value }).then((res) => {
- row.modelOptions = res || [];
- });
-};
-const getProductModel = (value, row) => {
- if (!row) return;
- // 濡傛灉娓呯┖閫夋嫨锛屽垯娓呯┖鐩稿叧瀛楁
- if (!value) {
- row.productModelId = '';
- row.specification = '';
- row.unit = '';
- return;
- }
- // 鏇存柊 productModelId锛坴-model 宸茬粡鑷姩鏇存柊锛岃繖閲岀‘淇濅竴鑷存�э級
- row.productModelId = value;
- const modelOptions = row.modelOptions || [];
- const index = modelOptions.findIndex((item) => item.id === value);
- if (index !== -1) {
- row.specification = modelOptions[index].model;
- row.unit = modelOptions[index].unit;
- } else {
- row.specification = '';
- row.unit = '';
- }
-};
-const findNodeById = (nodes, productId) => {
- for (let i = 0; i < nodes.length; i++) {
- if (nodes[i].value === productId) {
- return nodes[i].label; // 鎵惧埌鑺傜偣锛岃繑鍥� label
- }
- if (nodes[i].children && nodes[i].children.length > 0) {
- const foundLabel = findNodeById(nodes[i].children, productId);
- if (foundLabel) {
- return foundLabel; // 鍦ㄥ瓙鑺傜偣涓壘鍒帮紝杩斿洖 label
- }
- }
- }
- return null; // 娌℃湁鎵惧埌鑺傜偣锛岃繑鍥瀗ull
-};
const handleView = (row) => {
// 鍙鍒堕渶瑕佺殑瀛楁锛岄伩鍏嶅皢缁勪欢寮曠敤鏀惧叆鍝嶅簲寮忓璞�
currentQuotation.value = {
@@ -542,8 +462,6 @@
isEdit.value = true
editId.value = row.id
form.id = row.id || form.id || null
- // 鍏堝姞杞戒骇鍝佹爲鏁版嵁锛屽惁鍒� el-tree-select 鏃犳硶鍙嶆樉浜у搧鍚嶇О
- await getProductOptions()
await fetchCustomerOptions()
// 鍙鍒堕渶瑕佺殑瀛楁锛岄伩鍏嶅皢缁勪欢寮曠敤鏀惧叆鍝嶅簲寮忓璞�
@@ -556,45 +474,16 @@
form.paymentMethod = row.paymentMethod || ''
form.status = row.status || '鑽夌'
form.remark = row.remark || ''
- form.products = row.products ? await Promise.all(row.products.map(async (product) => {
- const productName = product.product || product.productName || ''
- // 浼樺厛鐢� productId锛涘鏋滃彧鏈夊悕绉帮紝灏濊瘯鍙嶆煡 id 浠ヤ究鏍戦�夋嫨鍣ㄥ弽鏄�
- const resolvedProductId = product.productId
- ? Number(product.productId)
- : findNodeIdByLabel(productOptions.value, productName) || ''
-
- // 濡傛灉鏈変骇鍝両D锛屽姞杞藉搴旂殑瑙勬牸鍨嬪彿鍒楄〃
- let modelOptions = [];
- let resolvedProductModelId = product.productModelId || '';
-
- if (resolvedProductId) {
- try {
- const res = await modelList({ id: resolvedProductId });
- modelOptions = res || [];
-
- // 濡傛灉杩斿洖鐨勬暟鎹病鏈� productModelId锛屼絾鏈� specification 鍚嶇О锛屾牴鎹悕绉版煡鎵� ID
- if (!resolvedProductModelId && product.specification) {
- const foundModel = modelOptions.find(item => item.model === product.specification);
- if (foundModel) {
- resolvedProductModelId = foundModel.id;
- }
- }
- } catch (error) {
- console.error('鍔犺浇瑙勬牸鍨嬪彿澶辫触:', error);
- }
- }
-
- return {
- productId: resolvedProductId,
- product: productName,
- productModelId: resolvedProductModelId,
- specification: product.specification || '',
- quantity: product.quantity || 0,
- unit: product.unit || '',
- unitPrice: product.unitPrice || 0,
- amount: product.amount || 0,
- modelOptions: modelOptions // 涓烘瘡琛屾坊鍔犵嫭绔嬬殑瑙勬牸鍨嬪彿鍒楄〃
- }
+ form.products = row.products ? row.products.map((product) => ({
+ productId: product.productId || '',
+ product: product.product || product.productName || '',
+ productName: product.productName || product.product || '',
+ productModelId: product.productModelId || '',
+ specification: product.specification || '',
+ quantity: product.quantity || 0,
+ unit: product.unit || '',
+ unitPrice: product.unitPrice || 0,
+ amount: product.amount || 0
})) : []
form.subtotal = row.subtotal || 0
form.freight = row.freight || 0
@@ -644,20 +533,6 @@
form.discountRate = 0
form.discountAmount = 0
form.totalAmount = 0
-}
-
-const addProduct = () => {
- form.products.push({
- productId: '',
- product: '',
- productName: '',
- productModelId: '',
- quantity: 1,
- unit: '',
- unitPrice: 0,
- amount: 0,
- modelOptions: [] // 涓烘瘡琛屾坊鍔犵嫭绔嬬殑瑙勬牸鍨嬪彿鍒楄〃
- })
}
const removeProduct = (index) => {
--
Gitblit v1.9.3