@7365admin1/layer-common 4.168.2 → 4.168.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -4
- package/components/InventoryItemDetail.vue +37 -3
- package/components/InventoryLinesDialog.vue +6 -1
- package/components/InventoryMain.vue +54 -3
- package/components/InventoryReportsTab.vue +9 -1
- package/components/InventorySettingsTab.vue +14 -2
- package/components/WorkOrder/MaterialsDialog.vue +756 -0
- package/components/WorkOrder/MaterialsGroups.vue +128 -0
- package/composables/useCommonPermission.ts +15 -1
- package/composables/useInventory.ts +10 -1
- package/composables/useInventoryPermission.ts +8 -1
- package/composables/useSecurityPermission.ts +6 -0
- package/package.json +1 -1
- package/types/inventory.d.ts +11 -0
- package/types/work-order-material.d.ts +15 -0
- package/utils/inventory-store-label.ts +36 -0
- package/utils/work-order-link.ts +24 -0
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<v-dialog
|
|
3
|
+
:model-value="modelValue"
|
|
4
|
+
max-width="480"
|
|
5
|
+
scrollable
|
|
6
|
+
@update:model-value="emit('update:modelValue', $event)"
|
|
7
|
+
>
|
|
8
|
+
<v-card class="mat">
|
|
9
|
+
<!-- header -->
|
|
10
|
+
<div class="mat__head">
|
|
11
|
+
<div class="mat__head-icon">
|
|
12
|
+
<v-icon icon="mdi-package-variant-closed" size="20" />
|
|
13
|
+
</div>
|
|
14
|
+
<div class="mat__head-text">
|
|
15
|
+
<div class="mat__title">Materials</div>
|
|
16
|
+
<div class="mat__subtitle">Parts taken from inventory for this job</div>
|
|
17
|
+
</div>
|
|
18
|
+
<v-btn icon="mdi-close" variant="text" size="small" aria-label="Close" @click="close" />
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<!-- search: opens the item list -->
|
|
22
|
+
<div class="mat__search">
|
|
23
|
+
<v-text-field
|
|
24
|
+
v-model="search"
|
|
25
|
+
placeholder="Search item, code or category"
|
|
26
|
+
prepend-inner-icon="mdi-magnify"
|
|
27
|
+
density="comfortable"
|
|
28
|
+
variant="outlined"
|
|
29
|
+
rounded="lg"
|
|
30
|
+
hide-details
|
|
31
|
+
clearable
|
|
32
|
+
@focus="listOpen = true"
|
|
33
|
+
@click="listOpen = true"
|
|
34
|
+
/>
|
|
35
|
+
</div>
|
|
36
|
+
|
|
37
|
+
<!-- the item list, like a multiple select -->
|
|
38
|
+
<template v-if="listOpen">
|
|
39
|
+
<div v-if="!noStore" class="mat__bar">
|
|
40
|
+
<span>{{ loading ? "Loading..." : `${items.length} item${items.length === 1 ? "" : "s"}` }}</span>
|
|
41
|
+
<span v-if="pickedList.length" class="mat__bar-picked">{{ pickedList.length }} selected</span>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<v-card-text class="mat__body pa-0">
|
|
45
|
+
<div v-if="loading && !items.length" class="mat__state">
|
|
46
|
+
<v-progress-circular indeterminate size="24" color="primary" />
|
|
47
|
+
</div>
|
|
48
|
+
<!-- no store here is set up for work orders: a setup gap, not a failure - say how to fix it -->
|
|
49
|
+
<div v-else-if="noStore" class="mat__state mat__state--empty">
|
|
50
|
+
<div class="mat__empty-icon">
|
|
51
|
+
<v-icon icon="mdi-store-off-outline" size="26" />
|
|
52
|
+
</div>
|
|
53
|
+
<div class="mat__empty-title">No store is set up for work orders here</div>
|
|
54
|
+
<div>
|
|
55
|
+
A store's manager can turn on "Use for work order materials" in Inventory, Settings. The store
|
|
56
|
+
must also supply this property.
|
|
57
|
+
</div>
|
|
58
|
+
</div>
|
|
59
|
+
<div v-else-if="loadError" class="mat__state">
|
|
60
|
+
<v-icon icon="mdi-alert-circle-outline" size="28" color="error" />
|
|
61
|
+
<span class="text-error">{{ loadError }}</span>
|
|
62
|
+
</div>
|
|
63
|
+
<div v-else-if="!items.length" class="mat__state">
|
|
64
|
+
<v-icon icon="mdi-magnify-close" size="28" />
|
|
65
|
+
<span>No items match "{{ search }}"</span>
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<div
|
|
69
|
+
v-for="item in items"
|
|
70
|
+
:key="item._id"
|
|
71
|
+
class="mat__opt"
|
|
72
|
+
:class="{ 'mat__opt--on': isPicked(item), 'mat__opt--out': !canPick(item) && !isPicked(item) }"
|
|
73
|
+
role="checkbox"
|
|
74
|
+
:aria-checked="isPicked(item)"
|
|
75
|
+
:aria-disabled="!canPick(item)"
|
|
76
|
+
@click="toggle(item)"
|
|
77
|
+
>
|
|
78
|
+
<v-checkbox-btn
|
|
79
|
+
:model-value="isPicked(item)"
|
|
80
|
+
color="primary"
|
|
81
|
+
density="compact"
|
|
82
|
+
class="flex-grow-0"
|
|
83
|
+
@update:model-value="toggle(item)"
|
|
84
|
+
@click.stop
|
|
85
|
+
/>
|
|
86
|
+
<div class="mat__main">
|
|
87
|
+
<div class="mat__name">{{ item.name }}</div>
|
|
88
|
+
<div class="mat__meta">{{ metaOf(item) }}</div>
|
|
89
|
+
</div>
|
|
90
|
+
<div class="mat__side">
|
|
91
|
+
<div class="mat__price">{{ money(item.unitCost) }}</div>
|
|
92
|
+
<span class="mat__pill" :class="`mat__pill--${stockTone(item)}`">{{ stockText(item) }}</span>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</v-card-text>
|
|
96
|
+
|
|
97
|
+
<div class="mat__foot">
|
|
98
|
+
<v-btn
|
|
99
|
+
block
|
|
100
|
+
color="primary"
|
|
101
|
+
elevation="0"
|
|
102
|
+
height="44"
|
|
103
|
+
rounded="lg"
|
|
104
|
+
class="text-none"
|
|
105
|
+
:text="pickedList.length ? `Done · ${pickedList.length} selected` : 'Done'"
|
|
106
|
+
@click="closeList"
|
|
107
|
+
/>
|
|
108
|
+
</div>
|
|
109
|
+
</template>
|
|
110
|
+
|
|
111
|
+
<!-- the selected items, with their quantities -->
|
|
112
|
+
<template v-else>
|
|
113
|
+
<v-card-text class="mat__body pa-0">
|
|
114
|
+
<div v-if="!pickedList.length" class="mat__state mat__state--empty">
|
|
115
|
+
<div class="mat__empty-icon">
|
|
116
|
+
<v-icon icon="mdi-package-variant" size="26" />
|
|
117
|
+
</div>
|
|
118
|
+
<div class="mat__empty-title">No materials yet</div>
|
|
119
|
+
<div>Search to pick parts from inventory.</div>
|
|
120
|
+
<v-btn
|
|
121
|
+
variant="tonal"
|
|
122
|
+
color="primary"
|
|
123
|
+
rounded="lg"
|
|
124
|
+
class="text-none mt-3"
|
|
125
|
+
prepend-icon="mdi-format-list-checks"
|
|
126
|
+
text="Browse items"
|
|
127
|
+
@click="listOpen = true"
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<div
|
|
132
|
+
v-for="line in pickedList"
|
|
133
|
+
:key="line.item"
|
|
134
|
+
class="mat__line"
|
|
135
|
+
:class="{ 'mat__line--out': line.stock <= 0 }"
|
|
136
|
+
>
|
|
137
|
+
<div class="mat__line-top">
|
|
138
|
+
<div class="mat__main">
|
|
139
|
+
<div class="mat__name">{{ line.name }}</div>
|
|
140
|
+
<div class="mat__meta">{{ money(line.unitCost) }} each<template v-if="stores.length > 1 && line.storeName"> · {{ line.storeName }}</template></div>
|
|
141
|
+
</div>
|
|
142
|
+
<div class="mat__subtotal">{{ money(line.qty * line.unitCost) }}</div>
|
|
143
|
+
</div>
|
|
144
|
+
<div class="mat__line-bottom">
|
|
145
|
+
<div class="mat__stepper" :class="{ 'mat__stepper--off': line.stock <= 0 }">
|
|
146
|
+
<button
|
|
147
|
+
type="button"
|
|
148
|
+
class="mat__step"
|
|
149
|
+
aria-label="Less"
|
|
150
|
+
:disabled="line.qty <= 1"
|
|
151
|
+
@click="setQty(lineItem(line), line.qty - 1)"
|
|
152
|
+
>
|
|
153
|
+
<v-icon icon="mdi-minus" size="16" />
|
|
154
|
+
</button>
|
|
155
|
+
<input
|
|
156
|
+
:value="line.qty"
|
|
157
|
+
type="number"
|
|
158
|
+
min="1"
|
|
159
|
+
:max="line.stock"
|
|
160
|
+
:disabled="line.stock <= 0"
|
|
161
|
+
class="mat__qty"
|
|
162
|
+
aria-label="Quantity"
|
|
163
|
+
@change="setQty(lineItem(line), Number(($event.target as HTMLInputElement).value))"
|
|
164
|
+
/>
|
|
165
|
+
<button
|
|
166
|
+
type="button"
|
|
167
|
+
class="mat__step"
|
|
168
|
+
aria-label="More"
|
|
169
|
+
:disabled="line.qty >= line.stock"
|
|
170
|
+
@click="setQty(lineItem(line), line.qty + 1)"
|
|
171
|
+
>
|
|
172
|
+
<v-icon icon="mdi-plus" size="16" />
|
|
173
|
+
</button>
|
|
174
|
+
</div>
|
|
175
|
+
<span v-if="line.stock <= 0" class="mat__pill mat__pill--err">Out of stock · remove it</span>
|
|
176
|
+
<span v-else class="mat__of">of {{ line.stock }} in stock</span>
|
|
177
|
+
<v-spacer />
|
|
178
|
+
<v-btn
|
|
179
|
+
icon="mdi-trash-can-outline"
|
|
180
|
+
variant="text"
|
|
181
|
+
size="small"
|
|
182
|
+
color="error"
|
|
183
|
+
aria-label="Remove"
|
|
184
|
+
@click="toggle(lineItem(line))"
|
|
185
|
+
/>
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
</v-card-text>
|
|
189
|
+
|
|
190
|
+
<div class="mat__foot">
|
|
191
|
+
<div class="mat__total">
|
|
192
|
+
<div>
|
|
193
|
+
<div class="mat__total-label">Grand Total</div>
|
|
194
|
+
<div v-if="pickedList.length" class="mat__total-sub">
|
|
195
|
+
{{ pickedList.length }} item{{ pickedList.length === 1 ? "" : "s" }} · {{ totalQty }} pcs
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
<div class="mat__total-value">{{ money(grandTotal) }}</div>
|
|
199
|
+
</div>
|
|
200
|
+
<div v-if="outOfStockLines.length" class="mat__blocked">
|
|
201
|
+
<v-icon icon="mdi-alert-circle-outline" size="16" />
|
|
202
|
+
Remove {{ outOfStockLines.length === 1 ? "the out-of-stock item" : `the ${outOfStockLines.length} out-of-stock items` }} to continue.
|
|
203
|
+
</div>
|
|
204
|
+
<v-btn
|
|
205
|
+
block
|
|
206
|
+
color="primary"
|
|
207
|
+
elevation="0"
|
|
208
|
+
height="44"
|
|
209
|
+
rounded="lg"
|
|
210
|
+
class="text-none"
|
|
211
|
+
:text="value.length ? 'Update Materials' : 'Add Materials'"
|
|
212
|
+
:disabled="(!value.length && !pickedList.length) || outOfStockLines.length > 0"
|
|
213
|
+
@click="save"
|
|
214
|
+
/>
|
|
215
|
+
</div>
|
|
216
|
+
</template>
|
|
217
|
+
</v-card>
|
|
218
|
+
|
|
219
|
+
<Snackbar v-model="snackbar" :text="snackText" color="error" />
|
|
220
|
+
</v-dialog>
|
|
221
|
+
</template>
|
|
222
|
+
|
|
223
|
+
<script setup lang="ts">
|
|
224
|
+
/**
|
|
225
|
+
* Pick materials (parts) for a work order from the inventory stores this
|
|
226
|
+
* account can see at the site. An item with no stock cannot be picked; the
|
|
227
|
+
* quantity cannot go above what is in stock, and each load re-reads the stock.
|
|
228
|
+
* The picks are taken from stock by the work order / feedback submit
|
|
229
|
+
* (API-core), all or nothing. Shared by the service apps (2026-11).
|
|
230
|
+
*/
|
|
231
|
+
import useInventory from "../../composables/useInventory";
|
|
232
|
+
import { errorConverter } from "../../utils/data";
|
|
233
|
+
const props = defineProps<{
|
|
234
|
+
modelValue: boolean;
|
|
235
|
+
site: string;
|
|
236
|
+
/** The materials already on the work order. */
|
|
237
|
+
value: TWorkOrderMaterial[];
|
|
238
|
+
}>();
|
|
239
|
+
const emit = defineEmits<{
|
|
240
|
+
(e: "update:modelValue", open: boolean): void;
|
|
241
|
+
(e: "save", lines: TWorkOrderMaterial[]): void;
|
|
242
|
+
}>();
|
|
243
|
+
|
|
244
|
+
const { getWorkOrderItems } = useInventory();
|
|
245
|
+
|
|
246
|
+
/** The stores the items come from (to name the store when there is more than one). */
|
|
247
|
+
const stores = ref<{ _id: string; name: string; orgName: string; ownerType: string }[]>([]);
|
|
248
|
+
type TPickItem = TInventoryItem & { storeName?: string };
|
|
249
|
+
const items = ref<TPickItem[]>([]);
|
|
250
|
+
const loading = ref(false);
|
|
251
|
+
const loadError = ref("");
|
|
252
|
+
const search = ref("");
|
|
253
|
+
|
|
254
|
+
/** Picked items by id, kept across searches. */
|
|
255
|
+
const picked = ref<Record<string, TWorkOrderMaterial>>({});
|
|
256
|
+
const pickedList = computed(() => Object.values(picked.value));
|
|
257
|
+
|
|
258
|
+
const snackbar = ref(false);
|
|
259
|
+
const snackText = ref("");
|
|
260
|
+
function warn(text: string) {
|
|
261
|
+
snackText.value = text;
|
|
262
|
+
snackbar.value = true;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const stockOf = (item: { available?: number; onHand?: number }) =>
|
|
266
|
+
Math.max(0, Number(item.available ?? item.onHand ?? 0));
|
|
267
|
+
const money = (n?: number) => `S$${Number(n ?? 0).toFixed(2)}`;
|
|
268
|
+
const isPicked = (item: TInventoryItem) => Boolean(picked.value[item._id]);
|
|
269
|
+
const canPick = (item: TInventoryItem) => stockOf(item) > 0;
|
|
270
|
+
|
|
271
|
+
/** Code · category · store, whichever are set. */
|
|
272
|
+
function metaOf(item: TPickItem) {
|
|
273
|
+
return [item.code, item.category, stores.value.length > 1 ? item.storeName : ""]
|
|
274
|
+
.filter(Boolean)
|
|
275
|
+
.join(" · ");
|
|
276
|
+
}
|
|
277
|
+
/** Stock pill: out of stock, low (at or below the alert level), or in stock. */
|
|
278
|
+
function stockTone(item: TInventoryItem) {
|
|
279
|
+
const n = stockOf(item);
|
|
280
|
+
if (n <= 0) return "err";
|
|
281
|
+
return item.lowStock || (item.reorderLevel > 0 && n <= item.reorderLevel) ? "warn" : "ok";
|
|
282
|
+
}
|
|
283
|
+
function stockText(item: TInventoryItem) {
|
|
284
|
+
const n = stockOf(item);
|
|
285
|
+
if (n <= 0) return "Out of stock";
|
|
286
|
+
return stockTone(item) === "warn" ? `Low · ${n} left` : `${n} in stock`;
|
|
287
|
+
}
|
|
288
|
+
const totalQty = computed(() => pickedList.value.reduce((sum, p) => sum + p.qty, 0));
|
|
289
|
+
|
|
290
|
+
/** The item list (checkboxes) is open: from the search box, closed with Done. */
|
|
291
|
+
const listOpen = ref(false);
|
|
292
|
+
function closeList() {
|
|
293
|
+
listOpen.value = false;
|
|
294
|
+
search.value = "";
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** A selected line as an item, for toggle / setQty. */
|
|
298
|
+
function lineItem(p: TWorkOrderMaterial): TInventoryItem {
|
|
299
|
+
return {
|
|
300
|
+
_id: p.item,
|
|
301
|
+
store: p.store,
|
|
302
|
+
storeName: p.storeName,
|
|
303
|
+
name: p.name,
|
|
304
|
+
unitCost: p.unitCost,
|
|
305
|
+
available: p.stock,
|
|
306
|
+
onHand: p.stock,
|
|
307
|
+
} as TInventoryItem;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const grandTotal = computed(() =>
|
|
311
|
+
pickedList.value.reduce((sum, p) => sum + p.qty * Number(p.unitCost ?? 0), 0),
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
function toggle(item: TInventoryItem) {
|
|
315
|
+
if (picked.value[item._id]) {
|
|
316
|
+
const { [item._id]: _gone, ...rest } = picked.value;
|
|
317
|
+
picked.value = rest;
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (stockOf(item) <= 0) {
|
|
321
|
+
warn(`${item.name} is out of stock.`);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
picked.value = {
|
|
325
|
+
...picked.value,
|
|
326
|
+
[item._id]: {
|
|
327
|
+
item: item._id,
|
|
328
|
+
store: item.store,
|
|
329
|
+
storeName: (item as TPickItem).storeName,
|
|
330
|
+
name: item.name,
|
|
331
|
+
code: item.code,
|
|
332
|
+
unit: item.unit,
|
|
333
|
+
unitCost: Number(item.unitCost ?? 0),
|
|
334
|
+
stock: stockOf(item),
|
|
335
|
+
qty: 1,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function setQty(item: TInventoryItem, qty: number) {
|
|
341
|
+
const line = picked.value[item._id];
|
|
342
|
+
if (!line) return;
|
|
343
|
+
const max = stockOf(item);
|
|
344
|
+
let next = Math.floor(Number.isFinite(qty) ? qty : 1);
|
|
345
|
+
if (next > max) {
|
|
346
|
+
warn(`Only ${max} in stock for ${item.name}.`);
|
|
347
|
+
next = max;
|
|
348
|
+
}
|
|
349
|
+
if (next < 1) next = max > 0 ? 1 : 0;
|
|
350
|
+
picked.value = { ...picked.value, [item._id]: { ...line, qty: next } };
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/** Selected lines whose item has run out since they were picked. */
|
|
354
|
+
const outOfStockLines = computed(() => pickedList.value.filter((p) => p.stock <= 0));
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Bring the selected lines up to date with fresh stock (someone else may have
|
|
358
|
+
* used it): the stock and price follow the store, and a quantity above what
|
|
359
|
+
* is left drops to what is left - the most that can be taken. Returns what
|
|
360
|
+
* changed, to tell the person.
|
|
361
|
+
*/
|
|
362
|
+
function syncPicked(fresh: TPickItem[]): string[] {
|
|
363
|
+
const byId = new Map(fresh.map((i) => [i._id, i]));
|
|
364
|
+
const changes: string[] = [];
|
|
365
|
+
const next = { ...picked.value };
|
|
366
|
+
for (const line of pickedList.value) {
|
|
367
|
+
const item = byId.get(line.item);
|
|
368
|
+
if (!item) continue;
|
|
369
|
+
const stock = stockOf(item);
|
|
370
|
+
const qty = Math.min(line.qty, stock);
|
|
371
|
+
if (stock === line.stock && qty === line.qty && Number(item.unitCost ?? 0) === line.unitCost) continue;
|
|
372
|
+
if (stock <= 0) changes.push(`${line.name} is now out of stock`);
|
|
373
|
+
else if (qty < line.qty) changes.push(`${line.name}: only ${stock} left, quantity set to ${qty}`);
|
|
374
|
+
next[line.item] = { ...line, stock, qty, unitCost: Number(item.unitCost ?? 0) };
|
|
375
|
+
}
|
|
376
|
+
picked.value = next;
|
|
377
|
+
return changes;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** No store at this property is switched on for work orders (asked again on each load). */
|
|
381
|
+
const noStore = ref(false);
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Items from the stores at the site that are switched on for work orders ("Use for work order
|
|
385
|
+
* materials") and this person may use - the company's own store, the property's store - in one
|
|
386
|
+
* call (API-core GET /inventory/work-order-items). Active items only ("Not in use" are hidden).
|
|
387
|
+
*/
|
|
388
|
+
let seq = 0;
|
|
389
|
+
/** `notice`: said first when the stock was re-read because a submit was refused. */
|
|
390
|
+
async function load(notice = "") {
|
|
391
|
+
const mine = ++seq;
|
|
392
|
+
loading.value = true;
|
|
393
|
+
loadError.value = "";
|
|
394
|
+
try {
|
|
395
|
+
const res = await getWorkOrderItems(props.site, search.value?.trim() || "");
|
|
396
|
+
if (mine !== seq) return;
|
|
397
|
+
stores.value = res?.stores ?? [];
|
|
398
|
+
noStore.value = !stores.value.length;
|
|
399
|
+
const merged: TPickItem[] = (res?.items ?? []).filter((item) => item.status !== "inactive");
|
|
400
|
+
if (mine === seq) {
|
|
401
|
+
items.value = merged;
|
|
402
|
+
const changes = syncPicked(merged);
|
|
403
|
+
const text = [notice, changes.join(". ")].filter(Boolean).join(" ");
|
|
404
|
+
if (text) warn(changes.length ? `${text}.` : text);
|
|
405
|
+
}
|
|
406
|
+
} catch (error) {
|
|
407
|
+
if (mine === seq) loadError.value = errorConverter(error);
|
|
408
|
+
} finally {
|
|
409
|
+
if (mine === seq) loading.value = false;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
414
|
+
watch(search, (text) => {
|
|
415
|
+
if (text) listOpen.value = true;
|
|
416
|
+
clearTimeout(timer);
|
|
417
|
+
timer = setTimeout(() => load(), 300);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* After a submit is refused for stock (another technician used it first): the
|
|
422
|
+
* page opens this dialog and calls refresh with the server's message; the
|
|
423
|
+
* stock is read again and the quantities brought down to what is left.
|
|
424
|
+
*/
|
|
425
|
+
async function refresh(notice = "") {
|
|
426
|
+
listOpen.value = false;
|
|
427
|
+
search.value = "";
|
|
428
|
+
clearTimeout(timer);
|
|
429
|
+
await load(notice);
|
|
430
|
+
}
|
|
431
|
+
defineExpose({ refresh });
|
|
432
|
+
|
|
433
|
+
watch(
|
|
434
|
+
() => props.modelValue,
|
|
435
|
+
(open) => {
|
|
436
|
+
if (!open) return;
|
|
437
|
+
picked.value = Object.fromEntries(props.value.map((m) => [m.item, { ...m }]));
|
|
438
|
+
listOpen.value = false;
|
|
439
|
+
if (search.value) search.value = ""; // its watcher reloads
|
|
440
|
+
else load();
|
|
441
|
+
},
|
|
442
|
+
{ immediate: true },
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
function close() {
|
|
446
|
+
emit("update:modelValue", false);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function save() {
|
|
450
|
+
if (outOfStockLines.value.length) {
|
|
451
|
+
warn("Remove the out-of-stock items first.");
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
emit("save", pickedList.value.map((p) => ({ ...p })));
|
|
455
|
+
close();
|
|
456
|
+
}
|
|
457
|
+
</script>
|
|
458
|
+
|
|
459
|
+
<style scoped>
|
|
460
|
+
.mat {
|
|
461
|
+
border-radius: 16px !important;
|
|
462
|
+
background: var(--card);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/* header */
|
|
466
|
+
.mat__head {
|
|
467
|
+
display: flex;
|
|
468
|
+
align-items: center;
|
|
469
|
+
gap: 12px;
|
|
470
|
+
padding: 16px 12px 12px 20px;
|
|
471
|
+
}
|
|
472
|
+
.mat__head-icon {
|
|
473
|
+
display: flex;
|
|
474
|
+
align-items: center;
|
|
475
|
+
justify-content: center;
|
|
476
|
+
width: 38px;
|
|
477
|
+
height: 38px;
|
|
478
|
+
border-radius: 10px;
|
|
479
|
+
background: var(--accent-soft);
|
|
480
|
+
color: var(--accent);
|
|
481
|
+
flex: 0 0 auto;
|
|
482
|
+
}
|
|
483
|
+
.mat__head-text {
|
|
484
|
+
flex: 1;
|
|
485
|
+
min-width: 0;
|
|
486
|
+
}
|
|
487
|
+
.mat__title {
|
|
488
|
+
font-size: 16px;
|
|
489
|
+
font-weight: 800;
|
|
490
|
+
line-height: 1.2;
|
|
491
|
+
}
|
|
492
|
+
.mat__subtitle {
|
|
493
|
+
font-size: 12.5px;
|
|
494
|
+
color: var(--muted);
|
|
495
|
+
margin-top: 2px;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
.mat__search {
|
|
499
|
+
padding: 0 20px 14px;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/* list header strip */
|
|
503
|
+
.mat__bar {
|
|
504
|
+
display: flex;
|
|
505
|
+
justify-content: space-between;
|
|
506
|
+
padding: 8px 20px;
|
|
507
|
+
font-size: 11.5px;
|
|
508
|
+
font-weight: 700;
|
|
509
|
+
letter-spacing: 0.04em;
|
|
510
|
+
text-transform: uppercase;
|
|
511
|
+
color: var(--muted);
|
|
512
|
+
background: var(--thead);
|
|
513
|
+
border-top: 1px solid var(--border);
|
|
514
|
+
border-bottom: 1px solid var(--border);
|
|
515
|
+
}
|
|
516
|
+
.mat__bar-picked {
|
|
517
|
+
color: var(--accent);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
.mat__body {
|
|
521
|
+
max-height: 56vh;
|
|
522
|
+
border-top: 1px solid var(--border);
|
|
523
|
+
}
|
|
524
|
+
.mat__bar + .mat__body {
|
|
525
|
+
border-top: 0;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/* empty / loading / error */
|
|
529
|
+
.mat__state {
|
|
530
|
+
display: flex;
|
|
531
|
+
flex-direction: column;
|
|
532
|
+
align-items: center;
|
|
533
|
+
gap: 8px;
|
|
534
|
+
padding: 36px 20px;
|
|
535
|
+
font-size: 13px;
|
|
536
|
+
color: var(--muted);
|
|
537
|
+
text-align: center;
|
|
538
|
+
}
|
|
539
|
+
.mat__empty-icon {
|
|
540
|
+
display: flex;
|
|
541
|
+
align-items: center;
|
|
542
|
+
justify-content: center;
|
|
543
|
+
width: 52px;
|
|
544
|
+
height: 52px;
|
|
545
|
+
border-radius: 50%;
|
|
546
|
+
background: var(--accent-soft);
|
|
547
|
+
color: var(--accent);
|
|
548
|
+
margin-bottom: 4px;
|
|
549
|
+
}
|
|
550
|
+
.mat__empty-title {
|
|
551
|
+
font-size: 14px;
|
|
552
|
+
font-weight: 700;
|
|
553
|
+
color: var(--text);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/* an option in the item list */
|
|
557
|
+
.mat__opt {
|
|
558
|
+
display: flex;
|
|
559
|
+
align-items: center;
|
|
560
|
+
gap: 10px;
|
|
561
|
+
padding: 10px 20px 10px 12px;
|
|
562
|
+
border-bottom: 1px solid var(--border);
|
|
563
|
+
cursor: pointer;
|
|
564
|
+
transition: background 0.12s ease;
|
|
565
|
+
}
|
|
566
|
+
.mat__opt:hover {
|
|
567
|
+
background: var(--hover);
|
|
568
|
+
}
|
|
569
|
+
.mat__opt--on {
|
|
570
|
+
background: var(--accent-soft);
|
|
571
|
+
}
|
|
572
|
+
.mat__opt--on:hover {
|
|
573
|
+
background: var(--accent-soft);
|
|
574
|
+
}
|
|
575
|
+
.mat__opt--out {
|
|
576
|
+
cursor: not-allowed;
|
|
577
|
+
}
|
|
578
|
+
.mat__opt--out .mat__main,
|
|
579
|
+
.mat__opt--out .mat__price,
|
|
580
|
+
.mat__opt--out :deep(.v-selection-control) {
|
|
581
|
+
opacity: 0.45;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
.mat__main {
|
|
585
|
+
flex: 1;
|
|
586
|
+
min-width: 0;
|
|
587
|
+
}
|
|
588
|
+
.mat__name {
|
|
589
|
+
font-size: 13.5px;
|
|
590
|
+
font-weight: 600;
|
|
591
|
+
line-height: 1.35;
|
|
592
|
+
color: var(--text);
|
|
593
|
+
}
|
|
594
|
+
.mat__meta {
|
|
595
|
+
font-size: 12px;
|
|
596
|
+
color: var(--muted);
|
|
597
|
+
margin-top: 2px;
|
|
598
|
+
white-space: nowrap;
|
|
599
|
+
overflow: hidden;
|
|
600
|
+
text-overflow: ellipsis;
|
|
601
|
+
}
|
|
602
|
+
.mat__side {
|
|
603
|
+
display: flex;
|
|
604
|
+
flex-direction: column;
|
|
605
|
+
align-items: flex-end;
|
|
606
|
+
gap: 4px;
|
|
607
|
+
flex: 0 0 auto;
|
|
608
|
+
}
|
|
609
|
+
.mat__price {
|
|
610
|
+
font-size: 13.5px;
|
|
611
|
+
font-weight: 700;
|
|
612
|
+
font-variant-numeric: tabular-nums;
|
|
613
|
+
}
|
|
614
|
+
.mat__pill {
|
|
615
|
+
display: inline-flex;
|
|
616
|
+
padding: 2px 8px;
|
|
617
|
+
border-radius: 999px;
|
|
618
|
+
font-size: 11px;
|
|
619
|
+
font-weight: 700;
|
|
620
|
+
white-space: nowrap;
|
|
621
|
+
}
|
|
622
|
+
.mat__pill--ok {
|
|
623
|
+
color: var(--ok);
|
|
624
|
+
background: var(--ok-bg);
|
|
625
|
+
}
|
|
626
|
+
.mat__pill--warn {
|
|
627
|
+
color: var(--warn);
|
|
628
|
+
background: var(--warn-bg);
|
|
629
|
+
}
|
|
630
|
+
.mat__pill--err {
|
|
631
|
+
color: var(--err);
|
|
632
|
+
background: var(--err-bg);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/* a selected line */
|
|
636
|
+
.mat__line {
|
|
637
|
+
padding: 14px 20px 10px;
|
|
638
|
+
border-bottom: 1px solid var(--border);
|
|
639
|
+
}
|
|
640
|
+
.mat__line-top {
|
|
641
|
+
display: flex;
|
|
642
|
+
align-items: flex-start;
|
|
643
|
+
gap: 12px;
|
|
644
|
+
}
|
|
645
|
+
.mat__subtotal {
|
|
646
|
+
font-size: 14px;
|
|
647
|
+
font-weight: 800;
|
|
648
|
+
font-variant-numeric: tabular-nums;
|
|
649
|
+
flex: 0 0 auto;
|
|
650
|
+
}
|
|
651
|
+
.mat__line-bottom {
|
|
652
|
+
display: flex;
|
|
653
|
+
align-items: center;
|
|
654
|
+
gap: 10px;
|
|
655
|
+
margin-top: 10px;
|
|
656
|
+
}
|
|
657
|
+
.mat__stepper {
|
|
658
|
+
display: inline-flex;
|
|
659
|
+
align-items: center;
|
|
660
|
+
border: 1px solid var(--border);
|
|
661
|
+
border-radius: 10px;
|
|
662
|
+
overflow: hidden;
|
|
663
|
+
}
|
|
664
|
+
.mat__step {
|
|
665
|
+
display: flex;
|
|
666
|
+
align-items: center;
|
|
667
|
+
justify-content: center;
|
|
668
|
+
width: 34px;
|
|
669
|
+
height: 34px;
|
|
670
|
+
color: var(--text2);
|
|
671
|
+
background: transparent;
|
|
672
|
+
border: 0;
|
|
673
|
+
cursor: pointer;
|
|
674
|
+
}
|
|
675
|
+
.mat__step:hover:not(:disabled) {
|
|
676
|
+
background: var(--hover);
|
|
677
|
+
}
|
|
678
|
+
.mat__step:disabled {
|
|
679
|
+
opacity: 0.35;
|
|
680
|
+
cursor: not-allowed;
|
|
681
|
+
}
|
|
682
|
+
.mat__qty {
|
|
683
|
+
width: 48px;
|
|
684
|
+
height: 34px;
|
|
685
|
+
border: 0;
|
|
686
|
+
border-left: 1px solid var(--border);
|
|
687
|
+
border-right: 1px solid var(--border);
|
|
688
|
+
outline: none;
|
|
689
|
+
background: transparent;
|
|
690
|
+
color: var(--text);
|
|
691
|
+
font: inherit;
|
|
692
|
+
font-size: 14px;
|
|
693
|
+
font-weight: 700;
|
|
694
|
+
text-align: center;
|
|
695
|
+
font-variant-numeric: tabular-nums;
|
|
696
|
+
-moz-appearance: textfield;
|
|
697
|
+
}
|
|
698
|
+
.mat__qty::-webkit-outer-spin-button,
|
|
699
|
+
.mat__qty::-webkit-inner-spin-button {
|
|
700
|
+
-webkit-appearance: none;
|
|
701
|
+
margin: 0;
|
|
702
|
+
}
|
|
703
|
+
.mat__qty:focus {
|
|
704
|
+
background: var(--hover);
|
|
705
|
+
}
|
|
706
|
+
.mat__line--out {
|
|
707
|
+
background: var(--err-bg);
|
|
708
|
+
}
|
|
709
|
+
.mat__line--out .mat__main,
|
|
710
|
+
.mat__line--out .mat__subtotal {
|
|
711
|
+
opacity: 0.55;
|
|
712
|
+
}
|
|
713
|
+
.mat__stepper--off {
|
|
714
|
+
opacity: 0.4;
|
|
715
|
+
pointer-events: none;
|
|
716
|
+
}
|
|
717
|
+
.mat__blocked {
|
|
718
|
+
display: flex;
|
|
719
|
+
align-items: center;
|
|
720
|
+
gap: 6px;
|
|
721
|
+
margin: -4px 0 12px;
|
|
722
|
+
font-size: 12.5px;
|
|
723
|
+
font-weight: 600;
|
|
724
|
+
color: var(--err);
|
|
725
|
+
}
|
|
726
|
+
.mat__of {
|
|
727
|
+
font-size: 12px;
|
|
728
|
+
color: var(--muted);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/* footer */
|
|
732
|
+
.mat__foot {
|
|
733
|
+
padding: 14px 20px 18px;
|
|
734
|
+
border-top: 1px solid var(--border);
|
|
735
|
+
}
|
|
736
|
+
.mat__total {
|
|
737
|
+
display: flex;
|
|
738
|
+
align-items: flex-end;
|
|
739
|
+
justify-content: space-between;
|
|
740
|
+
margin-bottom: 14px;
|
|
741
|
+
}
|
|
742
|
+
.mat__total-label {
|
|
743
|
+
font-size: 14px;
|
|
744
|
+
font-weight: 700;
|
|
745
|
+
}
|
|
746
|
+
.mat__total-sub {
|
|
747
|
+
font-size: 12px;
|
|
748
|
+
color: var(--muted);
|
|
749
|
+
margin-top: 2px;
|
|
750
|
+
}
|
|
751
|
+
.mat__total-value {
|
|
752
|
+
font-size: 20px;
|
|
753
|
+
font-weight: 800;
|
|
754
|
+
font-variant-numeric: tabular-nums;
|
|
755
|
+
}
|
|
756
|
+
</style>
|