diff --git a/config.xml b/config.xml index 668592a..7a0ad67 100644 --- a/config.xml +++ b/config.xml @@ -112,5 +112,4 @@ - diff --git a/package.json b/package.json index 8f82709..ff695d7 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "ng": "ng", "start": "ng serve", - "build": "ionic cordova build android --prod", + "build": "ionic cordova build android", + "build-prod": "ionic cordova build android --prod", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" @@ -35,7 +36,6 @@ "big.js": "^5.2.2", "clone-deep": "^4.0.1", "compressorjs": "^1.0.6", - "cordova-android": "^7.0.0", "cordova-plugin-android-permissions": "^1.0.2", "cordova-plugin-appminimize": "^1.0.1", "cordova-plugin-camera": "^4.1.0", @@ -75,6 +75,7 @@ "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", "codelyzer": "^6.0.0", + "cordova-android": "^9.1.0", "jasmine-core": "~3.5.0", "jasmine-spec-reporter": "~5.0.0", "karma": "~5.0.0", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 31f5702..bc68cd4 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -46,14 +46,14 @@ export class AppComponent { if (this.device.isMobile()) { this.persmission.getPermission().then(() => { this.file.init(); + this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE); + // 键盘监听 + this.keyboardEvent(); + this.statusBar.styleDefault(); + this.splashScreen.hide(); + this.orientationEvent(); + this.registerBackButtonAction(); }); - this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE); - // 键盘监听 - this.keyboardEvent(); - this.statusBar.styleDefault(); - this.splashScreen.hide(); - this.orientationEvent(); - this.registerBackButtonAction(); } else { const config = this.storage.get('config');; if (!config) { diff --git a/src/app/common/model/model.ts b/src/app/common/model/model.ts index 03892c1..f4385d5 100644 --- a/src/app/common/model/model.ts +++ b/src/app/common/model/model.ts @@ -112,6 +112,10 @@ export interface OutCar { * 来源 */ origin: string; + /** + * 夜班 + */ + night?: boolean; /** * 类型 */ diff --git a/src/app/common/pictures/pictures.component.scss b/src/app/common/pictures/pictures.component.scss index f19c8bc..e93244b 100644 --- a/src/app/common/pictures/pictures.component.scss +++ b/src/app/common/pictures/pictures.component.scss @@ -1,5 +1,5 @@ .img { - width: 90px; + width: 150px; margin: 5px 0px; display: inline-block; } diff --git a/src/app/common/pictures/pictures.component.ts b/src/app/common/pictures/pictures.component.ts index 08873ff..58110cd 100644 --- a/src/app/common/pictures/pictures.component.ts +++ b/src/app/common/pictures/pictures.component.ts @@ -100,4 +100,12 @@ export class PicturesComponent implements OnInit { }); } + shareAll() { + this.share.share(null, null, this.pictures, null ).then(() => { + this.toast.success('分享成功'); + }).catch(() => { + this.toast.fail('分享失败'); + }) + } + } diff --git a/src/app/common/total/total.component.html b/src/app/common/total/total.component.html index ff4ffb0..bd4b6c7 100644 --- a/src/app/common/total/total.component.html +++ b/src/app/common/total/total.component.html @@ -1,9 +1,24 @@ + +

{{date | date:'yyyy-MM-dd'}} 总计: + {{total}} + (吨) +

+
分享文字
+
-
-

{{date | date:'yyyy-MM-dd'}} 统计(单位:吨)

- -

车队  共计:{{carTotal.total}}({{carTotal.count}}车) + + +

车队  共计: + {{carTotal.total}}({{carTotal.count}}车) + + + {{car.type}}:{{car.jingzhong}}({{car.count}}车) + +

{{car.carNo}}({{car.person}}):
@@ -15,22 +30,48 @@ {{car.total}} ({{car.totalCount}}车)
-

外来车辆  共计:{{outCarTotal.total}}({{outCarTotal.count}}车)

-
- - {{outCar.origin}}-{{outCar.type}}:{{outCar.jingzhong}} - ({{outCar.count}}车)   + + +

外来车辆  共计: + {{outCarTotal.total}}({{outCarTotal.count}}车) + + + {{car.type}}:{{car.jingzhong}}({{car.count}}车) + +

+
+
+

白班:{{outCarTotal1.total}}

+ +
+ {{outCar.origin}}-{{outCar.type}}:{{outCar.jingzhong}} + ({{outCar.count}}车) +
+
+
小计:
+ +   {{car.type}}:{{car.jingzhong}}({{car.count}}车) + +   未去皮:{{outcarDetailoutpi1.total}}({{outcarDetailoutpi1.count}}车) +
+
+

夜班:{{outCarTotal2.total}}

