Kaynağa Gözat

零星物料出库修改

hh 2 hafta önce
ebeveyn
işleme
b68037fdc6

+ 7 - 6
entry/src/main/ets/common/util/mqtt.ets

@@ -1,4 +1,3 @@
-// src/main/ets/utils/MqttManager.ts
 import { MqttAsync, MqttClient, MqttClientOptions, MqttConnectOptions,MqttQos, MqttMessage, MqttPublishOptions } from '@ohos/mqtt';
 
 
@@ -77,14 +76,15 @@ class MqttManager {
       );
       //抽屉外的RFID
       const rfidStringOut = decodeRfidString(
-        valueJson?.d?.find(item => item.tag === 'RFID2Data1')?.value as number,
-        valueJson?.d?.find(item => item.tag === 'RFID2Data2')?.value as number,
-        valueJson?.d?.find(item => item.tag === 'RFID2Data3')?.value as number,
-        valueJson?.d?.find(item => item.tag === 'RFID2Data4')?.value as number
+        valueJson?.d?.find(item => item.tag === 'RFID3Data1')?.value as number,
+        valueJson?.d?.find(item => item.tag === 'RFID3Data2')?.value as number,
+        valueJson?.d?.find(item => item.tag === 'RFID3Data3')?.value as number,
+        valueJson?.d?.find(item => item.tag === 'RFID3Data4')?.value as number
       );
       AppStorage.SetOrCreate<number>('drawerPositionStatus', station2Set);
       AppStorage.SetOrCreate<number>('materialBoxWeight', station2Weight);
       AppStorage.SetOrCreate<string>('materialBoxID', rfidStringIn);
