store-qc-scanning.page.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. import { ActivatedRoute } from '@angular/router'
  9. import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';
  10. @Component({
  11. selector: 'app-store-qc-scanning',
  12. templateUrl: './store-qc-scanning.page.html',
  13. styleUrls: ['./store-qc-scanning.page.scss'],
  14. })
  15. export class StoreQCScanningPage implements OnInit {
  16. scanCode = ''
  17. storeQCList = []
  18. defaultHref = ''
  19. storeQCDetailList = []
  20. constructor(private router: Router,
  21. private barcodeScanner: BarcodeScanner,
  22. private activeRoute: ActivatedRoute,
  23. public commonService: commonService,
  24. private storage: Storage,
  25. public userData: UserData,
  26. private camera: Camera,
  27. private keyboard: Keyboard) { }
  28. @ViewChild('scanInput') scanInput;
  29. ngOnInit() {
  30. this.storage.get('storeQCList').then(async (val) => {
  31. if (val) {
  32. this.storeQCList = JSON.parse(val)
  33. }
  34. })
  35. }
  36. ionViewDidEnter() {
  37. this.activeRoute.paramMap.subscribe(params => {
  38. if (params['params'].sscId && params['params'].pId) {
  39. this.scanCode = params['params'].sscId + '_' + params['params'].pId
  40. this.defaultHref = '/store-pending'
  41. } else {
  42. this.scanCode = ''
  43. }
  44. // this.product = products[+params.get('productId')];
  45. });
  46. // this.initialData()
  47. }
  48. ionViewDidLeave() {
  49. if (this.storeQCList.length !== 0) {
  50. this.storage.set('storeQCList', JSON.stringify(this.storeQCList))
  51. } else {
  52. this.storage.remove('storeQCList')
  53. }
  54. }
  55. initialData() {
  56. this.storeQCDetailList = []
  57. this.scanInput.setFocus();
  58. // this.storage.get('store-pending').then(async (val) => {
  59. // if(val) {
  60. // this.scanCode = val.sscId + '_' +val.pid
  61. // this.defaultHref = '/store-pending'
  62. // } else {
  63. // this.defaultHref = ''
  64. // }
  65. // })
  66. this.scanCode = ''
  67. }
  68. showFullScreenImage(data) {
  69. this.commonService.fullScreenImg(data)
  70. }
  71. // 获取扫描详情
  72. async getStoreQCDetail(item?) {
  73. this.storeQCDetailList = []
  74. this.keyboard.hide()
  75. if (item) {
  76. this.scanCode = item.scanCode
  77. this.storeQCDetailList = item
  78. } else {
  79. if (this.scanCode.split('_').length === 2) {
  80. let filterData = []
  81. filterData = this.storeQCList.filter(item => { return item.sscId == this.scanCode.split('_')[0] && item.pid == this.scanCode.split('_')[1] })
  82. if (filterData.length !== 0) {
  83. this.storeQCDetailList = filterData
  84. } else {
  85. let data = await this.userData.getQCDetail(Number(this.scanCode.split('_')[0]), Number(this.scanCode.split('_')[1]))
  86. this.storeQCDetailList = new Array(data)
  87. }
  88. for (let i of this.storeQCDetailList) {
  89. i.qaimgList = []
  90. i.qcimgList = []
  91. i['qcIdList'] = []
  92. // 获取QA日志
  93. let qalogdata = await this.userData.getQAlog(i.sscId, i.pid)
  94. if (JSON.parse(qalogdata).data.length !== 0) {
  95. i.qalog = JSON.parse(qalogdata).data[0].mark
  96. i.qaimgList = JSON.parse(qalogdata).data[0].picture.split(",")
  97. }
  98. let qclogdata = await this.userData.getQClog(i.sscId, i.pid)
  99. if (JSON.parse(qclogdata).data.length !== 0) {
  100. for (let j of JSON.parse(qclogdata).data) {
  101. i['qcIdList'].push(j.id) // qc记录的id数组
  102. }
  103. i.qclog = JSON.parse(qclogdata).data[0].mark
  104. i.qcimgList = JSON.parse(qclogdata).data[0].picture.split(",")
  105. i.imageData = JSON.parse(qclogdata).data[0].picture
  106. // i.qcimgUrl = JSON.parse(qclogdata).data[0].picture.split(",")[0]
  107. }
  108. // 处理意见转换boolean(无deal)
  109. if (i.deal === undefined) {
  110. if (i.dealpropose == 1) {
  111. i.deal = true
  112. } else {
  113. i.deal = false
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120. // 生成QC验货初检报告
  121. async generateQC() {
  122. for (let i of this.storeQCList) {
  123. if (i.deal) {
  124. i.dealpropose = 1
  125. } else {
  126. i.dealpropose = 0
  127. }
  128. }
  129. await this.userData.createQC(this.storeQCList)
  130. this.initialData()
  131. this.storage.remove('storeQCList')
  132. this.storeQCList = []
  133. }
  134. // 记录数据
  135. async saveQCRecord() {
  136. // 是否已扫描记录过该数据
  137. let filterData = []
  138. filterData = this.storeQCList.filter(item => {
  139. return item.sscId == this.storeQCDetailList[0].sscId && item.pid == this.storeQCDetailList[0].pid
  140. })
  141. // 有则更新
  142. if (filterData.length !== 0) {
  143. filterData = this.storeQCDetailList
  144. // 无则加上
  145. } else {
  146. this.storeQCList = this.storeQCList.concat(this.storeQCDetailList)
  147. }
  148. // 显示记录中的外销合同号
  149. // this.scpCodes = []
  150. for (let i of this.storeQCList) {
  151. if (!i.scanCode) {
  152. i.scanCode = this.scanCode // 无scancode则加上
  153. }
  154. // this.scpCodes.push(i.scpCode)
  155. }
  156. this.addQClog()
  157. this.initialData()
  158. }
  159. // 添加qc记录
  160. async addQClog() {
  161. for (let i of this.storeQCDetailList) {
  162. for (let j of i['qcIdList']) {
  163. this.userData.deleteSampleQc(j)
  164. }
  165. if (i.qclog && i.imageData) {
  166. let form = {
  167. files: i.imageData,
  168. mark: i.qclog,
  169. pId: i.pid,
  170. sscId: i.sscId
  171. }
  172. await this.userData.addQClog(form)
  173. }
  174. }
  175. }
  176. takePicture(qc) {
  177. const options: CameraOptions = {
  178. quality: 100,
  179. destinationType: this.camera.DestinationType.DATA_URL,
  180. encodingType: this.camera.EncodingType.PNG,
  181. mediaType: this.camera.MediaType.PICTURE,
  182. targetWidth: 1500,
  183. targetHeight: 1125
  184. }
  185. this.camera.getPicture(options).then((imageData) => {
  186. qc.qcimgList.push(
  187. 'data:image/png;base64,' + imageData
  188. )
  189. if (qc.imageData) {
  190. qc.imageData = qc.imageData + ',' + imageData
  191. } else {
  192. qc.imageData = '' + imageData
  193. }
  194. }, (err) => {
  195. // Handle error
  196. console.log("Camera issue: " + err);
  197. });
  198. }
  199. qrscan() {
  200. this.barcodeScanner.scan().then(barcodeData => {
  201. this.scanCode = barcodeData.text
  202. }).catch(err => {
  203. console.log('Error', err);
  204. });
  205. }
  206. deletePicture(qc, index) {
  207. qc.qcimgList.splice(index, 1)
  208. let arr = qc.imageData.split(',')
  209. arr.splice(qc,1)
  210. qc.imageData = arr.toString()
  211. }
  212. deleteQCStore(store, index) {
  213. this.storeQCList.splice(index, 1)
  214. }
  215. }