gaoluyang
10 天以前 f3cac4aa2db56d6017c1d1dc035bcfeaec76c3e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<script setup lang="ts">
import { computed, ref } from 'vue';
import { Button, Form, FormItem, Input, InputNumber, Modal, Select, message } from 'ant-design-vue';
import { requestClient } from '#/api/request';
import { getWarehouseSimpleList } from '#/api/mes/wm/warehouse';
import { WmWarehouseAreaSelect, WmWarehouseLocationSelect } from '#/views/wls/warehouse/components';
 
const emit = defineEmits<{ success: [] }>();
const visible = ref(false);
const busy = ref(false);
const orderId = ref<number>();
const orderCode = ref('');
const requestId = ref('');
const outputs = ref<Array<{ itemId: number; itemCode?: string; itemName?: string; quantity: number; batchId?: number; batchCode?: string }>>([]);
const warehouses = ref<Array<{ id?: number; name?: string; warehouseType?: string; frozen?: boolean }>>([]);
const itemId = ref<number>();
const selectedOutput = ref<number>();
const batchId = ref<number>();
const quantity = ref<number>();
const warehouseId = ref<number>();
const locationId = ref<number>();
const areaId = ref<number>();
const batchCode = ref('');
const options = computed(() => outputs.value.map((item, index) => ({ value: index, label: `${item.itemName || item.itemCode || item.itemId}${item.batchCode ? ` · 批次 ${item.batchCode}` : ''}(产出 ${item.quantity})` })));
function selectOutput(index: number) {
  const output = outputs.value[index];
  itemId.value = output?.itemId; batchId.value = output?.batchId; batchCode.value = output?.batchCode || '';
}
 
async function open(id: number, code?: string) {
  orderId.value = id; orderCode.value = code || ''; itemId.value = undefined; selectedOutput.value = undefined; batchId.value = undefined; quantity.value = undefined;
  warehouseId.value = undefined; locationId.value = undefined; areaId.value = undefined; batchCode.value = '';
  requestId.value = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`;
  outputs.value = []; visible.value = true; busy.value = true;
  try {
    const [items, list] = await Promise.all([
      requestClient.get<typeof outputs.value>('/mes/wm/scrap-receipt/order-outputs', { params: { workOrderId: id } }),
      getWarehouseSimpleList(),
    ]);
    outputs.value = items || [];
    warehouses.value = (list || []).filter(w => ['废料仓', '废料'].includes(w.warehouseType || '') && !w.frozen);
    if (!outputs.value.length) message.warning('该订单没有已完成的产出物料');
    if (!warehouses.value.length) message.warning('请先在仓库设置中将废料仓的仓库类型设为“废料仓”');
  } finally { busy.value = false; }
}
 
async function submit() {
  if (!orderId.value || !itemId.value || !quantity.value || quantity.value <= 0 || !warehouseId.value || !locationId.value || !areaId.value) {
    message.warning('请选择产出物料、数量以及废料仓库和库位'); return;
  }
  busy.value = true;
  try {
    await requestClient.post('/mes/wm/scrap-receipt/create-from-output', {
      requestId: requestId.value, workOrderId: orderId.value, itemId: itemId.value,
      quantity: quantity.value, warehouseId: warehouseId.value, locationId: locationId.value,
      areaId: areaId.value, batchId: batchId.value, batchCode: batchCode.value || undefined,
    });
    message.success('废料已入库'); visible.value = false; emit('success');
  } finally { busy.value = false; }
}
defineExpose({ open });
</script>
 
<template>
  <Modal v-model:open="visible" title="废料入库" :confirm-loading="busy" :mask-closable="false" @ok="submit">
    <Form layout="vertical">
      <FormItem label="生产订单"><Input :value="orderCode" disabled /></FormItem>
      <FormItem label="产出物料" required><Select v-model:value="selectedOutput" :options="options" placeholder="请选择订单产出物料" @change="selectOutput" /></FormItem>
      <FormItem label="废料数量" required><InputNumber v-model:value="quantity" :min="0.0001" :precision="4" class="w-full" /></FormItem>
      <FormItem label="废料仓库" required><Select v-model:value="warehouseId" :options="warehouses.map(w => ({value: w.id, label: w.name}))" placeholder="请选择废料仓库" @change="locationId = undefined; areaId = undefined" /></FormItem>
      <FormItem label="库区" required><WmWarehouseLocationSelect v-model="locationId" :warehouse-id="warehouseId" @change="areaId = undefined" /></FormItem>
      <FormItem label="库位" required><WmWarehouseAreaSelect v-model="areaId" :location-id="locationId" /></FormItem>
      <FormItem label="批次号"><Input :value="batchCode || '无'" disabled /></FormItem>
    </Form>
    <template #footer><Button @click="visible = false">取消</Button><Button type="primary" :loading="busy" :disabled="busy" @click="submit">确认入库</Button></template>
  </Modal>
</template>