ReportTimeBasedDialog.ets 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. //工序(计时)报工
  2. import ProcessRequest from '../common/util/request/ProcessRequest'
  3. import ProcessInfo from '../viewmodel/process/ProcessInfo'
  4. import ReporterInfo from '../viewmodel/process/ReporterInfo'
  5. import ReportInfo from '../viewmodel/process/ReporterInfo'
  6. import TaskSeqVO from '../viewmodel/process/TaskSeqInfo'
  7. import RequestParamModel from '../viewmodel/RequestParamModel'
  8. import WorkOrderInfo from '../viewmodel/WorkOrderInfo'
  9. import promptAction from '@ohos.promptAction'
  10. import ProcessReportTimeBased from '../viewmodel/process/ProcessReportTimeBased'
  11. import { BindTaskSeq } from '../viewmodel/process/BindTaskSeq'
  12. import preferencesUtil from '../common/util/PerferencesUtil'
  13. import CommonConstants from '../common/constants/CommonConstants'
  14. @CustomDialog
  15. export struct ReportTimeBasedDialog {
  16. controller: CustomDialogController
  17. private scrollerList: Scroller = new Scroller()
  18. //选中的工序id
  19. @Link selectOperationId: string
  20. //从首页传来的工单
  21. @Link selectWorkOder: WorkOrderInfo
  22. // 当前生产过程
  23. @Link process: ProcessInfo
  24. //查询报工
  25. @Link reporterList: ReportInfo[]
  26. //工序名字
  27. selectOperationName: string = ''
  28. //当前工序已报工数量
  29. @State reportedNum: number = 0
  30. //计划报工数量
  31. @State planReportNum: number = 0
  32. // 记录当前点击的报工人索引
  33. @State currentReporterIndex: number = 0;
  34. //当前工位
  35. @Consume('currentStationId') currentStationId: string
  36. // 当前登录用户名称
  37. @Consume('currentUserName') userName: string
  38. // 当前登录用户名称
  39. @Consume('currentUserId') currentUserId: number
  40. @Consume ('bindTaskSeq') bindTaskSeq: BindTaskSeq[]
  41. // 开工时间
  42. startWorkTime: string = ''
  43. //选择报工数量
  44. onSelectReportNum: (index:number) => void = () => {}
  45. //选择不良品数量
  46. onSelectDefectNum: (index:number) => void = () => {}
  47. //选择用户用时占比
  48. onSelectWorkHourRate: (index:number) => void = () => {}
  49. //选择报工人
  50. onSelectReporter: (index:number) => void = () => {}
  51. // 报工后清除相关数据
  52. clearSelectData: () => void = () => {}
  53. //加载第一个报工人(无法删除)
  54. loadFirstReporter=async ()=>{
  55. if (this.reporterList.length > 0) {
  56. return
  57. }
  58. const firstReporter: ReporterInfo = {}
  59. firstReporter.userName = this.userName
  60. firstReporter.userId = this.currentUserId.toString()
  61. firstReporter.workingHoursRate = 1
  62. this.reporterList.push(firstReporter)
  63. }
  64. async aboutToAppear() {
  65. this.loadFirstReporter()
  66. // 查询所有流转卡号
  67. let res = await ProcessRequest.post('/api/v1/plan/task/list', {
  68. stationId: this.currentStationId,
  69. workOrderCode: this.selectWorkOder.workOrderCode!,
  70. operationId: this.selectOperationId
  71. } as RequestParamModel) as TaskSeqVO[];
  72. if (!res || res.length <= 0) {
  73. return
  74. }
  75. this.planReportNum = res.length
  76. // 计算已报工数量
  77. let num: number = 0
  78. for (const element of res) {
  79. if (element.state! === '2') {
  80. num++
  81. }
  82. }
  83. this.reportedNum = num
  84. }
  85. build() {
  86. Column() {
  87. Column() {
  88. Text('工序报工')
  89. .fontColor($r('app.color.FFFFFF'))
  90. .fontSize($r('app.float.fontSize_30'))
  91. }
  92. .height('10%')
  93. .width('100%')
  94. .justifyContent(FlexAlign.Center)
  95. Column(){
  96. Row(){
  97. Column({space:3}){
  98. Text(this.selectWorkOder.materialName)
  99. .fontSize($r('app.float.fontSize_24'))
  100. .fontColor($r('app.color.FFFFFF'))
  101. Text(this.selectWorkOder.materialCode)
  102. .fontSize($r('app.float.fontSize_12'))
  103. .fontColor($r('app.color.FFFFFF'))
  104. .fontWeight(FontWeight.Lighter)
  105. Row(){
  106. Text('工单 ')
  107. .fontSize($r('app.float.fontSize_16'))
  108. .fontColor($r('app.color.FFFFFF'))
  109. .fontWeight(FontWeight.Lighter)
  110. Text(this.selectWorkOder.workOrderCode)
  111. .fontSize($r('app.float.fontSize_16'))
  112. .fontColor($r('app.color.FFFFFF'))
  113. .fontWeight(FontWeight.Bold)
  114. }
  115. }
  116. .height('100%')
  117. .width('30%')
  118. .justifyContent(FlexAlign.End)
  119. .alignItems(HorizontalAlign.Start)
  120. Row(){
  121. Text('工序 ')
  122. .fontSize($r('app.float.fontSize_16'))
  123. .fontColor($r('app.color.FFFFFF'))
  124. .fontWeight(FontWeight.Lighter)
  125. Text(this.selectOperationName)
  126. .fontSize($r('app.float.fontSize_16'))
  127. .fontColor($r('app.color.FFFFFF'))
  128. .fontWeight(FontWeight.Bold)
  129. }
  130. .height('100%')
  131. .width('40%')
  132. .justifyContent(FlexAlign.Center)
  133. .alignItems(VerticalAlign.Bottom)
  134. Column(){
  135. Row(){
  136. Text(`${this.reportedNum}/`)
  137. .fontSize($r('app.float.fontSize_38'))
  138. .fontColor($r('app.color.FFFFFF'))
  139. Text(`${this.planReportNum}`)
  140. .fontSize($r('app.float.fontSize_38'))
  141. .fontColor($r('app.color.60FFFFFF'))
  142. }
  143. Text('当前工序已报工/计划')
  144. .fontSize($r('app.float.fontSize_12'))
  145. .fontColor($r('app.color.FFFFFF'))
  146. .fontWeight(FontWeight.Lighter)
  147. }
  148. .height('100%')
  149. .width('30%')
  150. .justifyContent(FlexAlign.End)
  151. .alignItems(HorizontalAlign.End)
  152. }
  153. .height('14.4%')
  154. .width('100%')
  155. .alignItems(VerticalAlign.Bottom)
  156. Divider()
  157. .vertical(false)
  158. .width('100%')
  159. .strokeWidth(1)
  160. .color($r('app.color.15FFFFFF'))
  161. .height('3.1%')
  162. // 报工流水号、不良流水号选择
  163. Row({space: 5}) {
  164. Column() {
  165. Text(`报工数量`)
  166. .fontColor($r('app.color.FFFFFF'))
  167. .fontSize($r('app.float.fontSize_16'))
  168. .fontWeight(FontWeight.Regular)
  169. .height('27%')
  170. .margin({left:'2%'})
  171. Row(){
  172. Text(this.reporterList && this.reporterList[0].reportNum ? this.reporterList[0].reportNum! : '0')
  173. .fontColor($r('app.color.FFFFFF'))
  174. .fontSize($r('app.float.fontSize_24'))
  175. .margin({left:'8%'})
  176. .width('82%')
  177. .textAlign(TextAlign.Start)
  178. Text('>')
  179. .fontColor($r('app.color.FFFFFF'))
  180. .fontSize($r('app.float.fontSize_24'))
  181. .textAlign(TextAlign.Start)
  182. .width('10%')
  183. }
  184. .justifyContent(FlexAlign.Start)
  185. .borderRadius($r('app.float.virtualSize_16'))
  186. .height('73%')
  187. .backgroundColor($r('app.color.20FFFFFF'))
  188. .onClick(()=>{
  189. this.onSelectReportNum(0)
  190. })
  191. }
  192. .width('30%')
  193. .height('100%')
  194. .alignItems(HorizontalAlign.Start)
  195. Column(){
  196. Text(`不良品数量`)
  197. .fontColor($r('app.color.FFFFFF'))
  198. .fontSize($r('app.float.fontSize_16'))
  199. .fontWeight(FontWeight.Regular)
  200. .height('27%')
  201. .margin({left:'2%'})
  202. Row(){
  203. Text(this.reporterList && this.reporterList[0].defectNum ? this.reporterList[0].defectNum! : '0')
  204. .fontColor($r('app.color.FFFFFF'))
  205. .fontSize($r('app.float.fontSize_24'))
  206. .margin({left:'8%'})
  207. .width('82%')
  208. .textAlign(TextAlign.Start)
  209. Text('>')
  210. .fontColor($r('app.color.FFFFFF'))
  211. .fontSize($r('app.float.fontSize_24'))
  212. .textAlign(TextAlign.Start)
  213. .width('10%')
  214. }
  215. .justifyContent(FlexAlign.Start)
  216. .borderRadius($r('app.float.virtualSize_16'))
  217. .backgroundColor($r('app.color.20FFFFFF'))
  218. .height('73%')
  219. .onClick(()=>{
  220. this.onSelectDefectNum(0)
  221. })
  222. }
  223. .width('30%')
  224. .alignItems(HorizontalAlign.Start)
  225. .height('100%')
  226. Blank()
  227. Text('开工时间:' +this.startWorkTime)
  228. .fontColor($r('app.color.FFFFFF'))
  229. .fontSize($r('app.float.fontSize_12'))
  230. .fontWeight(FontWeight.Lighter)
  231. }
  232. .width('100%')
  233. .height('17.2%')
  234. Row().height('7.9%')
  235. // 添加报工人
  236. Row(){
  237. Image($r('app.media.general_create'))
  238. .width($r('app.float.virtualSize_24'))
  239. .height($r('app.float.virtualSize_24'))
  240. .fillColor($r('app.color.0A84FF'))
  241. Text('添加报工人')
  242. .fontColor($r('app.color.0A84FF'))
  243. .fontSize($r('app.float.fontSize_24'))
  244. .margin({left:'4%'})
  245. }
  246. .height('8.8%')
  247. .width('14%')
  248. .justifyContent(FlexAlign.Center)
  249. .backgroundColor($r('app.color.20FFFFFF'))
  250. .borderRadius($r('app.float.virtualSize_16'))
  251. .onClick(() => {
  252. const newReporter: ReportInfo = {}
  253. // 默认占比为剩余占比
  254. if (this.reporterList && this.reporterList.length > 0) {
  255. let rateTotal: number = 1
  256. for (const element of this.reporterList) {
  257. if (element.workingHoursRate && element.workingHoursRate > 0) {
  258. rateTotal -= element.workingHoursRate
  259. }
  260. }
  261. newReporter.workingHoursRate = rateTotal
  262. }
  263. this.reporterList.push(newReporter)
  264. })
  265. Column(){
  266. List({space: 8, scroller: this.scrollerList}) {
  267. ForEach(this.reporterList, (item: ReporterInfo, index: number) => {
  268. ListItem() {
  269. Row(){
  270. Column(){
  271. Text(`报工人${index+1}`)
  272. .fontColor($r('app.color.FFFFFF'))
  273. .fontSize($r('app.float.fontSize_16'))
  274. .fontWeight(FontWeight.Regular)
  275. .height('30%')
  276. .margin({left:'2%'})
  277. Row(){
  278. Text(item.userName)
  279. .fontColor($r('app.color.FFFFFF'))
  280. .fontSize($r('app.float.fontSize_24'))
  281. .margin({left:'8%'})
  282. .width('82%')
  283. .textAlign(TextAlign.Start)
  284. Text('>')
  285. .fontColor($r('app.color.FFFFFF'))
  286. .fontSize($r('app.float.fontSize_24'))
  287. .textAlign(TextAlign.Start)
  288. .width('10%')
  289. }
  290. .justifyContent(FlexAlign.Start)
  291. .borderRadius($r('app.float.virtualSize_16'))
  292. .height('70%')
  293. .enabled(index!=0)
  294. .backgroundColor($r('app.color.20FFFFFF'))
  295. .onClick(()=>{
  296. this.onSelectReporter(index)
  297. this.currentReporterIndex = index;
  298. })
  299. }
  300. .width('29%')
  301. .height('100%')
  302. .alignItems(HorizontalAlign.Start)
  303. Column(){
  304. Text(`用时占比`)
  305. .fontColor($r('app.color.FFFFFF'))
  306. .fontSize($r('app.float.fontSize_16'))
  307. .fontWeight(FontWeight.Regular)
  308. .height('30%')
  309. .margin({left:'2%'})
  310. Row(){
  311. Text(item.workingHoursRate ? item.workingHoursRate * 100 + '%' : '0%')
  312. .fontColor($r('app.color.FFFFFF'))
  313. .fontSize($r('app.float.fontSize_24'))
  314. .margin({left:'8%'})
  315. .width('82%')
  316. .textAlign(TextAlign.Start)
  317. Text('>')
  318. .fontColor($r('app.color.FFFFFF'))
  319. .fontSize($r('app.float.fontSize_24'))
  320. .textAlign(TextAlign.Start)
  321. .width('10%')
  322. }
  323. .justifyContent(FlexAlign.Start)
  324. .borderRadius($r('app.float.virtualSize_16'))
  325. .height('70%')
  326. .backgroundColor($r('app.color.20FFFFFF'))
  327. .onClick(()=>{
  328. this.onSelectWorkHourRate(index)
  329. })
  330. }
  331. .width('29%')
  332. .height('100%')
  333. .alignItems(HorizontalAlign.Start)
  334. .margin({left:'2%',right:'2%'})
  335. Blank()
  336. if(index > 0) {
  337. Column(){
  338. Image($r('app.media.process_delete_seq'))
  339. .width($r('app.float.virtualSize_48'))
  340. .height($r('app.float.virtualSize_48'))
  341. .fillColor($r('app.color.FF453A'))
  342. .margin({top:'35%'})
  343. .onClick(()=>{
  344. this.reporterList.splice(index,1)
  345. })
  346. }
  347. .width('9%')
  348. .alignItems(HorizontalAlign.Center)
  349. .height('100%')
  350. }
  351. }
  352. .height('100%')
  353. .width('100%')
  354. }
  355. .height('40.7%')
  356. .width('100%')
  357. })
  358. }
  359. .width('100%')
  360. .height('87%')
  361. }
  362. .height('48.6%')
  363. .width('100%')
  364. .justifyContent(FlexAlign.Center)
  365. }
  366. .justifyContent(FlexAlign.Start)
  367. .alignItems(HorizontalAlign.Start)
  368. .width('96%')
  369. .height('82.7%')
  370. Column() {
  371. Divider()
  372. .vertical(false)
  373. .strokeWidth(1)
  374. .color($r('app.color.15FFFFFF'))
  375. Row() {
  376. Row() {
  377. Text('取消')
  378. .fontColor($r('app.color.60FFFFFF'))
  379. .fontSize($r('app.float.fontSize_30'))
  380. }
  381. .justifyContent(FlexAlign.Center)
  382. .width('50%')
  383. .onClick(() => this.controller.close())
  384. Divider()
  385. .vertical(true)
  386. .strokeWidth(1)
  387. .color($r('app.color.15FFFFFF'))
  388. Row() {
  389. Text('确认报工')
  390. .fontColor($r('app.color.007AFF'))
  391. .fontSize($r('app.float.fontSize_30'))
  392. }
  393. .justifyContent(FlexAlign.Center)
  394. .width('50%')
  395. .onClick(async () => {
  396. if (!this.process || !this.process.id) {
  397. promptAction.showToast({
  398. message: '请先工序开工',
  399. duration: 2000
  400. });
  401. return;
  402. }
  403. let rateTotal = 0
  404. for (const reporter of this.reporterList) {
  405. if (!reporter.workingHoursRate) {
  406. promptAction.showToast({
  407. message: `请给${reporter.userName!}选择用时占比`,
  408. duration: 2000
  409. });
  410. return;
  411. }
  412. rateTotal += reporter.workingHoursRate
  413. }
  414. if (rateTotal > 1) {
  415. promptAction.showToast({
  416. message: `用时占比超过100%,请修改`,
  417. duration: 2000
  418. });
  419. return;
  420. } else if (rateTotal < 1) {
  421. promptAction.showToast({
  422. message: `用时占比少于100%,请修改`,
  423. duration: 2000
  424. });
  425. return;
  426. }
  427. // 报工
  428. let seqNos: string [] = []
  429. if (this.bindTaskSeq[0].reportSeqNos) {
  430. seqNos = seqNos.concat(this.bindTaskSeq[0].reportSeqNos)
  431. }
  432. if (this.bindTaskSeq[0].defectSeqNos) {
  433. seqNos = seqNos.concat(this.bindTaskSeq[0].defectSeqNos)
  434. }
  435. if (seqNos.length <= 0) {
  436. promptAction.showToast({
  437. message: `请选择报工流水号或者不良流水号`,
  438. duration: 2000
  439. });
  440. return;
  441. }
  442. await ProcessRequest.post('/api/v1/process/info/reporting', {
  443. processId: this.process.id!,
  444. processUserReportList: this.reporterList,
  445. seqList: seqNos
  446. } as ProcessReportTimeBased)
  447. // 删除已报工的seqNo,并保存到数据库中
  448. let seqNoList: string[] = []
  449. seqNoList = await preferencesUtil.get(CommonConstants.PREFERENCE_INSTANCE_NAME, this.selectWorkOder.workOrderCode!, seqNoList)
  450. if (seqNoList.length === seqNos.length) {
  451. preferencesUtil.put(CommonConstants.PREFERENCE_INSTANCE_NAME, this.selectWorkOder.workOrderCode!, [])
  452. } else {
  453. seqNoList = seqNoList.filter(item => !seqNos.includes(item));
  454. await preferencesUtil.put(CommonConstants.PREFERENCE_INSTANCE_NAME, this.selectWorkOder.workOrderCode!, seqNoList)
  455. }
  456. this.clearSelectData()
  457. this.controller.close();
  458. })
  459. }
  460. }
  461. .width('100%')
  462. .height('7.3%')
  463. }
  464. .height('71%')
  465. .width('62%')
  466. .backgroundColor($r('app.color.2A2A2A'))
  467. .justifyContent(FlexAlign.End)
  468. .alignItems(HorizontalAlign.Center)
  469. .borderRadius($r('app.float.virtualSize_16'))
  470. }
  471. }