store-qc-scanning.page.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. this.storage.get('store-pending').then(async (val) => {
  34. if(val) {
  35. this.scanCode = val.sscId + '_' +val.pid
  36. }
  37. this.storage.remove('store-pending')
  38. })
  39. }
  40. showFullScreenImage(url) {
  41. this.commonService.fullScreenImg(url)
  42. }
  43. // 获取扫描详情
  44. async getStoreQCDetail(item) {
  45. this.keyboard.hide()
  46. if (item) {
  47. this.scanCode = item.scanCode
  48. this.storeQCDetailList = item
  49. } else {
  50. if (this.scanCode.split('_').length === 2) {
  51. let filterData = []
  52. filterData = this.storeQCList.filter(item => { return item.sscId == this.scanCode.split('_')[0] && item.pid == this.scanCode.split('_')[1] })
  53. if (filterData.length !== 0) {
  54. this.storeQCDetailList = filterData
  55. } else {
  56. let data = await this.userData.getQCDetail(Number(this.scanCode.split('_')[0]), Number(this.scanCode.split('_')[1]))
  57. this.storeQCDetailList = new Array(data)
  58. }
  59. for (let i of this.storeQCDetailList) {
  60. // 获取QA日志
  61. let qalogdata = await this.userData.getQAlog(i.sscId, i.pid)
  62. if (JSON.parse(qalogdata).data.length !== 0) {
  63. i.qalog = JSON.parse(qalogdata).data[0].mark
  64. i.qaimgUrl = JSON.parse(qalogdata).data[0].picture.split(",")[0]
  65. }
  66. let qclogdata = await this.userData.getQClog(i.sscId, i.pid)
  67. if (JSON.parse(qclogdata).data.length !== 0) {
  68. i.qclog = JSON.parse(qclogdata).data[0].mark
  69. i.qcimgUrl = JSON.parse(qclogdata).data[0].picture.split(",")[0]
  70. }
  71. // 处理意见转换boolean
  72. if (i.dealpropose == 1) {
  73. i.deal = true
  74. } else {
  75. i.deal = false
  76. }
  77. }
  78. }
  79. }
  80. }
  81. // 生成QC验货初检报告
  82. async generateQC() {
  83. for (let i of this.storeQCList) {
  84. if (i.deal) {
  85. i.dealpropose = 1
  86. } else {
  87. i.dealpropose = 0
  88. }
  89. }
  90. await this.userData.createQC(this.storeQCList)
  91. }
  92. // 记录数据
  93. async saveQCRecord() {
  94. let _this = this
  95. // 是否已扫描记录过该数据
  96. let filterData = []
  97. filterData = this.storeQCList.filter(item => {
  98. return item.sscId == this.storeQCDetailList[0].sscId && item.pid == this.storeQCDetailList[0].pid
  99. })
  100. // 有则更新
  101. if (filterData.length !== 0) {
  102. filterData = this.storeQCDetailList
  103. // 无则加上
  104. } else {
  105. this.storeQCList = this.storeQCList.concat(this.storeQCDetailList)
  106. }
  107. // 显示记录中的外销合同号
  108. // this.scpCodes = []
  109. for (let i of this.storeQCList) {
  110. i.scanCode = this.scanCode
  111. // this.scpCodes.push(i.scpCode)
  112. }
  113. this.addQClog()
  114. this.initialData()
  115. }
  116. // 添加qc记录
  117. async addQClog() {
  118. for (let i of this.storeQCDetailList) {
  119. // console.log(i)
  120. if (i.qclog && i.imgData) {
  121. // let file = []
  122. // file.push(i.imgData)
  123. let form = {
  124. files: i.imgData,
  125. mark: i.qclog,
  126. pId: i.pid,
  127. sscId: i.sscId
  128. }
  129. await this.userData.addQClog(form)
  130. }
  131. }
  132. }
  133. takePicture(qc) {
  134. const options: CameraOptions = {
  135. quality: 10,
  136. destinationType: this.camera.DestinationType.DATA_URL,
  137. encodingType: this.camera.EncodingType.JPEG,
  138. mediaType: this.camera.MediaType.PICTURE
  139. }
  140. this.camera.getPicture(options).then((imageData) => {
  141. // console.log(imageData)
  142. qc.imgData = imageData
  143. qc.qcimgUrl = 'data:image/jpeg;base64,' + imageData
  144. }, (err) => {
  145. // Handle error
  146. console.log("Camera issue: " + err);
  147. });
  148. }
  149. deletePicture(qc) {
  150. qc.imgData = ''
  151. qc.qcimgUrl = ''
  152. }
  153. deleteQCStore(store, index) {
  154. this.storeQCList.splice(index)
  155. }
  156. }