store-qc-detail.page.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { Component, OnInit } from '@angular/core';
  2. import { Storage } from '@ionic/storage'
  3. import { UserData } from '../../providers/user-data';
  4. import { Camera, CameraOptions } from '@ionic-native/camera/ngx';
  5. import { commonService } from '../../providers/common.service'
  6. // import { FullScreenImage } from '@ionic-native/full-screen-image/ngx';
  7. // import { PopoverController } from '@ionic/angular'
  8. // import { PopoverPage } from '../qc-popover/qc-popover';
  9. @Component({
  10. selector: 'app-store-qc-detail',
  11. templateUrl: './store-qc-detail.page.html',
  12. styleUrls: ['./store-qc-detail.page.scss'],
  13. })
  14. export class StoreQCDetailPage implements OnInit {
  15. defaultHref = ""
  16. qcData = {
  17. details: []
  18. }
  19. QCdetails = {
  20. details: []
  21. }
  22. pId = ''
  23. sscId = ''
  24. showDetail: boolean = true
  25. constructor(private storage: Storage,
  26. public commonService: commonService,
  27. // private fullScreenImage: FullScreenImage,
  28. // public popoverCtrl: PopoverController,
  29. private camera: Camera,
  30. public userData: UserData) { }
  31. ngOnInit() {
  32. this.showDetail = true
  33. this.storage.get('QCdetails').then((val) => {
  34. this.QCdetails = JSON.parse(val)
  35. });
  36. this.storage.get('qc-pId').then((val) => {
  37. this.pId = val
  38. });
  39. this.storage.get('qc-sscId').then((val) => {
  40. this.sscId = val
  41. });
  42. }
  43. ionViewDidEnter() {
  44. // console.log(this.fullScreenImage)
  45. this.getDetail()
  46. }
  47. showFullScreenImage(data) {
  48. this.commonService.fullScreenImg(data)
  49. }
  50. async getDetail() {
  51. if (this.QCdetails) {
  52. this.qcData = this.QCdetails
  53. for (let i of this.qcData['details']) {
  54. this.showDetail = false
  55. // 获取QA日志
  56. i.qaimgList = []
  57. i.qcimgList = []
  58. i['qcIdList'] = []
  59. let qalogdata = await this.userData.getQAlog(i.sscId, i.pid)
  60. if (JSON.parse(qalogdata).data.length !== 0) {
  61. i.qalog = JSON.parse(qalogdata).data[0].mark
  62. i.qaimgList = JSON.parse(qalogdata).data[0].picture.split(",")
  63. }
  64. let qclogdata = await this.userData.getQClog(i.sscId, i.pid)
  65. if (JSON.parse(qclogdata).data.length !== 0) {
  66. for (let j of JSON.parse(qclogdata).data) {
  67. i['qcIdList'].push(j.id) // qc记录的id数组
  68. }
  69. i.qclog = JSON.parse(qclogdata).data[0].mark
  70. i.qcimgList = JSON.parse(qclogdata).data[0].picture.split(",")
  71. i.imageData = JSON.parse(qclogdata).data[0].picture
  72. }
  73. // 处理意见转换boolean
  74. if (i.dealpropose == 1) {
  75. i.deal = true
  76. } else {
  77. i.deal = false
  78. }
  79. }
  80. this.defaultHref = `/store-qc`;
  81. }
  82. // if (this.pId && this.sscId) {
  83. // let data = await this.userData.getQCDetail(this.pId, this.sscId)
  84. // this.defaultHref = `/store-qc-scanning`;
  85. // this.qcData['details'] = new Array(data)
  86. // }
  87. }
  88. takePicture(qc) {
  89. const options: CameraOptions = {
  90. quality: 100,
  91. destinationType: this.camera.DestinationType.DATA_URL,
  92. encodingType: this.camera.EncodingType.PNG,
  93. mediaType: this.camera.MediaType.PICTURE,
  94. targetWidth: 1500,
  95. targetHeight: 1125
  96. }
  97. this.camera.getPicture(options).then((imageData) => {
  98. qc.qcimgList.push(
  99. 'data:image/png;base64,' + imageData
  100. )
  101. if (qc.imageData) {
  102. qc.imageData = qc.imageData + ',' + imageData
  103. } else {
  104. qc.imageData = '' + imageData
  105. }
  106. }, (err) => {
  107. // Handle error
  108. console.log("Camera issue: " + err);
  109. });
  110. }
  111. deletePicture(qc, index) {
  112. qc.qcimgList.splice(index, 1)
  113. let arr = qc.imageData.split(',')
  114. arr.splice(qc, 1)
  115. qc.imageData = arr.toString()
  116. }
  117. // async presentPopover(event: Event) {
  118. // const popover = await this.popoverCtrl.create({
  119. // component: PopoverPage,
  120. // event: event,
  121. // translucent: true
  122. // });
  123. // return await popover.present();
  124. // }
  125. async createQC() {
  126. await this.userData.createQC(this.qcData['details'])
  127. }
  128. async addQClog() {
  129. for (let i of this.qcData['details']) {
  130. for (let j of i['qcIdList']) {
  131. this.userData.deleteSampleQc(j)
  132. }
  133. if (i.qclog && i.imageData) {
  134. let form = {
  135. files: i.imageData,
  136. mark: i.qclog,
  137. pId: i.pid,
  138. sscId: i.sscId
  139. }
  140. await this.userData.addQClog(form)
  141. }
  142. }
  143. }
  144. }