store-qc-detail.page.ts 5.2 KB

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