Parcourir la source

物料采集代码实现

hh il y a 5 jours
Parent
commit
2b8655b7d1

+ 15 - 0
entry/src/main/ets/pages/ProcessIndex.ets

@@ -198,6 +198,21 @@ struct ProcessIndex {
   }
 
   async aboutToAppear() {
+    // todo 删除
+    let token:string = await ProcessRequest.post('api/auth/aioLogin', {
+      password: '123456',
+      userName: 'admin',
+    } as RequestParamModel) ;
+    if (token && token.length > 0) {
+      CommonConstants.AUTH_TOKEN = token
+      this.currentUserName = 'admin'
+    }
+    this.currentProductLine = '配件产线01'
+    this.currentPLCode = 'PL000018'
+    this.currentStationId = '71'
+    this.currentStation = '包装工位1'
+    // ---------------删除以上内容------------------
+
     if (!this.selectWorkOder || !this.selectWorkOder.workOrderCode) {
       this.selectOrderController.open()
     }

+ 4 - 5
entry/src/main/ets/view/LittleMaterialRequestDialog.ets

@@ -1,7 +1,6 @@
 import ProcessRequest from '../common/util/request/ProcessRequest'
-import DictInfo from '../viewmodel/DictInfo'
-import DictValue from '../viewmodel/DictValue'
-import MaterialInfo, { MaterialPage} from '../viewmodel/MaterialInfo'
+import MaterialInfo from '../viewmodel/MaterialInfo'
+import PageInfo from '../viewmodel/PageInfo'
 import RequestParamModel from '../viewmodel/RequestParamModel'
 
 @CustomDialog
@@ -30,7 +29,7 @@ export struct LittleMaterialRequestDialog {
     let res = await ProcessRequest.post('/api/v1/base/material/page',
       {
         materialName: this.queryMaterialName
-      }  as RequestParamModel) as MaterialPage;
+      }  as RequestParamModel) as PageInfo;
     this.materialTypesList = res.records??[]
     //初始所有物料数量为0
     this.materialTypesList.forEach(item => {
@@ -70,7 +69,7 @@ export struct LittleMaterialRequestDialog {
     let res = await ProcessRequest.post('/api/v1/process/vehicleOperation/sporadicCallItem',
       {
         // materialName: this.queryMaterialName
-      }  as RequestParamModel) as MaterialPage;
+      }  as RequestParamModel) as PageInfo;
   }
 
   build() {

+ 63 - 52
entry/src/main/ets/view/ModifyMaterialNumDialog.ets

@@ -15,49 +15,20 @@ export struct ModifyMaterialNumDialog {
   workOrderCode :string = ''
   operationId :string = ''
   processId :string = ''
+  seqNo :string = ''
   // 新增时扫码搜索到的物料
   scanMaterial: ProcessMaterial = {}
   // 新增或者修改采集物料(1:新增 2:修改)
   addOrModifyCollect: number = 1
-  @State collectMaterials: ProcessMaterial[] = [
-    {
-      batchNo:'dsfs',
-      materialCode:'Y11P1210ZJ10',
-      spec:'Y11P1210ZJ10',
-      materialName:'控制连接器插座',
-      needNum:6.0,
-      operationId:'679',
-      processId:'',
-      num:1.0,
-      unitDictValue: "只",
-      workOrderCode:'10.25.0022'
-    },{
-    batchNo:'32r4regrfd',
-    materialCode:'Y11P0804ZJ102',
-    spec:'Y11P0804ZJ102',
-    materialName:'电源连接器插座',
-    needNum:5.0,
-    operationId:'679',
-    processId:'',
-    num:0,
-    workOrderCode:'10.25.0022'
-  },
-    {
-      batchNo:'sdg',
-      materialCode:'Y11P1210ZJ10',
-      spec:'Y11P1210ZJ10',
-      materialName:'控制连接器插座',
-      needNum:6.0,
-      operationId:'679',
-      processId:'',
-      num:1.0,
-      workOrderCode:'10.25.0022'
-    }
-  ]
+  @State collectMaterials: ProcessMaterial[] = []
   @State collectNumArray: number[] = []
+  // 当前工位ID
+  @Consume('currentStationId') currentStationId: string
+  // 批次高度
+  batchHeight: number = 93.6
 
   controller: CustomDialogController
-  onConfirm: () => void = () => {}
+  confirm: () => void = () => {}
 
   async aboutToAppear() {
     if (!this.scanMaterial) {
@@ -70,7 +41,7 @@ export struct ModifyMaterialNumDialog {
     this.needNum = this.scanMaterial.totalNum!
     // 修改物料采集,则先查询采集历史
     if (this.addOrModifyCollect === 2) {
-      let result: OperationItem[] = await ProcessRequest.post('/v1/process/itemRecord/itemInfo/list',{
+      let result: OperationItem[] = await ProcessRequest.post('/api/v1/process/itemRecord/itemInfo/list',{
         itemCode: this.scanMaterial.materialCode!,
         opId: this.operationId,
         processId: this.processId
@@ -103,18 +74,17 @@ export struct ModifyMaterialNumDialog {
     // for (const element of this.collectMaterials) {
     //   this.collectNumArray.push(element.num ? element.num : 0)
     // }
-    console.log('hhtest', JSON.stringify(this.collectNumArray))
   }
 
   build() {
     Column() {
       // 标题
       Column(){
-        Text("数量")
+        Text('数量')
           .fontColor($r('app.color.FFFFFF'))
           .fontSize($r('app.float.fontSize_30'))
       }
-      .height($r('app.float.virtualSize_112'))
+      .height($r('app.float.virtualSize_100'))
       .justifyContent(FlexAlign.Center)
       Column(){
         Text(`物料名称:${this.materialName}`)
@@ -125,8 +95,12 @@ export struct ModifyMaterialNumDialog {
           .fontColor($r('app.color.FFFFFF'))
           .fontSize($r('app.float.fontSize_16'))
           .fontWeight(FontWeight.Lighter)
+        Text(`需求数量::${this.scanMaterial?.totalNum!}`)
+          .fontColor($r('app.color.FFFFFF'))
+          .fontSize($r('app.float.fontSize_16'))
+          .fontWeight(FontWeight.Lighter)
       }
-      .height($r('app.float.virtualSize_62'))
+      .height($r('app.float.virtualSize_56'))
       .width('70.4%')
       .justifyContent(FlexAlign.Start)
       .alignItems(HorizontalAlign.Start)
@@ -155,8 +129,8 @@ export struct ModifyMaterialNumDialog {
                   Text('还需采集:')
                     .fontColor($r('app.color.FFFFFF'))
                     .fontSize($r('app.float.fontSize_16'))
-                    .fontWeight(FontWeight.Regular)
-                  Text(`还需采集:${this.scanMaterial?.needNum!}`)
+                    .fontWeight(FontWeight.Lighter)
+                  Text(`${this.scanMaterial?.needNum!}`)
                     .fontColor($r('app.color.FFFFFF'))
                     .fontSize($r('app.float.fontSize_16'))
                     .fontWeight(FontWeight.Regular)
@@ -179,10 +153,18 @@ export struct ModifyMaterialNumDialog {
                   .borderRadius($r('app.float.virtualSize_16'))
                   .opacity(((this.addOrModifyCollect === 1 && this.collectNumArray[index] <= 1) || (this.addOrModifyCollect === 2 && this.collectNumArray[index] <= 0)) ? 0.3 : 1)
                   .onClick(() => {
-                    if (this.collectNumArray[index] > 0) {
-                      this.collectNumArray[index]--
+                    if (this.addOrModifyCollect === 1) {
+                      if (this.collectNumArray[index] > 1) {
+                        this.collectNumArray[index]--
+                      } else {
+                        this.collectNumArray[index] = 0
+                      }
                     } else {
-                      this.collectNumArray[index] = 0
+                      if (this.collectNumArray[index] > 0) {
+                        this.collectNumArray[index]--
+                      } else {
+                        this.collectNumArray[index] = 0
+                      }
                     }
                   })
                 }.width('22%')
@@ -195,6 +177,19 @@ export struct ModifyMaterialNumDialog {
                     .type(InputType.Number)
                     .onChange((value: string) => {
                       this.collectNumArray[index] = parseInt(value)
+                      if (this.addOrModifyCollect === 1) {
+                        if (this.collectNumArray[index] > this.scanMaterial?.needNum!) {
+                          this.collectNumArray[index] = this.scanMaterial?.needNum!
+                        } else if (this.collectNumArray[index] < 1) {
+                          this.collectNumArray[index] = 1
+                        }
+                      } else {
+                        if (this.collectNumArray[index] > this.needNum) {
+                          this.collectNumArray[index] = this.needNum
+                        } else if (this.collectNumArray[index] < 0) {
+                          this.collectNumArray[index] = 0
+                        }
+                      }
                     })
                 }
                 .width('56%')
@@ -244,7 +239,7 @@ export struct ModifyMaterialNumDialog {
                 .width('100%')
               }
             }
-            .height($r('app.float.virtualSize_156'))
+            .height(this.batchHeight)
             .alignItems(HorizontalAlign.Start)
           })
         }
@@ -253,8 +248,9 @@ export struct ModifyMaterialNumDialog {
       .scrollable(ScrollDirection.Vertical) // 垂直滚动
       .scrollBar(BarState.Auto)
       .width('70.4%')
-      .layoutWeight(1)
+      .height(this.collectMaterials.length * this.batchHeight)
       .align(Alignment.Top)
+      .constraintSize({ maxHeight: '70%' })
 
       Column(){
         Divider()
@@ -281,8 +277,7 @@ export struct ModifyMaterialNumDialog {
           }
           .justifyContent(FlexAlign.Center)
           .width('50%')
-          .onClick(() => {
-            this.onConfirm();
+          .onClick(async () => {
             if (this.addOrModifyCollect === 1) {
               if (this.collectNumArray[0] > this.scanMaterial?.needNum!) {
                 promptAction.showToast({
@@ -290,8 +285,15 @@ export struct ModifyMaterialNumDialog {
                   duration: 1500,
                   bottom: 100
                 })
+                return
               }
-            //   todo 调接口新增
+              // 调接口新增采集
+              this.scanMaterial.stationId = this.currentStationId
+              this.scanMaterial.num = this.collectNumArray[0]
+              this.scanMaterial.seqNo = this.seqNo
+              let params: ProcessMaterial[] = []
+              params.push(this.scanMaterial)
+              await ProcessRequest.post('/api/v1/process/itemRecord/add', params)
             } else {
               let total: number = 0
               for (const element of this.collectNumArray) {
@@ -303,9 +305,18 @@ export struct ModifyMaterialNumDialog {
                   duration: 1500,
                   bottom: 100
                 })
+                return
+              }
+             // 调批量修改的接口
+              let stillNeed: number = this.needNum
+              for (let i = 0; i < this.collectMaterials.length; i++) {
+                this.collectMaterials[i].num = this.collectNumArray[i]
+                stillNeed -= this.collectNumArray[i]
+                this.collectMaterials[i].needNum = stillNeed
               }
-            //   todo 调修改接口
+              await ProcessRequest.post('/api/v1/process/itemRecord/batchUpdate', this.collectMaterials)
             }
+            this.confirm();
             this.controller.close();
           })
         }

+ 1 - 1
entry/src/main/ets/view/SelectWorkOrderDialog.ets

@@ -13,7 +13,7 @@ export struct SelectWorkOrderDialog {
   //扫描的工单号
   @State scanOrderValue:string = ''
   @Link selectWorkOder: WorkOrderInfo
-  // 当前工位
+  // 当前工位ID
   @Consume('currentStationId') currentStationId: string
   controller: CustomDialogController
   onConfirm: () => void = () => {

+ 36 - 16
entry/src/main/ets/view/process/MaterialCollectView.ets

@@ -6,6 +6,7 @@ import RequestParamModel from '../../viewmodel/RequestParamModel'
 import WorkOrderInfo from '../../viewmodel/WorkOrderInfo'
 import promptAction from '@ohos.promptAction'
 import { ModifyMaterialNumDialog } from '../ModifyMaterialNumDialog'
+import PageInfo from '../../viewmodel/PageInfo'
 
 @Component
 export struct MaterialCollectView {
@@ -21,7 +22,7 @@ export struct MaterialCollectView {
   // 新增或者修改采集物料(1:新增 2:修改)(采集物料数量修改弹窗使用)
   addOrModifyCollect: number = 1
   // 扫码开工状态(0:未开工 1:已开工)
-  @Link scanState: number
+  @Link @Watch('queryCollectHistory')scanState: number
   // 当前流转卡号
   @Link seqNo: string
   // 选中工单
@@ -30,6 +31,8 @@ export struct MaterialCollectView {
   @Link selectOperationId: string
   // 扫码开工后的生产过程信息
   @Link process: ProcessInfo
+  // 当前工位ID
+  @Consume('currentStationId') currentStationId: string
 
   modifyMaterialNumDialogController: CustomDialogController = new CustomDialogController({
     builder: ModifyMaterialNumDialog({
@@ -37,6 +40,10 @@ export struct MaterialCollectView {
       addOrModifyCollect: this.addOrModifyCollect,
       operationId: this.selectOperationId!,
       processId: this.process.id!,
+      seqNo: this.seqNo,
+      confirm: async ()=>{
+        this.queryCollectHistory()
+      },
     }),
     autoCancel: true, // 点击遮罩关闭
     customStyle: true,
@@ -44,27 +51,29 @@ export struct MaterialCollectView {
     maskColor: 'rgba(0,0,0,0.8)',  // 黑色遮罩
   })
 
+  // 采集历史查询
+  async queryCollectHistory() {
+    this.itemArray = await ProcessRequest.post('/api/v1/process/itemRecord/list', {
+      operationId: this.selectOperationId,
+      workOrderCode: this.selectWorkOder.workOrderCode!,
+      seqNo: this.seqNo,
+      processId: this.process.id,
+      pageNo: 1,
+      pageSize: 999999} as RequestParamModel)
+  }
+
   async aboutToAppear() {
     if (this.scanState === 1) {
-      this.itemArray = await ProcessRequest.post('/api/v1/process/itemRecord/list', {
-        operationId: this.selectOperationId,
-        workOrderCode: this.selectWorkOder.workOrderCode!,
-        seqNo: this.seqNo,
-        processId: this.process.id,
-        pageNo: 1,
-        pageSize: 999999} as RequestParamModel)
+      this.queryCollectHistory()
     } else {
-      this.itemArray = await ProcessRequest.post('/api/v1/op/operationItem/page', {
+      let res = await ProcessRequest.post('/api/v1/op/operationItem/page', {
         operationId: this.selectOperationId,
         pageNo: 1,
-        pageSize: 999999} as RequestParamModel)
+        pageSize: 999999} as RequestParamModel) as PageInfo
+      this.itemArray = res.records??[]
     }
     if (this.itemArray) {
-      console.log('hhtest', '-----------')
-      console.log('hhtest', '-----------')
-      console.log('hhtest', '-----------')
       for (const element of this.itemArray) {
-        console.log('hhtest', '-----------' + JSON.stringify(element))
         this.needNum += element.needNum || 0
         this.realNum += element.realNum || 0
       }
@@ -98,6 +107,7 @@ export struct MaterialCollectView {
                   duration: 1500,
                   bottom: 100
                 })
+                return
               }
               let result: ProcessMaterial[] = await ProcessRequest.post('/api/v1/process/itemRecord/searchMaterial', {
               operationId: this.selectOperationId,
@@ -123,10 +133,12 @@ export struct MaterialCollectView {
                   element.itemSeq = this.scanCode
                 }
                 if ('BATCH' === result[0].codeType!) {
-
+                  this.modifyMaterialNumDialogController.open()
                 } else {
+                  result[0].stationId = this.currentStationId
                   await ProcessRequest.post('/api/v1/process/itemRecord/add', result)
                 }
+                this.queryCollectHistory()
               }
             })
             .onChange((value: string) => {
@@ -166,7 +178,7 @@ export struct MaterialCollectView {
       .height('13.5%')
       .width('93%')
       .justifyContent(FlexAlign.SpaceBetween)
-      // 动态排列容器
+      // 需要采集物料展示,动态排列容器
       Scroll() {
         Flex({ wrap: FlexWrap.Wrap, direction: FlexDirection.Row, justifyContent: FlexAlign.Start, alignItems: ItemAlign.Start}) {
           ForEach(this.itemArray, (item: OperationItem, index: number) => {
@@ -232,6 +244,14 @@ export struct MaterialCollectView {
             .backgroundColor($r('app.color.20FFFFFF'))
             .margin({ top: index > 2 ? '1%' : '0%', left: (index % 3) === 0 ? '0%' : '0.8%' })
             .onClick(()=>{
+              if (this.scanState === 0) {
+                promptAction.showToast({
+                  message: '工序未开工,请先开工',
+                  duration: 1500,
+                  bottom: 100
+                })
+                return
+              }
               this.scanMaterial = {
                 materialCode: item.itemCode!,
                 materialName: item.itemName!,

+ 0 - 6
entry/src/main/ets/viewmodel/MaterialInfo.ets

@@ -22,9 +22,3 @@ export default class MaterialInfo {
   unitDictValue?:string
 }
 
-export interface MaterialPage{
-  pageNo?:string,
-  pageSize?:string,
-  //消息记录
-  records?:MaterialInfo[]
-}

+ 9 - 0
entry/src/main/ets/viewmodel/PageInfo.ets

@@ -0,0 +1,9 @@
+import MaterialInfo from './MaterialInfo'
+import OperationItem from './OperationItem'
+
+export default interface PageInfo {
+  pageNo?:string,
+  pageSize?:string,
+  //消息记录
+  records?: MaterialInfo[] | OperationItem[]
+}

+ 2 - 0
entry/src/main/ets/viewmodel/process/ProcessMaterial.ets

@@ -80,4 +80,6 @@ export default class ProcessMaterial {
   processId?: string;
   // 流转卡号
   seqNo?: string;
+  // 工位id
+  stationId?: string;
 }