gaoluyang
2026-11-03 2d8b1a28fa5c8b852f0d0078bac4894bfb4abed5
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<script setup lang="ts">
import { computed, reactive, ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { getMaterialPage, getMeasureUnitPage, type MaterialItem, type MeasureUnit } from "../../../api/basic-data";
import { getSimpleDictDataList, type DictData } from "../../../api/crm";
import { getSaleOrderPage, type SaleOrder } from "../../../api/sale";
import { getCrmUserList } from "../../../api/crm";
import type { UserSimple } from "../../../api/purchase";
import {
  addChildPackage,
  createPackage,
  createPackageLine,
  createStockTakingPlan,
  createStockTakingPlanParam,
  createStockTakingResult,
  createStockTakingTask,
  createStockTakingTaskLine,
  createTransfer,
  createTransferDetail,
  createTransferLine,
  deletePackageLine,
  deleteStockTakingPlanParam,
  deleteStockTakingResult,
  deleteStockTakingTaskLine,
  deleteTransferDetail,
  deleteTransferLine,
  finishPackage,
  finishStockTakingTask,
  finishTransfer,
  confirmTransfer,
  generateAutoCode,
  getBatchPage,
  getMaterialStockPage,
  getPackage,
  getPackageLinePage,
  getPackagePage,
  getStockTakingPlan,
  getStockTakingPlanPage,
  getStockTakingPlanParamPage,
  getStockTakingResultPage,
  getStockTakingTask,
  getStockTakingTaskLinePage,
  getStockTakingTaskLineSimpleList,
  getTransfer,
  getTransferDetailList,
  getTransferLineList,
  getWorkOrderPage,
  getWarehouseAreaSimpleList,
  getWarehouseLocationSimpleList,
  getWarehouseSimpleList,
  removeChildPackage,
  stockTransfer,
  submitStockTakingTask,
  submitTransfer,
  updatePackage,
  updatePackageLine,
  updateStockTakingPlan,
  updateStockTakingPlanParam,
  updateStockTakingResult,
  updateStockTakingTask,
  updateStockTakingTaskLine,
  updateTransfer,
  updateTransferDetail,
  updateTransferLine,
  type MaterialStock,
  type Batch,
  type PackageLine,
  type StockTakingPlan,
  type StockTakingPlanParam,
  type StockTakingResult,
  type StockTakingTask,
  type StockTakingTaskLine,
  type Transfer,
  type TransferDetail,
  type TransferLine,
  type Warehouse,
  type WarehouseArea,
  type WarehouseLocation,
  type WlsWorkOrder,
  type WlsPackage,
} from "../../../api/wls";
import { useAuth } from "../../../stores/auth";
import { booleanText, dateText, dayText, dictLabel, materialOptionText } from "./shared";
 
type Kind = "transfer" | "stock-plan" | "stock-task" | "package";
type Mode = "create" | "edit" | "detail" | "stock" | "finish" | "confirm" | "execute" | "submit";
type Header = Transfer & StockTakingPlan & StockTakingTask & WlsPackage;
type Line = TransferLine & StockTakingPlanParam & StockTakingTaskLine & PackageLine & StockTakingResult;
const props = defineProps<{ kind: Kind }>();
const { hasPermission, state } = useAuth();
const id = ref<number>();
const mode = ref<Mode>("create");
const saving = ref(false);
const showLine = ref(false);
const lineKind = ref<"line" | "detail" | "result" | "child">("line");
const editIndex = ref<number>();
const stockLine = ref<Line>();
const form = reactive<Header>({ status: 0, blindFlag: false, frozen: false, deliveryFlag: false });
const lineForm = reactive<Line>({});
const lines = ref<Line[]>([]);
const details = ref<Record<number, TransferDetail[]>>({});
const results = ref<StockTakingResult[]>([]);
const dicts = ref<DictData[]>([]);
const materials = ref<MaterialItem[]>([]);
const stocks = ref<MaterialStock[]>([]);
const warehouses = ref<Warehouse[]>([]);
const locations = ref<WarehouseLocation[]>([]);
const areas = ref<WarehouseArea[]>([]);
const users = ref<UserSimple[]>([]);
const plans = ref<StockTakingPlan[]>([]);
const saleOrders = ref<SaleOrder[]>([]);
const units = ref<MeasureUnit[]>([]);
const packages = ref<WlsPackage[]>([]);
const workOrders = ref<WlsWorkOrder[]>([]);
const batches = ref<Batch[]>([]);
const config = computed(() => ({
  transfer: { title: "转移调拨", permission: "mes:wm-transfer", rule: "TRANSFER_CODE", code: "转移单编号", name: "转移单名称" },
  "stock-plan": { title: "盘点方案", permission: "mes:wm-stock-taking-plan", rule: "WM_STOCK_TAKING_PLAN_CODE", code: "方案编码", name: "方案名称" },
  "stock-task": { title: "盘点任务", permission: "mes:wm-stock-taking-task", rule: "WM_STOCK_TAKING_CODE", code: "任务编码", name: "任务名称" },
  package: { title: "装箱管理", permission: "mes:wm-package", rule: "WM_PACKAGE_CODE", code: "装箱单编号", name: "" },
}[props.kind]));
const readonly = computed(() => mode.value === "detail" || mode.value === "stock" || mode.value === "finish" || mode.value === "confirm" || mode.value === "execute" || mode.value === "submit");
const editable = computed(() => mode.value === "create" || mode.value === "edit");
const canSave = computed(() => editable.value && (id.value ? hasPermission(`${config.value.permission}:update`) : hasPermission(`${config.value.permission}:create`)));
const canSubmit = computed(() => id.value && Number(form.status) === 0 && (props.kind === "transfer" || props.kind === "stock-task") && hasPermission(`${config.value.permission}:update`) && (editable.value || mode.value === "submit"));
const canLine = computed(() => editable.value && id.value && hasPermission(`${config.value.permission}:update`));
const canStock = computed(() => props.kind === "transfer" && mode.value === "stock" && hasPermission("mes:wm-transfer:update"));
const canConfirm = computed(() => props.kind === "transfer" && mode.value === "confirm" && hasPermission("mes:wm-transfer:update"));
const canFinish = computed(() => (props.kind === "transfer" && mode.value === "finish" && hasPermission("mes:wm-transfer:finish")) || (props.kind === "stock-task" && mode.value === "execute" && hasPermission("mes:wm-stock-taking-task:update")) || (props.kind === "package" && editable.value && id.value && Number(form.status) === 0 && hasPermission("mes:wm-package:update")));
const showTransferDeliveryFields = computed(() => props.kind === "transfer" && Number(form.type) === 2);
const showStockTakingTimeFields = computed(() => (props.kind === "stock-plan" || props.kind === "stock-task") && Number(form.type) === 2);
const typeOptions = computed(() => dicts.value.filter(i => i.dictType === (props.kind === "transfer" ? "mes_wm_transfer_type" : "mes_wm_stock_taking_type")).map(i => i.label));
const paramTypeOptions = computed(() => dicts.value.filter(i => i.dictType === "mes_wm_stock_taking_plan_param_type").map(i => i.label));
const materialOptions = computed(() => materials.value.map(materialOptionText));
const stockOptions = computed(() => stocks.value.map(i => `${i.itemCode || "--"} - ${i.itemName || "--"} / ${i.specification || "无规格"} / ${i.unitMeasureName || "无单位"} / ${i.batchCode || "无批次"} / ${i.warehouseName || "--"}-${i.locationName || "--"}-${i.areaName || "--"} / 可用${i.availableQuantity ?? i.quantity ?? 0}`));
const warehouseOptions = computed(() => warehouses.value.map(i => `${i.code || "--"} - ${i.name || "--"}`));
const locationOptions = computed(() => locations.value.map(i => `${i.code || "--"} - ${i.name || "--"} / ${i.warehouseName || "--"}`));
const areaOptions = computed(() => areas.value.map(i => `${i.code || "--"} - ${i.name || "--"} / ${i.locationName || "--"}`));
const userOptions = computed(() => users.value.map(i => `${i.nickname || i.username || i.id}`));
const planOptions = computed(() => plans.value.map(i => `${i.code || "--"} - ${i.name || "--"} / ${dictLabel(dicts.value, "mes_wm_stock_taking_type", i.type)}`));
const saleOrderOptions = computed(() => saleOrders.value.map(i => `${i.no || "--"} / ${i.customerName || "--"} / ${i.productNames || "无产品"}`));
const unitOptions = computed(() => units.value.map(i => `${i.code || "--"} - ${i.name || "--"}`));
const packageOptions = computed(() => packages.value.map(i => `${i.code || "--"} / ${i.clientName || "无客户"} / ${dayText(i.packageDate)}`));
const workOrderOptions = computed(() => workOrders.value.map(i => `${i.code || "--"} - ${i.name || i.itemName || "--"}`));
const batchOptions = computed(() => batches.value.map(i => `${i.code || "--"} / ${i.itemCode || "--"} - ${i.itemName || "--"} / ${i.itemSpecification || "无规格"} / ${i.unitName || "无单位"}`));
const qualityOptions = computed(() => dicts.value.filter(i => i.dictType === "mes_wm_quality_status").map(i => i.label));
const stockLineMaterialText = () => materialOptionText({ code: stockLine.value?.itemCode || lineForm.itemCode, name: stockLine.value?.itemName || lineForm.itemName, specification: stockLine.value?.specification || lineForm.specification, unitMeasureName: stockLine.value?.unitMeasureName || lineForm.unitMeasureName });
 
const num = (value: string) => { const n = Number(value); return Number.isFinite(n) ? n : 0; };
function clear(target: Record<string, unknown>, next: Record<string, unknown> = {}) { Object.keys(target).forEach(k => delete target[k]); Object.assign(target, next); }
function setType(event: { detail: { value: string } }) {
  const row = dicts.value.filter(i => i.dictType === (props.kind === "transfer" ? "mes_wm_transfer_type" : "mes_wm_stock_taking_type"))[Number(event.detail.value)];
  form.type = row?.value === undefined ? undefined : Number(row.value);
  if (props.kind === "transfer" && Number(form.type) !== 2) Object.assign(form, { deliveryFlag: false, confirmFlag: undefined, recipientName: "", recipientTelephone: "", carrier: "", shippingNumber: "", destinationAddress: "" });
  if ((props.kind === "stock-plan" || props.kind === "stock-task") && Number(form.type) !== 2) Object.assign(form, { startTime: "", endTime: "" });
}
function setParamType(event: { detail: { value: string } }) { const row = dicts.value.filter(i => i.dictType === "mes_wm_stock_taking_plan_param_type")[Number(event.detail.value)]; lineForm.type = row?.value === undefined ? undefined : Number(row.value); lineForm.valueId = undefined; lineForm.valueCode = ""; lineForm.valueName = ""; }
function selectUser(event: { detail: { value: string } }) { const row = users.value[Number(event.detail.value)]; form.userId = row?.id; form.userNickname = row?.nickname || row?.username; form.inspectorUserId = row?.id; form.inspectorName = row?.nickname || row?.username; }
function selectPlan(event: { detail: { value: string } }) { const row = plans.value[Number(event.detail.value)]; Object.assign(form, { planId: row?.id, planCode: row?.code, planName: row?.name, type: row?.type, blindFlag: row?.blindFlag, frozen: row?.frozen, startTime: row?.startTime, endTime: row?.endTime }); }
function selectSaleOrder(event: { detail: { value: string } }) { const row = saleOrders.value[Number(event.detail.value)]; Object.assign(form, { saleOrderId: row?.id, salesOrderCode: row?.no, clientId: row?.customerId, clientName: row?.customerName }); }
function selectUnit(event: { detail: { value: string } }, key: "size" | "weight") { const row = units.value[Number(event.detail.value)]; if (key === "size") Object.assign(form, { sizeUnitId: row?.id, sizeUnitName: row?.name }); else Object.assign(form, { weightUnitId: row?.id, weightUnitName: row?.name }); }
async function selectWarehouse(event: { detail: { value: string } }, prefix = "to") { const row = warehouses.value[Number(event.detail.value)]; Object.assign(lineForm, { [`${prefix}WarehouseId`]: row?.id, [`${prefix}WarehouseName`]: row?.name, warehouseId: row?.id, warehouseName: row?.name }); locations.value = row?.id && state.accessToken ? await getWarehouseLocationSimpleList(state.accessToken, row.id) : []; }
async function selectLocation(event: { detail: { value: string } }, prefix = "to") { const row = locations.value[Number(event.detail.value)]; Object.assign(lineForm, { [`${prefix}LocationId`]: row?.id, [`${prefix}LocationName`]: row?.name, locationId: row?.id, locationName: row?.name }); areas.value = row?.id && state.accessToken ? await getWarehouseAreaSimpleList(state.accessToken, row.id) : []; }
function selectArea(event: { detail: { value: string } }, prefix = "to") { const row = areas.value[Number(event.detail.value)]; Object.assign(lineForm, { [`${prefix}AreaId`]: row?.id, [`${prefix}AreaName`]: row?.name, areaId: row?.id, areaName: row?.name }); }
function selectMaterial(event: { detail: { value: string } }) { const row = materials.value[Number(event.detail.value)]; Object.assign(lineForm, { itemId: row?.id, itemCode: row?.code, itemName: row?.name, specification: row?.specification, unitMeasureName: row?.unitMeasureName }); }
function selectStock(event: { detail: { value: string } }) {
  const row = stocks.value[Number(event.detail.value)];
  Object.assign(lineForm, { materialStockId: row?.id, itemId: row?.itemId, itemCode: row?.itemCode, itemName: row?.itemName, specification: row?.specification, unitMeasureName: row?.unitMeasureName, batchId: row?.batchId, batchCode: row?.batchCode, quantity: row?.availableQuantity ?? row?.quantity, quantityMax: row?.availableQuantity ?? row?.quantity, fromWarehouseId: row?.warehouseId, fromWarehouseName: row?.warehouseName, fromLocationId: row?.locationId, fromLocationName: row?.locationName, fromAreaId: row?.areaId, fromAreaName: row?.areaName, warehouseId: row?.warehouseId, warehouseName: row?.warehouseName, locationId: row?.locationId, locationName: row?.locationName, areaId: row?.areaId, areaName: row?.areaName });
}
function selectTaskLine(event: { detail: { value: string } }) { const row = lines.value[Number(event.detail.value)]; Object.assign(lineForm, { lineId: row?.id, materialStockId: row?.materialStockId, itemId: row?.itemId, itemCode: row?.itemCode, itemName: row?.itemName, specification: row?.specification, unitMeasureName: row?.unitMeasureName, batchId: row?.batchId, batchCode: row?.batchCode, warehouseId: row?.warehouseId, warehouseName: row?.warehouseName, locationId: row?.locationId, locationName: row?.locationName, areaId: row?.areaId, areaName: row?.areaName, quantity: row?.quantity, takingQuantity: row?.takingQuantity }); }
function selectPackage(event: { detail: { value: string } }) { const row = packages.value[Number(event.detail.value)]; lineForm.id = row?.id; lineForm.code = row?.code; }
function selectWorkOrder(event: { detail: { value: string } }) { const row = workOrders.value[Number(event.detail.value)]; lineForm.workOrderId = row?.id; lineForm.workOrderCode = row?.code; }
function setCondition(row?: { id?: number; code?: string; name?: string; nickname?: string }) { lineForm.valueId = row?.id; lineForm.valueCode = row?.code || ""; lineForm.valueName = row?.name || row?.nickname || ""; }
function conditionText(fallback: string) { return lineForm.valueName ? `${lineForm.valueCode || "--"} - ${lineForm.valueName}` : fallback; }
function selectConditionWarehouse(event: { detail: { value: string } }) { setCondition(warehouses.value[Number(event.detail.value)]); }
async function selectConditionLocationWarehouse(event: { detail: { value: string } }) { const row = warehouses.value[Number(event.detail.value)]; locations.value = row?.id && state.accessToken ? await getWarehouseLocationSimpleList(state.accessToken, row.id) : []; clear(lineForm as Record<string, unknown>, { ...lineForm, valueId: undefined, valueCode: "", valueName: "" }); }
async function selectConditionAreaWarehouse(event: { detail: { value: string } }) { const row = warehouses.value[Number(event.detail.value)]; locations.value = row?.id && state.accessToken ? await getWarehouseLocationSimpleList(state.accessToken, row.id) : []; areas.value = []; clear(lineForm as Record<string, unknown>, { ...lineForm, valueId: undefined, valueCode: "", valueName: "" }); }
async function selectConditionAreaLocation(event: { detail: { value: string } }) { const row = locations.value[Number(event.detail.value)]; areas.value = row?.id && state.accessToken ? await getWarehouseAreaSimpleList(state.accessToken, row.id) : []; clear(lineForm as Record<string, unknown>, { ...lineForm, valueId: undefined, valueCode: "", valueName: "" }); }
function selectConditionLocation(event: { detail: { value: string } }) { setCondition(locations.value[Number(event.detail.value)]); }
function selectConditionArea(event: { detail: { value: string } }) { setCondition(areas.value[Number(event.detail.value)]); }
function selectConditionMaterial(event: { detail: { value: string } }) { const row = materials.value[Number(event.detail.value)]; setCondition(row ? { id: row.id, code: row.code, name: row.name } : undefined); }
function selectConditionBatch(event: { detail: { value: string } }) { const row = batches.value[Number(event.detail.value)]; lineForm.valueId = row?.id; lineForm.valueCode = row?.code || ""; lineForm.valueName = row?.code || ""; }
function selectConditionQuality(event: { detail: { value: string } }) { const row = dicts.value.filter(i => i.dictType === "mes_wm_quality_status")[Number(event.detail.value)]; lineForm.valueId = undefined; lineForm.valueCode = row?.value === undefined ? "" : String(row.value); lineForm.valueName = row?.label || ""; }
function requireText() {
  if (!form.code) return `请填写${config.value.code}`;
  if (props.kind !== "package" && !form.name) return `请填写${config.value.name}`;
  if ((props.kind === "transfer" || props.kind === "stock-plan" || props.kind === "stock-task") && !form.type) return "请选择类型";
  if (props.kind === "transfer" && !form.transferDate) return "请选择转移日期";
  if (props.kind === "stock-plan" && showStockTakingTimeFields.value && (!form.startTime || !form.endTime)) return "请选择开始时间和结束时间";
  if (props.kind === "stock-task" && !form.planId) return "请选择盘点方案";
  if (props.kind === "stock-task" && (!form.takingDate || !form.userId)) return "请选择盘点日期和盘点人";
  if (props.kind === "package" && (!form.packageDate || !form.saleOrderId)) return "请选择装箱日期和销售订单";
  return "";
}
function requireLineText() {
  if (lineKind.value === "child" && !lineForm.id) return "请选择装箱单";
  if (props.kind === "stock-plan") {
    if (!lineForm.type) return "请选择条件类型";
    if (lineForm.type !== 900 && !lineForm.valueId) return "请选择条件值";
    if (lineForm.type === 900 && !lineForm.valueCode) return "请选择条件值";
  }
  if (lineKind.value === "detail") {
    if (!lineForm.toWarehouseId || !lineForm.toLocationId || !lineForm.toAreaId) return "请选择移入仓库、库区和库位";
    if (!lineForm.quantity) return "请填写数量";
  }
  if (props.kind === "transfer" && lineKind.value === "line") {
    if (!lineForm.materialStockId) return "请选择库存记录";
    if (!lineForm.quantity) return "请填写转移数量";
  }
  if (props.kind === "stock-task" && lineKind.value === "line") {
    if (!lineForm.materialStockId) return "请选择库存记录";
    if (!lineForm.quantity) return "请填写数量";
  }
  if (props.kind === "stock-task" && lineKind.value === "result") {
    if (!lineForm.itemId) return "请选择物料";
    if (!lineForm.takingQuantity) return "请填写盘点数量";
    if (!lineForm.warehouseId || !lineForm.locationId || !lineForm.areaId) return "请选择仓库、库区和库位";
  }
  if (props.kind === "package" && lineKind.value === "line") {
    if (!lineForm.workOrderId) return "请选择生产订单";
    if (!lineForm.itemId) return "请选择产品物料";
    if (!lineForm.quantity) return "请填写装箱数量";
  }
  return "";
}
async function loadOptions() {
  if (!state.accessToken) return;
  const [ds, ms, ss, ws] = await Promise.all([
    getSimpleDictDataList(state.accessToken),
    getMaterialPage(state.accessToken, { pageNo: 1, pageSize: 100 }),
    getMaterialStockPage(state.accessToken, { pageNo: 1, pageSize: 100 }),
    getWarehouseSimpleList(state.accessToken),
  ]);
  dicts.value = ds; materials.value = ms.list; stocks.value = ss.list; warehouses.value = ws;
  if (props.kind === "stock-plan") batches.value = (await getBatchPage(state.accessToken, { pageNo: 1, pageSize: 100 })).list;
  if (props.kind === "stock-task") { users.value = await getCrmUserList(state.accessToken); plans.value = (await getStockTakingPlanPage(state.accessToken, { pageNo: 1, pageSize: 100, status: 0 })).list; }
  if (props.kind === "package") { const [u, so, ps, wo] = await Promise.all([getMeasureUnitPage(state.accessToken, { pageNo: 1, pageSize: 100 }), getSaleOrderPage(state.accessToken, { pageNo: 1, pageSize: 100 }), getPackagePage(state.accessToken, { pageNo: 1, pageSize: 100, childableOnly: true }), getWorkOrderPage(state.accessToken, { pageNo: 1, pageSize: 100, status: 1 })]); units.value = u.list; saleOrders.value = so.list; packages.value = ps.list; workOrders.value = wo.list; users.value = await getCrmUserList(state.accessToken); }
}
async function loadDoc() {
  if (!state.accessToken || !id.value) return;
  const data = props.kind === "transfer" ? await getTransfer(state.accessToken, id.value) : props.kind === "stock-plan" ? await getStockTakingPlan(state.accessToken, id.value) : props.kind === "stock-task" ? await getStockTakingTask(state.accessToken, id.value) : await getPackage(state.accessToken, id.value);
  Object.assign(form, data);
  await loadLines();
}
async function loadLines() {
  if (!state.accessToken || !id.value) return;
  if (props.kind === "transfer") { lines.value = await getTransferLineList(state.accessToken, id.value); for (const line of lines.value) if (line.id) details.value[line.id] = await getTransferDetailList(state.accessToken, line.id); }
  if (props.kind === "stock-plan") lines.value = (await getStockTakingPlanParamPage(state.accessToken, { pageNo: 1, pageSize: 100, planId: id.value })).list as Line[];
  if (props.kind === "stock-task") { lines.value = (await getStockTakingTaskLinePage(state.accessToken, { pageNo: 1, pageSize: 100, taskId: id.value })).list as Line[]; results.value = (await getStockTakingResultPage(state.accessToken, { pageNo: 1, pageSize: 100, taskId: id.value })).list; }
  if (props.kind === "package") lines.value = (await getPackageLinePage(state.accessToken, { pageNo: 1, pageSize: 100, packageId: id.value })).list as Line[];
}
async function generateCode() { if (state.accessToken) form.code = await generateAutoCode(state.accessToken, config.value.rule); }
async function save() {
  if (!state.accessToken || saving.value || !canSave.value) return false;
  const msg = requireText(); if (msg) { uni.showToast({ title: msg, icon: "none" }); return false; }
  saving.value = true;
  try {
    const data = { ...form, id: id.value };
    const newId = props.kind === "transfer" ? (id.value ? await updateTransfer(state.accessToken, data) : await createTransfer(state.accessToken, data))
      : props.kind === "stock-plan" ? (id.value ? await updateStockTakingPlan(state.accessToken, data) : await createStockTakingPlan(state.accessToken, data))
      : props.kind === "stock-task" ? (id.value ? await updateStockTakingTask(state.accessToken, data) : await createStockTakingTask(state.accessToken, data))
      : (id.value ? await updatePackage(state.accessToken, data) : await createPackage(state.accessToken, data));
    if (!id.value && typeof newId === "number") id.value = newId;
    mode.value = "edit"; uni.showToast({ title: "保存成功", icon: "success" }); await loadDoc(); return true;
  } catch (error) { uni.showToast({ title: error instanceof Error ? error.message : "保存失败", icon: "none" }); return false; }
  finally { saving.value = false; }
}
async function submitDoc() { if (!id.value && !(await save())) return; if (!state.accessToken || !id.value) return; try { props.kind === "transfer" ? await submitTransfer(state.accessToken, id.value) : await submitStockTakingTask(state.accessToken, id.value); uni.showToast({ title: "提交成功", icon: "success" }); setTimeout(() => uni.navigateBack(), 500); } catch (e) { uni.showToast({ title: e instanceof Error ? e.message : "提交失败", icon: "none" }); } }
function openLine(row?: Line, index?: number, kind: "line" | "detail" | "result" | "child" = "line", parent?: Line) { lineKind.value = kind; editIndex.value = index; stockLine.value = parent; clear(lineForm as Record<string, unknown>, row ? { ...row } : {}); showLine.value = true; }
async function saveLine() {
  if (!state.accessToken || !id.value) return;
  const msg = requireLineText(); if (msg) { uni.showToast({ title: msg, icon: "none" }); return; }
  try {
    if (lineKind.value === "detail") {
      const data = { ...lineForm, transferId: id.value, lineId: stockLine.value?.id, itemId: stockLine.value?.itemId, itemCode: stockLine.value?.itemCode, itemName: stockLine.value?.itemName, specification: stockLine.value?.specification, unitMeasureName: stockLine.value?.unitMeasureName, batchId: stockLine.value?.batchId, batchCode: stockLine.value?.batchCode };
      lineForm.id ? await updateTransferDetail(state.accessToken, data) : await createTransferDetail(state.accessToken, data);
    } else if (lineKind.value === "result") {
      const data = { ...lineForm, taskId: id.value };
      lineForm.id ? await updateStockTakingResult(state.accessToken, data) : await createStockTakingResult(state.accessToken, data);
    } else if (lineKind.value === "child") {
      if (lineForm.id) await addChildPackage(state.accessToken, id.value, lineForm.id);
    } else if (props.kind === "transfer") {
      const data = { ...lineForm, transferId: id.value };
      lineForm.id ? await updateTransferLine(state.accessToken, data) : await createTransferLine(state.accessToken, data);
    } else if (props.kind === "stock-plan") {
      const data = { ...lineForm, planId: id.value };
      lineForm.id ? await updateStockTakingPlanParam(state.accessToken, data) : await createStockTakingPlanParam(state.accessToken, data);
    } else if (props.kind === "stock-task") {
      const data = { ...lineForm, taskId: id.value };
      lineForm.id ? await updateStockTakingTaskLine(state.accessToken, data) : await createStockTakingTaskLine(state.accessToken, data);
    } else if (props.kind === "package") {
      const data = { ...lineForm, packageId: id.value };
      lineForm.id ? await updatePackageLine(state.accessToken, data) : await createPackageLine(state.accessToken, data);
    }
    showLine.value = false; uni.showToast({ title: "保存成功", icon: "success" }); await loadLines();
  } catch (error) { uni.showToast({ title: error instanceof Error ? error.message : "保存失败", icon: "none" }); }
}
async function removeLine(row: Line, kind: "line" | "detail" | "result" | "child" = "line") {
  if (!state.accessToken || !row.id) return;
  const ok = await new Promise<boolean>(resolve => uni.showModal({ title: "确认删除", content: "确定删除该明细吗?", success: r => resolve(r.confirm) })); if (!ok) return;
  try {
    if (kind === "detail") await deleteTransferDetail(state.accessToken, row.id);
    else if (kind === "result") await deleteStockTakingResult(state.accessToken, row.id);
    else if (kind === "child") await removeChildPackage(state.accessToken, row.id);
    else if (props.kind === "transfer") await deleteTransferLine(state.accessToken, row.id);
    else if (props.kind === "stock-plan") await deleteStockTakingPlanParam(state.accessToken, row.id);
    else if (props.kind === "stock-task") await deleteStockTakingTaskLine(state.accessToken, row.id);
    else await deletePackageLine(state.accessToken, row.id);
    await loadLines();
  } catch (e) { uni.showToast({ title: e instanceof Error ? e.message : "删除失败", icon: "none" }); }
}
async function finishAction() {
  if (!state.accessToken || !id.value) return;
  const ok = await new Promise<boolean>(resolve => uni.showModal({ title: "确认操作", content: props.kind === "package" ? "确认完成该装箱单?" : props.kind === "transfer" ? "确认完成转移?" : "确认执行盘点操作?", success: r => resolve(r.confirm) })); if (!ok) return;
  try { if (props.kind === "transfer") (mode.value === "stock" ? await stockTransfer(state.accessToken, id.value) : await finishTransfer(state.accessToken, id.value)); else if (props.kind === "stock-task") await finishStockTakingTask(state.accessToken, id.value); else await finishPackage(state.accessToken, id.value); uni.showToast({ title: "操作成功", icon: "success" }); setTimeout(() => uni.navigateBack(), 500); } catch (e) { uni.showToast({ title: e instanceof Error ? e.message : "操作失败", icon: "none" }); }
}
async function confirmAction() {
  if (!state.accessToken || !id.value) return;
  const ok = await new Promise<boolean>(resolve => uni.showModal({ title: "确认操作", content: "确认到货后,将进入待上架状态,是否继续?", success: r => resolve(r.confirm) }));
  if (!ok) return;
  try { await confirmTransfer(state.accessToken, id.value); uni.showToast({ title: "确认成功", icon: "success" }); setTimeout(() => uni.navigateBack(), 500); } catch (e) { uni.showToast({ title: e instanceof Error ? e.message : "确认失败", icon: "none" }); }
}
onLoad(async q => { id.value = q.id ? Number(q.id) : undefined; mode.value = (q.mode as Mode) || (id.value ? "edit" : "create"); await loadOptions(); if (id.value) await loadDoc(); else { form.status = 0; if (props.kind === "stock-task") { form.userId = state.user?.id; form.userNickname = state.user?.nickname; } } });
</script>
 
<template>
  <view class="page">
    <view class="form-card">
      <view class="field code-field"><text>{{ config.code }} <text class="required">*</text></text><input v-model="form.code" :disabled="readonly" :placeholder="`请输入${config.code}`" /><button v-if="!readonly" @click="generateCode">生成</button></view>
      <view v-if="kind!=='package'" class="field"><text>{{ config.name }} <text class="required">*</text></text><input v-model="form.name" :disabled="readonly" :placeholder="`请输入${config.name}`" /></view>
      <view v-if="kind==='transfer'||kind==='stock-plan'||kind==='stock-task'" class="field"><text>{{ kind==='transfer'?'转移单类型':'盘点类型' }} <text class="required">*</text></text><picker v-if="!readonly" :range="typeOptions" @change="setType"><view class="picker"><text>{{ dictLabel(dicts, kind==='transfer'?'mes_wm_transfer_type':'mes_wm_stock_taking_type', form.type, '请选择类型') }}</text><text>›</text></view></picker><text v-else class="value">{{ dictLabel(dicts, kind==='transfer'?'mes_wm_transfer_type':'mes_wm_stock_taking_type', form.type) }}</text></view>
      <view v-if="kind==='transfer'" class="field"><text>转移日期 <text class="required">*</text></text><picker v-if="!readonly" mode="date" :value="form.transferDate" @change="form.transferDate=$event.detail.value"><view class="picker"><text>{{ dayText(form.transferDate) }}</text><text>›</text></view></picker><text v-else class="value">{{ dayText(form.transferDate) }}</text></view>
      <template v-if="showTransferDeliveryFields"><view class="field"><text>是否配送</text><switch :checked="form.deliveryFlag" :disabled="readonly" @change="form.deliveryFlag=$event.detail.value" /></view><view class="field"><text>是否确认</text><text class="value">{{ booleanText(form.confirmFlag) }}</text></view><view v-if="form.deliveryFlag" class="field"><text>收货人</text><input v-model="form.recipientName" :disabled="readonly" placeholder="请输入收货人" /></view><view v-if="form.deliveryFlag" class="field"><text>联系电话</text><input v-model="form.recipientTelephone" :disabled="readonly" placeholder="请输入联系电话" /></view><view v-if="form.deliveryFlag" class="field"><text>承运商</text><input v-model="form.carrier" :disabled="readonly" placeholder="请输入承运商" /></view><view v-if="form.deliveryFlag" class="field"><text>运输单号</text><input v-model="form.shippingNumber" :disabled="readonly" placeholder="请输入运输单号" /></view><view v-if="form.deliveryFlag" class="field column"><text>目的地</text><textarea v-model="form.destinationAddress" :disabled="readonly" placeholder="请输入目的地" ></textarea></view></template>
      <template v-if="kind==='stock-plan'"><view v-if="showStockTakingTimeFields" class="field"><text>开始时间 <text class="required">*</text></text><picker v-if="!readonly" mode="date" :value="form.startTime" @change="form.startTime=$event.detail.value"><view class="picker"><text>{{ dayText(form.startTime) }}</text><text>›</text></view></picker><text v-else class="value">{{ dayText(form.startTime) }}</text></view><view v-if="showStockTakingTimeFields" class="field"><text>结束时间 <text class="required">*</text></text><picker v-if="!readonly" mode="date" :value="form.endTime" @change="form.endTime=$event.detail.value"><view class="picker"><text>{{ dayText(form.endTime) }}</text><text>›</text></view></picker><text v-else class="value">{{ dayText(form.endTime) }}</text></view><view class="field"><text>是否盲盘</text><switch :checked="form.blindFlag" :disabled="readonly" @change="form.blindFlag=$event.detail.value" /></view><view class="field"><text>冻结库存</text><switch :checked="form.frozen" :disabled="readonly" @change="form.frozen=$event.detail.value" /></view></template>
      <template v-if="kind==='stock-task'"><view class="field"><text>盘点方案 <text class="required">*</text></text><picker v-if="!readonly" :range="planOptions" @change="selectPlan"><view class="picker"><text>{{ form.planName || form.planCode || '请选择盘点方案' }}</text><text>›</text></view></picker><text v-else class="value">{{ form.planName || form.planCode || '--' }}</text></view><view v-if="showStockTakingTimeFields" class="field"><text>开始时间</text><picker v-if="!readonly" mode="date" :value="form.startTime" @change="form.startTime=$event.detail.value"><view class="picker"><text>{{ dayText(form.startTime) }}</text><text>›</text></view></picker><text v-else class="value">{{ dayText(form.startTime) }}</text></view><view v-if="showStockTakingTimeFields" class="field"><text>结束时间</text><picker v-if="!readonly" mode="date" :value="form.endTime" @change="form.endTime=$event.detail.value"><view class="picker"><text>{{ dayText(form.endTime) }}</text><text>›</text></view></picker><text v-else class="value">{{ dayText(form.endTime) }}</text></view><view class="field"><text>盘点日期 <text class="required">*</text></text><picker v-if="!readonly" mode="date" :value="form.takingDate" @change="form.takingDate=$event.detail.value"><view class="picker"><text>{{ dayText(form.takingDate) }}</text><text>›</text></view></picker><text v-else class="value">{{ dayText(form.takingDate) }}</text></view><view class="field"><text>盘点人 <text class="required">*</text></text><picker v-if="!readonly" :range="userOptions" @change="selectUser"><view class="picker"><text>{{ form.userNickname || '请选择盘点人' }}</text><text>›</text></view></picker><text v-else class="value">{{ form.userNickname || '--' }}</text></view><view class="field"><text>是否盲盘</text><switch :checked="form.blindFlag" :disabled="readonly" @change="form.blindFlag=$event.detail.value" /></view><view class="field"><text>冻结库存</text><switch :checked="form.frozen" :disabled="readonly" @change="form.frozen=$event.detail.value" /></view></template>
      <template v-if="kind==='package'"><view class="field"><text>装箱日期 <text class="required">*</text></text><picker v-if="!readonly" mode="date" :value="form.packageDate" @change="form.packageDate=$event.detail.value"><view class="picker"><text>{{ dayText(form.packageDate) }}</text><text>›</text></view></picker><text v-else class="value">{{ dayText(form.packageDate) }}</text></view><view class="field"><text>销售订单 <text class="required">*</text></text><picker v-if="!readonly" :range="saleOrderOptions" @change="selectSaleOrder"><view class="picker"><text>{{ form.salesOrderCode || '请选择销售订单' }}</text><text>›</text></view></picker><text v-else class="value">{{ form.salesOrderCode || '--' }}</text></view><view class="field"><text>发票编号</text><input v-model="form.invoiceCode" :disabled="readonly" placeholder="请输入发票编号" /></view><view class="field"><text>客户</text><text class="value">{{ form.clientName || '--' }}</text></view><view class="field"><text>检查员</text><picker v-if="!readonly" :range="userOptions" @change="selectUser"><view class="picker"><text>{{ form.inspectorName || '请选择检查员' }}</text><text>›</text></view></picker><text v-else class="value">{{ form.inspectorName || '--' }}</text></view><view class="field"><text>尺寸单位</text><picker v-if="!readonly" :range="unitOptions" @change="selectUnit($event,'size')"><view class="picker"><text>{{ form.sizeUnitName || '请选择尺寸单位' }}</text><text>›</text></view></picker><text v-else class="value">{{ form.sizeUnitName || '--' }}</text></view><view class="field"><text>箱长度</text><input :value="String(form.length||'')" :disabled="readonly" type="digit" @input="form.length=num($event.detail.value)" /></view><view class="field"><text>箱宽度</text><input :value="String(form.width||'')" :disabled="readonly" type="digit" @input="form.width=num($event.detail.value)" /></view><view class="field"><text>箱高度</text><input :value="String(form.height||'')" :disabled="readonly" type="digit" @input="form.height=num($event.detail.value)" /></view><view class="field"><text>重量单位</text><picker v-if="!readonly" :range="unitOptions" @change="selectUnit($event,'weight')"><view class="picker"><text>{{ form.weightUnitName || '请选择重量单位' }}</text><text>›</text></view></picker><text v-else class="value">{{ form.weightUnitName || '--' }}</text></view><view class="field"><text>净重</text><input :value="String(form.netWeight||'')" :disabled="readonly" type="digit" @input="form.netWeight=num($event.detail.value)" /></view><view class="field"><text>毛重</text><input :value="String(form.grossWeight||'')" :disabled="readonly" type="digit" @input="form.grossWeight=num($event.detail.value)" /></view></template>
      <view class="field column"><text>备注</text><textarea v-model="form.remark" :disabled="readonly" placeholder="请输入备注" ></textarea></view><view v-if="id && mode==='detail'" class="field"><text>创建时间</text><text class="value">{{ dateText(form.createTime) }}</text></view>
    </view>
    <view v-if="id" class="form-card">
      <view class="section"><text>{{ kind==='stock-plan'?'盘点参数':kind==='stock-task'?(mode==='execute'?'盘点结果':'盘点清单'):kind==='package'?'装箱清单':'转移单行' }}</text><button v-if="canLine || (mode==='execute'&&kind==='stock-task')" @click="openLine(undefined,undefined,mode==='execute'?'result':'line')">新增明细</button></view>
      <view v-for="(line,index) in (mode==='execute'&&kind==='stock-task'?results:lines)" :key="line.id || index" class="line">
        <view class="line-head"><text>明细 {{ index+1 }}</text><view><button v-if="kind==='transfer'&&canStock&&line.id" @click="openLine(undefined,undefined,'detail',line)">新增上架明细</button><button v-if="(canLine || (mode==='execute'&&kind==='stock-task'))" @click="openLine(line,index,mode==='execute'?'result':'line')">编辑</button><button v-if="canLine || (mode==='execute'&&kind==='stock-task')" class="danger" @click="removeLine(line,mode==='execute'?'result':'line')">删除</button></view></view>
        <view class="grid"><text v-if="kind==='stock-plan'">条件类型:{{ dictLabel(dicts,'mes_wm_stock_taking_plan_param_type',line.type) }}</text><text v-if="kind==='stock-plan'">条件编码:{{ line.valueCode || '--' }}</text><text v-if="kind==='stock-plan'">条件名称:{{ line.valueName || '--' }}</text><text v-if="kind!=='stock-plan'">物料编码:{{ line.itemCode || '--' }}</text><text v-if="kind!=='stock-plan'">物料名称:{{ line.itemName || '--' }}</text><text v-if="kind!=='stock-plan'">规格型号:{{ line.specification || '--' }}</text><text v-if="kind!=='stock-plan'">单位:{{ line.unitMeasureName || line.unitName || '--' }}</text><text v-if="kind==='transfer'">转移数量:{{ line.quantity ?? '--' }}</text><text v-if="kind==='transfer'">移出仓库:{{ line.fromWarehouseName || '--' }}</text><text v-if="kind==='transfer'">移出库区:{{ line.fromLocationName || '--' }}</text><text v-if="kind==='transfer'">移出库位:{{ line.fromAreaName || '--' }}</text><text v-if="kind==='stock-task'">批次号:{{ line.batchCode || '--' }}</text><text v-if="kind==='stock-task'">在库数量:{{ line.quantity ?? '--' }}</text><text v-if="kind==='stock-task'">盘点数量:{{ line.takingQuantity ?? '--' }}</text><text v-if="kind==='package'">装箱数量:{{ line.quantity ?? '--' }}</text><text v-if="kind==='package'">生产订单:{{ line.workOrderCode || '--' }}</text><text>备注:{{ line.remark || '--' }}</text></view>
        <view v-if="kind==='transfer'&&line.id" class="details"><view class="stock-title">调拨明细</view><view v-for="detail in (details[line.id]||[])" :key="detail.id" class="detail-row"><view><text>移入仓库:{{ detail.toWarehouseName || '--' }}</text><text>移入库区:{{ detail.toLocationName || '--' }}</text><text>移入库位:{{ detail.toAreaName || '--' }}</text><text>数量:{{ detail.quantity ?? '--' }}</text></view><view v-if="canStock" class="detail-actions"><button @click="openLine(detail,undefined,'detail',line)">编辑</button><button class="danger" @click="removeLine(detail,'detail')">删除</button></view></view><view v-if="!(details[line.id]||[]).length" class="empty small">暂无调拨明细</view></view>
      </view><view v-if="!(mode==='execute'&&kind==='stock-task'?results:lines).length" class="empty">暂无明细</view>
    </view>
    <view v-if="kind==='package'&&id" class="form-card"><view class="section"><text>子箱列表</text><button v-if="canLine" @click="openLine(undefined,undefined,'child')">添加子箱</button></view><view v-for="child in form.children||[]" :key="child.id" class="line"><view class="grid"><text>装箱单编号:{{ child.code || '--' }}</text><text>客户:{{ child.clientName || '--' }}</text><text>装箱日期:{{ dayText(child.packageDate) }}</text></view><view v-if="canLine" class="line-bottom"><button class="danger" @click="removeLine(child as Line,'child')">移除</button></view></view><view v-if="!form.children?.length" class="empty">暂无子箱</view></view>
    <button v-if="canSave" class="save" :loading="saving" @click="save">保存</button><button v-if="canSubmit" class="submit" @click="submitDoc">提交</button><button v-if="canConfirm" class="submit" @click="confirmAction">到货确认</button><button v-if="canStock" class="submit" @click="finishAction">执行上架</button><button v-if="canFinish" class="submit" @click="finishAction">{{ kind==='package'?'完成装箱':kind==='transfer'?'执行转移':'执行盘点' }}</button><button v-if="readonly&&hasPermission(`${config.permission}:update`)&&mode==='detail'" class="save" @click="mode='edit'">编辑</button>
    <view v-if="showLine" class="mask"><view class="modal"><view class="modal-title">{{ lineForm.id?'编辑':'新增' }}明细</view>
      <template v-if="lineKind==='child'"><view class="field"><text>装箱单 <text class="required">*</text></text><picker :range="packageOptions" @change="selectPackage"><view class="picker"><text>{{ lineForm.code || '请选择装箱单' }}</text><text>›</text></view></picker></view></template>
      <template v-else-if="kind==='stock-plan'">
        <view class="field"><text>条件类型 <text class="required">*</text></text><picker :range="paramTypeOptions" @change="setParamType"><view class="picker"><text>{{ dictLabel(dicts,'mes_wm_stock_taking_plan_param_type',lineForm.type,'请选择条件类型') }}</text><text>›</text></view></picker></view>
        <template v-if="lineForm.type===102">
          <view class="field"><text>条件值</text><picker :range="warehouseOptions" @change="selectConditionWarehouse"><view class="picker"><text>{{ lineForm.valueName || '请选择仓库' }}</text><text>›</text></view></picker></view>
        </template>
        <template v-else-if="lineForm.type===103">
          <view class="field"><text>仓库</text><picker :range="warehouseOptions" @change="selectConditionLocationWarehouse"><view class="picker"><text>请选择仓库</text><text>›</text></view></picker></view>
          <view class="field"><text>条件值</text><picker :range="locationOptions" @change="selectConditionLocation"><view class="picker"><text>{{ lineForm.valueName || '请选择库区' }}</text><text>›</text></view></picker></view>
        </template>
        <template v-else-if="lineForm.type===104">
          <view class="field"><text>仓库</text><picker :range="warehouseOptions" @change="selectConditionAreaWarehouse"><view class="picker"><text>请选择仓库</text><text>›</text></view></picker></view>
          <view class="field"><text>库区</text><picker :range="locationOptions" @change="selectConditionAreaLocation"><view class="picker"><text>请选择库区</text><text>›</text></view></picker></view>
          <view class="field"><text>条件值</text><picker :range="areaOptions" @change="selectConditionArea"><view class="picker"><text>{{ lineForm.valueName || '请选择库位' }}</text><text>›</text></view></picker></view>
        </template>
        <template v-else-if="lineForm.type===600">
          <view class="field"><text>条件值</text><picker :range="materialOptions" @change="selectConditionMaterial"><view class="picker"><text>{{ conditionText('请选择物料') }}</text><text>›</text></view></picker></view>
        </template>
        <template v-else-if="lineForm.type===107">
          <view class="field"><text>条件值</text><picker :range="batchOptions" @change="selectConditionBatch"><view class="picker"><text>{{ lineForm.valueCode || '请选择批次' }}</text><text>›</text></view></picker></view>
        </template>
        <template v-else-if="lineForm.type===900">
          <view class="field"><text>条件值</text><picker :range="qualityOptions" @change="selectConditionQuality"><view class="picker"><text>{{ lineForm.valueName || '请选择质量状态' }}</text><text>›</text></view></picker></view>
        </template>
      </template>
      <template v-else-if="lineKind==='detail'"><view class="field"><text>物料</text><text class="value">{{ stockLineMaterialText() }}</text></view><view class="field"><text>移入仓库 <text class="required">*</text></text><picker :range="warehouseOptions" @change="selectWarehouse($event,'to')"><view class="picker"><text>{{ lineForm.toWarehouseName || '请选择移入仓库' }}</text><text>›</text></view></picker></view><view class="field"><text>移入库区 <text class="required">*</text></text><picker :range="locationOptions" @change="selectLocation($event,'to')"><view class="picker"><text>{{ lineForm.toLocationName || '请选择移入库区' }}</text><text>›</text></view></picker></view><view class="field"><text>移入库位 <text class="required">*</text></text><picker :range="areaOptions" @change="selectArea($event,'to')"><view class="picker"><text>{{ lineForm.toAreaName || '请选择移入库位' }}</text><text>›</text></view></picker></view><view class="field"><text>数量 <text class="required">*</text></text><input :value="String(lineForm.quantity||'')" type="digit" @input="lineForm.quantity=num($event.detail.value)" /></view></template>
      <template v-else>
        <template v-if="kind==='package'">
          <view class="field"><text>生产订单 <text class="required">*</text></text><picker :range="workOrderOptions" @change="selectWorkOrder"><view class="picker"><text>{{ lineForm.workOrderCode || '请选择生产订单' }}</text><text>›</text></view></picker></view>
          <view class="field"><text>产品物料 <text class="required">*</text></text><picker :range="materialOptions" @change="selectMaterial"><view class="picker"><text>{{ materialOptionText(lineForm.itemId ? { code: lineForm.itemCode, name: lineForm.itemName, specification: lineForm.specification, unitMeasureName: lineForm.unitMeasureName } : undefined) }}</text><text>›</text></view></picker></view>
          <view class="field"><text>装箱数量 <text class="required">*</text></text><input :value="String(lineForm.quantity||'')" type="digit" @input="lineForm.quantity=num($event.detail.value)" /></view>
          <view class="field"><text>有效期</text><picker mode="date" :value="lineForm.expireDate" @change="lineForm.expireDate=$event.detail.value"><view class="picker"><text>{{ dayText(lineForm.expireDate) }}</text><text>›</text></view></picker></view>
        </template>
        <template v-else-if="lineKind==='result'">
          <view v-if="!form.blindFlag" class="field"><text>盘点清单</text><picker :range="lines.map(i=>`${i.itemCode||'--'} - ${i.itemName||'--'} (${i.warehouseName||'--'}${i.locationName?' / '+i.locationName:''}${i.areaName?' / '+i.areaName:''})`)" @change="selectTaskLine"><view class="picker"><text>{{ lineForm.lineId ? `${lineForm.itemCode||'--'} / ${lineForm.batchCode||'无批次'}` : '请选择盘点清单(可选)' }}</text><text>›</text></view></picker></view>
          <view class="field"><text>物料 <text class="required">*</text></text><picker :range="materialOptions" @change="selectMaterial"><view class="picker"><text>{{ materialOptionText(lineForm.itemId ? { code: lineForm.itemCode, name: lineForm.itemName, specification: lineForm.specification, unitMeasureName: lineForm.unitMeasureName } : undefined) }}</text><text>›</text></view></picker></view>
          <view class="field"><text>批次编码</text><input v-model="lineForm.batchCode" placeholder="请输入批次编码" /></view>
          <view class="field"><text>盘点数量 <text class="required">*</text></text><input :value="String(lineForm.takingQuantity||'')" type="digit" @input="lineForm.takingQuantity=num($event.detail.value)" /></view>
          <view class="field"><text>仓库 <text class="required">*</text></text><picker :range="warehouseOptions" @change="selectWarehouse($event,'')"><view class="picker"><text>{{ lineForm.warehouseName || '请选择仓库' }}</text><text>›</text></view></picker></view>
          <view v-if="lineForm.warehouseId" class="field"><text>库区 <text class="required">*</text></text><picker :range="locationOptions" @change="selectLocation($event,'')"><view class="picker"><text>{{ lineForm.locationName || '请选择库区' }}</text><text>›</text></view></picker></view>
          <view v-if="lineForm.locationId" class="field"><text>库位 <text class="required">*</text></text><picker :range="areaOptions" @change="selectArea($event,'')"><view class="picker"><text>{{ lineForm.areaName || '请选择库位' }}</text><text>›</text></view></picker></view>
        </template>
        <template v-else>
          <view v-if="kind==='transfer'||kind==='stock-task'" class="field"><text>库存记录 <text class="required">*</text></text><picker :range="stockOptions" @change="selectStock"><view class="picker"><text>{{ lineForm.materialStockId ? `${lineForm.itemCode||'--'} / ${lineForm.batchCode||'无批次'}` : '请选择库存记录' }}</text><text>›</text></view></picker></view>
          <view class="field"><text>数量 <text class="required">*</text></text><input :value="String(lineForm.quantity||'')" type="digit" @input="lineForm.quantity=num($event.detail.value)" /></view>
        </template>
      </template>
      <view class="field column"><text>备注</text><textarea v-model="lineForm.remark" placeholder="请输入备注" ></textarea></view><view class="modal-actions"><button @click="showLine=false">取消</button><button class="primary" @click="saveLine">保存</button></view>
    </view></view>
  </view>
</template>
 
<style lang="scss" scoped>
.page{min-height:100vh;padding:20rpx 24rpx 60rpx;box-sizing:border-box;background:#f3f6fb}.form-card{margin-bottom:18rpx;background:#fff;border-radius:16rpx;overflow:hidden}.field{display:flex;align-items:center;min-height:86rpx;padding:0 22rpx;border-bottom:1rpx solid #edf1f6;box-sizing:border-box}.field>text:first-child{flex:none;width:190rpx;color:#10233f;font-size:26rpx}.field>picker{display:block;flex:1;min-width:0}.field input,.field textarea,.value,.picker{flex:1;min-width:0;color:#10233f;font-size:26rpx;text-align:right}.field textarea{height:120rpx;padding:22rpx 0}.field.column{align-items:flex-start;flex-direction:column;padding:22rpx}.field.column>text:first-child{width:auto;margin-bottom:12rpx}.field.column textarea{text-align:left;width:100%;height:120rpx;padding:0}.required{color:#e23b3b}.picker{display:flex;width:100%;align-items:center;justify-content:space-between;gap:10rpx}.picker text:first-child{min-width:0;flex:1;overflow:hidden;text-align:right;text-overflow:ellipsis;white-space:nowrap}.picker text:last-child{flex:none;width:24rpx;text-align:right}.code-field input{text-align:left}.code-field button,.section button,.line-head button,.detail-actions button,.line-bottom button{height:52rpx;min-height:52rpx;padding:0 16rpx;margin:0;color:var(--color-primary, #1769d8);font-size:23rpx;line-height:50rpx;background:var(--color-primary-soft, #f5f8ff);border:1rpx solid var(--color-primary-border, #8ab3ee);border-radius:8rpx}.section{display:flex;align-items:center;justify-content:space-between;height:82rpx;padding:0 22rpx;color:#10233f;font-size:30rpx;font-weight:600}.line{margin:0 18rpx 18rpx;border:1rpx solid #edf1f6;border-radius:12rpx;overflow:hidden}.line-head{display:flex;align-items:center;justify-content:space-between;padding:16rpx 18rpx;color:#10233f;font-size:27rpx;font-weight:600;background:#f9fbff}.line-head>view{display:flex;gap:10rpx}.grid{display:grid;gap:10rpx;padding:16rpx 18rpx;color:#66778c;font-size:23rpx;border-top:1rpx solid #edf1f6}.grid text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.danger{color:#c65050!important;background:#fff7f7!important;border-color:#e3a0a0!important}.details{padding:10rpx 18rpx 16rpx;border-top:1rpx solid #edf1f6}.stock-title{color:#10233f;font-size:26rpx;font-weight:600}.detail-row{display:flex;align-items:flex-start;justify-content:space-between;gap:14rpx;padding:14rpx 0;color:#66778c;font-size:23rpx;border-bottom:1rpx solid #f2f4f8}.detail-row>view:first-child{display:flex;min-width:0;flex:1;flex-direction:column;gap:8rpx}.detail-actions{display:flex;flex:none;align-items:center;justify-content:flex-end;gap:10rpx}.line-bottom{display:flex;justify-content:flex-end;padding:0 18rpx 18rpx}.empty{padding:34rpx;color:#8795a8;font-size:25rpx;text-align:center}.empty.small{padding:18rpx}.save,.submit{width:100%;height:78rpx;margin:18rpx 0 0;color:#fff;font-size:28rpx;line-height:78rpx;background:var(--color-primary, #1769d8);border-radius:10rpx}.submit{background:#16a36f}.mask{position:fixed;left:0;right:0;top:0;bottom:0;z-index:60;display:flex;align-items:flex-end;background:rgba(0,0,0,.35)}.modal{width:100%;max-height:86vh;overflow:auto;padding-bottom:28rpx;box-sizing:border-box;background:#fff;border-radius:24rpx 24rpx 0 0}.modal-title{height:88rpx;line-height:88rpx;color:#10233f;font-size:30rpx;font-weight:600;text-align:center}.modal-actions{display:flex;gap:18rpx;padding:24rpx}.modal-actions button{flex:1;height:72rpx;line-height:72rpx;font-size:27rpx;border-radius:10rpx}.modal-actions .primary{color:#fff;background:var(--color-primary, #1769d8)}.code-field button::after,.section button::after,.line-head button::after,.detail-actions button::after,.save::after,.submit::after,.modal-actions button::after,.line-bottom button::after{border:0}
</style>