import { Component, OnInit, ViewChild } from '@angular/core'; import { Router } from '@angular/router'; import { Storage } from '@ionic/storage' import { Keyboard } from '@ionic-native/keyboard/ngx'; import { UserData } from '../../providers/user-data'; import { Camera, CameraOptions } from '@ionic-native/camera/ngx'; import { commonService } from '../../providers/common.service' @Component({ selector: 'app-store-qc-scanning', templateUrl: './store-qc-scanning.page.html', styleUrls: ['./store-qc-scanning.page.scss'], }) export class StoreQCScanningPage implements OnInit { scanCode = '' storeQCList = [] storeQCDetailList = [] constructor(private router: Router, public commonService: commonService, private storage: Storage, public userData: UserData, private camera: Camera, private keyboard: Keyboard) { } @ViewChild('scanInput') scanInput; ngOnInit() { } ionViewDidEnter() { this.initialData() } initialData() { this.storeQCDetailList = [] this.scanCode = '' this.scanInput.setFocus(); } showFullScreenImage(url) { this.commonService.fullScreenImg(url) } // 获取扫描详情 async getStoreQCDetail(item) { this.keyboard.hide() if (item) { this.scanCode = item.scanCode this.storeQCDetailList = item } else { if (this.scanCode.split('_').length === 2) { let filterData = [] filterData = this.storeQCList.filter(item => { return item.sscId == this.scanCode.split('_')[0] && item.pid == this.scanCode.split('_')[1] }) if (filterData.length !== 0) { this.storeQCDetailList = filterData } else { let data = await this.userData.getQCDetail(Number(this.scanCode.split('_')[0]), Number(this.scanCode.split('_')[1])) this.storeQCDetailList = new Array(data) } for (let i of this.storeQCDetailList) { // 获取QA日志 let qalogdata = await this.userData.getQAlog(i.sscId, i.pid) if (JSON.parse(qalogdata).data.length !== 0) { i.qalog = JSON.parse(qalogdata).data[0].mark i.qaimgUrl = JSON.parse(qalogdata).data[0].picture.split(",")[0] } let qclogdata = await this.userData.getQClog(i.sscId, i.pid) if (JSON.parse(qclogdata).data.length !== 0) { i.qclog = JSON.parse(qclogdata).data[0].mark i.qcimgUrl = JSON.parse(qclogdata).data[0].picture.split(",")[0] } // 处理意见转换boolean if (i.dealpropose == 1) { i.deal = true } else { i.deal = false } } } } } // 生成QC验货初检报告 async generateQC() { for (let i of this.storeQCList) { if (i.deal) { i.dealpropose = 1 } else { i.dealpropose = 0 } } await this.userData.createQC(this.storeQCList) } // 记录数据 async saveQCRecord() { let _this = this // 是否已扫描记录过该数据 let filterData = [] filterData = this.storeQCList.filter(item => { return item.sscId == this.storeQCDetailList[0].sscId && item.pid == this.storeQCDetailList[0].pid }) // 有则更新 if (filterData.length !== 0) { filterData = this.storeQCDetailList // 无则加上 } else { this.storeQCList = this.storeQCList.concat(this.storeQCDetailList) } // 显示记录中的外销合同号 // this.scpCodes = [] for (let i of this.storeQCList) { i.scanCode = this.scanCode // this.scpCodes.push(i.scpCode) } this.addQClog() this.initialData() } // 添加qc记录 async addQClog() { for (let i of this.storeQCDetailList) { // console.log(i) if (i.qclog && i.imgData) { // let file = [] // file.push(i.imgData) let form = { files: i.imgData, mark: i.qclog, pId: i.pid, sscId: i.sscId } await this.userData.addQClog(form) } } } takePicture(qc) { const options: CameraOptions = { quality: 10, destinationType: this.camera.DestinationType.DATA_URL, encodingType: this.camera.EncodingType.JPEG, mediaType: this.camera.MediaType.PICTURE } this.camera.getPicture(options).then((imageData) => { // console.log(imageData) qc.imgData = imageData qc.qcimgUrl = 'data:image/jpeg;base64,' + imageData }, (err) => { // Handle error console.log("Camera issue: " + err); }); } deletePicture(qc) { qc.imgData = '' qc.qcimgUrl = '' } deleteQCStore(store, index) { this.storeQCList.splice(index) } }