ProductionProcessesView.ets 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import WorkOrderInfo from '../viewmodel/WorkOrderInfo';
  2. import OperationInfo from '../viewmodel/process/OperationInfo';
  3. import promptAction from '@ohos.promptAction';
  4. import { ProcessStatus } from '../viewmodel/process/EnumerationType';
  5. interface Tmp {
  6. index: number;
  7. item: OperationInfo
  8. }
  9. @Component
  10. export struct OperationList {
  11. // 必需属性
  12. @Link @Watch('onWorkOrderChange') selectWorkOder: WorkOrderInfo;
  13. @Link selectOperationId: string ;
  14. @Link stationId: string;
  15. @Link isStationProcess:boolean;
  16. @Link currentProcessStatus: ProcessStatus
  17. // 新增:监听selectWorkOder变化的回调
  18. onWorkOrderChange() {
  19. this.findAndSelectMatchingOperation();
  20. }
  21. findAndSelectMatchingOperation(): void {
  22. // 如果已经有选中的工序,且该工序匹配当前工位,则保持选中
  23. if (this.selectOperationId) {
  24. const currentSelected = this.selectWorkOder.ops?.find(op => op.operationId === this.selectOperationId);
  25. if (currentSelected && currentSelected.stationId === this.stationId) {
  26. return; // 当前选中的工序仍然匹配,不需要更改
  27. }
  28. }
  29. // 查找第一个匹配当前工位且未完成的工序
  30. const matchingOperation = this.selectWorkOder.ops?.find(op =>
  31. op.stationId === this.stationId && !op.isEnd
  32. );
  33. if (matchingOperation) {
  34. this.selectOperationId = matchingOperation.operationId!;
  35. this.isStationProcess = true;
  36. } else {
  37. promptAction.showToast({
  38. message: `当前没有该工位未完成工序`,
  39. duration: 1500,
  40. });
  41. this.isStationProcess = false;
  42. }
  43. }
  44. build() {
  45. List() {
  46. ForEach(this.selectWorkOder.ops!, (item: OperationInfo, index: number) => {
  47. ListItem() {
  48. this.OperationListItem({ item: item, index: index })
  49. }
  50. })
  51. }
  52. .width('83.4%')
  53. .height('88.6%')
  54. .alignListItem(ListItemAlign.Center)
  55. }
  56. @Builder
  57. OperationListItem(params: Tmp) {
  58. Column() {
  59. // 工序项
  60. Row() {
  61. // 序号
  62. Row() {
  63. Text((params.index + 1).toString())
  64. .fontSize($r('app.float.fontSize_16'))
  65. .fontColor(this.selectOperationId === params.item.operationId ? $r('app.color.90000000') : $r('app.color.FFFFFF'))
  66. .fontWeight(FontWeight.Bold)
  67. }
  68. .width('14.6%')
  69. .height('80%')
  70. .justifyContent(FlexAlign.Center)
  71. // 工序名称
  72. Row() {
  73. Text(params.item.operationName)
  74. .fontSize($r('app.float.fontSize_16'))
  75. .fontColor(this.selectOperationId === params.item.operationId ? $r('app.color.90000000') : $r('app.color.FFFFFF'))
  76. .fontWeight(FontWeight.Regular)
  77. .padding({ left: 5 })
  78. }
  79. .width('70.8%')
  80. .height('100%')
  81. .alignItems(VerticalAlign.Center)
  82. .justifyContent(FlexAlign.Start)
  83. // 状态图标
  84. Row() {
  85. Image(this.selectOperationId === params.item.operationId ?
  86. $r('app.media.process_current_operation') :
  87. (params.item.isEnd! ? $r('app.media.process_complete') : ''))
  88. .width($r('app.float.virtualSize_24'))
  89. .height($r('app.float.virtualSize_24'))
  90. .fillColor(this.selectOperationId === params.item.operationId ? $r('app.color.90000000') : $r('app.color.FFFFFF'))
  91. .opacity(!(this.selectOperationId === params.item.operationId) && !params.item.isEnd! ? 0 : 1)
  92. }
  93. .width('14.6%')
  94. .height('100%')
  95. .justifyContent(FlexAlign.Center)
  96. }
  97. .width('100%')
  98. .height('70%')
  99. .borderRadius($r('app.float.virtualSize_40'))
  100. .backgroundImage(this.selectOperationId === params.item.operationId ?
  101. $r('app.media.process_select_operation') :
  102. $r('app.media.process_no_select_operation'))
  103. .backgroundImageSize(ImageSize.Cover)
  104. .onClick(async () => {
  105. if(this.selectOperationId == params.item.operationId!) return
  106. this.isStationProcess = false;
  107. this.currentProcessStatus = ProcessStatus.INITIAL
  108. this.selectOperationId = params.item.operationId!;
  109. if (this.stationId != params.item.stationId!) {
  110. promptAction.showToast({
  111. message: `${params.item.operationName}需要在${params.item.stationId}工位上生产`,
  112. duration: 1500,
  113. });
  114. return;
  115. }
  116. if (params.item.isEnd!) {
  117. promptAction.showToast({
  118. message: `${params.item.operationName}已经完成`,
  119. duration: 1500,
  120. });
  121. return;
  122. }
  123. this.isStationProcess = true;
  124. })
  125. // 分隔线(非最后一项显示)
  126. if (params.index < (this.selectWorkOder?.ops?.length ? this.selectWorkOder.ops!.length - 1 : 0)) {
  127. Row() {
  128. Divider()
  129. .vertical(true)
  130. .color($r('app.color.60FFFFFF'))
  131. .padding({ right: '15%' })
  132. }
  133. .justifyContent(FlexAlign.Center)
  134. .width('20%')
  135. .layoutWeight(1)
  136. }
  137. }
  138. .width('100%')
  139. .height('10.6%')
  140. .alignItems(HorizontalAlign.Start)
  141. }
  142. }