Commit 242ce5e6361d40b4a9ce9128705cba39b55031da

Authored by Dunfa Jiang
1 parent 47d53c85

fix:修改扫码逻辑和增加开始暂停接口内容

@@ -144,8 +144,27 @@ export function editScanTask(query) { @@ -144,8 +144,27 @@ export function editScanTask(query) {
144 }); 144 });
145 } 145 }
146 146
  147 +export function startTask(id) {
  148 + return request({
  149 + url: `/scanTask/${id}/start`,
  150 + method: "PUT"
  151 + });
  152 +}
147 153
  154 +export function pauseTask(id) {
  155 + return request({
  156 + url: `/scanTask/${id}/pause`,
  157 + method: "PUT"
  158 + });
  159 +}
148 160
  161 +export function searchBusinessInfo(query) {
  162 + return request({
  163 + url: "/business/detailByNumber",
  164 + method: "GET",
  165 + params: query,
  166 + });
  167 +}
149 168
150 export function addScanTask(query) { 169 export function addScanTask(query) {
151 return request({ 170 return request({
@@ -159,7 +178,7 @@ export function scanCode(query) { @@ -159,7 +178,7 @@ export function scanCode(query) {
159 return request({ 178 return request({
160 url: "/scanLog/latest", 179 url: "/scanLog/latest",
161 method: "GET", 180 method: "GET",
162 - data: query, 181 + params: query,
163 }); 182 });
164 } 183 }
165 184
@@ -122,12 +122,24 @@ @@ -122,12 +122,24 @@
122 > 122 >
123 </el-tooltip> 123 </el-tooltip>
124 <el-tooltip content="开始" placement="top"> 124 <el-tooltip content="开始" placement="top">
125 - <el-button link type="primary" @click="handleStart(scope.row)" 125 + <el-button
  126 + link
  127 + type="primary"
  128 + :disabled="scope.row.status !== 'PAUSE'"
  129 + @click="handleStart(scope.row)"
126 >开始</el-button 130 >开始</el-button
127 > 131 >
128 </el-tooltip> 132 </el-tooltip>
129 <el-tooltip content="暂停" placement="top"> 133 <el-tooltip content="暂停" placement="top">
130 - <el-button link type="primary" @click="handlePause(scope.row)" 134 + <el-button
  135 + link
  136 + type="primary"
  137 + :disabled="
  138 + (scope.row.status !== 'WAITING' &&
  139 + scope.row.status == 'ONGOING' )||
  140 + scope.row.status == 'PAUSE'
  141 + "
  142 + @click="handlePause(scope.row)"
131 >暂停</el-button 143 >暂停</el-button
132 > 144 >
133 </el-tooltip> 145 </el-tooltip>
@@ -198,7 +210,7 @@ import { ElMessageBox } from "element-plus"; @@ -198,7 +210,7 @@ import { ElMessageBox } from "element-plus";
198 210
199 import { getToken } from "@/utils/auth"; 211 import { getToken } from "@/utils/auth";
200 import { onMounted, ref } from "vue"; 212 import { onMounted, ref } from "vue";
201 -import { taskList } from "@/api/system/scan"; 213 +import { taskList, startTask, pauseTask } from "@/api/system/scan";
202 const route = useRoute(); 214 const route = useRoute();
203 const router = useRouter(); 215 const router = useRouter();
204 216
@@ -357,7 +369,10 @@ const handleStart = (row) => { @@ -357,7 +369,10 @@ const handleStart = (row) => {
357 proxy.$modal 369 proxy.$modal
358 .confirm("确认重新开始此任务?") 370 .confirm("确认重新开始此任务?")
359 .then(() => { 371 .then(() => {
360 - // 372 + startTask(row.id).then((res) => {
  373 + proxy.$modal.msgSuccess("重新开始成功");
  374 + getList();
  375 + });
361 }) 376 })
362 .catch(() => { 377 .catch(() => {
363 proxy.$modal.msgWarning("已取消"); 378 proxy.$modal.msgWarning("已取消");
@@ -368,7 +383,10 @@ const handlePause = (row) => { @@ -368,7 +383,10 @@ const handlePause = (row) => {
368 proxy.$modal 383 proxy.$modal
369 .confirm("确认暂停此任务?") 384 .confirm("确认暂停此任务?")
370 .then(() => { 385 .then(() => {
371 - // 386 + pauseTask(row.id).then((res) => {
  387 + proxy.$modal.msgSuccess("暂停任务成功");
  388 + getList();
  389 + });
372 }) 390 })
373 .catch(() => { 391 .catch(() => {
374 proxy.$modal.msgWarning("已取消"); 392 proxy.$modal.msgWarning("已取消");
@@ -4,12 +4,21 @@ @@ -4,12 +4,21 @@
4 <el-descriptions-item label="任务ID:">{{ 4 <el-descriptions-item label="任务ID:">{{
5 detailData.id 5 detailData.id
6 }}</el-descriptions-item> 6 }}</el-descriptions-item>
7 - <el-descriptions-item label="任务名称:">  
8 - <el-input  
9 - style="width: 200px"  
10 - v-model="taskName"  
11 - placeholder="请输入任务名称"  
12 - /> 7 + <el-descriptions-item label="">
  8 + <el-form
  9 + class="taskForm"
  10 + :model="taskForm"
  11 + :rules="taskRules"
  12 + ref="taskFormRef"
  13 + >
  14 + <el-form-item label="任务名称:" prop="taskName">
  15 + <el-input
  16 + style="width: 200px"
  17 + v-model="taskForm.taskName"
  18 + placeholder="请输入任务名称"
  19 + />
  20 + </el-form-item>
  21 + </el-form>
13 </el-descriptions-item> 22 </el-descriptions-item>
14 <el-descriptions-item label="对应营业厅:">{{ 23 <el-descriptions-item label="对应营业厅:">{{
15 detailData.businessName 24 detailData.businessName
@@ -196,16 +205,29 @@ @@ -196,16 +205,29 @@
196 <el-row> 205 <el-row>
197 <el-col :span="24"> 206 <el-col :span="24">
198 <el-form-item label="对应营业厅:" prop="businessName"> 207 <el-form-item label="对应营业厅:" prop="businessName">
199 - <el-input  
200 - v-model="form.businessName"  
201 - placeholder="请输入对应营业厅"  
202 - disabled  
203 - /> 208 + <div style="width: 100%; display: flex">
  209 + <el-input
  210 + v-model="form.businessName"
  211 + placeholder="请查询对应营业厅"
  212 + disabled
  213 + />
  214 + <el-button
  215 + type="primary"
  216 + :loading="searchBusinessLoading"
  217 + @click="searchBusiness"
  218 + style="margin-left: 10px"
  219 + >查询营业厅</el-button
  220 + >
  221 + </div>
204 </el-form-item> 222 </el-form-item>
205 </el-col> 223 </el-col>
206 <el-col :span="24"> 224 <el-col :span="24">
207 <el-form-item label="条码" prop="barcode"> 225 <el-form-item label="条码" prop="barcode">
208 - <el-input v-model="form.barcode" placeholder="请输入条码" /> 226 + <el-input
  227 + v-model="form.barcode"
  228 + placeholder="请输入条码"
  229 + @change="handleBarcodeChange"
  230 + />
209 </el-form-item> 231 </el-form-item>
210 </el-col> 232 </el-col>
211 <el-col :span="24"> 233 <el-col :span="24">
@@ -291,6 +313,7 @@ import { @@ -291,6 +313,7 @@ import {
291 scanTaskdetal, 313 scanTaskdetal,
292 editScanSpec, 314 editScanSpec,
293 editScanTask, 315 editScanTask,
  316 + searchBusinessInfo,
294 } from "@/api/system/scan"; 317 } from "@/api/system/scan";
295 import { ElLoading } from "element-plus"; 318 import { ElLoading } from "element-plus";
296 import { da, fa } from "element-plus/es/locales.mjs"; 319 import { da, fa } from "element-plus/es/locales.mjs";
@@ -343,7 +366,7 @@ const data = reactive({ @@ -343,7 +366,7 @@ const data = reactive({
343 }, 366 },
344 rules: { 367 rules: {
345 businessName: [ 368 businessName: [
346 - { required: true, message: "请输入对应营业厅", trigger: "blur" }, 369 + { required: true, message: "请查询对应营业厅", trigger: "blur" },
347 ], 370 ],
348 barcode: [{ required: true, message: "请输入条码", trigger: "blur" }], 371 barcode: [{ required: true, message: "请输入条码", trigger: "blur" }],
349 deviceTypeId: [{ required: true, message: "请选择类型", trigger: "blur" }], 372 deviceTypeId: [{ required: true, message: "请选择类型", trigger: "blur" }],
@@ -355,14 +378,21 @@ const data = reactive({ @@ -355,14 +378,21 @@ const data = reactive({
355 }, 378 },
356 ], 379 ],
357 }, 380 },
  381 + taskForm: {
  382 + taskName: undefined,
  383 + },
  384 + taskRules: {
  385 + taskName: [{ required: true, message: "请输入任务名称", trigger: "blur" }],
  386 + },
358 }); 387 });
359 388
360 -const { queryParams, form, rules } = toRefs(data); 389 +const { queryParams, form, rules, taskForm, taskRules } = toRefs(data);
361 390
362 const open = ref(false); 391 const open = ref(false);
363 const title = ref(""); 392 const title = ref("");
364 const deviceTypeList = ref([]); 393 const deviceTypeList = ref([]);
365 -const taskName = ref([]); 394 +
  395 +const searchBusinessLoading = ref(false);
366 396
367 const getDeviceTypeList = () => { 397 const getDeviceTypeList = () => {
368 deviceTypeQueryList( 398 deviceTypeQueryList(
@@ -373,6 +403,35 @@ const getDeviceTypeList = () => { @@ -373,6 +403,35 @@ const getDeviceTypeList = () => {
373 }); 403 });
374 }; 404 };
375 405
  406 +const handleBarcodeChange = () => {
  407 + form.value.businessName = undefined;
  408 + form.value.businessId = undefined;
  409 +};
  410 +
  411 +const searchBusiness = () => {
  412 + proxy.$refs["userRef"].clearValidate();
  413 + proxy.$refs["userRef"].validateField("barcode", (valid) => {
  414 + console.log(valid, "1111");
  415 +
  416 + if (valid) {
  417 + searchBusinessLoading.value = true;
  418 + searchBusinessInfo({
  419 + number: form.value.barcode,
  420 + })
  421 + .then((res) => {
  422 + console.log(res, 111);
  423 + if (res.data) {
  424 + form.value.businessName = res.data.name;
  425 + form.value.businessId = res.data.id;
  426 + }
  427 + })
  428 + .finally(() => {
  429 + searchBusinessLoading.value = false;
  430 + });
  431 + }
  432 + });
  433 +};
  434 +
376 function submitForm() { 435 function submitForm() {
377 proxy.$refs["userRef"].validate((valid) => { 436 proxy.$refs["userRef"].validate((valid) => {
378 if (valid) { 437 if (valid) {
@@ -382,56 +441,22 @@ function submitForm() { @@ -382,56 +441,22 @@ function submitForm() {
382 // getList(); 441 // getList();
383 // }); 442 // });
384 443
385 - const localStoreTableData = localStorage.getItem("localStoreTableData")  
386 - ? JSON.parse(localStorage.getItem("localStoreTableData"))  
387 - : []; 444 + if (
  445 + dataList.value.length == 0 ||
  446 + form.value.businessId === dataList.value[0].businessId
  447 + ) {
  448 + const localStoreTableData = localStorage.getItem("localStoreTableData")
  449 + ? JSON.parse(localStorage.getItem("localStoreTableData"))
  450 + : [];
388 451
389 - const target = localStoreTableData.find(  
390 - (item) => item.id === form.value.id  
391 - );  
392 - if (target) {  
393 - target.barcode = form.value.barcode;  
394 - target.deviceTypeName = form.value.deviceTypeName;  
395 - target.deviceTypeId = form.value.deviceTypeId;  
396 - target.quantity = form.value.quantity;  
397 - localStorage.setItem(  
398 - "localStoreTableData",  
399 - JSON.stringify(localStoreTableData)  
400 - );  
401 - open.value = false;  
402 - proxy.$modal.msgSuccess("扫码录入成功!");  
403 - getList();  
404 - } else {  
405 - const editTarget = dataList.value.find( 452 + const target = localStoreTableData.find(
406 (item) => item.id === form.value.id 453 (item) => item.id === form.value.id
407 ); 454 );
408 - console.log(1111);  
409 - if (editTarget) {  
410 - editScanSpec({  
411 - id: form.value.id,  
412 - scanTaskId: proxy.$route.query.scanTaskId,  
413 - businessId: form.value.businessId,  
414 - deviceTypeId: form.value.deviceTypeId,  
415 - barcode: form.value.barcode,  
416 - quantity: form.value.quantity,  
417 - }).then((res) => {  
418 - open.value = false;  
419 - proxy.$modal.msgSuccess("编辑成功!");  
420 - getList();  
421 - });  
422 - } else {  
423 - localStoreTableData.push({  
424 - id: new Date().getTime(),  
425 - barcode: form.value.barcode,  
426 - deviceTypeName: deviceTypeList.value.find(  
427 - (item) => item.id === form.value.deviceTypeId  
428 - ).name,  
429 - deviceTypeId: form.value.deviceTypeId,  
430 - quantity: form.value.quantity,  
431 - businessId: form.value.businessId,  
432 - businessName: form.value.businessName,  
433 - status: "WAITING",  
434 - }); 455 + if (target) {
  456 + target.barcode = form.value.barcode;
  457 + target.deviceTypeName = form.value.deviceTypeName;
  458 + target.deviceTypeId = form.value.deviceTypeId;
  459 + target.quantity = form.value.quantity;
435 localStorage.setItem( 460 localStorage.setItem(
436 "localStoreTableData", 461 "localStoreTableData",
437 JSON.stringify(localStoreTableData) 462 JSON.stringify(localStoreTableData)
@@ -439,7 +464,50 @@ function submitForm() { @@ -439,7 +464,50 @@ function submitForm() {
439 open.value = false; 464 open.value = false;
440 proxy.$modal.msgSuccess("扫码录入成功!"); 465 proxy.$modal.msgSuccess("扫码录入成功!");
441 getList(); 466 getList();
  467 + } else {
  468 + const editTarget = dataList.value.find(
  469 + (item) => item.id === form.value.id
  470 + );
  471 + console.log(1111);
  472 + if (editTarget) {
  473 + editScanSpec({
  474 + id: form.value.id,
  475 + scanTaskId: proxy.$route.query.scanTaskId,
  476 + businessId: form.value.businessId,
  477 + deviceTypeId: form.value.deviceTypeId,
  478 + barcode: form.value.barcode,
  479 + quantity: form.value.quantity,
  480 + }).then((res) => {
  481 + open.value = false;
  482 + proxy.$modal.msgSuccess("编辑成功!");
  483 + getList();
  484 + });
  485 + } else {
  486 + localStoreTableData.push({
  487 + id: new Date().getTime(),
  488 + barcode: form.value.barcode,
  489 + deviceTypeName: deviceTypeList.value.find(
  490 + (item) => item.id === form.value.deviceTypeId
  491 + ).name,
  492 + deviceTypeId: form.value.deviceTypeId,
  493 + quantity: form.value.quantity,
  494 + businessId: form.value.businessId,
  495 + businessName: form.value.businessName,
  496 + status: "WAITING",
  497 + });
  498 + localStorage.setItem(
  499 + "localStoreTableData",
  500 + JSON.stringify(localStoreTableData)
  501 + );
  502 + open.value = false;
  503 + proxy.$modal.msgSuccess("扫码录入成功!");
  504 + getList();
  505 + }
442 } 506 }
  507 + } else {
  508 + proxy.$modal.msgError(
  509 + "营业厅不一致,请检查输入条码,并重新查询对应营业厅!"
  510 + );
443 } 511 }
444 } 512 }
445 }); 513 });
@@ -463,12 +531,15 @@ const timer = ref(null); @@ -463,12 +531,15 @@ const timer = ref(null);
463 531
464 const downloadLoadingInstance = ref(""); 532 const downloadLoadingInstance = ref("");
465 function handleAdd() { 533 function handleAdd() {
466 - downloadLoadingInstance.value = ElLoading.service({  
467 - text: "正在连接设备中...,请稍候",  
468 - background: "rgba(0, 0, 0, 0.7)",  
469 - }); 534 + // downloadLoadingInstance.value = ElLoading.service({
  535 + // text: "正在连接设备中...,请稍候",
  536 + // background: "rgba(0, 0, 0, 0.7)",
  537 + // });
470 538
471 - scanCodeCallback(scanCodeCallback); 539 + // scanCodeCallback(scanCodeCallback);
  540 + reset();
  541 + open.value = true;
  542 + title.value = "扫码录入";
472 } 543 }
473 544
474 // 递归调用接口,直至设备有所返回 545 // 递归调用接口,直至设备有所返回
@@ -489,7 +560,7 @@ const scanCodeCallback = (callback) => { @@ -489,7 +560,7 @@ const scanCodeCallback = (callback) => {
489 reset(); 560 reset();
490 open.value = true; 561 open.value = true;
491 title.value = "扫码录入"; 562 title.value = "扫码录入";
492 - form.value.name = taskName.value; 563 + form.value.name = taskForm.value.taskName;
493 form.value.businessId = data.businessId; 564 form.value.businessId = data.businessId;
494 form.value.businessName = data.businessName; 565 form.value.businessName = data.businessName;
495 form.value.barcode = data.barcode; 566 form.value.barcode = data.barcode;
@@ -523,65 +594,72 @@ const goBack = () => { @@ -523,65 +594,72 @@ const goBack = () => {
523 594
524 const taskLoading = ref(false); 595 const taskLoading = ref(false);
525 const confirmAddTask = () => { 596 const confirmAddTask = () => {
526 - const localStoreTableData = localStorage.getItem("localStoreTableData")  
527 - ? JSON.parse(localStorage.getItem("localStoreTableData"))  
528 - : []; 597 + proxy.$refs["taskFormRef"].validate((valid) => {
  598 + if (valid) {
  599 + const localStoreTableData = localStorage.getItem("localStoreTableData")
  600 + ? JSON.parse(localStorage.getItem("localStoreTableData"))
  601 + : [];
529 602
530 - if (localStoreTableData.length == 0 && dataList.value.length == 0) {  
531 - proxy.$modal.msgError("请先点击扫码!");  
532 - return;  
533 - }  
534 - const data = {  
535 - name: taskName.value,  
536 - businessId: dataList.value[0].businessId,  
537 - specList: localStoreTableData.map((item) => ({  
538 - businessId: item.businessId,  
539 - deviceTypeId: item.deviceTypeId,  
540 - barcode: item.barcode,  
541 - quantity: item.quantity,  
542 - })),  
543 - };  
544 - if (proxy.$route.query.scanTaskId) {  
545 - data.id = detailData.value.id;  
546 - data.name = taskName.value;  
547 - data.businessId = detailData.value.businessId;  
548 - data.specList = data.specList.concat(  
549 - dataList.value  
550 - .filter(  
551 - (filterItem) => localStoreTableData.map(local=>local.id).indexOf(filterItem.id) == -1  
552 - )  
553 - .map((item) => ({  
554 - id:item.id, 603 + if (localStoreTableData.length == 0 && dataList.value.length == 0) {
  604 + proxy.$modal.msgError("请先点击扫码!");
  605 + return;
  606 + }
  607 + const data = {
  608 + name: taskForm.value.taskName,
  609 + businessId: dataList.value[0].businessId,
  610 + specList: localStoreTableData.map((item) => ({
555 businessId: item.businessId, 611 businessId: item.businessId,
556 deviceTypeId: item.deviceTypeId, 612 deviceTypeId: item.deviceTypeId,
557 barcode: item.barcode, 613 barcode: item.barcode,
558 quantity: item.quantity, 614 quantity: item.quantity,
559 - }))  
560 - );  
561 - taskLoading.value = true;  
562 - editScanTask(data)  
563 - .then((response) => {  
564 - proxy.$modal.msgSuccess("编辑任务成功!");  
565 - open.value = false;  
566 - localStorage.removeItem("localStoreTableData");  
567 - goBack();  
568 - })  
569 - .finally(() => {  
570 - taskLoading.value = false;  
571 - });  
572 - } else {  
573 - taskLoading.value = true;  
574 - addScanTask(data)  
575 - .then((response) => {  
576 - proxy.$modal.msgSuccess("新增任务成功!");  
577 - open.value = false;  
578 - localStorage.removeItem("localStoreTableData");  
579 - goBack();  
580 - })  
581 - .finally(() => {  
582 - taskLoading.value = false;  
583 - });  
584 - } 615 + })),
  616 + };
  617 + if (proxy.$route.query.scanTaskId) {
  618 + data.id = detailData.value.id;
  619 + data.name = taskForm.value.taskName;
  620 + data.businessId = detailData.value.businessId;
  621 + data.specList = data.specList.concat(
  622 + dataList.value
  623 + .filter(
  624 + (filterItem) =>
  625 + localStoreTableData
  626 + .map((local) => local.id)
  627 + .indexOf(filterItem.id) == -1
  628 + )
  629 + .map((item) => ({
  630 + id: item.id,
  631 + businessId: item.businessId,
  632 + deviceTypeId: item.deviceTypeId,
  633 + barcode: item.barcode,
  634 + quantity: item.quantity,
  635 + }))
  636 + );
  637 + taskLoading.value = true;
  638 + editScanTask(data)
  639 + .then((response) => {
  640 + proxy.$modal.msgSuccess("编辑任务成功!");
  641 + open.value = false;
  642 + localStorage.removeItem("localStoreTableData");
  643 + goBack();
  644 + })
  645 + .finally(() => {
  646 + taskLoading.value = false;
  647 + });
  648 + } else {
  649 + taskLoading.value = true;
  650 + addScanTask(data)
  651 + .then((response) => {
  652 + proxy.$modal.msgSuccess("新增任务成功!");
  653 + open.value = false;
  654 + localStorage.removeItem("localStoreTableData");
  655 + goBack();
  656 + })
  657 + .finally(() => {
  658 + taskLoading.value = false;
  659 + });
  660 + }
  661 + }
  662 + });
585 }; 663 };
586 664
587 // Query list 665 // Query list
@@ -653,7 +731,7 @@ const detailData = ref({}); @@ -653,7 +731,7 @@ const detailData = ref({});
653 const getDetail = () => { 731 const getDetail = () => {
654 scanTaskdetal(proxy.$route.query.scanTaskId).then((res) => { 732 scanTaskdetal(proxy.$route.query.scanTaskId).then((res) => {
655 detailData.value = res.data; 733 detailData.value = res.data;
656 - taskName.value = detailData.value.name; 734 + taskForm.value.taskName = detailData.value.name;
657 }); 735 });
658 }; 736 };
659 737
Please register or login to post a comment