ReportDefectNumDialog.ets 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. import ProcessRequest from '../common/util/request/ProcessRequest';
  2. import { BindTaskSeq } from '../viewmodel/process/BindTaskSeq';
  3. import TaskSeqVO from '../viewmodel/process/TaskSeqInfo';
  4. import RequestParamModel from '../viewmodel/RequestParamModel';
  5. import promptAction from '@ohos.promptAction';
  6. import preferencesUtil from '../common/util/PerferencesUtil';
  7. import CommonConstants from '../common/constants/CommonConstants';
  8. import ProcessDefectRecord from '../viewmodel/process/ProcessDefectRecord';
  9. //报工-不良品数量
  10. @CustomDialog
  11. export struct ReportDefectNumDialog {
  12. controller: CustomDialogController
  13. onConfirm: (num:number)=> void = () => {}
  14. scroller: Scroller = new Scroller()
  15. //是否全选
  16. @State isAllSelected: boolean = false
  17. //选择的数量
  18. @State selectNum:number= 0
  19. //当前工单
  20. @State currentWorkOrderCode:string = ''
  21. //当前工序号
  22. @State currentOperationId:string = ''
  23. //当前工位
  24. @State currentStationId:string = ''
  25. //总数量
  26. @State totalNum: number= 0
  27. //查询报工
  28. @State queryTaskSeq: TaskSeqVO[] = []
  29. @Consume ('bindTaskSeq') bindTaskSeq: BindTaskSeq[]
  30. @Prop userName:string= ''
  31. @State selectedIndexes:number[] =[]
  32. onQueryTask=async ()=>{
  33. let result: TaskSeqVO[] = await ProcessRequest.post('/api/v1/plan/task/list', {
  34. stationId:this.currentStationId,
  35. workOrderCode:this.currentWorkOrderCode,
  36. operationId:this.currentOperationId,
  37. stateList:[-1,0,1]
  38. } as RequestParamModel) as TaskSeqVO[];
  39. let seqNos: string[] = []
  40. seqNos = await preferencesUtil.get(CommonConstants.PREFERENCE_INSTANCE_NAME, this.currentWorkOrderCode, seqNos)
  41. if (!seqNos || seqNos.length <= 0) {
  42. this.queryTaskSeq = []
  43. this.totalNum = 0
  44. return
  45. }
  46. // 根据流水号查询不良记录
  47. let defectRecords = await ProcessRequest.post('/api/v1/process/defectRecord/list', {
  48. seqNos: seqNos
  49. } as RequestParamModel) as ProcessDefectRecord[];
  50. let defectSeqNos: string[] = []
  51. if (defectRecords && defectRecords.length > 0) {
  52. for (const element of defectRecords) {
  53. defectSeqNos.push(element.seqNo!);
  54. }
  55. }
  56. for (const element of result) {
  57. if (seqNos.includes(element.seqNo!) && defectSeqNos.includes(element.seqNo!)) {
  58. this.queryTaskSeq.push(element)
  59. }
  60. }
  61. this.totalNum = this.queryTaskSeq.length
  62. }
  63. private isSelectedByOthers(item: TaskSeqVO): boolean {
  64. // 检查所有其他用户的选择记录
  65. return this.bindTaskSeq.some(userSelection =>
  66. userSelection.userName !== this.userName &&
  67. userSelection.defectSeqNos?.some(seqNo => seqNo === item.seqNo));
  68. }
  69. // 获取选择当前项的用户名
  70. private getSelectingUserName(item: TaskSeqVO): string | undefined {
  71. const userSelection = this.bindTaskSeq.find(userSelection =>
  72. userSelection.defectSeqNos?.some(seqNo => seqNo === item.seqNo));
  73. return userSelection?.userName;
  74. }
  75. //选择单个
  76. private onSelectSeqNo(index: number) {
  77. const item = this.queryTaskSeq[index];
  78. if (this.isSelectedByOthers(item)) {
  79. return; // 已被其他用户选择,不允许操作
  80. }
  81. if (this.selectedIndexes.includes(index)) {
  82. this.selectedIndexes = this.selectedIndexes.filter(i => i !== index);
  83. } else {
  84. this.selectedIndexes = [index, ...this.selectedIndexes];
  85. }
  86. this.updateSelectState();
  87. }
  88. //全选
  89. private handleSelectAll() {
  90. this.isAllSelected = !this.isAllSelected;
  91. if (this.isAllSelected) {
  92. // 只选择未被其他用户选中的项
  93. this.selectedIndexes = [];
  94. this.queryTaskSeq.forEach((item: TaskSeqVO, index: number) => {
  95. if (!this.isSelectedByOthers(item)) {
  96. this.selectedIndexes.push(index);
  97. }
  98. });
  99. } else {
  100. this.selectedIndexes = [];
  101. }
  102. this.updateSelectState();
  103. }
  104. //更新选择状态
  105. private updateSelectState() {
  106. this.selectNum = this.selectedIndexes.length;
  107. const availableItems = this.queryTaskSeq.filter(item => !this.isSelectedByOthers(item));
  108. this.isAllSelected = availableItems.length > 0 &&
  109. this.selectedIndexes.length === availableItems.length;
  110. }
  111. aboutToAppear(): void {
  112. this.onQueryTask().then(() => {
  113. // 查询完成后检查是否有当前用户已选的项
  114. this.queryTaskSeq.forEach((item, index) => {
  115. const selectingUser = this.getSelectingUserName(item);
  116. if (selectingUser === this.userName) {
  117. this.selectedIndexes.push(index);
  118. }
  119. });
  120. this.updateSelectState();
  121. });
  122. }
  123. build() {
  124. Column(){
  125. Column() {
  126. Text("不良品数量")
  127. .fontColor($r('app.color.FFFFFF'))
  128. .fontSize($r('app.float.fontSize_30'))
  129. }
  130. .height('8%')
  131. .width('100%')
  132. .justifyContent(FlexAlign.Center)
  133. Row() {
  134. Row(){
  135. Row(){}.width('5%')
  136. Checkbox()
  137. .select(this.isAllSelected)
  138. .selectedColor($r('app.color.0A84FF'))
  139. .unselectedColor($r('app.color.60FFFFFF'))
  140. .width($r('app.float.virtualSize_24'))
  141. .mark({
  142. strokeColor:$r('app.color.000000'),
  143. size: $r('app.float.virtualSize_20'),
  144. strokeWidth: 1
  145. })
  146. .height($r('app.float.virtualSize_24'))
  147. .onChange(async (value: boolean) => {
  148. })
  149. .onClick(()=>{
  150. this.handleSelectAll()
  151. })
  152. Text("全选")
  153. .fontColor($r('app.color.FFFFFF'))
  154. .fontSize($r('app.float.fontSize_16'))
  155. }
  156. .width('20%')
  157. .justifyContent(FlexAlign.Start)
  158. .backgroundColor(this.isAllSelected?$r('app.color.200A84FF'):$r('app.color.20FFFFFF'))
  159. .borderRadius($r('app.float.virtualSize_16'))
  160. .onClick(()=>{
  161. this.handleSelectAll()
  162. })
  163. Row(){
  164. Text(`${this.selectNum}`)
  165. .fontColor($r('app.color.30D158'))
  166. .fontSize($r('app.float.fontSize_16'))
  167. .fontWeight(FontWeight.Lighter)
  168. Text(`/${this.totalNum}`)
  169. .fontColor($r('app.color.FFFFFF'))
  170. .fontSize($r('app.float.fontSize_16'))
  171. .fontWeight(FontWeight.Lighter)
  172. }
  173. .margin({left:'49%'})
  174. .width('30%')
  175. .justifyContent(FlexAlign.End)
  176. }
  177. .borderRadius($r('app.float.virtualSize_16'))
  178. .height('7%')
  179. .width('96%')
  180. .margin({left:'2%',right:'2%',bottom:'1.5%'})
  181. Row() {
  182. List({space:8,scroller:this.scroller}){
  183. ForEach(this.queryTaskSeq, (item:TaskSeqVO,index) => {
  184. ListItem() {
  185. Row(){
  186. Checkbox()
  187. .select(this.selectedIndexes.includes(index)||this.isSelectedByOthers(item))
  188. .selectedColor($r('app.color.30D158'))
  189. .unselectedColor($r('app.color.60FFFFFF'))
  190. .width($r('app.float.virtualSize_24'))
  191. .mark({
  192. strokeColor:$r('app.color.000000'),
  193. size: $r('app.float.virtualSize_20'),
  194. strokeWidth: 1
  195. })
  196. .height($r('app.float.virtualSize_24'))
  197. .onClick(()=>{
  198. this.onSelectSeqNo(index)
  199. this.selectNum = this.selectedIndexes.length;
  200. })
  201. Text('S/N')
  202. .fontColor($r('app.color.FFFFFF'))
  203. .fontSize($r('app.float.fontSize_16'))
  204. .fontWeight(FontWeight.Lighter)
  205. Text(item.seqNo)
  206. .fontColor($r('app.color.FFFFFF'))
  207. .fontSize($r('app.float.fontSize_16'))
  208. .fontWeight(FontWeight.Bold)
  209. .margin({left:'2%'})
  210. Text(this.getSelectingUserName(item))
  211. .fontColor($r('app.color.FFFFFF'))
  212. .fontSize($r('app.float.fontSize_12'))
  213. .fontWeight(FontWeight.Lighter)
  214. .width('50%')
  215. .textAlign(TextAlign.End)
  216. }
  217. .borderRadius($r('app.float.virtualSize_16'))
  218. .backgroundColor(
  219. this.selectedIndexes.includes(index) ||this.isSelectedByOthers(item)?
  220. $r('app.color.2030D158') :
  221. $r('app.color.20FFFFFF')
  222. )
  223. .border({
  224. width: 1 ,
  225. color: this.selectedIndexes.includes(index)||this.isSelectedByOthers(item) ?
  226. $r('app.color.30D158') :
  227. $r('app.color.20FFFFFF')
  228. })
  229. .width('100%')
  230. .opacity(this.isSelectedByOthers(item) ? 0.3 : 1)
  231. .onClick(()=>{
  232. this.onSelectSeqNo(index)
  233. this.selectNum = this.selectedIndexes.length;
  234. })
  235. }
  236. .width('96%')
  237. .margin({left:'2%',right:'2%'})
  238. })
  239. }
  240. .height('100%')
  241. .width('100%')
  242. }
  243. .height('73%')
  244. .width('100%')
  245. .margin({bottom:'1.5%'})
  246. Column() {
  247. Divider()
  248. .vertical(false)
  249. .strokeWidth(1)
  250. .color($r('app.color.15FFFFFF'))
  251. Row() {
  252. Row() {
  253. Text('取消')
  254. .fontColor($r('app.color.60FFFFFF'))
  255. .fontSize($r('app.float.fontSize_30'))
  256. }
  257. .justifyContent(FlexAlign.Center)
  258. .width('50%')
  259. .onClick(() => this.controller.close())
  260. Divider()
  261. .vertical(true)
  262. .strokeWidth(1)
  263. .color($r('app.color.15FFFFFF'))
  264. Row() {
  265. Text('确定')
  266. .fontColor($r('app.color.007AFF'))
  267. .fontSize($r('app.float.fontSize_30'))
  268. }
  269. .justifyContent(FlexAlign.Center)
  270. .width('50%')
  271. .onClick(() => {
  272. let selectTasks = this.queryTaskSeq.filter((_, index) => this.selectedIndexes.includes(index));
  273. if (!selectTasks || selectTasks.length <= 0) {
  274. promptAction.showToast({
  275. message: '请先不良品的流水号',
  276. duration: 2000
  277. });
  278. return;
  279. }
  280. let seqNos: string[] = []
  281. for (const element of selectTasks) {
  282. seqNos.push(element.seqNo)
  283. }
  284. const currentUserSelection: BindTaskSeq = {
  285. userName: this.userName,
  286. defectSeqNos: seqNos
  287. };
  288. const existingUserIndex = this.bindTaskSeq.findIndex(
  289. item => item.userName === this.userName
  290. );
  291. if (existingUserIndex >= 0) {
  292. this.bindTaskSeq[existingUserIndex].defectSeqNos = currentUserSelection.defectSeqNos;
  293. } else {
  294. this.bindTaskSeq.push(currentUserSelection);
  295. }
  296. this.onConfirm(this.selectedIndexes.length);
  297. this.controller.close()
  298. })
  299. }
  300. }
  301. .width('100%')
  302. .height('8%')
  303. }
  304. .height('71%')
  305. .width('30%')
  306. .backgroundColor($r('app.color.2A2A2A'))
  307. .justifyContent(FlexAlign.End)
  308. .alignItems(HorizontalAlign.Start)
  309. .borderColor($r('app.color.000000'))
  310. .borderWidth(1)
  311. .borderRadius($r('app.float.virtualSize_16'))
  312. }
  313. }