123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- 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';
- import { ActivatedRoute } from '@angular/router'
- import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';
- @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 = []
- defaultHref = ''
- storeQCDetailList = []
- constructor(private router: Router,
- private barcodeScanner: BarcodeScanner,
- private activeRoute: ActivatedRoute,
- public commonService: commonService,
- private storage: Storage,
- public userData: UserData,
- private camera: Camera,
- private keyboard: Keyboard) { }
- @ViewChild('scanInput') scanInput;
- ngOnInit() {
- this.storage.get('storeQCList').then(async (val) => {
- if (val) {
- this.storeQCList = JSON.parse(val)
- }
- })
- }
- ionViewDidEnter() {
- this.activeRoute.paramMap.subscribe(params => {
- if (params['params'].sscId && params['params'].pId) {
- this.scanCode = params['params'].sscId + '_' + params['params'].pId
- this.defaultHref = '/store-pending'
- } else {
- this.scanCode = ''
- }
- // this.product = products[+params.get('productId')];
- });
- // this.initialData()
- }
- ionViewDidLeave() {
- if (this.storeQCList.length !== 0) {
- this.storage.set('storeQCList', JSON.stringify(this.storeQCList))
- } else {
- this.storage.remove('storeQCList')
- }
- }
- initialData() {
- this.storeQCDetailList = []
- this.scanInput.setFocus();
- // this.storage.get('store-pending').then(async (val) => {
- // if(val) {
- // this.scanCode = val.sscId + '_' +val.pid
- // this.defaultHref = '/store-pending'
- // } else {
- // this.defaultHref = ''
- // }
- // })
- this.scanCode = ''
- }
- showFullScreenImage(data) {
- this.commonService.fullScreenImg(data)
- }
- // 获取扫描详情
- async getStoreQCDetail(item?) {
- this.storeQCDetailList = []
- 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) {
- i.qaimgList = []
- i.qcimgList = []
- i['qcIdList'] = []
- // 获取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.qaimgList = JSON.parse(qalogdata).data[0].picture.split(",")
- }
- let qclogdata = await this.userData.getQClog(i.sscId, i.pid)
- if (JSON.parse(qclogdata).data.length !== 0) {
- for (let j of JSON.parse(qclogdata).data) {
- i['qcIdList'].push(j.id) // qc记录的id数组
- }
- i.qclog = JSON.parse(qclogdata).data[0].mark
- i.qcimgList = JSON.parse(qclogdata).data[0].picture.split(",")
- i.imageData = JSON.parse(qclogdata).data[0].picture
- // i.qcimgUrl = JSON.parse(qclogdata).data[0].picture.split(",")[0]
- }
- // 处理意见转换boolean(无deal)
- if (i.deal === undefined) {
- 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)
- this.initialData()
- this.storage.remove('storeQCList')
- this.storeQCList = []
- }
- // 记录数据
- async saveQCRecord() {
- // 是否已扫描记录过该数据
- 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) {
- if (!i.scanCode) {
- i.scanCode = this.scanCode // 无scancode则加上
- }
- // this.scpCodes.push(i.scpCode)
- }
- this.addQClog()
- this.initialData()
- }
- // 添加qc记录
- async addQClog() {
- for (let i of this.storeQCDetailList) {
- for (let j of i['qcIdList']) {
- this.userData.deleteSampleQc(j)
- }
- if (i.qclog && i.imageData) {
- let form = {
- files: i.imageData,
- mark: i.qclog,
- pId: i.pid,
- sscId: i.sscId
- }
- await this.userData.addQClog(form)
- }
- }
- }
- takePicture(qc) {
- const options: CameraOptions = {
- quality: 100,
- destinationType: this.camera.DestinationType.DATA_URL,
- encodingType: this.camera.EncodingType.PNG,
- mediaType: this.camera.MediaType.PICTURE,
- targetWidth: 1500,
- targetHeight: 1125
- }
- this.camera.getPicture(options).then((imageData) => {
- qc.qcimgList.push(
- 'data:image/png;base64,' + imageData
- )
- if (qc.imageData) {
- qc.imageData = qc.imageData + ',' + imageData
- } else {
- qc.imageData = '' + imageData
- }
- }, (err) => {
- // Handle error
- console.log("Camera issue: " + err);
- });
- }
- qrscan() {
- this.barcodeScanner.scan().then(barcodeData => {
- this.scanCode = barcodeData.text
- }).catch(err => {
- console.log('Error', err);
- });
- }
- deletePicture(qc, index) {
- qc.qcimgList.splice(index, 1)
- let arr = qc.imageData.split(',')
- arr.splice(qc,1)
- qc.imageData = arr.toString()
- }
- deleteQCStore(store, index) {
- this.storeQCList.splice(index, 1)
- }
- }
|