MaterialCollectView.ets 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import CommonConstants from '../../common/constants/CommonConstants'
  2. import MaterialInfo from '../../model/MaterialInfo'
  3. import HashMap from '@ohos.util.HashMap'
  4. import ProcessData from '../../model/ProcessData'
  5. @Component
  6. export struct MaterialCollectView {
  7. mainMaterial: string
  8. @Link process: ProcessData
  9. // 查询到工序需要的物料
  10. @State materialArray: MaterialInfo[] = CommonConstants.MATERIAL_ARRAY
  11. // 采集到的物料
  12. @State collectMaterials: MaterialInfo[] = []
  13. @State collectCode: string = ''
  14. // 方便查询已采集的物料信息
  15. private collectMap:HashMap<string, MaterialInfo> = new HashMap()
  16. scroller: Scroller = new Scroller()
  17. aboutToAppear() {
  18. // todo 查询需要的物料信息
  19. //遍历已采集的物料
  20. for (const material of this.materialArray) {
  21. if (material.materialNo && material.materialNo.length > 0) {
  22. if (this.collectMap.hasKey(material.materialNo)) {
  23. this.collectMap.get(material.materialNo).collectNum++
  24. } else {
  25. material.collectNum = 0
  26. this.collectMap.set(material.materialNo, material)
  27. }
  28. } else if (material.batchCode && material.batchCode.length > 0) {
  29. if (this.collectMap.hasKey(material.batchCode)) {
  30. this.collectMap.get(material.batchCode).collectNum++
  31. } else {
  32. material.collectNum = 0
  33. this.collectMap.set(material.batchCode, material)
  34. }
  35. }
  36. }
  37. }
  38. build() {
  39. Column() {
  40. // 扫描物料栏
  41. Row() {
  42. Row() {
  43. Row() {
  44. Image($r('app.media.qr_code'))
  45. .height('31%')
  46. }
  47. .width('8%')
  48. .justifyContent(FlexAlign.End)
  49. TextInput({ placeholder: '请扫描物料编码', text: this.collectCode })
  50. .placeholderColor($r('app.color.text_input_placeholder_font_color'))
  51. .placeholderFont({ size: $r('app.float.robot_set_font_size'), weight: FontWeight.Medium })
  52. .fontSize($r('app.float.robot_set_font_size'))
  53. .fontWeight(FontWeight.Medium)
  54. .fontColor($r('app.color.general_font_color'))
  55. .textAlign(TextAlign.Start)
  56. .height('100%')
  57. .layoutWeight(1)
  58. .maxLength(100)
  59. .borderRadius($r('app.float.robot_set_radius'))
  60. .backgroundColor($r('app.color.general_font_white_color'))
  61. .onChange((value: string) => {
  62. this.collectCode = value
  63. })
  64. .onSubmit(() => {
  65. // 遍历需要的物料
  66. for (const needMaterial of this.materialArray) {
  67. if (needMaterial.materialNo && needMaterial.materialNo.length > 0 && this.collectCode === needMaterial.materialNo) {
  68. if (this.collectMap.hasKey(needMaterial.materialNo)) {
  69. this.collectMap.get(needMaterial.materialNo).collectNum++
  70. } else {
  71. needMaterial.collectNum = 1
  72. let collect: MaterialInfo = new MaterialInfo()
  73. Object.assign(collect, needMaterial)
  74. this.collectMap.set(needMaterial.materialNo, collect)
  75. this.collectMaterials.push(collect)
  76. console.log('testTag', '---collect-------' +JSON.stringify(collect))
  77. }
  78. break
  79. } else if (needMaterial.batchCode && needMaterial.batchCode.length > 0 && this.collectCode === needMaterial.batchCode) {
  80. if (this.collectMap.hasKey(needMaterial.batchCode)) {
  81. this.collectMap.get(needMaterial.batchCode).collectNum++
  82. } else {
  83. needMaterial.collectNum = 1
  84. let collect: MaterialInfo = new MaterialInfo()
  85. Object.assign(collect, needMaterial)
  86. this.collectMap.set(needMaterial.batchCode, collect)
  87. this.collectMaterials.push(collect)
  88. }
  89. break
  90. }
  91. }
  92. this.collectCode = ''
  93. })
  94. }
  95. .borderRadius($r('app.float.robot_set_radius'))
  96. .backgroundColor($r('app.color.general_font_white_color'))
  97. .width('39%')
  98. .height('76%')
  99. }
  100. .width('100%')
  101. .height('13%')
  102. .justifyContent(FlexAlign.Start)
  103. if (this.collectMaterials && this.collectMaterials.length > 0) {
  104. Grid() {
  105. ForEach(this.collectMaterials, (material: MaterialInfo) => {
  106. GridItem() {
  107. Row() {
  108. Column() {
  109. Text(material.materialName)
  110. .fontSize($r('app.float.process_card_middle_font_size'))
  111. .fontColor($r('app.color.general_font_color'))
  112. .opacity($r('app.float.general_font_opacity'))
  113. .fontWeight(FontWeight.Medium)
  114. // todo 不知道是啥
  115. Text('100*200')
  116. .fontSize($r('app.float.process_card_small_font_size'))
  117. .fontColor($r('app.color.general_font_color'))
  118. .opacity($r('app.float.process_step_font_opacity'))
  119. .fontWeight(FontWeight.Regular)
  120. Text('需求:' + material.needNum)
  121. .fontSize($r('app.float.process_card_small_font_size'))
  122. .fontColor($r('app.color.general_font_color'))
  123. .opacity($r('app.float.process_step_font_opacity'))
  124. .fontWeight(FontWeight.Regular)
  125. }
  126. .justifyContent(FlexAlign.Center)
  127. .alignItems(HorizontalAlign.Start)
  128. .width('70%')
  129. .height('100%')
  130. .padding({left: '4%'})
  131. Column() {
  132. if (material.needNum - material.collectNum > 0) {
  133. Column() {
  134. Text((material.needNum - material.collectNum).toString())
  135. .fontSize($r('app.float.process_card_large_font_size'))
  136. .fontColor($r('app.color.general_font_color'))
  137. .opacity($r('app.float.general_font_opacity'))
  138. .fontWeight(FontWeight.Bold)
  139. Text('还需采集')
  140. .fontSize($r('app.float.process_card_small_font_size'))
  141. .fontColor($r('app.color.general_font_color'))
  142. .opacity($r('app.float.process_step_font_opacity'))
  143. .fontWeight(FontWeight.Regular)
  144. Row(){}
  145. .height('5%')
  146. }
  147. .justifyContent(FlexAlign.End)
  148. .alignItems(HorizontalAlign.End)
  149. .width('100%')
  150. .height('71%')
  151. .padding({right: '12%'})
  152. } else {
  153. Column() {
  154. Image($r('app.media.collect_completed'))
  155. .width('182px')
  156. .height('182px')
  157. }
  158. .alignItems(HorizontalAlign.End)
  159. .justifyContent(FlexAlign.Start)
  160. .width('100%')
  161. .height('71%')
  162. }
  163. Row() {
  164. Image($r('app.media.subscript'))
  165. .height($r('app.float.card_subscript_size'))
  166. .width($r('app.float.card_subscript_size'))
  167. }
  168. .width('100%')
  169. .justifyContent(FlexAlign.End)
  170. .alignItems(VerticalAlign.Center)
  171. .layoutWeight(1)
  172. .padding({right: '12%'})
  173. }
  174. .layoutWeight(1)
  175. .height('100%')
  176. .justifyContent(FlexAlign.Center)
  177. .alignItems(HorizontalAlign.Center)
  178. }
  179. .width('97%')
  180. .height('26%')
  181. .backgroundColor($r('app.color.general_font_white_color'))
  182. .borderRadius($r('app.float.general_border_radius'))
  183. .justifyContent(FlexAlign.Center)
  184. }
  185. })
  186. }
  187. .columnsTemplate('1fr 1fr')
  188. .rowsGap(10)
  189. .width('100%')
  190. .layoutWeight(1)
  191. } else {
  192. Column() {
  193. Image($r('app.media.scan_qr'))
  194. .width($r('app.float.material_collect_image_size'))
  195. .height($r('app.float.material_collect_image_size'))
  196. Text('扫描物料编码添加物料')
  197. .fontSize($r('app.float.card_info_font_size'))
  198. .fontColor($r('app.color.general_font_color'))
  199. .fontWeight(FontWeight.Medium)
  200. .opacity($r('app.float.material_collect_font_opacity'))
  201. }
  202. .width('80%')
  203. .height('60%')
  204. .justifyContent(FlexAlign.Center)
  205. }
  206. }
  207. .width('100%')
  208. .height('100%')
  209. .margin({left: '2%'})
  210. }
  211. }