store-qc-scanning.page.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { Component, OnInit, ViewChild } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { Storage } from '@ionic/storage'
  4. import { Keyboard } from '@ionic-native/keyboard/ngx';
  5. import { UserData } from '../../providers/user-data';
  6. import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
  7. import { commonService } from '../../providers/common.service'
  8. @Component({
  9. selector: 'app-store-qc-scanning',
  10. templateUrl: './store-qc-scanning.page.html',
  11. styleUrls: ['./store-qc-scanning.page.scss'],
  12. })
  13. export class StoreQCScanningPage implements OnInit {
  14. scanCode = ''
  15. storeQCList = []
  16. storeQCDetailList = []
  17. constructor(private router: Router,
  18. public commonService: commonService,
  19. private storage: Storage,
  20. public userData: UserData,
  21. private camera: Camera,
  22. private keyboard: Keyboard) { }
  23. @ViewChild('scanInput') scanInput;
  24. ngOnInit() {
  25. }
  26. ionViewDidEnter() {
  27. this.initialData()
  28. }
  29. initialData() {
  30. this.storeQCDetailList = []
  31. this.scanCode = ''
  32. this.scanInput.setFocus();
  33. }
  34. showFullScreenImage(url) {
  35. this.commonService.fullScreenImg(url)
  36. }
  37. // 获取扫描详情
  38. async getStoreQCDetail(item) {
  39. this.keyboard.hide()
  40. if (item) {
  41. this.scanCode = item.scanCode
  42. this.storeQCDetailList = item
  43. } else {
  44. if (this.scanCode.split('_').length === 2) {
  45. let filterData = []
  46. filterData = this.storeQCList.filter(item => { return item.sscId == this.scanCode.split('_')[0] && item.pid == this.scanCode.split('_')[1] })
  47. if (filterData.length !== 0) {
  48. this.storeQCDetailList = filterData
  49. } else {
  50. let data = await this.userData.getQCDetail(Number(this.scanCode.split('_')[0]), Number(this.scanCode.split('_')[1]))
  51. this.storeQCDetailList = new Array(data)
  52. }
  53. for (let i of this.storeQCDetailList) {
  54. // 获取QA日志
  55. let qalogdata = await this.userData.getQAlog(i.sscId, i.pid)
  56. if (JSON.parse(qalogdata).data.length !== 0) {
  57. i.qalog = JSON.parse(qalogdata).data[0].mark
  58. i.qaimgUrl = JSON.parse(qalogdata).data[0].picture.split(",")[0]
  59. }
  60. let qclogdata = await this.userData.getQClog(i.sscId, i.pid)
  61. if (JSON.parse(qclogdata).data.length !== 0) {
  62. i.qclog = JSON.parse(qclogdata).data[0].mark
  63. i.qcimgUrl = JSON.parse(qclogdata).data[0].picture.split(",")[0]
  64. }
  65. // 处理意见转换boolean
  66. if (i.dealpropose == 1) {
  67. i.deal = true
  68. } else {
  69. i.deal = false
  70. }
  71. }
  72. }
  73. }
  74. }
  75. // 生成QC验货初检报告
  76. async generateQC() {
  77. for (let i of this.storeQCList) {
  78. if (i.deal) {
  79. i.dealpropose = 1
  80. } else {
  81. i.dealpropose = 0
  82. }
  83. }
  84. await this.userData.createQC(this.storeQCList)
  85. }
  86. // 记录数据
  87. async saveQCRecord() {
  88. let _this = this
  89. // 是否已扫描记录过该数据
  90. let filterData = []
  91. filterData = this.storeQCList.filter(item => {
  92. return item.sscId == this.storeQCDetailList[0].sscId && item.pid == this.storeQCDetailList[0].pid
  93. })
  94. // 有则更新
  95. if (filterData.length !== 0) {
  96. filterData = this.storeQCDetailList
  97. // 无则加上
  98. } else {
  99. this.storeQCList = this.storeQCList.concat(this.storeQCDetailList)
  100. }
  101. // 显示记录中的外销合同号
  102. // this.scpCodes = []
  103. for (let i of this.storeQCList) {
  104. i.scanCode = this.scanCode
  105. // this.scpCodes.push(i.scpCode)
  106. }
  107. this.addQClog()
  108. this.initialData()
  109. }
  110. // 添加qc记录
  111. async addQClog() {
  112. for (let i of this.storeQCDetailList) {
  113. // console.log(i)
  114. if (i.qclog && i.imgData) {
  115. // let file = []
  116. // file.push(i.imgData)
  117. let form = {
  118. files: i.imgData,
  119. mark: i.qclog,
  120. pId: i.pid,
  121. sscId: i.sscId
  122. }
  123. await this.userData.addQClog(form)
  124. }
  125. }
  126. }
  127. takePicture(qc) {
  128. const options: CameraOptions = {
  129. quality: 10,
  130. destinationType: this.camera.DestinationType.DATA_URL,
  131. encodingType: this.camera.EncodingType.JPEG,
  132. mediaType: this.camera.MediaType.PICTURE
  133. }
  134. this.camera.getPicture(options).then((imageData) => {
  135. // console.log(imageData)
  136. qc.imgData = imageData
  137. qc.qcimgUrl = 'data:image/jpeg;base64,' + imageData
  138. }, (err) => {
  139. // Handle error
  140. console.log("Camera issue: " + err);
  141. });
  142. }
  143. deletePicture(qc) {
  144. qc.imgData = ''
  145. qc.qcimgUrl = ''
  146. }
  147. deleteQCStore(store, index) {
  148. this.storeQCList.splice(index)
  149. }
  150. }