This commit is contained in:
2026-03-18 00:07:53 +08:00
parent 2a5821805c
commit 434bc59266
4 changed files with 115 additions and 27 deletions
+51 -15
View File
@@ -1808,7 +1808,7 @@ const InventoryView = {
if (item) {
if (type === 'salesOrder') {
await loadCustomers();
await loadProducts();
await loadFinishedProducts();
const detail = await apiRequest(`/api/sales-orders/${item.id}`);
state.form = {
customer_id: detail.customer_id,
@@ -1816,6 +1816,8 @@ const InventoryView = {
remark: detail.remark || '',
items: (detail.items || []).map(line => ({
product_id: line.product_id,
product_sku: '',
product_name: '',
quantity: line.quantity,
unit_price: line.unit_price,
remark: line.remark || ''
@@ -1879,13 +1881,15 @@ const InventoryView = {
}
if (type === 'salesOrder') {
await loadCustomers();
await loadProducts();
await loadFinishedProducts();
state.form = {
customer_id: state.customers[0]?.id || null,
delivery_date: '',
remark: '',
items: [{
product_id: state.products.find(p => p.item_type === 'finished')?.id || null,
product_id: state.finishedProducts[0]?.id || null,
product_sku: '',
product_name: '',
quantity: 1,
unit_price: 0,
remark: ''
@@ -2105,7 +2109,9 @@ const InventoryView = {
const addSalesOrderItem = () => {
state.form.items = state.form.items || [];
state.form.items.push({
product_id: state.products.find(p => p.item_type === 'finished')?.id || null,
product_id: state.finishedProducts[0]?.id || null,
product_sku: '',
product_name: '',
quantity: 1,
unit_price: 0,
remark: ''
@@ -2126,7 +2132,16 @@ const InventoryView = {
customer_id: state.form.customer_id,
delivery_date: state.form.delivery_date ? new Date(state.form.delivery_date).toISOString() : null,
remark: state.form.remark,
items: state.form.items
items: state.form.items.map(item => ({
product_id: item.product_id || null,
product_sku: item.product_id ? null : (item.product_sku || null),
product_name: item.product_id ? null : (item.product_name || null),
product_category: null,
product_unit: '件',
quantity: item.quantity,
unit_price: item.unit_price,
remark: item.remark || ''
}))
};
if (state.editingItem) {
await apiRequest(`/api/sales-orders/${state.editingItem.id}`, {
@@ -2143,6 +2158,7 @@ const InventoryView = {
}
closeModal();
loadProductionOrders();
loadFinishedProducts();
loadInventory();
loadMovements();
} catch (e) {
@@ -2150,6 +2166,19 @@ const InventoryView = {
}
};
const updateSalesOrderStatus = async (order, targetStatus) => {
try {
await apiRequest(`/api/sales-orders/${order.id}/status`, {
method: 'PATCH',
body: JSON.stringify({ status: targetStatus })
});
addNotification('订单状态已更新', 'success');
loadProductionOrders();
} catch (e) {
handleApiError(e, '更新订单状态');
}
};
const deleteSalesOrder = async (orderId) => {
if (!confirm('确定删除这个销售订单吗?系统会自动回补已扣减物料。')) return;
try {
@@ -2288,6 +2317,7 @@ const InventoryView = {
removeSalesOrderItem,
saveSalesOrder,
deleteSalesOrder,
updateSalesOrderStatus,
addPurchaseOrderItem,
removePurchaseOrderItem,
savePurchaseOrder,
@@ -2623,10 +2653,9 @@ const InventoryView = {
<tr>
<th>销售单</th>
<th>客户</th>
<th>生产单号</th>
<th>生产状态</th>
<th>计划物料成本</th>
<th>实际领料成本</th>
<th>订单金额</th>
<th>预计交付</th>
<th>订单状态</th>
<th>操作</th>
</tr>
</thead>
@@ -2634,12 +2663,14 @@ const InventoryView = {
<tr v-for="order in state.productionOrders" :key="'production-order-' + order.id">
<td>{{ order.order_no }}</td>
<td>{{ order.customer_name }}</td>
<td>{{ order.production_no || '-' }}</td>
<td>{{ order.production_status || '-' }}</td>
<td>{{ formatCurrency(order.planned_material_cost || 0) }}</td>
<td>{{ formatCurrency(order.actual_material_cost || 0) }}</td>
<td>{{ formatCurrency(order.total_amount || 0) }}</td>
<td>{{ order.delivery_date ? formatDateTime(order.delivery_date) : '-' }}</td>
<td>{{ order.status === 'manufacturing' ? '制造中' : order.status === 'delivered' ? '已交付' : order.status === 'paid' ? '已收款' : order.status }}</td>
<td>
<div class="action-btns">
<button class="btn btn-sm btn-secondary" @click="updateSalesOrderStatus(order, 'manufacturing')">制造中</button>
<button class="btn btn-sm btn-secondary" @click="updateSalesOrderStatus(order, 'delivered')">已交付</button>
<button class="btn btn-sm btn-secondary" @click="updateSalesOrderStatus(order, 'paid')">已收款</button>
<button class="btn btn-sm btn-secondary" @click="openModal('salesOrder', order)">编辑</button>
<button class="btn btn-sm btn-danger" @click="deleteSalesOrder(order.id)">删除</button>
<button class="btn btn-sm btn-secondary" @click="loadOrderProductionPlan(order.id)">领料建议</button>
@@ -2994,11 +3025,16 @@ const InventoryView = {
<tbody>
<tr v-for="(line, index) in state.form.items" :key="'sales-order-line-' + index">
<td>
<select v-model.number="line.product_id" class="form-input" required>
<option v-for="product in state.products.filter(p => p.item_type === 'finished')" :key="'sales-order-product-' + product.id" :value="product.id">
<select v-model.number="line.product_id" class="form-input">
<option :value="null">配置新产品</option>
<option v-for="product in state.finishedProducts" :key="'sales-order-product-' + product.id" :value="product.id">
{{ product.sku }} - {{ product.name }}
</option>
</select>
<div v-if="!line.product_id" style="margin-top:8px; display:flex; gap:8px;">
<input v-model="line.product_sku" class="form-input" placeholder="新产品SKU" />
<input v-model="line.product_name" class="form-input" placeholder="新产品名称" />
</div>
</td>
<td><input v-model.number="line.quantity" type="number" min="1" class="form-input" required /></td>
<td><input v-model.number="line.unit_price" type="number" min="0" step="0.01" class="form-input" required /></td>