+ +
+ {{outCar.origin}}-{{outCar.type}}:{{outCar.jingzhong}} + ({{outCar.count}}车) +
+
+
小计:
+ +   {{car.type}}:{{car.jingzhong}}({{car.count}}车) + +   未去皮:{{outcarDetailoutpi2.total}}({{outcarDetailoutpi2.count}}车) +
- - -
- 总计:  - {{total}} -
-
+ +
\ No newline at end of file diff --git a/src/app/common/total/total.component.scss b/src/app/common/total/total.component.scss index 2a3b9c3..3e90d23 100644 --- a/src/app/common/total/total.component.scss +++ b/src/app/common/total/total.component.scss @@ -5,20 +5,10 @@ margin: 0px 0px; } .car, -.outcar, -.total { +.outcar{ display: flex; flex-direction: row; } -.carlabel { - width: 100px; - text-align: right; - font-size: 16px; - font-weight: bold; -} -.carbox { - flex: 1; -} .title { font-size: 14px; font-weight: bold; @@ -42,12 +32,44 @@ .total { font-size: 18px; font-weight: bold; - padding-left: 16px; - margin: 0px 0px; - & > span { - color: #e94f4f; - } + padding-left: 8px; + color: #e94f4f; +} +.outDetail{ + display: flex; +} +.day { + display: inline-block; + box-sizing: border-box; + padding-left: 8px; + width: 50%; +} +.night { + width: 50%; + box-sizing: border-box; + padding-left: 8px; + flex: 1; +} + + +.day>p,.night>p{ + color: #108ee9; + font-weight: bold; + font-size: 15px; + margin-bottom: 6px; +} +.day>p>span,.night>p>span{ + color: #e94f4f; + padding-left: 8px; +} +.day>.row,.night>.row { + display: inline-block; + font-size: 13px; + width: 50%; } -.box{ - transform: scale(0.8); + +.copyText{ + float: right; + right: 8px; + top: -20px; } diff --git a/src/app/common/total/total.component.ts b/src/app/common/total/total.component.ts index 8dfcd1a..ac2345a 100644 --- a/src/app/common/total/total.component.ts +++ b/src/app/common/total/total.component.ts @@ -1,172 +1,581 @@ import { AccountBook } from './../model/model'; import { Component, OnInit, Input } from '@angular/core'; -import { Big } from "big.js"; +import { Big } from 'big.js'; import { CameraService } from '../camera/camera.service'; import html2canvas from 'html2canvas'; import { SocialSharing } from '@ionic-native/social-sharing/ngx'; -import { ModalController } from '@ionic/angular'; +import { ModalController, ToastController } from '@ionic/angular'; +import * as moment from 'moment'; +import { ToastService } from 'ng-zorro-antd-mobile'; @Component({ - selector: 'app-total', - templateUrl: './total.component.html', - styleUrls: ['./total.component.scss'], + selector: 'app-total', + templateUrl: './total.component.html', + styleUrls: ['./total.component.scss'], }) export class TotalComponent implements OnInit { + @Input() + accountBook: AccountBook; + date = ''; + cars: any[] = []; + outCars: any[] = []; // 外来车辆 + outCars1: any[] = []; // 白天外来车 + outCars2: any[] = []; // 黑夜外来车 + guozhaCars: any[] = []; + total = '0'; + carTotal = { total: '0', count: 0 }; + carDetail = []; // 公司车辆拉货详情 + outcarDetail = []; // 外来车辆拉货详情 + outcarDetail1 = []; // 外来车辆拉货详情(白) + outcarDetail2 = []; // 外来车辆拉货详情(夜) + outcarDetailoutpi1 = { total: '0', count: 0 } // 外来车辆详情没有皮重(白) + outcarDetailoutpi2 = { total: '0', count: 0 } // 外来车辆详情没有皮重(夜) + outCarTotal = { total: '0', count: 0 }; + outCarTotal1 = { total: '0', count: 0 }; + outCarTotal2 = { total: '0', count: 0 }; + guozhaCarTotal = { total: '0', count: 0 }; + constructor( + private camera: CameraService, + private socialSharing: SocialSharing, + private modal: ModalController, + private toast: ToastService, + private toastCtrl: ToastController + ) {} - @Input() - accountBook: AccountBook - date = ''; - cars: any[] = []; - outCars: any[] = []; - guozhaCars: any[] = []; - total = '0'; - carTotal = { total: '0', count: 0 }; - outCarTotal = { total: '0', count: 0 }; - guozhaCarTotal = { total: '0', count: 0 }; - constructor( - private camera: CameraService, - private socialSharing: SocialSharing, - private modal: ModalController - ) { } - - ngOnInit() { - this.init(); - } - init() { - this.date = this.accountBook.date; - // this.cars = this.accountBook.cars; - this.cars = this.initCar(); - this.outCars = this.initOutCar(); - this.guozhaCars = this.initGuozhaCar(); - this.carTotal = this.getTotalCar(); - this.outCarTotal = this.getOutTotalCar(); - this.guozhaCarTotal = this.getGuozhaTotalCar(); - this.total = this.initTotal(); - } - initCar() { - const cars = []; - this.accountBook.cars.forEach(car => { - const obj = {}; - let total = '0'; - let totalCount = 0; - const car1: string[] = []; - const car2 = []; - car.datas.forEach((d) => { - const jingzhong = d.jingzhong.trim(); - if (jingzhong && jingzhong !== '0') { - const index = car1.indexOf(d.type) - if (index !== -1) { - car2[index].count++; - car2[index].jingzhong = new Big(car2[index].jingzhong).plus(d.jingzhong || '0').toString(); - } else { - car2.push({ type: d.type, count: 1, jingzhong: d.jingzhong || '0' }) - car1.push(d.type); - } - total = new Big(total).plus(d.jingzhong || '0').toString(); - totalCount++; - } - }) - const persons = []; - car.persons.forEach(person => persons.push(person.userName)); - Reflect.set(obj, 'carNo', car.carNo); - Reflect.set(obj, 'person', persons.join('、')); - Reflect.set(obj, 'total', total); - Reflect.set(obj, 'types', car2), - Reflect.set(obj, 'totalCount', totalCount) - cars.push(obj); - }) - return cars; - } - initOutCar() { - const cars = []; - const outCars = this.accountBook.outCars || []; - const car1: string[] = []; - outCars.forEach(car => { - const jingzhong = car.jingzhong.trim(); - if (jingzhong && jingzhong !== '0') { - const index = car1.indexOf(car.origin + car.type) - if (index !== -1) { - cars[index].count++; - cars[index].jingzhong = new Big(cars[index].jingzhong).plus(car.jingzhong || '0').toString(); - } else { - cars.push({ origin: car.origin, type: car.type, count: 1, jingzhong: car.jingzhong || '0' }) - car1.push(car.origin + car.type); - } - } - }); - return cars; - } - initGuozhaCar(){ - const cars = []; - const guozhaCars = this.accountBook.guozhaCars || []; - const car1: string[] = []; - guozhaCars.forEach(car => { - const jingzhong = car.jingzhong.trim(); - if (jingzhong && jingzhong !== '0') { - const index = car1.indexOf(car.origin + car.type) - if (index !== -1) { - cars[index].count++; - cars[index].jingzhong = new Big(cars[index].jingzhong).plus(car.jingzhong || '0').toString(); - } else { - cars.push({ origin: car.origin, type: car.type, count: 1, jingzhong: car.jingzhong || '0' }) - car1.push(car.origin + car.type); - } - } - }); - return cars; - } - - initTotal() { - let total = '0'; - this.cars.forEach(car => { - total = new Big(car.total).plus(total).toString(); - }); - this.outCars.forEach(outCar => { - total = new Big(outCar.jingzhong).plus(total).toString(); - }); - return total; - } - - getTotalCar() { - let total = { total: '0', count: 0 }; - this.cars.forEach(car => { - total.total = new Big(car.total || '0').plus(total.total).toString(); - total.count = total.count + car.totalCount; - }); - return total; - } - - getOutTotalCar() { - let total = { total: '0', count: 0 }; - this.outCars.forEach(car => { - total.total = new Big(car.jingzhong || '0').plus(total.total).toString(); - total.count = total.count + car.count; - }); - return total; - } - - getGuozhaTotalCar() { - let total = { total: '0', count: 0 }; - this.guozhaCars.forEach(car => { - total.total = new Big(car.jingzhong || '0').plus(total.total).toString(); - total.count = total.count + car.count; - }); - return total; - } - - /** - * 分享 - */ - share() { - const element = document.getElementById('content_box'); - this.modal.getTop().then((modal: any) => { - html2canvas(modal).then(canvas => { - canvas.toBlob(content => { - this.camera.saveFile(content, new Date().toDateString()).then((path: string) => { - this.socialSharing.share(null, null, path, null).then(() => { }, err => console.log('分享失败', err)) - }); - }); - }) - }) - } + ngOnInit() { + this.init(); + } + init() { + this.date = this.accountBook.date; + // this.cars = this.accountBook.cars; + this.cars = this.initCar(); + this.outCars = this.initOutCar(); + this.outCars1 = this.initOutCar1(); + this.outCars2 = this.initOutCar2(); + this.guozhaCars = this.initGuozhaCar(); + this.carTotal = this.getTotalCar(); + this.outCarTotal = this.getOutTotalCar(); + this.outCarTotal1 = this.getOutTotalCar1(); + this.outCarTotal2 = this.getOutTotalCar2(); + this.guozhaCarTotal = this.getGuozhaTotalCar(); + this.total = this.initTotal(); + this.carDetail = this.getDetailCar(); + this.outcarDetail = this.getOutDetailCar(); + this.outcarDetail1 = this.getOutDetailCar1(); + this.outcarDetail2 = this.getOutDetailCar2(); + } + initCar() { + const cars = []; + this.accountBook.cars.forEach((car) => { + const obj = {}; + let total = '0'; + let totalCount = 0; + const car1: string[] = []; + const car2 = []; + car.datas.forEach((d) => { + const jingzhong = d.jingzhong.trim(); + if (jingzhong && jingzhong !== '0') { + const index = car1.indexOf(d.type); + if (index !== -1) { + car2[index].count++; + car2[index].jingzhong = new Big(car2[index].jingzhong) + .plus(d.jingzhong || '0') + .toString(); + } else { + car2.push({ + type: d.type, + count: 1, + jingzhong: d.jingzhong || '0', + }); + car1.push(d.type); + } + total = new Big(total).plus(d.jingzhong || '0').toString(); + totalCount++; + } + }); + const persons = []; + car.persons.forEach((person) => persons.push(person.userName)); + obj['carNo'] = car.carNo; + obj['person'] = persons.join('、'); + obj['total'] = total; + obj['types'] = car2; + obj['totalCount'] = totalCount; + cars.push(obj); + }); + return cars; + } + initOutCar() { + const cars = []; + const car1: string[] = []; + let outCars = this.accountBook.outCars || []; + const types: string[] = []; + outCars = outCars.filter(car => car.jingzhong.trim() && car.jingzhong !== '0'); + let type = ''; + outCars.forEach((outcar) => { + type = outcar.type; + if (!types.includes(type)) { + const filOutCars = outCars.filter(c =>c.type === type); + filOutCars.forEach(car =>{ + const index = car1.indexOf(car.origin + car.type); + if (index !== -1) { + cars[index].count++; + cars[index].jingzhong = new Big(cars[index].jingzhong) + .plus(car.jingzhong || '0') + .toString(); + } else { + cars.push({ + origin: car.origin, + type: car.type, + count: 1, + jingzhong: car.jingzhong || '0', + }); + car1.push(car.origin + car.type); + } + }); + types.push(type); + } + }); + return cars; + } + // 白天外来车辆 + initOutCar1() { + // const cars = []; + // const outCars = this.accountBook.outCars || []; + // const car1: string[] = []; + // outCars.forEach((car) => { + // if (!car.night) { + // const jingzhong = car.jingzhong.trim(); + // if (jingzhong && jingzhong !== '0') { + // const index = car1.indexOf(car.origin + car.type); + // if (index !== -1) { + // cars[index].count++; + // cars[index].jingzhong = new Big(cars[index].jingzhong) + // .plus(car.jingzhong || '0') + // .toString(); + // } else { + // cars.push({ + // origin: car.origin, + // type: car.type, + // count: 1, + // jingzhong: car.jingzhong || '0', + // }); + // car1.push(car.origin + car.type); + // } + // } + // } + // }); + // return cars; + const cars = []; + const car1: string[] = []; + let outCars = this.accountBook.outCars || []; + const types: string[] = []; + outCars = outCars.filter(car => car.jingzhong.trim() && car.jingzhong !== '0' && !car.night); + let type = ''; + outCars.forEach((outcar) => { + type = outcar.type; + if (!types.includes(type)) { + const filOutCars = outCars.filter(c =>c.type === type); + filOutCars.forEach(car =>{ + const index = car1.indexOf(car.origin + car.type); + if (index !== -1) { + cars[index].count++; + cars[index].jingzhong = new Big(cars[index].jingzhong) + .plus(car.jingzhong || '0') + .toString(); + } else { + cars.push({ + origin: car.origin, + type: car.type, + count: 1, + jingzhong: car.jingzhong || '0', + }); + car1.push(car.origin + car.type); + } + }); + types.push(type); + } + }); + return cars; + } + + // 黑夜外来车辆 + initOutCar2() { + // const cars = []; + // const outCars = this.accountBook.outCars || []; + // const car1: string[] = []; + // outCars.forEach((car) => { + // if (car.night) { + // const jingzhong = car.jingzhong.trim(); + // if (jingzhong && jingzhong !== '0') { + // const index = car1.indexOf(car.origin + car.type); + // if (index !== -1) { + // cars[index].count++; + // cars[index].jingzhong = new Big(cars[index].jingzhong) + // .plus(car.jingzhong || '0') + // .toString(); + // } else { + // cars.push({ + // origin: car.origin, + // type: car.type, + // count: 1, + // jingzhong: car.jingzhong || '0', + // }); + // car1.push(car.origin + car.type); + // } + // } + // } + // }); + // return cars; + const cars = []; + const car1: string[] = []; + let outCars = this.accountBook.outCars || []; + const types: string[] = []; + outCars = outCars.filter(car => car.jingzhong.trim() && car.jingzhong !== '0' && car.night); + let type = ''; + outCars.forEach((outcar) => { + type = outcar.type; + if (!types.includes(type)) { + const filOutCars = outCars.filter(c =>c.type === type); + filOutCars.forEach(car =>{ + const index = car1.indexOf(car.origin + car.type); + if (index !== -1) { + cars[index].count++; + cars[index].jingzhong = new Big(cars[index].jingzhong) + .plus(car.jingzhong || '0') + .toString(); + } else { + cars.push({ + origin: car.origin, + type: car.type, + count: 1, + jingzhong: car.jingzhong || '0', + }); + car1.push(car.origin + car.type); + } + }); + types.push(type); + } + }); + return cars; + } + // + initGuozhaCar() { + const cars = []; + const guozhaCars = this.accountBook.guozhaCars || []; + const car1: string[] = []; + guozhaCars.forEach((car) => { + const jingzhong = car.jingzhong.trim(); + if (jingzhong && jingzhong !== '0') { + const index = car1.indexOf(car.origin + car.type); + if (index !== -1) { + cars[index].count++; + cars[index].jingzhong = new Big(cars[index].jingzhong) + .plus(car.jingzhong || '0') + .toString(); + } else { + cars.push({ + origin: car.origin, + type: car.type, + count: 1, + jingzhong: car.jingzhong || '0', + }); + car1.push(car.origin + car.type); + } + } + }); + return cars; + } + + initTotal() { + let total = '0'; + this.cars.forEach((car) => { + total = new Big(car.total).plus(total).toString(); + }); + this.outCars.forEach((outCar) => { + total = new Big(outCar.jingzhong).plus(total).toString(); + }); + return total; + } + + getTotalCar() { + let total = { total: '0', count: 0 }; + this.cars.forEach((car) => { + total.total = new Big(car.total || '0') + .plus(total.total) + .toString(); + total.count = total.count + car.totalCount; + }); + return total; + } + + getDetailCar() { + const types = []; + const detail = []; + this.cars.forEach((car) => { + car.types.forEach((type) => { + const index = types.indexOf(type.type); + if (index !== -1) { + const count = detail[index].count; + const jingzhong = detail[index].jingzhong; + detail[index].count = new Big(type.count) + .plus(count) + .toString(); + detail[index].jingzhong = new Big(type.jingzhong) + .plus(jingzhong) + .toString(); + } else { + types.push(type.type); + detail.push({ + type: type.type, + count: type.count, + jingzhong: type.jingzhong, + }); + } + }); + }); + return detail; + } + + getOutDetailCar() { + const types = []; + const detail = []; + this.outCars.forEach((car) => { + const index = types.indexOf(car.type); + if (index !== -1) { + const count = detail[index].count; + const jingzhong = detail[index].jingzhong; + detail[index].count = new Big(car.count).plus(count).toString(); + detail[index].jingzhong = new Big(car.jingzhong) + .plus(jingzhong) + .toString(); + } else { + types.push(car.type); + detail.push({ + type: car.type, + count: car.count, + jingzhong: car.jingzhong, + }); + } + }); + return detail; + } + + getOutDetailCar1() { + const types = []; + const detail = []; + this.outCars1.forEach((car) => { + const index = types.indexOf(car.type); + if (index !== -1) { + const count = detail[index].count; + const jingzhong = detail[index].jingzhong; + detail[index].count = new Big(car.count).plus(count).toString(); + detail[index].jingzhong = new Big(car.jingzhong) + .plus(jingzhong) + .toString(); + } else { + types.push(car.type); + detail.push({ + type: car.type, + count: car.count, + jingzhong: car.jingzhong, + }); + } + }); + let outCars = this.accountBook.outCars || []; + outCars = outCars.filter(car => car.jingzhong.trim() && car.jingzhong !== '0' && !car.night); + outCars.forEach(car =>{ + if (!car.pizhong || !car.pizhong.trim() || car.pizhong === '0' ) { + this.outcarDetailoutpi1.total = new Big(this.outcarDetailoutpi1.total).plus(car.jingzhong).toString(); + this.outcarDetailoutpi1.count++; + } + }); + return detail; + } + getOutDetailCar2() { + const types = []; + const detail = []; + this.outCars2.forEach((car) => { + const index = types.indexOf(car.type); + if (index !== -1) { + const count = detail[index].count; + const jingzhong = detail[index].jingzhong; + detail[index].count = new Big(car.count).plus(count).toString(); + detail[index].jingzhong = new Big(car.jingzhong) + .plus(jingzhong) + .toString(); + } else { + types.push(car.type); + detail.push({ + type: car.type, + count: car.count, + jingzhong: car.jingzhong, + }); + } + }); + let outCars = this.accountBook.outCars || []; + outCars = outCars.filter(car => car.jingzhong.trim() && car.jingzhong !== '0' && car.night); + outCars.forEach(car =>{ + if (!car.pizhong || !car.pizhong.trim() || car.pizhong === '0' ) { + this.outcarDetailoutpi2.total = new Big(this.outcarDetailoutpi2.total).plus(car.jingzhong).toString(); + this.outcarDetailoutpi2.count++; + } + }); + return detail; + } + + getOutTotalCar() { + let total = { total: '0', count: 0 }; + this.outCars.forEach((car) => { + const j = new Big(car.jingzhong || '0'); + total.total = j.plus(total.total).toString(); + total.count = total.count + car.count; + this.outCarTotal1.total = new Big(car.jingzhong || '0') + .plus(this.outCarTotal1.total) + .toString(); + }); + return total; + } + + getOutTotalCar1() { + let total = { total: '0', count: 0 }; + this.outCars1.forEach((car) => { + const j = new Big(car.jingzhong || '0'); + total.total = j.plus(total.total).toString(); + total.count = total.count + car.count; + this.outCarTotal1.total = new Big(car.jingzhong || '0') + .plus(this.outCarTotal1.total) + .toString(); + }); + return total; + } + + getOutTotalCar2() { + let total = { total: '0', count: 0 }; + this.outCars2.forEach((car) => { + const j = new Big(car.jingzhong || '0'); + total.total = j.plus(total.total).toString(); + total.count = total.count + car.count; + this.outCarTotal2.total = new Big(car.jingzhong || '0') + .plus(this.outCarTotal2.total) + .toString(); + }); + return total; + } + + getGuozhaTotalCar() { + let total = { total: '0', count: 0 }; + this.guozhaCars.forEach((car) => { + total.total = new Big(car.jingzhong || '0') + .plus(total.total) + .toString(); + total.count = total.count + car.count; + }); + return total; + } + + /** + * 分享 + */ + share() { + const element = document.getElementById('content_box'); + this.modal.getTop().then((modal: any) => { + html2canvas(modal).then((canvas) => { + canvas.toBlob((content) => { + this.camera + .saveFile(content, new Date().toDateString()) + .then((path: string) => { + this.socialSharing + .share(null, null, path, null) + .then( + () => {}, + (err) => console.log('分享失败', err) + ); + }); + }); + }); + }); + } + /** + * 复制文字 + */ + copyText() { + const copyToClipboard = (str) => { + const el = document.createElement('textarea'); + el.value = str; + el.setAttribute('readonly', ''); + el.style.position = 'absolute'; + el.style.left = '-9999px'; + document.body.appendChild(el); + const selected = + document.getSelection().rangeCount > 0 + ? document.getSelection().getRangeAt(0) + : false; + el.select(); + document.execCommand('copy'); + document.body.removeChild(el); + if (selected) { + document.getSelection().removeAllRanges(); + document.getSelection().addRange(selected); + } + }; + const date = moment(this.accountBook.date).format('YYYY-MM-DD'); + let day = ''; + let night = ''; + this.outCars1.forEach((car) => { + day += ` + ${car.origin}-${car.type}:${car.jingzhong}(${car.count}车)`; + }); + this.outCars2.forEach((car) => { + night += ` + ${car.origin}-${car.type}:${car.jingzhong}(${car.count}车)`; + }); + let dayDetail = ''; + this.outcarDetail1.forEach((car) => { + dayDetail += ` + ${car.type}:${car.jingzhong}(${car.count}车)`; + }); + let nightDetail = ''; + this.outcarDetail2.forEach((car) => { + nightDetail += ` + ${car.type}:${car.jingzhong}(${car.count}车)`; + }); + let car = ''; + this.cars.forEach((c) => { + car += ` + ${c.carNo}:`; + c.types.forEach((t) => { + car += ` + ${t.type}:${t.jingzhong}(${t.count}车)`; + }); + }); + let carDetail = ''; + this.carDetail.forEach((c) => { + carDetail += ` ${c.type}:${c.jingzhong}(${c.count}车) + `; + }); + + const msg = ` +${date} 单位(吨): + +车队: ${car} +车队小计:${this.carTotal.total}(${this.carTotal.count}车) +${carDetail} +白班:${day} +白班小计: ${this.outCarTotal1.total}(${this.outCarTotal1.count}车)${dayDetail} + +夜班:${night} +夜班小计: ${this.outCarTotal2.total}(${this.outCarTotal2.count}车)${nightDetail} + +今日统计: ${this.total}`; + // copyToClipboard(msg); + // this.toastCtrl.create({ + // message:'复制成功', + // duration: 1000, + // position: 'middle' + // }).then(toast => { + // toast.present(); + // }) + console.log(msg); + this.socialSharing.share(msg, null, null, null); + } } diff --git a/src/app/note/note.component.html b/src/app/note/note.component.html index c49e79f..ba36d35 100644 --- a/src/app/note/note.component.html +++ b/src/app/note/note.component.html @@ -22,10 +22,10 @@ - + 车队 - 出发时间 + 回厂时间 货料来源 货料种类 @@ -39,7 +39,7 @@ - @@ -49,7 +49,7 @@ - {{data.startTime}} + {{data.endTime}} {{data.origin}} {{data.type}} @@ -75,16 +75,17 @@ - +
- + 来源 车牌号 货料种类 + 夜班 毛重(吨) 皮重(吨) 扣秤(%) @@ -97,12 +98,13 @@ - {{data.origin}} {{data.carNo}} {{data.type}} + {{data.night ? "夜班": "白班"}} {{data.maozhong}} {{data.pizhong}} @@ -126,12 +128,12 @@
- +
- + 来源 车牌号 @@ -148,7 +150,7 @@ - {{data.origin}} @@ -162,7 +164,7 @@ {{data.jingzhong}} {{data.price}} - {{data.amount}} + {{data.amount}} 0张 (); // 选中的id + // setOfCheckedId = new Set(); // 选中的id + setOfCheckedId = ''; // 选中的id @ViewChild('tableBox') tableBox: ElementRef; - @ViewChild('tableHeader') tableHeader: ElementRef; + // @ViewChild('tableHeader') tableHeader: ElementRef; constructor( private alertCtrl: AlertController, private file: FileService, @@ -70,21 +72,22 @@ export class NoteComponent implements OnInit, AfterViewInit { }); }, 10); } - }) - + }); } ngAfterViewInit(): void { this.getResize(); - } getResize() { const width = this.tableBox.nativeElement.offsetWidth; const height = this.tableBox.nativeElement.offsetHeight; // 计算高度 - const scrollHeight = height - 45 - 61; + const scrollHeight = height - 120; this.scroll.y = scrollHeight + 'px'; - this.scroll.x = width + 'px'; + this.scroll.x = width - 15 + 'px'; + setTimeout(() => { + this.isReady = true; + }, 100); } /** * @description 读取账本文件 @@ -112,7 +115,8 @@ export class NoteComponent implements OnInit, AfterViewInit { * @param index any */ changeTab(index: any) { - this.setOfCheckedId.clear(); + // this.setOfCheckedId.clear(); + this.setOfCheckedId = ''; setTimeout(() => { this.activeTabIndex = index.index; if (this.activeTabIndex >= this.accountBook.cars.length) { @@ -277,7 +281,7 @@ export class NoteComponent implements OnInit, AfterViewInit { const outCars = cloneDeep(this.accountBook.outCars); outCars.push(outCar); this.accountBook.outCars = outCars; - } else if(this.activeTabIndex < this.accountBook.cars.length) { + } else if (this.activeTabIndex < this.accountBook.cars.length) { const car = this.accountBook.cars[this.activeTabIndex]; const row = { id: uuidv4(), carNo: car.carNo, startTime: '', @@ -314,56 +318,104 @@ export class NoteComponent implements OnInit, AfterViewInit { if (!this.editable) { return false; } - if (!this.setOfCheckedId.size) { + if (!this.setOfCheckedId.length) { this.toast.info('请勾选一行', 1500); return false; } - this.modal.alert('删除', '确定要删除么', [ - { text: '取消', onPress: () => { } }, - { - text: '删除', - onPress: () => - new Promise(resolve => { + // this.modal.alert('删除', '确定要删除么', [ + // { text: '取消', onPress: () => { } }, + // { + // text: '删除', + // onPress: () => + // new Promise(resolve => { + // if (this.isHidden) { + // this.accountBook.cars[this.activeTabIndex].datas.forEach((data, i) => { + // if (this.setOfCheckedId.has(data.id)) { + // const data = cloneDeep(this.accountBook.cars[this.activeTabIndex].datas); + // data.splice(i, 1); + // this.accountBook.cars[this.activeTabIndex].datas = data; + // this.save(true); + // resolve(true); + // } + // }) + // } else if (this.activeTabIndex === this.accountBook.cars.length) { + + // this.accountBook.outCars.forEach((car, i) => { + // if (this.setOfCheckedId.has(car.id)) { + // const data = cloneDeep(this.accountBook.outCars); + // data.splice(i, 1); + // this.accountBook.outCars = data; + // this.save(true); + // resolve(true); + // } + // }) + // } else { + // this.accountBook.guozhaCars.forEach((car, i) => { + // if (this.setOfCheckedId.has(car.id)) { + // const data = cloneDeep(this.accountBook.guozhaCars); + // data.splice(i, 1); + // this.accountBook.guozhaCars = data; + // this.save(true); + // resolve(true); + // } + // }) + // } + + // }), + // style: { + // color: '#ffffff', + // background: '#e94f4f' + // } + // } + // ]); + + this.alertCtrl.create({ + header: '删除', + message:'确定要删除么', + buttons: [ + { + text:'取消', + role: 'cancel', + }, + { + text:'删除', + cssClass: 'delete', + handler: ()=>{ if (this.isHidden) { this.accountBook.cars[this.activeTabIndex].datas.forEach((data, i) => { - if (this.setOfCheckedId.has(data.id)) { + if (this.setOfCheckedId === data.id) { const data = cloneDeep(this.accountBook.cars[this.activeTabIndex].datas); data.splice(i, 1); this.accountBook.cars[this.activeTabIndex].datas = data; this.save(true); - resolve(true); } }) - } else if(this.activeTabIndex === this.accountBook.cars.length) { - + } else if (this.activeTabIndex === this.accountBook.cars.length) { + this.accountBook.outCars.forEach((car, i) => { - if (this.setOfCheckedId.has(car.id)) { + if (this.setOfCheckedId === car.id) { const data = cloneDeep(this.accountBook.outCars); data.splice(i, 1); this.accountBook.outCars = data; this.save(true); - resolve(true); } }) } else { this.accountBook.guozhaCars.forEach((car, i) => { - if (this.setOfCheckedId.has(car.id)) { + if (this.setOfCheckedId === car.id) { const data = cloneDeep(this.accountBook.guozhaCars); data.splice(i, 1); this.accountBook.guozhaCars = data; this.save(true); - resolve(true); } }) } - - }), - style: { - color: '#ffffff', - background: '#e94f4f' + } } - } - ]); + ] + }).then(alert => { + alert.present(); + }); } /** * 添加车辆弹出框 @@ -475,7 +527,7 @@ export class NoteComponent implements OnInit, AfterViewInit { const input: AlertInput = { type: 'checkbox', label: type.originName, value: type.originName }; inputs.push(input); }); - inputs.push({ value: 'edit', type: 'checkbox', label: '自定义', }); + inputs.unshift({ value: 'edit', type: 'checkbox', label: '自定义', }); const alert = await this.alertCtrl.create({ header: '选择货料来源', backdropDismiss: false, @@ -513,7 +565,7 @@ export class NoteComponent implements OnInit, AfterViewInit { const input: AlertInput = { type: 'radio', label: type.typeName, value: type.typeName }; inputs.push(input); }); - inputs.push({ value: 'edit', type: 'radio', label: '自定义', }); + inputs.unshift({ value: 'edit', type: 'radio', label: '自定义', }); const alert = await this.alertCtrl.create({ header: '选择货料类型', inputs: inputs, @@ -532,7 +584,7 @@ export class NoteComponent implements OnInit, AfterViewInit { } else { if (this.activeTabIndex === this.accountBook.cars.length) { this.setOutCellValue('type', blah); - } else if(this.activeTabIndex > this.accountBook.cars.length) { + } else if (this.activeTabIndex > this.accountBook.cars.length) { this.setGuozhaCellValue('type', blah); } else { this.setCellValue('type', blah); @@ -585,7 +637,7 @@ export class NoteComponent implements OnInit, AfterViewInit { if (blah[type]) { if (this.activeTabIndex === this.accountBook.cars.length) { this.setOutCellValue(type, blah[type]); - } else if(this.activeTabIndex > this.accountBook.cars.length) { + } else if (this.activeTabIndex > this.accountBook.cars.length) { this.setGuozhaCellValue(type, blah[type]); } else { this.setCellValue(type, blah[type]); @@ -697,9 +749,11 @@ export class NoteComponent implements OnInit, AfterViewInit { * @memberof NoteComponent */ onItemChecked(id: string, checked: boolean): void { - this.setOfCheckedId.clear(); + // this.setOfCheckedId.clear(); + this.setOfCheckedId = ''; if (checked) { - this.setOfCheckedId.add(id); + // this.setOfCheckedId.add(id); + this.setOfCheckedId = id; } } @@ -715,20 +769,20 @@ export class NoteComponent implements OnInit, AfterViewInit { * 复制一行 */ copy() { - let id = ''; - this.setOfCheckedId.forEach(a => { - id = a - }); + let id = this.setOfCheckedId; + // this.setOfCheckedId.forEach(a => { + // id = a + // }); if (!id) { this.toast.info('请勾选一行', 1500); return false; } - if(this.activeTabIndex > this.accountBook.cars.length){ - const newrow = { + if (this.activeTabIndex > this.accountBook.cars.length) { + const newrow = { id: uuidv4(), - pizhong: '', maozhong: '', - jingzhong: '', amount: '', img: [], + pizhong: '', maozhong: '', + jingzhong: '', amount: '', img: [], thumbnail: [], koucheng: '0', price: '0' } const copyRow = this.accountBook.guozhaCars.filter(car => car.id === id).pop(); @@ -790,7 +844,36 @@ export class NoteComponent implements OnInit, AfterViewInit { await alert.present(); } - setOutCellValue(type: string, value: string) { + /** + * 编辑夜班白班 + * @param z index + */ + async editNight(z: number) { + this.editRowIndex = z; + const alert = await this.alertCtrl.create({ + header: '白/夜班', + backdropDismiss: false, + inputs: [{ type: 'radio', label: '白班', value: false }, { type: 'radio', label: '夜班', value: true }], + buttons: [ + { + text: '取消', + role: 'cancel', + cssClass: 'secondary', + handler: () => { } + }, { + text: '确定', + handler: (blah: string) => { + console.log(blah); + this.setOutCellValue('night', blah); + // this.setOutCellValue(type, blah[type]) + } + } + ] + }); + await alert.present(); + } + + setOutCellValue(type: string, value: any) { if (!this.editable) { return false; } @@ -802,21 +885,21 @@ export class NoteComponent implements OnInit, AfterViewInit { if (type === 'maozhong') { const koucheng = this.accountBook.outCars[this.editRowIndex].koucheng || '0'; const pizhong = this.accountBook.outCars[this.editRowIndex].pizhong || '0'; - const jingzhong = new Big(value).minus(pizhong).times(new Big(100).minus(koucheng).div(100)).toString(); + const jingzhong = new Big(value).minus(pizhong).times(new Big(100).minus(koucheng).div(100)).toFixed(2).toString(); this.accountBook.outCars[this.editRowIndex].jingzhong = jingzhong; const price = this.accountBook.outCars[this.editRowIndex].price || '0'; this.accountBook.outCars[this.editRowIndex].amount = new Big(price).times(jingzhong).toString(); } else if (type === 'pizhong') { const koucheng = this.accountBook.outCars[this.editRowIndex].koucheng || '0'; const maozhong = this.accountBook.outCars[this.editRowIndex].maozhong || '0'; - const jingzhong = new Big(maozhong).minus(value).times(new Big(100).minus(koucheng).div(100)).toString(); + const jingzhong = new Big(maozhong).minus(value).times(new Big(100).minus(koucheng).div(100)).toFixed(2).toString(); this.accountBook.outCars[this.editRowIndex].jingzhong = jingzhong; const price = this.accountBook.outCars[this.editRowIndex].price || '0'; this.accountBook.outCars[this.editRowIndex].amount = new Big(price).times(jingzhong).toString(); } else if (type === 'koucheng') { const maozhong = this.accountBook.outCars[this.editRowIndex].maozhong || '0'; const pizhong = this.accountBook.outCars[this.editRowIndex].pizhong || '0'; - const jingzhong = new Big(maozhong).minus(pizhong).times(new Big(100).minus(value).div(100)).toString(); + const jingzhong = new Big(maozhong).minus(pizhong).times(new Big(100).minus(value).div(100)).toFixed(2).toString(); this.accountBook.outCars[this.editRowIndex].jingzhong = jingzhong; const price = this.accountBook.outCars[this.editRowIndex].price || '0'; this.accountBook.outCars[this.editRowIndex].amount = new Big(price).times(jingzhong).toString(); @@ -852,13 +935,13 @@ export class NoteComponent implements OnInit, AfterViewInit { this.setCellValue('thumbnail', ''); } - async editGuozha(oldValue: string, z: number, type: string){ + async editGuozha(oldValue: string, z: number, type: string) { if (!this.editable) { return false; } this.editRowIndex = z; - const config = { origin: '来源', type:'果渣', carNo: '车牌号', maozhong: "毛重", pizhong: '皮重', amount: '料款', koucheng: '扣秤' }; - const config1 = { type: 'text', origin: 'text', carNo:'text', maozhong: "number", pizhong: 'number', amount: 'number', koucheng: 'number' }; + const config = { origin: '来源', type: '果渣', carNo: '车牌号', maozhong: "毛重", pizhong: '皮重', amount: '料款', koucheng: '扣秤' }; + const config1 = { type: 'text', origin: 'text', carNo: 'text', maozhong: "number", pizhong: 'number', amount: 'number', koucheng: 'number' }; const title = config[type]; const inputType = config1[type]; const inputs: AlertInput[] = [ @@ -894,7 +977,7 @@ export class NoteComponent implements OnInit, AfterViewInit { await alert.present(); } - setGuozhaCellValue(type: string, value: string){ + setGuozhaCellValue(type: string, value: string) { if (!this.editable) { return false; } @@ -906,21 +989,21 @@ export class NoteComponent implements OnInit, AfterViewInit { if (type === 'maozhong') { const koucheng = this.accountBook.guozhaCars[this.editRowIndex].koucheng || '0'; const pizhong = this.accountBook.guozhaCars[this.editRowIndex].pizhong || '0'; - const jingzhong = new Big(value).minus(pizhong).times(new Big(100).minus(koucheng).div(100)).toString(); + const jingzhong = new Big(value).minus(pizhong).times(new Big(100).minus(koucheng).div(100)).toFixed(2).toString(); this.accountBook.guozhaCars[this.editRowIndex].jingzhong = jingzhong; const price = this.accountBook.guozhaCars[this.editRowIndex].price || '0'; this.accountBook.guozhaCars[this.editRowIndex].amount = new Big(price).times(jingzhong).toString(); } else if (type === 'pizhong') { const koucheng = this.accountBook.guozhaCars[this.editRowIndex].koucheng || '0'; const maozhong = this.accountBook.guozhaCars[this.editRowIndex].maozhong || '0'; - const jingzhong = new Big(maozhong).minus(value).times(new Big(100).minus(koucheng).div(100)).toString(); + const jingzhong = new Big(maozhong).minus(value).times(new Big(100).minus(koucheng).div(100)).toFixed(2).toString(); this.accountBook.guozhaCars[this.editRowIndex].jingzhong = jingzhong; const price = this.accountBook.guozhaCars[this.editRowIndex].price || '0'; this.accountBook.guozhaCars[this.editRowIndex].amount = new Big(price).times(jingzhong).toString(); } else if (type === 'koucheng') { const maozhong = this.accountBook.guozhaCars[this.editRowIndex].maozhong || '0'; const pizhong = this.accountBook.guozhaCars[this.editRowIndex].pizhong || '0'; - const jingzhong = new Big(maozhong).minus(pizhong).times(new Big(100).minus(value).div(100)).toString(); + const jingzhong = new Big(maozhong).minus(pizhong).times(new Big(100).minus(value).div(100)).toFixed(2).toString(); this.accountBook.guozhaCars[this.editRowIndex].jingzhong = jingzhong; const price = this.accountBook.guozhaCars[this.editRowIndex].price || '0'; this.accountBook.guozhaCars[this.editRowIndex].amount = new Big(price).times(jingzhong).toString(); @@ -931,7 +1014,7 @@ export class NoteComponent implements OnInit, AfterViewInit { this.save(true); } - async openGuozhaPicture(index: number){ + async openGuozhaPicture(index: number) { const thumbnails = this.accountBook.guozhaCars[index].thumbnail; const pictures = this.accountBook.guozhaCars[index].img; @@ -946,7 +1029,7 @@ export class NoteComponent implements OnInit, AfterViewInit { await modal.present(); } - openGuozhaCamera(z: number){ + openGuozhaCamera(z: number) { if (!this.editable) { this.toast.info('只有当天的账本可以修改'); return false;