|
@@ -0,0 +1,174 @@
|
|
|
+import { Component, OnInit, ViewChild } from '@angular/core';
|
|
|
+import { Storage } from '@ionic/storage'
|
|
|
+import { UserData } from '../../providers/user-data';
|
|
|
+import { NgForm } from '@angular/forms';
|
|
|
+import { Keyboard } from '@ionic-native/keyboard/ngx';
|
|
|
+import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';
|
|
|
+import { Device } from '@ionic-native/device/ngx'
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'app-es-apply-scan',
|
|
|
+ templateUrl: './es-apply-scan.page.html',
|
|
|
+ styleUrls: ['./es-apply-scan.page.scss'],
|
|
|
+})
|
|
|
+export class EsApplyScanPage implements OnInit {
|
|
|
+
|
|
|
+ esStoreDetailList = []
|
|
|
+ clicked = false
|
|
|
+ esStoreList = [
|
|
|
+ ]
|
|
|
+ scpCodes = []
|
|
|
+ scanCode: string
|
|
|
+ pId: number
|
|
|
+ sscId: number
|
|
|
+ entergoodsCode: any
|
|
|
+ constructor(
|
|
|
+ private device: Device,
|
|
|
+ private storage: Storage,
|
|
|
+ private barcodeScanner: BarcodeScanner,
|
|
|
+ public userData: UserData,
|
|
|
+ private keyboard: Keyboard) { }
|
|
|
+
|
|
|
+ @ViewChild('scanInput') scanInput;
|
|
|
+ ngOnInit() {
|
|
|
+ this.storage.get('esStoreList').then(async (val) => {
|
|
|
+ if (val) {
|
|
|
+ this.esStoreList = JSON.parse(val)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 进入页面
|
|
|
+ ionViewDidEnter() {
|
|
|
+ // 已打开键盘状态,切换另外input,不会再次进入此事件,故需hideKeyboard事件来隐藏键盘
|
|
|
+ window['keyboard'] = this.keyboard
|
|
|
+ window.addEventListener('keyboardDidShow', this.ifHideKeyboard)
|
|
|
+ this.initialData()
|
|
|
+ }
|
|
|
+
|
|
|
+ ifHideKeyboard() {
|
|
|
+ if (window['keyboardVisible'] === false) {
|
|
|
+ window['keyboard'].hide()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ionViewWillLeave() {
|
|
|
+ window.removeEventListener('keyboardDidShow', this.ifHideKeyboard)
|
|
|
+ }
|
|
|
+
|
|
|
+ ionViewDidLeave() {
|
|
|
+ if (this.esStoreList.length !== 0) {
|
|
|
+ this.storage.set('esStoreList', JSON.stringify(this.esStoreList))
|
|
|
+ } else {
|
|
|
+ this.storage.remove('esStoreList')
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ hideKeyboard() {
|
|
|
+ // 收缩键盘后还是聚焦状态,不会进入此事件,需监听事件来隐藏键盘
|
|
|
+ if (this.device.version == '6' || this.device.version == '6.0' || this.device.version == '6.0.0') {
|
|
|
+ window['keyboardVisible'] = false
|
|
|
+ setTimeout(() => {
|
|
|
+ this.keyboard.hide()
|
|
|
+ }, 300)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // enterEdit(e, key, index) {
|
|
|
+ // e.preventDefault()
|
|
|
+ // let keycode = window.event ? e.keyCode : e.which;
|
|
|
+ // if (keycode == 13) {
|
|
|
+ // e.preventDefault();
|
|
|
+ // this[key].setFocus();
|
|
|
+ // if(key==='complete') {
|
|
|
+ // this.saveRecord(this.esStoreDetailList[index])
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 显示键盘
|
|
|
+ showKeyboard() {
|
|
|
+ window['keyboardVisible'] = true
|
|
|
+ }
|
|
|
+
|
|
|
+ // 隐藏键盘
|
|
|
+ initialData() {
|
|
|
+ this.esStoreDetailList = []
|
|
|
+ this.clicked = false
|
|
|
+ this.scanCode = ''
|
|
|
+ this.scanInput.setFocus();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取入库单详情
|
|
|
+ async getStoreDetail(item?) {
|
|
|
+ console.log('detail')
|
|
|
+ if (item) {
|
|
|
+ this.scanCode = item.scanCode
|
|
|
+ this.esStoreDetailList = new Array(item)
|
|
|
+ } else {
|
|
|
+ if (this.scanCode) {
|
|
|
+ let filterData = []
|
|
|
+ filterData = this.esStoreList.filter(item => {
|
|
|
+ return item.scanCode === this.scanCode
|
|
|
+ })
|
|
|
+ if (filterData.length === 0) {
|
|
|
+ let data = await this.userData.getAppStoreDetail(this.scanCode)
|
|
|
+ this.esStoreDetailList.push({
|
|
|
+ scanCode: this.scanCode,
|
|
|
+ detailList: data.data
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.esStoreDetailList = filterData
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 记录数据
|
|
|
+ async saveRecord(form: NgForm) {
|
|
|
+ this.clicked = true
|
|
|
+ // if (form.valid) {
|
|
|
+ // 是否已扫描记录过该数据
|
|
|
+ let filterData = []
|
|
|
+ filterData = this.esStoreList.filter(item => {
|
|
|
+ return item.scanCode === this.esStoreDetailList[0].scanCode
|
|
|
+ })
|
|
|
+ // 有则更新
|
|
|
+ if (filterData.length !== 0) {
|
|
|
+ filterData = this.esStoreDetailList
|
|
|
+ // 无则加上
|
|
|
+ } else {
|
|
|
+ this.esStoreList = this.esStoreList.concat(this.esStoreDetailList)
|
|
|
+ }
|
|
|
+ // 显示记录中的外销合同号
|
|
|
+ for (let i of this.esStoreList) {
|
|
|
+ for (let j of i.detailList) {
|
|
|
+ j.enterCount = Number(j.enterBoxs) * Number(j.scpOutrate)
|
|
|
+ j.amount = j.enterCount
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.storage.set('esStoreList', JSON.stringify(this.esStoreList))
|
|
|
+ this.initialData()
|
|
|
+ // }
|
|
|
+ }
|
|
|
+
|
|
|
+ deleteStore(_store, index) {
|
|
|
+ this.esStoreList.splice(index)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存并生成货号
|
|
|
+ async saveStore() {
|
|
|
+ for (let i of this.esStoreList) {
|
|
|
+ await this.userData.saveStoreDetail(i.detailList)
|
|
|
+ }
|
|
|
+ this.initialData()
|
|
|
+ this.esStoreList = []
|
|
|
+ }
|
|
|
+
|
|
|
+ qrscan() {
|
|
|
+ this.barcodeScanner.scan().then(barcodeData => {
|
|
|
+ this.scanCode = barcodeData.text
|
|
|
+ }).catch(err => {
|
|
|
+ console.log('Error', err);
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|