index.vue
24.7 KB
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
<template>
<div class="app-container">
<el-descriptions title="" column="3" v-if="detailData">
<el-descriptions-item label="任务ID:">{{
detailData.id
}}</el-descriptions-item>
<el-descriptions-item label="">
<el-form
class="taskForm"
:model="taskForm"
:rules="taskRules"
ref="taskFormRef"
>
<el-form-item label="任务名称:" prop="taskName">
<el-input
style="width: 200px"
v-model="taskForm.taskName"
placeholder="请输入任务名称"
/>
</el-form-item>
</el-form>
</el-descriptions-item>
<el-descriptions-item label="对应营业厅:">{{
detailData.businessName
}}</el-descriptions-item>
<el-descriptions-item label="分拣数量:">{{
detailData.totalItemCount
}}</el-descriptions-item>
<el-descriptions-item label="创建时间:">{{
detailData.createTime
}}</el-descriptions-item>
</el-descriptions>
<el-divider></el-divider>
<el-form
v-if="false"
:model="queryParams"
ref="queryRef"
v-show="showSearch"
:inline="true"
label-width="100px"
label-position="left"
>
<el-form-item label="Type:" prop="type">
<el-input
v-model="queryParams.type"
placeholder="Please enter type"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="Trans:" prop="trans">
<el-input
v-model="queryParams.trans"
placeholder="Please enter trans"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="Contract No:" prop="contractNo">
<el-input
v-model="queryParams.contractNo"
placeholder="Please enter contractNo"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="Del:" prop="del">
<el-input
v-model="queryParams.del"
placeholder="Please enter del"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item label="EX-Fact:" prop="exFact">
<el-input
v-model="queryParams.exFact"
placeholder="Please enter exFact"
clearable
style="width: 240px"
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="handleQuery"
>Search</el-button
>
<el-button icon="Refresh" @click="resetQuery">Reset</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd"
>扫码</el-button
>
</el-col>
<!-- <el-col :span="1.5">
<el-button
type="primary"
plain
icon="Upload"
@click="handleImport"
v-hasPermi="['tool:gen:import']"
>Import</el-button
>
</el-col> -->
<right-toolbar
v-model:showSearch="showSearch"
:search="false"
@queryTable="getList"
></right-toolbar>
</el-row>
<!-- Table Data -->
<el-table v-loading="loading" :data="dataList">
<el-table-column
v-for="(column, columnIndex) in columnList"
:key="columnIndex"
:label="column.label"
:prop="column.prop"
:show-overflow-tooltip="column.showOverflowTooltip || true"
:align="column.align || 'center'"
:width="column.width || 'auto'"
>
<template #default="scope">
<span
v-if="column.prop === 'status'"
:style="{
fontWeight: 500,
color:
scope.row[column.prop] == 'COMPLETED'
? '#27B148'
: scope.row[column.prop] === 'WAITING'
? '#ff6200'
: '#409EFF',
}"
>
{{ scope.row[column.prop] }}
</span>
<span v-else-if="column.prop === 'id'">
{{ scope.row.hideId ? "" : scope.row[column.prop] }}
</span>
<span v-else>{{ scope.row[column.prop] }}</span>
</template>
</el-table-column>
<el-table-column
label="操作"
fixed="right"
align="center"
width="100"
class-name="small-padding fixed-width"
>
<template #default="scope">
<el-tooltip content="编辑" placement="top">
<el-button
link
type="primary"
:disabled="
scope.row.status !== 'WAITING' && scope.row.status !== 'PAUSE'
"
@click="handleEdit(scope.row)"
>编辑</el-button
>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button
link
type="primary"
:disabled="
scope.row.status !== 'WAITING' && scope.row.status !== 'PAUSE'
"
@click="handleDelete(scope.row)"
>删除</el-button
>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
layout="prev, pager, next"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
<div class="footer">
<el-divider></el-divider>
<div class="content">
<el-button @click="goBack">取消</el-button>
<el-button type="primary" :loading="taskLoading" @click="confirmAddTask"
>确认</el-button
>
</div>
</div>
<!-- Add or Edit User Config Dialog -->
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
<template #header>
<div class="header" style="text-align: center">
{{ title }}
</div>
</template>
<el-form :model="form" :rules="rules" ref="userRef" label-width="120px">
<el-row>
<el-col :span="24">
<el-form-item label="对应营业厅:" prop="businessName">
<div style="width: 100%; display: flex">
<el-input
v-model="form.businessName"
placeholder="请查询对应营业厅"
disabled
/>
<el-button
type="primary"
:loading="searchBusinessLoading"
@click="searchBusiness"
style="margin-left: 10px"
>查询营业厅</el-button
>
</div>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="条码" prop="barcode">
<el-input
ref="barcodeRef"
v-model="form.barcode"
placeholder="请输入条码"
@change="handleBarcodeChange"
/>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="类型" prop="deviceTypeId">
<el-select
v-model="form.deviceTypeId"
placeholder="请选择类型"
@change="handleDeviceType"
>
<el-option
v-for="item in deviceTypeList"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="数量" prop="quantity">
<el-input v-model="form.quantity" placeholder="请输入数量" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm">确认</el-button>
<el-button @click="() => (open = false)">取消</el-button>
</div>
</template>
</el-dialog>
<el-dialog
:title="upload.title"
v-model="upload.open"
width="400px"
append-to-body
>
<el-upload
ref="uploadRef"
:limit="1"
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
drag
>
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
<div class="el-upload__text">
Drag file here, or <em>click to upload</em>
</div>
<template #tip>
<div class="el-upload__tip text-center">
<span>Only xls, xlsx files are allowed.</span>
<!-- <el-link
type="primary"
:underline="false"
style="font-size: 12px; vertical-align: baseline"
@click="importTemplate"
>Download Template</el-link> -->
</div>
</template>
</el-upload>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitFileForm">Confirm</el-button>
<el-button @click="upload.open = false">Cancel</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { getToken } from "@/utils/auth";
import { formatDate } from "@/utils/index";
import { nextTick, onMounted, onUnmounted, ref } from "vue";
import {
scanSpecQueryList,
deviceTypeQueryList,
deleteScanSpec,
addScanTask,
scanCode,
scanTaskdetal,
editScanSpec,
editScanTask,
searchBusinessInfo,
} from "@/api/system/scan";
import { ElLoading } from "element-plus";
import { da, fa } from "element-plus/es/locales.mjs";
const router = useRouter();
const route = useRoute();
const { proxy } = getCurrentInstance();
const dataList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const dateRange = ref([]);
const barcodeRef = ref();
const columnList = ref([
{
label: "序号",
prop: "id",
width: 70,
},
{
label: "条码",
prop: "barcode",
width: 300,
},
{
label: "类型",
prop: "deviceTypeName",
},
{
label: "数量",
prop: "quantity",
},
// {
// label: "状态",
// prop: "status",
// },
]);
const data = reactive({
form: {},
queryParams: {
pageNo: 1,
pageSize: 10,
scanTaskId: route.query.scanTaskId,
type: undefined,
trans: undefined,
contractNo: undefined,
del: undefined,
exFact: undefined,
},
rules: {
businessName: [
{ required: true, message: "请查询对应营业厅", trigger: "blur" },
],
barcode: [{ required: true, message: "请输入条码", trigger: "blur" }],
deviceTypeId: [{ required: true, message: "请选择类型", trigger: "blur" }],
quantity: [
{
required: true,
message: "请输入数量",
trigger: "blur",
},
],
},
taskForm: {
taskName: undefined,
},
taskRules: {
taskName: [{ required: true, message: "请输入任务名称", trigger: "blur" }],
},
});
const { queryParams, form, rules, taskForm, taskRules } = toRefs(data);
const open = ref(false);
const title = ref("");
const deviceTypeList = ref([]);
const searchBusinessLoading = ref(false);
const getDeviceTypeList = () => {
deviceTypeQueryList(
proxy.addDateRange(queryParams.value, dateRange.value)
).then((res) => {
console.log(res, 111);
deviceTypeList.value = res.data;
});
};
const handleDeviceType = (e) => {
if (e) {
form.value.deviceTypeName = deviceTypeList.value.find(
(item) => item.id == e
).name;
} else {
form.value.deviceTypeName = undefined;
}
};
const handleBarcodeChange = (e) => {
form.value.businessName = undefined;
form.value.businessId = undefined;
console.log(e);
if (e) {
searchBusiness();
}
};
const searchBusiness = () => {
proxy.$refs["userRef"].clearValidate();
proxy.$refs["userRef"].validateField("barcode", (valid) => {
console.log(valid, "1111");
if (valid) {
searchBusinessLoading.value = true;
searchBusinessInfo({
number: form.value.barcode,
})
.then((res) => {
console.log(res, 111);
if (res.data) {
form.value.businessName = res.data.name;
form.value.businessId = res.data.id;
}
})
.finally(() => {
searchBusinessLoading.value = false;
});
}
});
};
function submitForm() {
proxy.$refs["userRef"].validate((valid) => {
if (valid) {
// addScanSpec(form.value).then((response) => {
// proxy.$modal.msgSuccess("扫码录入成功!");
// open.value = false;
// getList();
// });
if (
dataList.value.length == 0 ||
form.value.businessId === dataList.value[0].businessId
) {
const localStoreTableData = localStorage.getItem("localStoreTableData")
? JSON.parse(localStorage.getItem("localStoreTableData"))
: [];
const target = localStoreTableData.find(
(item) => item.id === form.value.id
);
if (target) {
target.barcode = form.value.barcode;
target.deviceTypeName = form.value.deviceTypeName;
target.deviceTypeId = form.value.deviceTypeId;
target.quantity = form.value.quantity;
localStorage.setItem(
"localStoreTableData",
JSON.stringify(localStoreTableData)
);
open.value = false;
proxy.$modal.msgSuccess("扫码录入成功!");
getList();
} else {
const editTarget = dataList.value.find(
(item) => item.id === form.value.id
);
console.log(1111);
if (editTarget) {
editScanSpec({
id: form.value.id,
scanTaskId: proxy.$route.query.scanTaskId,
businessId: form.value.businessId,
deviceTypeId: form.value.deviceTypeId,
barcode: form.value.barcode,
quantity: form.value.quantity,
}).then((res) => {
open.value = false;
proxy.$modal.msgSuccess("编辑成功!");
getList();
});
} else {
localStoreTableData.push({
id: new Date().getTime(),
barcode: form.value.barcode,
deviceTypeName: deviceTypeList.value.find(
(item) => item.id === form.value.deviceTypeId
).name,
deviceTypeId: form.value.deviceTypeId,
quantity: form.value.quantity,
businessId: form.value.businessId,
businessName: form.value.businessName,
status: "WAITING",
});
localStorage.setItem(
"localStoreTableData",
JSON.stringify(localStoreTableData)
);
open.value = false;
proxy.$modal.msgSuccess("扫码录入成功!");
getList();
}
}
} else {
proxy.$modal.msgError(
"营业厅不一致,请检查输入条码,并重新查询对应营业厅!"
);
}
}
});
}
// Reset operation form
function reset() {
form.value = {
scanTaskId: route.query.scanTaskId,
name: undefined,
businessId: undefined,
businessName: undefined,
barcode: undefined,
deviceTypeId: undefined,
quantity: undefined,
};
proxy.resetForm("userRef");
}
const timer = ref(null);
const downloadLoadingInstance = ref("");
function handleAdd() {
// downloadLoadingInstance.value = ElLoading.service({
// text: "正在连接设备中...,请稍候",
// background: "rgba(0, 0, 0, 0.7)",
// });
// scanCodeCallback(scanCodeCallback);
reset();
open.value = true;
title.value = "扫码录入";
nextTick(() => {
setTimeout(() => {
barcodeRef.value.focus();
}, 100);
});
}
// 递归调用接口,直至设备有所返回
const scanCodeCallback = (callback) => {
scanCode({})
.then((res) => {
const data = res.data;
if (!data) {
callback();
} else {
// 这里还需要判断扫描出来营业厅是否跟表格营业厅一致,不是报错提示重新扫码
downloadLoadingInstance.value.close();
if (
dataList.value.length == 0 ||
data.businessId === dataList.value[0].businessId
) {
downloadLoadingInstance.value.close();
reset();
open.value = true;
title.value = "扫码录入";
form.value.name = taskForm.value.taskName;
form.value.businessId = data.businessId;
form.value.businessName = data.businessName;
form.value.barcode = data.barcode;
} else {
proxy.$modal.msgError("营业厅不一致,请检查设备,请重新点击扫码!");
}
}
})
.catch(() => {
proxy.$modal.msgError("连接设备失败,请检查设备,并重新点击扫码!");
downloadLoadingInstance.value.close();
});
};
const handleEdit = (row) => {
reset();
open.value = true;
title.value = "编辑录入";
form.value = {
...row,
};
if (proxy.$route.query.scanTaskId) {
form.value.businessName = detailData.value.businessName;
form.value.businessId = detailData.value.businessId;
}
nextTick(() => {
setTimeout(() => {
barcodeRef.value.focus();
}, 100);
});
};
const goBack = () => {
proxy.$router.go(-1);
};
const taskLoading = ref(false);
const confirmAddTask = () => {
proxy.$refs["taskFormRef"].validate((valid) => {
if (valid) {
const localStoreTableData = localStorage.getItem("localStoreTableData")
? JSON.parse(localStorage.getItem("localStoreTableData"))
: [];
if (localStoreTableData.length == 0 && dataList.value.length == 0) {
proxy.$modal.msgError("请先点击扫码!");
return;
}
const data = {
name: taskForm.value.taskName,
businessId: dataList.value[0].businessId,
specList: localStoreTableData.map((item) => ({
businessId: item.businessId,
deviceTypeId: item.deviceTypeId,
barcode: item.barcode,
quantity: item.quantity,
})),
};
if (proxy.$route.query.scanTaskId) {
data.id = detailData.value.id;
data.name = taskForm.value.taskName;
data.businessId = detailData.value.businessId;
data.specList = data.specList.concat(
dataList.value
.filter(
(filterItem) =>
localStoreTableData
.map((local) => local.id)
.indexOf(filterItem.id) == -1
)
.map((item) => ({
id: item.id,
businessId: item.businessId,
deviceTypeId: item.deviceTypeId,
barcode: item.barcode,
quantity: item.quantity,
}))
);
taskLoading.value = true;
editScanTask(data)
.then((response) => {
proxy.$modal.msgSuccess("编辑任务成功!");
open.value = false;
localStorage.removeItem("localStoreTableData");
goBack();
})
.finally(() => {
taskLoading.value = false;
});
} else {
taskLoading.value = true;
addScanTask(data)
.then((response) => {
proxy.$modal.msgSuccess("新增任务成功!");
open.value = false;
localStorage.removeItem("localStoreTableData");
goBack();
})
.finally(() => {
taskLoading.value = false;
});
}
}
});
};
// Query list
const getList = () => {
let localStoreTableData = localStorage.getItem("localStoreTableData")
? JSON.parse(localStorage.getItem("localStoreTableData"))
: [];
localStoreTableData = localStoreTableData.map((item) => ({
...item,
hideId: true,
}));
if (!proxy.$route.query.scanTaskId) {
loading.value = false;
dataList.value = localStoreTableData;
} else {
loading.value = true;
scanSpecQueryList(
proxy.addDateRange(queryParams.value, dateRange.value)
).then((res) => {
loading.value = false;
dataList.value = res.data.concat(localStoreTableData);
});
}
};
// Search button operation
const handleQuery = () => {
queryParams.value.pageNo = 1;
getList();
};
// Reset button operation
const resetQuery = () => {
dateRange.value = [];
proxy.resetForm("queryRef");
handleQuery();
};
const upload = reactive({
open: false,
title: "Import",
isUploading: false,
updateSupport: 0,
headers: { Authorization: "Bearer " + getToken() },
url: import.meta.env.VITE_APP_BASE_API + "/scan/specification/import",
});
const uploadRef = ref(null);
const handleImport = () => {
upload.title = "Import";
upload.open = true;
upload.isUploading = false;
upload.updateSupport = 0;
};
const handleFileUploadProgress = (event, file, fileList) => {
upload.isUploading = true;
};
const handleFileSuccess = (response, file, fileList) => {
upload.isUploading = false;
if (response.code === 200) {
upload.open = false;
proxy.$modal.msgSuccess(response.msg);
getList(); // Refresh main table
} else {
proxy.$modal.msgError(response.msg);
}
};
const detailData = ref({});
const getDetail = () => {
scanTaskdetal(proxy.$route.query.scanTaskId).then((res) => {
detailData.value = res.data;
taskForm.value.taskName = detailData.value.name;
detailData.value.createTime = formatDate(detailData.value.createTime);
});
};
const importTemplate = () => {
proxy.download("/system/user/importTemplate");
};
const submitFileForm = () => {
uploadRef.value.submit();
};
const handleDelete = (row) => {
proxy.$modal
.confirm("确认删除?")
.then(() => {
let localStoreTableData = localStorage.getItem("localStoreTableData")
? JSON.parse(localStorage.getItem("localStoreTableData"))
: [];
const target = localStoreTableData.find((item) => item.id === row.id);
if (!proxy.$route.query.scanTaskId || target) {
localStoreTableData = localStoreTableData.filter(
(item) => item.id !== row.id
);
localStorage.setItem(
"localStoreTableData",
JSON.stringify(localStoreTableData)
);
proxy.$modal.msgSuccess("删除成功!");
getList();
} else {
deleteScanSpec(row.id).then((response) => {
proxy.$modal.msgSuccess("删除成功!");
getList();
});
}
})
.catch(() => {
proxy.$modal.msgWarning("已取消");
});
};
const enterDetail = (row) => {
router.push({
path: "/scan-manage/order-manage/order-detail",
query: {
scanTaskId: row.scanTaskId,
scanOrderId: row.id,
},
});
};
const handleKeydown = (e) => {
if (e.key === "Enter") {
e.preventDefault();
if (open.value) {
searchBusiness();
}
}
};
onMounted(() => {
getList();
getDeviceTypeList();
if (proxy.$route.query.scanTaskId) {
getDetail();
}
window.addEventListener("keydown", handleKeydown);
});
onUnmounted(() => {
window.removeEventListener("keydown", handleKeydown);
});
</script>
<style lang="scss" scoped>
.el-divider--horizontal {
margin: 10px 0 24px;
}
.footer {
.el-divider--horizontal {
margin: 0;
}
position: absolute;
width: 100%;
right: 0;
bottom: 0;
height: 70px;
background: #fff;
box-sizing: border-box;
.content {
height: 70px;
padding: 0 30px;
display: flex;
align-items: center;
}
}
</style>