contract-detail.page.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. @Component({
  7. selector: 'app-contract-detail',
  8. templateUrl: './contract-detail.page.html',
  9. styleUrls: ['./contract-detail.page.scss'],
  10. })
  11. export class ContractDetailPage implements OnInit {
  12. defaultHref = '';
  13. contractDetailList=[]
  14. sscCode=''
  15. sscCreator=''
  16. scpModifiedtime=''
  17. sscId=''
  18. constructor(
  19. private camera: Camera,
  20. public commonService: commonService,
  21. private storage: Storage,
  22. public userData: UserData
  23. ) { }
  24. ngOnInit() {
  25. this.storage.get('sscId').then(async (val) => {
  26. if (val) {
  27. this.sscId = val
  28. let data = await this.userData.getContractDetail(val)
  29. if (JSON.parse(data).data.length !== 0) {
  30. this.sscCode = JSON.parse(data).data[0].scbCode
  31. this.scpModifiedtime = JSON.parse(data).data[0].scpModifiedtime
  32. this.contractDetailList = JSON.parse(data).data
  33. for (let i of this.contractDetailList) {
  34. i.imgsrc = i.pictures[0].smallPicture
  35. let data = await this.userData.getQAlog(val, i.pid)
  36. if (JSON.parse(data).data.length !== 0) {
  37. i.qalog = JSON.parse(data).data[0].mark
  38. i.imgUrl = JSON.parse(data).data[0].picture.split(",")[0]
  39. }
  40. }
  41. }
  42. }
  43. });
  44. }
  45. ionViewDidEnter() {
  46. this.defaultHref = `/contract-table`;
  47. }
  48. showFullScreenImage(data) {
  49. this.commonService.fullScreenImg(data)
  50. }
  51. takePicture(contract) {
  52. const options: CameraOptions = {
  53. quality: 10,
  54. destinationType: this.camera.DestinationType.DATA_URL,
  55. encodingType: this.camera.EncodingType.JPEG,
  56. mediaType: this.camera.MediaType.PICTURE
  57. }
  58. this.camera.getPicture(options).then((imageData) => {
  59. contract.showPicture = true
  60. contract.imgData = imageData
  61. contract.imgUrl = 'data:image/jpeg;base64,' + imageData
  62. }, (err) => {
  63. // Handle error
  64. console.log("Camera issue: " + err);
  65. });
  66. }
  67. deletePicture(contract) {
  68. contract.imgData = ''
  69. contract.showPicture = false
  70. }
  71. async saveDetail() {
  72. for(let i of this.contractDetailList) {
  73. if(i.qalog && i.imgData) {
  74. // let file = []
  75. // file.push(i.imgData)
  76. let form = {
  77. files: i.imgData,
  78. mark: i.qalog,
  79. pId: i.pid,
  80. sscId: this.sscId
  81. }
  82. await this.userData.contractQAlog(form)
  83. }
  84. }
  85. }
  86. }