|
|
@ -2,10 +2,19 @@ import { Component, OnInit } from '@angular/core'; |
|
|
|
import {environment} from '../../../../environments/environment'; |
|
|
|
import {environment} from '../../../../environments/environment'; |
|
|
|
import {FormBuilder, FormGroup, Validators} from '_@angular_forms@9.0.7@@angular/forms'; |
|
|
|
import {FormBuilder, FormGroup, Validators} from '_@angular_forms@9.0.7@@angular/forms'; |
|
|
|
import {IconService} from '../../../services/icon.service'; |
|
|
|
import {IconService} from '../../../services/icon.service'; |
|
|
|
import {NzMessageService} from '_ng-zorro-antd@9.3.0@ng-zorro-antd'; |
|
|
|
import {NzMessageService, NzUploadFile} from '_ng-zorro-antd@9.3.0@ng-zorro-antd'; |
|
|
|
import {Router} from '_@angular_router@9.0.7@@angular/router'; |
|
|
|
import {Router} from '_@angular_router@9.0.7@@angular/router'; |
|
|
|
import {ConfigService} from '../../../services/config.service'; |
|
|
|
import {ConfigService} from '../../../services/config.service'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getBase64(file: File): Promise<string | ArrayBuffer | null> { |
|
|
|
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
|
|
|
const reader = new FileReader(); |
|
|
|
|
|
|
|
reader.readAsDataURL(file); |
|
|
|
|
|
|
|
reader.onload = () => resolve(reader.result); |
|
|
|
|
|
|
|
reader.onerror = error => reject(error); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@Component({ |
|
|
|
selector: 'app-goods-type', |
|
|
|
selector: 'app-goods-type', |
|
|
|
templateUrl: './goods-type.component.html', |
|
|
|
templateUrl: './goods-type.component.html', |
|
|
@ -13,7 +22,7 @@ import {ConfigService} from '../../../services/config.service'; |
|
|
|
}) |
|
|
|
}) |
|
|
|
export class GoodsTypeComponent implements OnInit { |
|
|
|
export class GoodsTypeComponent implements OnInit { |
|
|
|
|
|
|
|
|
|
|
|
WEB_SERVE_URL = environment.imageUrl; |
|
|
|
WEB_SERVE_URL = environment.baseUrl; |
|
|
|
searchForm: FormGroup; // 搜索框
|
|
|
|
searchForm: FormGroup; // 搜索框
|
|
|
|
requestData = []; // 列表数据
|
|
|
|
requestData = []; // 列表数据
|
|
|
|
total: number; // 页码
|
|
|
|
total: number; // 页码
|
|
|
@ -21,9 +30,12 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
pageSize = 10; // 条码
|
|
|
|
pageSize = 10; // 条码
|
|
|
|
loading = true; |
|
|
|
loading = true; |
|
|
|
isVisible = false; |
|
|
|
isVisible = false; |
|
|
|
id; |
|
|
|
editFlag = false; |
|
|
|
|
|
|
|
id: number; |
|
|
|
validateForm!: FormGroup; |
|
|
|
validateForm!: FormGroup; |
|
|
|
|
|
|
|
imgFile = []; |
|
|
|
|
|
|
|
previewImage: string | undefined = ''; |
|
|
|
|
|
|
|
previewVisible = false; |
|
|
|
constructor( |
|
|
|
constructor( |
|
|
|
private form: FormBuilder, |
|
|
|
private form: FormBuilder, |
|
|
|
private config: ConfigService, |
|
|
|
private config: ConfigService, |
|
|
@ -44,11 +56,20 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
title: [null, [Validators.required]], |
|
|
|
title: [null, [Validators.required]], |
|
|
|
img: [null, [Validators.required]], |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 图片查看
|
|
|
|
|
|
|
|
handlePreview = async (file: NzUploadFile) => { |
|
|
|
|
|
|
|
if (!file.url && !file.preview) { |
|
|
|
|
|
|
|
// tslint:disable-next-line:no-non-null-assertion
|
|
|
|
|
|
|
|
file.preview = await getBase64(file.originFileObj!); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.previewImage = file.url || file.preview; |
|
|
|
|
|
|
|
this.previewVisible = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 查询列表
|
|
|
|
// 查询列表
|
|
|
|
public getRequest(reset: boolean = false, whereObject: object) { |
|
|
|
public getRequest(reset: boolean = false, whereObject: object) { |
|
|
|
|
|
|
|
|
|
|
@ -91,7 +112,43 @@ export class GoodsTypeComponent implements OnInit { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleOk(): void { |
|
|
|
handleOk(): void { |
|
|
|
this.isVisible = false; |
|
|
|
// tslint:disable-next-line:forin
|
|
|
|
|
|
|
|
for (const i in this.validateForm.controls) { |
|
|
|
|
|
|
|
this.validateForm.controls[i].markAsDirty(); |
|
|
|
|
|
|
|
this.validateForm.controls[i].updateValueAndValidity(); |
|
|
|
|
|
|
|
if (this.validateForm.controls[i].errors != null) { |
|
|
|
|
|
|
|
this.message.error('必填项不能为空'); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.imgFile.length !== 0) { |
|
|
|
|
|
|
|
if (this.imgFile[0]['response'] != null) { |
|
|
|
|
|
|
|
this.validateForm.value.img = this.imgFile[0]['response']['return_data'][0]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.validateForm.value.img = this.imgFile[0].name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.editFlag) { |
|
|
|
|
|
|
|
this.validateForm.value.id = this.id; |
|
|
|
|
|
|
|
this.config.insertGoodsType(this.validateForm.value, data => { |
|
|
|
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
|
|
|
this.message.success('修改成功'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.create('error', '修改失败'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.config.insertGoodsType(this.validateForm.value, data => { |
|
|
|
|
|
|
|
console.log(data); |
|
|
|
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
|
|
|
this.message.success('添加成功'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleCancel(): void { |
|
|
|
handleCancel(): void { |
|
|
|