Showing
3 changed files
with
120 additions
and
44 deletions
| ... | ... | @@ -94,7 +94,8 @@ |
| 94 | 94 | </el-form> |
| 95 | 95 | <el-row :gutter="10" class="mb8"> |
| 96 | 96 | <el-col :span="1.5"> |
| 97 | - <el-button type="primary" :disabled="scanCodeDisabled" plain icon="Plus" @click="handleAdd" | |
| 97 | + <!-- :disabled="scanCodeDisabled" --> | |
| 98 | + <el-button type="primary" plain icon="Plus" @click="handleAdd" | |
| 98 | 99 | >扫码</el-button |
| 99 | 100 | > |
| 100 | 101 | </el-col> |
| ... | ... | @@ -244,6 +245,7 @@ |
| 244 | 245 | <el-select |
| 245 | 246 | v-model="form.deviceTypeId" |
| 246 | 247 | placeholder="请选择类型" |
| 248 | + :disabled="deviceTypeList.length == 1" | |
| 247 | 249 | @change="handleDeviceType" |
| 248 | 250 | > |
| 249 | 251 | <el-option |
| ... | ... | @@ -317,7 +319,7 @@ |
| 317 | 319 | <script setup> |
| 318 | 320 | import { getToken } from "@/utils/auth"; |
| 319 | 321 | import { formatDate } from "@/utils/index"; |
| 320 | -import { nextTick, onMounted, onUnmounted, ref,computed } from "vue"; | |
| 322 | +import { nextTick, onMounted, onUnmounted, ref, computed } from "vue"; | |
| 321 | 323 | import { |
| 322 | 324 | scanSpecQueryList, |
| 323 | 325 | deviceTypeQueryList, |
| ... | ... | @@ -409,7 +411,7 @@ const deviceTypeList = ref([]); |
| 409 | 411 | |
| 410 | 412 | const searchBusinessLoading = ref(false); |
| 411 | 413 | |
| 412 | -const scanCodeDisabled = computed(() => dataList.value.length >= 1) | |
| 414 | +const scanCodeDisabled = computed(() => dataList.value.length >= 1); | |
| 413 | 415 | |
| 414 | 416 | const getDeviceTypeList = () => { |
| 415 | 417 | deviceTypeQueryList( |
| ... | ... | @@ -417,6 +419,12 @@ const getDeviceTypeList = () => { |
| 417 | 419 | ).then((res) => { |
| 418 | 420 | console.log(res, 111); |
| 419 | 421 | deviceTypeList.value = res.data; |
| 422 | + // 编辑的时候 只允许一个类型 | |
| 423 | + if (proxy.$route.query.scanTaskId && dataList.value.length > 0) { | |
| 424 | + deviceTypeList.value = deviceTypeList.value.filter( | |
| 425 | + (item) => dataList.value[0].deviceTypeId === item.id | |
| 426 | + ); | |
| 427 | + } | |
| 420 | 428 | }); |
| 421 | 429 | }; |
| 422 | 430 | |
| ... | ... | @@ -471,10 +479,30 @@ function submitForm() { |
| 471 | 479 | // open.value = false; |
| 472 | 480 | // getList(); |
| 473 | 481 | // }); |
| 482 | + // 判断是否是第一个 | |
| 483 | + const isFirstOne = | |
| 484 | + dataList.value.length > 0 | |
| 485 | + ? form.value.id === dataList.value[0].id | |
| 486 | + : false; | |
| 487 | + | |
| 488 | + // 安全地获取要比较的businessId | |
| 489 | + let compareBusinessId = null; | |
| 490 | + if (dataList.value.length === 0) { | |
| 491 | + // 数组为空,无法比较 | |
| 492 | + compareBusinessId = null; | |
| 493 | + } else if (isFirstOne && dataList.value.length > 1) { | |
| 494 | + // 如果是第一个元素且数组有第二个元素,比较第二个元素的businessId | |
| 495 | + compareBusinessId = dataList.value[1]?.businessId; | |
| 496 | + } else { | |
| 497 | + // 其他情况比较第一个元素的businessId | |
| 498 | + compareBusinessId = dataList.value[0]?.businessId; | |
| 499 | + } | |
| 474 | 500 | |
| 475 | 501 | if ( |
| 476 | - dataList.value.length <= 1 || | |
| 477 | - form.value.businessId === dataList.value[0].businessId | |
| 502 | + dataList.value.length == 0 || | |
| 503 | + isFirstOne || | |
| 504 | + (compareBusinessId !== null && | |
| 505 | + form.value.businessId === compareBusinessId) | |
| 478 | 506 | ) { |
| 479 | 507 | const localStoreTableData = localStorage.getItem("localStoreTableData") |
| 480 | 508 | ? JSON.parse(localStorage.getItem("localStoreTableData")) |
| ... | ... | @@ -488,6 +516,7 @@ function submitForm() { |
| 488 | 516 | target.deviceTypeName = form.value.deviceTypeName; |
| 489 | 517 | target.deviceTypeId = form.value.deviceTypeId; |
| 490 | 518 | target.quantity = form.value.quantity; |
| 519 | + target.businessId = form.value.businessId; | |
| 491 | 520 | localStorage.setItem( |
| 492 | 521 | "localStoreTableData", |
| 493 | 522 | JSON.stringify(localStoreTableData) |
| ... | ... | @@ -571,6 +600,10 @@ function handleAdd() { |
| 571 | 600 | reset(); |
| 572 | 601 | open.value = true; |
| 573 | 602 | title.value = "扫码录入"; |
| 603 | + if (deviceTypeList.value.length == 1) { | |
| 604 | + form.value.deviceTypeId = deviceTypeList.value[0].id; | |
| 605 | + form.value.deviceTypeName = deviceTypeList.value[0].name; | |
| 606 | + } | |
| 574 | 607 | nextTick(() => { |
| 575 | 608 | setTimeout(() => { |
| 576 | 609 | barcodeRef.value.focus(); |
| ... | ... | @@ -619,8 +652,14 @@ const handleEdit = (row) => { |
| 619 | 652 | ...row, |
| 620 | 653 | }; |
| 621 | 654 | if (proxy.$route.query.scanTaskId) { |
| 622 | - form.value.businessName = detailData.value.businessName; | |
| 623 | - form.value.businessId = detailData.value.businessId; | |
| 655 | + // form.value.businessName = detailData.value.businessName; | |
| 656 | + // form.value.businessId = detailData.value.businessId; | |
| 657 | + form.value.businessName = row.businessName; | |
| 658 | + form.value.businessId = row.businessId; | |
| 659 | + } | |
| 660 | + if (deviceTypeList.value.length == 1) { | |
| 661 | + form.value.deviceTypeId = deviceTypeList.value[0].id; | |
| 662 | + form.value.deviceTypeName = deviceTypeList.value[0].name; | |
| 624 | 663 | } |
| 625 | 664 | nextTick(() => { |
| 626 | 665 | setTimeout(() => { |
| ... | ... | @@ -655,6 +694,7 @@ const confirmAddTask = () => { |
| 655 | 694 | quantity: item.quantity, |
| 656 | 695 | })), |
| 657 | 696 | }; |
| 697 | + // 新增的时候 类型需保持一致 | |
| 658 | 698 | if (proxy.$route.query.scanTaskId) { |
| 659 | 699 | data.id = detailData.value.id; |
| 660 | 700 | data.name = taskForm.value.taskName; |
| ... | ... | @@ -675,36 +715,70 @@ const confirmAddTask = () => { |
| 675 | 715 | quantity: item.quantity, |
| 676 | 716 | })) |
| 677 | 717 | ); |
| 678 | - taskLoading.value = true; | |
| 679 | - editScanTask(data) | |
| 680 | - .then((response) => { | |
| 681 | - proxy.$modal.msgSuccess("编辑任务成功!"); | |
| 682 | - open.value = false; | |
| 683 | - localStorage.removeItem("localStoreTableData"); | |
| 684 | - goBack(); | |
| 685 | - }) | |
| 686 | - .finally(() => { | |
| 687 | - taskLoading.value = false; | |
| 688 | - }); | |
| 718 | + const businessIdList = data.specList.map((item) => item.businessId); | |
| 719 | + console.log(businessIdList, "businessIdList"); | |
| 720 | + const businessIdFlag = businessIdList.every( | |
| 721 | + (element) => element === businessIdList[0] | |
| 722 | + ); | |
| 723 | + if (businessIdFlag) { | |
| 724 | + taskLoading.value = true; | |
| 725 | + editScanTask(data) | |
| 726 | + .then((response) => { | |
| 727 | + proxy.$modal.msgSuccess("编辑任务成功!"); | |
| 728 | + open.value = false; | |
| 729 | + localStorage.removeItem("localStoreTableData"); | |
| 730 | + goBack(); | |
| 731 | + }) | |
| 732 | + .finally(() => { | |
| 733 | + taskLoading.value = false; | |
| 734 | + }); | |
| 735 | + } else { | |
| 736 | + proxy.$modal.msgError( | |
| 737 | + "营业厅需保持一致,请检查输入条码修改后重新提交!" | |
| 738 | + ); | |
| 739 | + } | |
| 689 | 740 | } else { |
| 690 | - taskLoading.value = true; | |
| 691 | - addScanTask(data) | |
| 692 | - .then((response) => { | |
| 693 | - proxy.$modal.msgSuccess("新增任务成功!"); | |
| 694 | - open.value = false; | |
| 695 | - localStorage.removeItem("localStoreTableData"); | |
| 696 | - goBack(); | |
| 697 | - }) | |
| 698 | - .finally(() => { | |
| 699 | - taskLoading.value = false; | |
| 700 | - }); | |
| 741 | + // 新增的时候 类型需保持一致 | |
| 742 | + const specList = data.specList.map((item) => item.deviceTypeId); | |
| 743 | + const specListFlag = specList.every( | |
| 744 | + (element) => element === specList[0] | |
| 745 | + ); | |
| 746 | + console.log(data); | |
| 747 | + console.log(specListFlag); | |
| 748 | + console.log(specList); | |
| 749 | + const businessIdList = data.specList.map((item) => item.businessId); | |
| 750 | + console.log(businessIdList, "businessIdList"); | |
| 751 | + const businessIdFlag = businessIdList.every( | |
| 752 | + (element) => element === businessIdList[0] | |
| 753 | + ); | |
| 754 | + if (businessIdFlag) { | |
| 755 | + if (specListFlag) { | |
| 756 | + taskLoading.value = true; | |
| 757 | + addScanTask(data) | |
| 758 | + .then((response) => { | |
| 759 | + proxy.$modal.msgSuccess("新增任务成功!"); | |
| 760 | + open.value = false; | |
| 761 | + localStorage.removeItem("localStoreTableData"); | |
| 762 | + goBack(); | |
| 763 | + }) | |
| 764 | + .finally(() => { | |
| 765 | + taskLoading.value = false; | |
| 766 | + }); | |
| 767 | + } else { | |
| 768 | + proxy.$modal.msgError("类型需保持一致,请检查修改后重新提交!"); | |
| 769 | + } | |
| 770 | + } else { | |
| 771 | + proxy.$modal.msgError( | |
| 772 | + "营业厅需保持一致,请检查输入条码修改后重新提交!" | |
| 773 | + ); | |
| 774 | + } | |
| 701 | 775 | } |
| 702 | 776 | } |
| 703 | 777 | }); |
| 704 | 778 | }; |
| 705 | 779 | |
| 706 | 780 | // Query list |
| 707 | -const getList = () => { | |
| 781 | +const getList = (isTrigged) => { | |
| 708 | 782 | let localStoreTableData = localStorage.getItem("localStoreTableData") |
| 709 | 783 | ? JSON.parse(localStorage.getItem("localStoreTableData")) |
| 710 | 784 | : []; |
| ... | ... | @@ -714,16 +788,20 @@ const getList = () => { |
| 714 | 788 | })); |
| 715 | 789 | if (!proxy.$route.query.scanTaskId) { |
| 716 | 790 | loading.value = false; |
| 717 | - | |
| 718 | 791 | dataList.value = localStoreTableData; |
| 792 | + getDeviceTypeList(); | |
| 719 | 793 | } else { |
| 720 | 794 | loading.value = true; |
| 721 | - scanSpecQueryList( | |
| 722 | - proxy.addDateRange(queryParams.value, dateRange.value) | |
| 723 | - ).then((res) => { | |
| 724 | - loading.value = false; | |
| 725 | - dataList.value = res.data.concat(localStoreTableData); | |
| 726 | - }); | |
| 795 | + scanSpecQueryList(proxy.addDateRange(queryParams.value, dateRange.value)) | |
| 796 | + .then((res) => { | |
| 797 | + loading.value = false; | |
| 798 | + dataList.value = res.data.concat(localStoreTableData); | |
| 799 | + }) | |
| 800 | + .finally(() => { | |
| 801 | + if (isTrigged) { | |
| 802 | + getDeviceTypeList(); | |
| 803 | + } | |
| 804 | + }); | |
| 727 | 805 | } |
| 728 | 806 | }; |
| 729 | 807 | |
| ... | ... | @@ -840,8 +918,7 @@ const handleKeydown = (e) => { |
| 840 | 918 | }; |
| 841 | 919 | |
| 842 | 920 | onMounted(() => { |
| 843 | - getList(); | |
| 844 | - getDeviceTypeList(); | |
| 921 | + getList(true); | |
| 845 | 922 | |
| 846 | 923 | if (proxy.$route.query.scanTaskId) { |
| 847 | 924 | getDetail(); | ... | ... |
| ... | ... | @@ -315,17 +315,16 @@ const columnList = ref([ |
| 315 | 315 | { |
| 316 | 316 | label: "分拣时间", |
| 317 | 317 | prop: "scanTime", |
| 318 | - width: 150, | |
| 318 | + width: 200, | |
| 319 | 319 | }, |
| 320 | 320 | { |
| 321 | 321 | label: "分拣结果", |
| 322 | - prop: "scanResult", | |
| 323 | - width: 150 | |
| 322 | + prop: "scanResult" | |
| 324 | 323 | }, |
| 325 | 324 | { |
| 326 | 325 | label: "备注", |
| 327 | 326 | prop: "remark", |
| 328 | - width: 150 | |
| 327 | + width: 200 | |
| 329 | 328 | }, |
| 330 | 329 | { |
| 331 | 330 | label: "分拣人", | ... | ... |
Please
register
or
login
to post a comment