init
This commit is contained in:
+50
-9
@@ -2194,6 +2194,16 @@ const InventoryView = {
|
||||
warehouse_id: state.purchaseWarehouseId || state.warehouses.find(w => w.is_default)?.id || state.warehouses[0]?.id || null,
|
||||
remark: ''
|
||||
};
|
||||
} else if (type === 'product') {
|
||||
state.form = { ...item };
|
||||
if (item.item_type === 'finished') {
|
||||
await loadMaterials();
|
||||
const bom = await apiRequest(`/api/products/${item.id}/materials`);
|
||||
state.productBomItems = (bom.items || []).map(bomItem => ({
|
||||
material_id: bomItem.material_id,
|
||||
quantity: bomItem.quantity
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
state.form = { ...item };
|
||||
}
|
||||
@@ -2459,6 +2469,12 @@ const InventoryView = {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(state.form)
|
||||
});
|
||||
if (state.form.item_type === 'finished' && state.productBomItems.length > 0) {
|
||||
await apiRequest(`/api/products/${state.editingItem.id}/materials`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ items: state.productBomItems })
|
||||
});
|
||||
}
|
||||
addNotification('产品更新成功', 'success');
|
||||
} else {
|
||||
await apiRequest('/api/products', {
|
||||
@@ -2495,20 +2511,18 @@ const InventoryView = {
|
||||
state.editingItem = product;
|
||||
state.productBomItems = (bom.items || []).map(item => ({
|
||||
material_id: item.material_id,
|
||||
quantity: item.quantity,
|
||||
loss_rate: item.loss_rate
|
||||
quantity: item.quantity
|
||||
}));
|
||||
state.showModal = true;
|
||||
} catch (e) {
|
||||
handleApiError(e, '加载产品BOM');
|
||||
handleApiError(e, '加载产品 BOM');
|
||||
}
|
||||
};
|
||||
|
||||
const addBomItem = () => {
|
||||
state.productBomItems.push({
|
||||
material_id: state.materials[0]?.id || null,
|
||||
quantity: 1,
|
||||
loss_rate: 0
|
||||
quantity: 1
|
||||
});
|
||||
};
|
||||
|
||||
@@ -3116,7 +3130,6 @@ const InventoryView = {
|
||||
<td>{{ formatCurrency(product.material_cost || 0) }}</td>
|
||||
<td>
|
||||
<div class="action-btns">
|
||||
<button class="btn btn-sm btn-secondary" @click="editProductBom(product)">BOM</button>
|
||||
<button class="btn btn-sm btn-secondary" @click="openModal('product', product)">编辑</button>
|
||||
<button class="btn btn-sm btn-danger" @click="deleteProduct(product.id)">删除</button>
|
||||
</div>
|
||||
@@ -3618,7 +3631,7 @@ const InventoryView = {
|
||||
<div v-if="state.showModal" class="modal-overlay" @click.self="closeModal">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h3>{{ state.editingItem ? '编辑' : '新增' }}{{ state.modalType === 'product' ? '产品/物料' : state.modalType === 'productBom' ? '产品BOM' : state.modalType === 'inventoryItem' ? '物料库存' : state.modalType === 'salesOrder' ? '销售订单' : state.modalType === 'purchaseOrder' ? '采购订单' : state.modalType === 'purchaseReceive' ? '采购到货入库' : state.modalType === 'supplier' ? '供应商' : '客户' }}</h3>
|
||||
<h3>{{ state.editingItem ? '编辑' : '新增' }}{{ state.modalType === 'product' ? (state.form.item_type === 'finished' ? '成品' : '物料') : state.modalType === 'productBom' ? '产品物料' : state.modalType === 'inventoryItem' ? '物料库存' : state.modalType === 'salesOrder' ? '销售订单' : state.modalType === 'purchaseOrder' ? '采购订单' : state.modalType === 'purchaseReceive' ? '采购到货入库' : state.modalType === 'supplier' ? '供应商' : '客户' }}</h3>
|
||||
<button class="modal-close" @click="closeModal">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@@ -3661,6 +3674,36 @@ const InventoryView = {
|
||||
<label class="form-label">说明</label>
|
||||
<input disabled value="成品不做库存,成本由下方BOM定义物料构成后自动计算" class="form-input" />
|
||||
</div>
|
||||
<div v-if="state.form.item_type === 'finished' && state.editingItem" class="bom-section">
|
||||
<div class="form-group">
|
||||
<label class="form-label">BOM物料配置</label>
|
||||
<button type="button" class="btn btn-secondary" @click="addBomItem" style="margin-bottom: 8px;">+ 添加物料</button>
|
||||
<div class="table-container">
|
||||
<table class="data-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>物料</th>
|
||||
<th>数量</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, idx) in state.productBomItems" :key="'edit-bom-item-' + idx">
|
||||
<td>
|
||||
<select v-model.number="item.material_id" class="form-input" required>
|
||||
<option v-for="material in state.materials" :key="'edit-bom-material-' + material.id" :value="material.id">
|
||||
{{ material.sku }} - {{ material.name }}
|
||||
</option>
|
||||
</select>
|
||||
</td>
|
||||
<td><input v-model.number="item.quantity" type="number" min="0.0001" step="0.0001" class="form-input" required /></td>
|
||||
<td><button type="button" class="btn btn-sm btn-danger" @click="removeBomItem(idx)">删除</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" @click="closeModal">取消</button>
|
||||
<button type="submit" class="btn btn-primary">保存</button>
|
||||
@@ -3923,7 +3966,6 @@ const InventoryView = {
|
||||
<tr>
|
||||
<th>物料</th>
|
||||
<th>数量</th>
|
||||
<th>损耗率</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -3937,7 +3979,6 @@ const InventoryView = {
|
||||
</select>
|
||||
</td>
|
||||
<td><input v-model.number="item.quantity" type="number" min="0.0001" step="0.0001" class="form-input" required /></td>
|
||||
<td><input v-model.number="item.loss_rate" type="number" min="0" step="0.0001" class="form-input" required /></td>
|
||||
<td><button type="button" class="btn btn-sm btn-danger" @click="removeBomItem(idx)">删除</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user