|
@@ -1,6 +1,6 @@
|
1
|
|
-import { Component, OnInit, ViewChild } from "@angular/core";
|
|
1
|
+import { Component, OnInit, ViewChild, ElementRef } from "@angular/core";
|
2
|
2
|
import { ActivatedRoute, Router } from "@angular/router";
|
3
|
|
-import { FormBuilder, Validators, FormGroup } from "@angular/forms";
|
|
3
|
+import { FormBuilder, Validators, FormGroup, FormControl } from "@angular/forms";
|
4
|
4
|
|
5
|
5
|
import { MainService } from "../../services/main.service";
|
6
|
6
|
import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
|
|
@@ -8,6 +8,7 @@ import { ToolService } from "../../services/tool.service";
|
8
|
8
|
import { NzMessageService } from "ng-zorro-antd";
|
9
|
9
|
import { Subject } from 'rxjs';
|
10
|
10
|
import { debounceTime } from 'rxjs/operators';
|
|
11
|
+import { format } from 'date-fns';
|
11
|
12
|
|
12
|
13
|
@Component({
|
13
|
14
|
selector: "app-barcode-prefabrication",
|
|
@@ -15,6 +16,7 @@ import { debounceTime } from 'rxjs/operators';
|
15
|
16
|
styleUrls: ["./barcode-prefabrication.component.less"],
|
16
|
17
|
})
|
17
|
18
|
export class BarcodePrefabricationComponent implements OnInit {
|
|
19
|
+ @ViewChild('printBtn', { static: false }) printBtn: ElementRef<HTMLElement>;
|
18
|
20
|
@ViewChild("osComponentRef1", {
|
19
|
21
|
read: OverlayScrollbarsComponent,
|
20
|
22
|
static: false,
|
|
@@ -224,8 +226,30 @@ export class BarcodePrefabricationComponent implements OnInit {
|
224
|
226
|
}
|
225
|
227
|
|
226
|
228
|
// 生成
|
227
|
|
- generateQRcode(id) {
|
228
|
|
- this.coopId = id;
|
|
229
|
+ dateText: string = '';
|
|
230
|
+ isYear: boolean = false;
|
|
231
|
+ isMonth: boolean = false;
|
|
232
|
+ isDay: boolean = false;
|
|
233
|
+ generateQRcode(data) {
|
|
234
|
+ this.coopData = data;
|
|
235
|
+ if(this.coopData.snConfigDTO.dateType){
|
|
236
|
+ this.dateText = '';
|
|
237
|
+ this.isYear = false;
|
|
238
|
+ this.isMonth = false;
|
|
239
|
+ this.isDay = false;
|
|
240
|
+ if(this.coopData.snConfigDTO.dateType.name.includes('y')){
|
|
241
|
+ this.dateText += '年';
|
|
242
|
+ this.isYear = true;
|
|
243
|
+ }
|
|
244
|
+ if(this.coopData.snConfigDTO.dateType.name.includes('m')){
|
|
245
|
+ this.dateText += '月';
|
|
246
|
+ this.isMonth = true;
|
|
247
|
+ }
|
|
248
|
+ if(this.coopData.snConfigDTO.dateType.name.includes('d')){
|
|
249
|
+ this.dateText += '日';
|
|
250
|
+ this.isDay = true;
|
|
251
|
+ }
|
|
252
|
+ }
|
229
|
253
|
this.showGenerateModal();
|
230
|
254
|
}
|
231
|
255
|
|
|
@@ -243,40 +267,47 @@ export class BarcodePrefabricationComponent implements OnInit {
|
243
|
267
|
// 初始化新增form表单
|
244
|
268
|
initGenerateForm() {
|
245
|
269
|
this.validateGenerateForm = this.fb.group({
|
246
|
|
- title: [null, [Validators.required]],
|
247
|
|
- snConfig: [null, [Validators.required]],
|
248
|
|
- codeType: [null, [Validators.required]],
|
|
270
|
+ date: [null, [Validators.required]],
|
|
271
|
+ count: [1, [Validators.required]],
|
249
|
272
|
});
|
|
273
|
+ if(this.coopData.snConfigDTO.dateType){
|
|
274
|
+ this.validateGenerateForm.addControl(
|
|
275
|
+ 'date',
|
|
276
|
+ new FormControl(null, Validators.required)
|
|
277
|
+ );
|
|
278
|
+ }else{
|
|
279
|
+ this.validateGenerateForm.removeControl('date');
|
|
280
|
+ }
|
250
|
281
|
}
|
251
|
282
|
// 生成表单提交
|
|
283
|
+ codeList: any[] = [];
|
252
|
284
|
submitGenerateForm(): void {
|
253
|
|
- // todo
|
254
|
|
- return;
|
255
|
|
- for (const i in this.validateForm.controls) {
|
256
|
|
- this.validateForm.controls[i].markAsDirty({ onlySelf: true });
|
257
|
|
- this.validateForm.controls[i].updateValueAndValidity();
|
|
285
|
+ console.log(this.validateGenerateForm.value)
|
|
286
|
+ for (const i in this.validateGenerateForm.controls) {
|
|
287
|
+ this.validateGenerateForm.controls[i].markAsDirty({ onlySelf: true });
|
|
288
|
+ this.validateGenerateForm.controls[i].updateValueAndValidity();
|
258
|
289
|
}
|
259
|
|
- if (this.validateForm.invalid) return;
|
|
290
|
+ if (this.validateGenerateForm.invalid) return;
|
260
|
291
|
this.btnLoading = true;
|
261
|
|
- let data:any = {
|
262
|
|
- title: this.validateForm.value.title,
|
263
|
|
- snConfig: this.validateForm.value.snConfig,
|
264
|
|
- codeType: this.validateForm.value.codeType ? { id: this.validateForm.value.codeType } : undefined,
|
265
|
|
- hosId: this.hosId,
|
|
292
|
+ let postData:any = {
|
|
293
|
+ count: this.validateGenerateForm.value.count,
|
|
294
|
+ date: this.validateGenerateForm.value.date ? format(this.validateGenerateForm.value.date, 'yyyy-MM-dd HH:mm:ss') : undefined,
|
|
295
|
+ id: this.coopData.id,
|
266
|
296
|
};
|
267
|
|
- if (!this.add) {
|
268
|
|
- data = {...data, ...this.coopData};
|
269
|
|
- }
|
270
|
297
|
this.mainService
|
271
|
|
- .simplePost("addData", "precastCode", data)
|
|
298
|
+ .coopWorkerOrder("generatePrecastCode", postData)
|
272
|
299
|
.subscribe((data) => {
|
273
|
300
|
this.btnLoading = false;
|
274
|
|
- this.hideModal();
|
275
|
|
- this.initForm();
|
276
|
|
- if (data.status == 200) {
|
277
|
|
- this.showPromptModal(this.add ? "新增" : "编辑", true, "");
|
|
301
|
+ this.hideGenerateModal();
|
|
302
|
+ this.initGenerateForm();
|
|
303
|
+ if (data.state == 200) {
|
|
304
|
+ this.codeList = data.data || [];
|
|
305
|
+ // 打印
|
|
306
|
+ setTimeout(()=>{
|
|
307
|
+ this.printBtn.nativeElement.click();
|
|
308
|
+ }, )
|
278
|
309
|
} else {
|
279
|
|
- this.showPromptModal(this.add ? "新增" : "编辑", false, data.msg);
|
|
310
|
+ this.showPromptModal("生成", false, data.msg);
|
280
|
311
|
}
|
281
|
312
|
});
|
282
|
313
|
}
|