|
@@ -0,0 +1,122 @@
|
|
|
|
+import { Component, OnInit } from '@angular/core';
|
|
|
|
+import { ActivatedRoute } from '@angular/router'
|
|
|
|
+import { UserData } from '../../providers/user-data';
|
|
|
|
+import { Camera } from '@ionic-native/camera/ngx';
|
|
|
|
+import { CameraSetting } from '../../providers/camera-photo'
|
|
|
|
+import { commonService } from '../../providers/common.service'
|
|
|
|
+import { ImagePicker, ImagePickerOptions } from '@ionic-native/image-picker/ngx';
|
|
|
|
+import { Base64 } from '@ionic-native/base64/ngx';
|
|
|
|
+import { ToastController } from '@ionic/angular';
|
|
|
|
+
|
|
|
|
+@Component({
|
|
|
|
+ selector: 'app-inspection-list',
|
|
|
|
+ templateUrl: './inspection-list.page.html',
|
|
|
|
+ styleUrls: ['./inspection-list.page.scss'],
|
|
|
|
+})
|
|
|
|
+export class InspectionListPage implements OnInit {
|
|
|
|
+
|
|
|
|
+ public inspectionList = []
|
|
|
|
+ public imgList = []
|
|
|
|
+ public imageData = ''
|
|
|
|
+
|
|
|
|
+ constructor(private activeRoute: ActivatedRoute,
|
|
|
|
+ public userData: UserData,
|
|
|
|
+ public commonService: commonService,
|
|
|
|
+ private cameraSetting: CameraSetting,
|
|
|
|
+ private base64: Base64,
|
|
|
|
+ private imagePicker: ImagePicker,
|
|
|
|
+ private camera: Camera,
|
|
|
|
+ private toastCtrl: ToastController) { }
|
|
|
|
+
|
|
|
|
+ ngOnInit() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ionViewDidEnter() {
|
|
|
|
+ this.activeRoute.paramMap.subscribe(async params => {
|
|
|
|
+ let data = await this.userData.getInspectionList(params['params']['poCode'], params['params']['scCode'])
|
|
|
|
+ this.inspectionList = data
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ choosePicture() {
|
|
|
|
+ const options: ImagePickerOptions = {
|
|
|
|
+ maximumImagesCount: 30,
|
|
|
|
+ outputType: 1,
|
|
|
|
+ width: 1800,
|
|
|
|
+ height: 1350,
|
|
|
|
+ quality: 90
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ this.imagePicker.getPictures(options).then((results) => {
|
|
|
|
+ for (var i = 0; i < results.length; i++) {
|
|
|
|
+ this.base64.encodeFile(results[i]).then((base64File: string) => {
|
|
|
|
+ this.imgList.push(
|
|
|
|
+ base64File
|
|
|
|
+ )
|
|
|
|
+ let imageData = base64File.split('base64,')[1]
|
|
|
|
+ if (this.imageData) {
|
|
|
|
+ this.imageData = this.imageData + ',' + imageData
|
|
|
|
+ } else {
|
|
|
|
+ this.imageData = '' + imageData
|
|
|
|
+ }
|
|
|
|
+ }, (err) => {
|
|
|
|
+ console.log(err);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }, (err) => { });
|
|
|
|
+ // this.showPicture(qc, this.cameraSetting.albumOption)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ takePicture() {
|
|
|
|
+ this.showPicture(this.cameraSetting.takePhotoOption)
|
|
|
|
+ }
|
|
|
|
+ showPicture(options) {
|
|
|
|
+ this.camera.getPicture(options).then((imageData) => {
|
|
|
|
+ this.imgList.push(
|
|
|
|
+ 'data:image/png;base64,' + imageData
|
|
|
|
+ )
|
|
|
|
+ if (this.imageData) {
|
|
|
|
+ this.imageData = this.imageData + ',' + imageData
|
|
|
|
+ } else {
|
|
|
|
+ this.imageData = '' + imageData
|
|
|
|
+ }
|
|
|
|
+ }, (err) => {
|
|
|
|
+ // Handle error
|
|
|
|
+ console.log("Camera issue: " + err);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ deletePicture(index) {
|
|
|
|
+ this.imgList.splice(index, 1)
|
|
|
|
+ let arr = this.imageData.split(',')
|
|
|
|
+ arr.splice(index, 1)
|
|
|
|
+ this.imageData = arr.toString()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async upload() {
|
|
|
|
+ let scId = this.inspectionList[0].scId
|
|
|
|
+ let result: boolean = true
|
|
|
|
+ for (let i of this.inspectionList) {
|
|
|
|
+ if (i.scId !== scId) {
|
|
|
|
+ result = false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (this.imgList.length !== 0) {
|
|
|
|
+ if (result === false) {
|
|
|
|
+ const toast = await this.toastCtrl.create({
|
|
|
|
+ message: '筛选出的数据scId不一致,无法上传',
|
|
|
|
+ duration: 3000,
|
|
|
|
+ position: 'top'
|
|
|
|
+ });
|
|
|
|
+ await toast.present();
|
|
|
|
+ } else {
|
|
|
|
+ let form = {
|
|
|
|
+ scId: scId,
|
|
|
|
+ files: this.imageData
|
|
|
|
+ }
|
|
|
|
+ await this.userData.inspectionUpload(form)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|