+      AppStorage.SetOrCreate<string>('materialBoxRfid', rfidStringOut);
 
     } catch (e) {
       console.error("MQTT消息处理异常:", e);
@@ -197,7 +197,8 @@ export interface MQTTReceiveData {
 
 
 function decodeRegister(regValue: number | undefined): string {
-  if (regValue === undefined) return ''; // 处理undefined
+  if (regValue === undefined || regValue === 0) return '';
+  //if (regValue === undefined) return ''; // 处理undefined
 
   // 确保是16位无符号整数
   const value = regValue & 0xFFFF;

+ 240 - 90
entry/src/main/ets/pages/EmptyBoxStorage.ets

@@ -5,21 +5,161 @@ import {NavigationBar} from '../component/NavigationBar'
 import {TimeAndTitle} from "../component/TimeAndTitle"
 import {InBoundView} from '../component/InBoundView'
 import router from '@ohos.router';
-import WorkOrderInfo from '../viewmodel/wms/WorkOrderInfo'
 import MaterialInfo from '../viewmodel/wms/MaterialInfo';
+import WmsRequest from '../common/util/request/WmsRequest'
+import MaterialBoxInfo from '../viewmodel/wms/MaterialBoxInfo';
+import RequestParamModel from '../viewmodel/wms/RequestParamModel';
+import {CommonConfirmDialog}from "../component/OrderMaterialsStorageView"
+import {ConfirmDialogParams} from "../viewmodel/wms/ConfirmDialogParam"
 
 @Entry
 @Component
 struct emptyBoxStorage {
-  @State materialBoxID: string = 'LX-00010';
-  @State isMaterialBoxExist: Boolean = true;
-  @State isPrinterOnline: Boolean = true;
-  @State isRfidOnline: Boolean = true;
+  private scrollerForList: Scroller = new Scroller()
   @State generateButtonClick :number = 1
-  @State printButtonClick :number = 1
   @State writeButtonClick :number = 1
   @State materialNum: number=0
   @State scanMaterialList: MaterialInfo[] = []
+  @State existMaterialBoxesID:string[] = []
+  @State queryMaterialBoxID:string = ''
+  @State filteredMaterialBoxes: string[] = []; // 过滤后的料箱
+  @State remindText :string =''
+  //是否允许确认添加
+  @State isAllowedAdd : boolean = false
+  //手动生成的料箱rfid
+  @State manualGeneratedId: string = '';
+  //是否手动生成的
+  @State isManualGenerating:boolean = false;
+  //表示对当前读取rfid状态
+  //no_box:没有rfid new_manual_box:手动新生成rfid existing_box:已经存在的rfid new_rfid_box:读取的新rfid
+  @State currentStatus: 'no_box' | 'new_manual_box' | 'existing_box' |'new_rfid_box'= 'no_box';
+  @StorageLink('materialBoxRfid') @Watch('onMaterialBoxRfidChange') materialBoxRfid: string = '';
+
+  commonDialogController: CustomDialogController | null = null;
+  private showConfirmDialog(params: ConfirmDialogParams) {
+    if (this.commonDialogController) {
+      this.commonDialogController.close()
+    }
+
+    this.commonDialogController = new CustomDialogController({
+      builder: CommonConfirmDialog({
+        title: params.title || '提示',
+        message: params.message,
+        confirmText: params.confirmText || '确定',
+        cancelText: params.cancelText || '取消',
+        onConfirm: params.onConfirm
+      }),
+      cancel: () => console.log('用户取消操作'),
+      customStyle: true,
+      autoCancel:false,
+      maskColor: 'rgba(0,0,0,0.6)'
+    });
+
+    this.commonDialogController.open();
+  }
+
+  //加载所有料箱载具
+  loadMaterialBoxes = async () => {
+    try {
+      let res: MaterialBoxInfo[] = await WmsRequest.post("/api/v1/wms/vehicle/list", {} as RequestParamModel);
+
+      this.existMaterialBoxesID = [
+        ...res.map(item => item.code).filter(Boolean) as string[]
+      ];
+      console.log('Loaded material boxes:', this.existMaterialBoxesID);
+    } catch (error) {
+      console.error('Failed to load material boxes:', error);
+    }
+  }
+
+  //copy一份载具列表用于筛选过滤
+  filterMaterialBoxes = () => {
+    if (!this.queryMaterialBoxID?.trim()) {
+      this.filteredMaterialBoxes = [...this.existMaterialBoxesID];
+    } else {
+      const searchTerm = this.queryMaterialBoxID.toLowerCase();
+      this.filteredMaterialBoxes = this.existMaterialBoxesID.filter(id =>
+      id.toLowerCase().includes(searchTerm)
+      );
+    }
+  }
+  //确认添加
+  onConfirmAdd=async()=>{
+    const getBoxNumber = (boxId: string) => {
+      if (!boxId || !boxId.includes('-')) return '';
+      const numPart = boxId.split('-')[1];
+      return parseInt(numPart).toString(); // 关键修改:parseInt会自动去除前导零
+    };
+    let res: MaterialBoxInfo[] = await WmsRequest.post("/api/v1/wms/vehicle/add", {
+      capacity:100,
+      category:'0',
+      code:this.isManualGenerating?this.manualGeneratedId:this.materialBoxRfid,
+      name: `料箱${getBoxNumber(
+        this.isManualGenerating ? this.manualGeneratedId : this.materialBoxRfid
+      )}`,
+      propertyCode:'',
+      universal:0
+    } as RequestParamModel);
+    this.isManualGenerating=false;
+    //添加后加载新列表
+    await this.loadMaterialBoxes().then(() => {
+      this.filterMaterialBoxes();
+    });
+    //添加后更新料箱rfid显示
+    await this.checkRfidStatus(this.materialBoxRfid ?? '');
+  }
+
+  onMaterialBoxRfidChange() {
+    //如果是手动生成rfid直接返回
+    if(this.isManualGenerating) return
+    this.checkRfidStatus(this.materialBoxRfid ?? '');
+  }
+
+  //检查从读卡器传来的rfid值
+  private checkRfidStatus(rfidValue: string) {
+    if (!rfidValue || rfidValue.trim() === '') {
+      this.currentStatus = 'no_box';
+      this.remindText = "";
+      this.isAllowedAdd = false;
+    } else if (this.existMaterialBoxesID.includes(rfidValue)) {
+      this.currentStatus = 'existing_box';
+      this.remindText = "当前为已有料箱";
+      this.isAllowedAdd = false;
+    } else {
+      this.currentStatus = 'new_rfid_box';
+      this.remindText = "新料箱编号请添加";
+      this.isAllowedAdd = true;
+    }
+  }
+
+
+  aboutToAppear(): void {
+    this.loadMaterialBoxes().then(() => {
+      this.filterMaterialBoxes();
+    });
+    setTimeout(() => {
+      this.checkRfidStatus(this.materialBoxRfid);
+    }, 500);
+  }
+
+  createMaterialBoxesID = () => {
+    if (!this.existMaterialBoxesID || this.existMaterialBoxesID.length === 0) {
+      this.manualGeneratedId = "LX-00001";
+    } else {
+      const maxNumber = Math.max(...this.existMaterialBoxesID.map(code => {
+        const numPart = code.split('-')[1];
+        return parseInt(numPart) || 0;
+      }), 0);
+      this.manualGeneratedId = `LX-${(maxNumber + 1).toString().padStart(5, '0')}`;
+    }
+
+    this.isManualGenerating = true;
+    this.currentStatus = 'new_manual_box';
+    this.remindText = "已生成新料箱编号请添加";
+    this.isAllowedAdd = true;
+  }
+
+
   build() {
     Row() {
       Column() {
@@ -62,30 +202,28 @@ struct emptyBoxStorage {
                 .margin({top:'3%'})
               Row(){
                 Stack() {
-                  Image(this.isMaterialBoxExist? $r('app.media.identified_material_box'):$r('app.media.not_identified_material_box'))
+                  Image(this.materialBoxRfid != ''? $r('app.media.identified_material_box'):$r('app.media.not_identified_material_box'))
                     .width('100%')
                     .height('100%')
                     .borderRadius($r('app.float.virtualSize_16'))
                     .objectFit(ImageFit.Contain)
-                  Text("LX-00010")
-                    .fontSize($r('app.float.fontSize_48'))
-                    .fontColor($r('app.color.FFFFFF'))
-                    .position({
-                      x: '38%',
-                      y: '80%',
-                    })
-                  Text("已生成新编号")
-                    .fontSize($r('app.float.fontSize_12'))
-                    .fontColor($r('app.color.60FFFFFF'))
-                    .position({
-                      x: '45%',
-                      y: '87%',
-                    })
+                  Column(){
+                    Text(this.isManualGenerating ? this.manualGeneratedId : this.materialBoxRfid)
+                      .fontSize($r('app.float.fontSize_48'))
+                      .fontColor($r('app.color.FFFFFF'))
+                    Text(this.remindText)
+                      .fontSize($r('app.float.fontSize_12'))
+                      .fontColor($r('app.color.60FFFFFF'))
+                  }.alignItems(HorizontalAlign.Center)
+                  .height('20%')
+                  .margin({top:'77%'})
+                  .justifyContent(FlexAlign.Center)
                 }
               }
               .margin({top:'3%'})
               .height('75%')
               .width('100%')
+              .justifyContent(FlexAlign.Start)
               Button({type:ButtonType.Normal}) {
                 Row() {
                   Image($r('app.media.material_qr_code'))
@@ -100,9 +238,14 @@ struct emptyBoxStorage {
                 .justifyContent(FlexAlign.Center)
               }
               .margin({top:'10%'})
-              .width('35%')
+              .width('40%')
               .height('6%')
-              .backgroundColor($r('app.color.20FFFFFF'))
+              .enabled(this.currentStatus === 'no_box')
+              .backgroundColor(
+                this.currentStatus === 'no_box'
+                  ? $r('app.color.20FFFFFF')
+                  : $r('app.color.10FFFFFF')
+              )
               .borderRadius($r('app.float.virtualSize_16'))
               .scale({ x: this.generateButtonClick, y: this.generateButtonClick })
               .animation({
@@ -113,6 +256,13 @@ struct emptyBoxStorage {
                 this.generateButtonClick = 0.9;
                 setTimeout(() => {
                   this.generateButtonClick = 1;
+                  this.showConfirmDialog({
+                    title: '生成料箱编码',
+                    message: `确定要生成新料箱编码吗?`,
+                    onConfirm: ()=> {
+                      this.createMaterialBoxesID();
+                    }
+                  });
                 }, 200);
               })
             }
@@ -124,93 +274,86 @@ struct emptyBoxStorage {
               .height($r('app.float.virtualSize_48'))
               .fillColor($r('app.color.FFFFFF'))
             Column(){
-              Text("打印条码")
+              Text("料箱编码列表")
                 .fontColor($r('app.color.FFFFFF'))
                 .fontSize($r('app.float.fontSize_38'))
                 .margin({top:'3%'})
-              Column(){
-                Image(this.isPrinterOnline? $r('app.media.printer_online'):$r('app.media.printer_offline'))
-                  .width('100%')
-                  .height('40%')
-                  .borderRadius($r('app.float.virtualSize_16'))
-                  .objectFit(ImageFit.Contain)
-                Button({type:ButtonType.Normal}) {
-                  Row() {
-                    Image($r('app.media.material_qr_code'))
-                      .width('15%')
-                      .height('50%')
-                      .margin({ right: 8 })
-                      .fillColor($r('app.color.0A84FF'))
-                    Text("打印编号")
-                      .fontSize($r('app.float.fontSize_30'))
-                      .fontColor($r('app.color.0A84FF'))
-                  }
-                  .justifyContent(FlexAlign.Center)
+              Row() {
+                TextInput({ text:this.queryMaterialBoxID,placeholder: '输入料箱编码' })
+                  .type(InputType.Normal)
+                  .placeholderFont({ size: $r('app.float.fontSize_30') })
+                  .placeholderColor($r('app.color.30FFFFFF'))
+                  .fontSize($r('app.float.fontSize_30'))
+                  .fontColor($r('app.color.FFFFFF'))
+                  .enableKeyboardOnFocus(false)
+                  .width('84%')
+                  .onChange((value: string) => {
+                    this.queryMaterialBoxID = value;
+                    this.filterMaterialBoxes(); // 实时触发过滤
+                  })
+                Row() {
+                  Image($r('app.media.wms_search'))
+                    .width($r('app.float.virtualSize_48'))
+                    .height($r('app.float.virtualSize_48'))
+                    .fillColor($r('app.color.0A84FF'))
                 }
-                .margin({top:'6%'})
-                .width('35%')
-                .height('8%')
-                .backgroundColor($r('app.color.20FFFFFF'))
+                .width('16%')
+                .height('100%')
+                .justifyContent(FlexAlign.Center)
                 .borderRadius($r('app.float.virtualSize_16'))
-                .scale({ x: this.printButtonClick, y: this.printButtonClick })
-                .animation({
-                  duration: 200,
-                  curve: Curve.Linear
-                })
-                .onClick(() => {
-                  this.printButtonClick = 0.9;
-                  setTimeout(() => {
-                    this.printButtonClick = 1;
-                  }, 200);
+                .backgroundColor($r('app.color.20FFFFFF'))
+              }
+              .height('6%')
+              .width('75%')
+              .borderRadius($r('app.float.virtualSize_16'))
+              .backgroundColor($r('app.color.000000'))
+              .margin({top:'5%'})
+
+              List({scroller:this.scrollerForList}) {
+                ForEach(this.filteredMaterialBoxes, (item:string) => {
+                  ListItem() {
+                    Column() {
+                      Text(item)
+                        .fontSize($r('app.float.fontSize_30'))
+                        .fontColor($r('app.color.FFFFFF'))
+                        .width('90%')
+                        .textAlign(TextAlign.Start)
+                    }.width('100%')
+                    .alignItems(HorizontalAlign.Start)
+                    .justifyContent(FlexAlign.SpaceEvenly)
+                    .height('10%')
+                  }
                 })
-                Divider()
-                  .margin({top:'3%'})
-                  .vertical(false)
-                  .strokeWidth(1)
-                  .color($r('app.color.15FFFFFF'))
-                  .width('100%')
-                Text("写入磁卡")
-                  .fontColor($r('app.color.FFFFFF'))
-                  .fontSize($r('app.float.fontSize_38'))
-                  .margin({top:'3%'})
-                Image(this.isRfidOnline? $r('app.media.rfid_online'):$r('app.media.rfid_offline'))
-                  .width('100%')
-                  .height('40%')
-                  .margin({top:'1%'})
-                  .borderRadius($r('app.float.virtualSize_16'))
-                  .objectFit(ImageFit.Contain)
               }
-              .height('75%')
-              .width('100%')
-              .justifyContent(FlexAlign.Start)
-              Row(){
-                Text("当前编号:")
-                  .fontColor($r('app.color.FFFFFF'))
-                  .fontSize($r('app.float.fontSize_24'))
-                  .margin({top:'3%'})
-                Text("LX-00010")
-                  .fontColor($r('app.color.0A84FF'))
-                  .fontSize($r('app.float.fontSize_24'))
-                  .margin({top:'3%'})
-              }.height('5%')
-              .margin({top:'2%'})
+              .width('80%')
+              .height('70%')
+              .divider({
+                strokeWidth: 1,
+                color: $r('app.color.20FFFFFF')
+              })
+
               Button({type:ButtonType.Normal}) {
                 Row() {
-                  Image($r('app.media.material_qr_code'))
+                  Image($r('app.media.wms_confirm_add'))
                     .width('15%')
                     .height('45%')
                     .margin({ right: 8 })
                     .fillColor($r('app.color.0A84FF'))
-                  Text("写入磁卡")
+                  Text("确认添加")
                     .fontSize($r('app.float.fontSize_30'))
                     .fontColor($r('app.color.0A84FF'))
                 }
                 .justifyContent(FlexAlign.Center)
               }
-              .margin({top:'3%'})
+              .margin({top:'7%'})
               .width('35%')
               .height('6%')
-              .backgroundColor($r('app.color.20FFFFFF'))
+              .enabled(this.isAllowedAdd)
+              .backgroundColor(
+                this.isAllowedAdd
+                  ? $r('app.color.20FFFFFF')
+                  : $r('app.color.10FFFFFF')
+              )
               .borderRadius($r('app.float.virtualSize_16'))
               .scale({ x: this.writeButtonClick, y: this.writeButtonClick })
               .animation({
@@ -221,6 +364,13 @@ struct emptyBoxStorage {
                 this.writeButtonClick = 0.9;
                 setTimeout(() => {
                   this.writeButtonClick = 1;
+                  this.showConfirmDialog({
+                    title: '确认添加',
+                    message: `确定要添加新料箱${this.materialBoxRfid}吗?`,
+                    onConfirm: ()=> {
+                      this.onConfirmAdd()
+                    }
+                  });
                 }, 200);
               })
             }