|
|
@ -1,4 +1,4 @@ |
|
|
|
import { Component, OnInit } from '@angular/core'; |
|
|
|
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'; |
|
|
@ -7,212 +7,213 @@ 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> { |
|
|
|
function getBase64(file: File): Promise<string | ArrayBuffer | null> { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
const reader = new FileReader(); |
|
|
|
const reader = new FileReader(); |
|
|
|
reader.readAsDataURL(file); |
|
|
|
reader.readAsDataURL(file); |
|
|
|
reader.onload = () => resolve(reader.result); |
|
|
|
reader.onload = () => resolve(reader.result); |
|
|
|
reader.onerror = error => reject(error); |
|
|
|
reader.onerror = error => reject(error); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
|
@Component({ |
|
|
|
selector: 'app-brand', |
|
|
|
selector: 'app-brand', |
|
|
|
templateUrl: './brand.component.html', |
|
|
|
templateUrl: './brand.component.html', |
|
|
|
styleUrls: ['./brand.component.scss'] |
|
|
|
styleUrls: ['./brand.component.scss'] |
|
|
|
}) |
|
|
|
}) |
|
|
|
export class BrandComponent implements OnInit { |
|
|
|
export class BrandComponent implements OnInit { |
|
|
|
|
|
|
|
WEB_SERVE_URL = environment.baseUrl; |
|
|
|
|
|
|
|
imageUrl = environment.imageUrl; |
|
|
|
|
|
|
|
searchForm: FormGroup; // 搜索框
|
|
|
|
|
|
|
|
requestData = []; // 列表数据
|
|
|
|
|
|
|
|
total: number; // 页码
|
|
|
|
|
|
|
|
pageNum = 1; // 页码
|
|
|
|
|
|
|
|
pageSize = 10; // 条码
|
|
|
|
|
|
|
|
loading = true; |
|
|
|
|
|
|
|
isVisible = false; |
|
|
|
|
|
|
|
editFlag = false; |
|
|
|
|
|
|
|
id: number; |
|
|
|
|
|
|
|
validateForm!: FormGroup; |
|
|
|
|
|
|
|
imgFile = []; |
|
|
|
|
|
|
|
previewImage: string | undefined = ''; |
|
|
|
|
|
|
|
previewVisible = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
goodTypData; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( |
|
|
|
|
|
|
|
private form: FormBuilder, |
|
|
|
|
|
|
|
private config: ConfigService, |
|
|
|
|
|
|
|
private iconService: IconService, |
|
|
|
|
|
|
|
private message: NzMessageService, |
|
|
|
|
|
|
|
private router: Router, |
|
|
|
|
|
|
|
private modalService: NzModalService, |
|
|
|
|
|
|
|
private fb: FormBuilder, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WEB_SERVE_URL = environment.baseUrl; |
|
|
|
ngOnInit(): void { |
|
|
|
searchForm: FormGroup; // 搜索框
|
|
|
|
this.init(); |
|
|
|
requestData = []; // 列表数据
|
|
|
|
} |
|
|
|
total: number; // 页码
|
|
|
|
|
|
|
|
pageNum = 1; // 页码
|
|
|
|
|
|
|
|
pageSize = 10; // 条码
|
|
|
|
|
|
|
|
loading = true; |
|
|
|
|
|
|
|
isVisible = false; |
|
|
|
|
|
|
|
editFlag = false; |
|
|
|
|
|
|
|
id: number; |
|
|
|
|
|
|
|
validateForm!: FormGroup; |
|
|
|
|
|
|
|
imgFile = []; |
|
|
|
|
|
|
|
previewImage: string | undefined = ''; |
|
|
|
|
|
|
|
previewVisible = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
goodTypData; |
|
|
|
|
|
|
|
constructor( |
|
|
|
|
|
|
|
private form: FormBuilder, |
|
|
|
|
|
|
|
private config: ConfigService, |
|
|
|
|
|
|
|
private iconService: IconService, |
|
|
|
|
|
|
|
private message: NzMessageService, |
|
|
|
|
|
|
|
private router: Router, |
|
|
|
|
|
|
|
private modalService: NzModalService, |
|
|
|
|
|
|
|
private fb: FormBuilder, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
|
|
|
|
this.init(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public init(): void { |
|
|
|
|
|
|
|
this.searchForm = this.form.group({ |
|
|
|
|
|
|
|
title: [null], |
|
|
|
|
|
|
|
goodTypeId: [null], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
|
|
|
|
title: [null, [Validators.required]], |
|
|
|
|
|
|
|
goodTypeId: [null, [Validators.required]], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.config.getListGoodsType({ |
|
|
|
public init(): void { |
|
|
|
pageNum: 1 , |
|
|
|
this.searchForm = this.form.group({ |
|
|
|
pageSize: 1000000 , |
|
|
|
title: [null], |
|
|
|
} , data => { |
|
|
|
goodTypeId: [null], |
|
|
|
this.goodTypData = data['return_data']['list']; |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.validateForm = this.fb.group({ |
|
|
|
} |
|
|
|
title: [null, [Validators.required]], |
|
|
|
|
|
|
|
goodTypeId: [null, [Validators.required]], |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
|
|
|
|
|
|
|
// 图片查看
|
|
|
|
this.config.getListGoodsType({ |
|
|
|
handlePreview = async (file: NzUploadFile) => { |
|
|
|
pageNum: 1, |
|
|
|
if (!file.url && !file.preview) { |
|
|
|
pageSize: 1000000, |
|
|
|
// tslint:disable-next-line:no-non-null-assertion
|
|
|
|
}, data => { |
|
|
|
file.preview = await getBase64(file.originFileObj!); |
|
|
|
this.goodTypData = data['return_data']['list']; |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
this.previewImage = file.url || file.preview; |
|
|
|
|
|
|
|
this.previewVisible = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 查询列表
|
|
|
|
// 图片查看
|
|
|
|
public getRequest(reset: boolean = false, whereObject: object) { |
|
|
|
handlePreview = async (file: NzUploadFile) => { |
|
|
|
|
|
|
|
if (!file.url && !file.preview) { |
|
|
|
this.loading = false; |
|
|
|
// tslint:disable-next-line:no-non-null-assertion
|
|
|
|
if (reset) { |
|
|
|
file.preview = await getBase64(file.originFileObj!); |
|
|
|
this.pageNum = 1; |
|
|
|
} |
|
|
|
|
|
|
|
this.previewImage = file.url || file.preview; |
|
|
|
|
|
|
|
this.previewVisible = true; |
|
|
|
} |
|
|
|
} |
|
|
|
whereObject['pageNum'] = this.pageNum; |
|
|
|
|
|
|
|
whereObject['pageSize'] = this.pageSize; |
|
|
|
// 查询列表
|
|
|
|
this.config.getBrandByList(whereObject, data => { |
|
|
|
public getRequest(reset: boolean = false, whereObject: object) { |
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
|
|
|
this.requestData = data['return_data'].list; |
|
|
|
this.loading = false; |
|
|
|
this.total = data['return_data'].total; |
|
|
|
if (reset) { |
|
|
|
} else { |
|
|
|
this.pageNum = 1; |
|
|
|
this.message.error(data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重置
|
|
|
|
|
|
|
|
public resetForm(): void { |
|
|
|
|
|
|
|
this.searchForm.reset(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 修改
|
|
|
|
|
|
|
|
public getEdit(id?: number): void { |
|
|
|
|
|
|
|
this.validateForm.reset(); |
|
|
|
|
|
|
|
this.editFlag = false; |
|
|
|
|
|
|
|
this.imgFile = []; |
|
|
|
|
|
|
|
this.id = id; |
|
|
|
|
|
|
|
if (id != null) { |
|
|
|
|
|
|
|
this.editFlag = true; |
|
|
|
|
|
|
|
this.config.findById(id , data => { |
|
|
|
|
|
|
|
data['return_data'].goodTypeId = String(data['return_data'].goodTypeId); |
|
|
|
|
|
|
|
if (data['return_data']['img'] != null && data['return_data']['img'] !== '') { |
|
|
|
|
|
|
|
const img = String(data['return_data']['img']); |
|
|
|
|
|
|
|
const imgArray = []; |
|
|
|
|
|
|
|
imgArray.push( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
uid: 1, |
|
|
|
|
|
|
|
name: img, |
|
|
|
|
|
|
|
status: 'done', |
|
|
|
|
|
|
|
url: environment.imageUrl + img |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.imgFile = imgArray; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
this.validateForm.patchValue(data['return_data']); |
|
|
|
whereObject['pageNum'] = this.pageNum; |
|
|
|
}); |
|
|
|
whereObject['pageSize'] = this.pageSize; |
|
|
|
|
|
|
|
this.config.getBrandByList(whereObject, data => { |
|
|
|
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
|
|
|
this.requestData = data['return_data'].list; |
|
|
|
|
|
|
|
this.total = data['return_data'].total; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.error(data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 重置
|
|
|
|
|
|
|
|
public resetForm(): void { |
|
|
|
|
|
|
|
this.searchForm.reset(); |
|
|
|
} |
|
|
|
} |
|
|
|
this.isVisible = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 修改
|
|
|
|
// 查看详情
|
|
|
|
public getEdit(id?: number): void { |
|
|
|
public getDetail(id: number): void { |
|
|
|
this.validateForm.reset(); |
|
|
|
this.router.navigate(['/admin/company/company-detail'], { |
|
|
|
this.editFlag = false; |
|
|
|
queryParams: { |
|
|
|
this.imgFile = []; |
|
|
|
companyId: id |
|
|
|
this.id = id; |
|
|
|
} |
|
|
|
if (id != null) { |
|
|
|
}).then(r => console.log(r)); |
|
|
|
this.editFlag = true; |
|
|
|
} |
|
|
|
this.config.findById(id, data => { |
|
|
|
|
|
|
|
data['return_data'].goodTypeId = String(data['return_data'].goodTypeId); |
|
|
|
handleOk(): void { |
|
|
|
if (data['return_data']['img'] != null && data['return_data']['img'] !== '') { |
|
|
|
// tslint:disable-next-line:forin
|
|
|
|
const img = String(data['return_data']['img']); |
|
|
|
for (const i in this.validateForm.controls) { |
|
|
|
const imgArray = []; |
|
|
|
this.validateForm.controls[i].markAsDirty(); |
|
|
|
imgArray.push( |
|
|
|
this.validateForm.controls[i].updateValueAndValidity(); |
|
|
|
{ |
|
|
|
if (this.validateForm.controls[i].errors != null) { |
|
|
|
uid: 1, |
|
|
|
this.message.error('必填项不能为空'); |
|
|
|
name: img, |
|
|
|
return; |
|
|
|
status: 'done', |
|
|
|
} |
|
|
|
url: environment.imageUrl + img |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
this.imgFile = imgArray; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.validateForm.patchValue(data['return_data']); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.isVisible = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.imgFile.length !== 0) { |
|
|
|
// 查看详情
|
|
|
|
if (this.imgFile[0]['response'] != null) { |
|
|
|
public getDetail(id: number): void { |
|
|
|
this.validateForm.value.img = this.imgFile[0]['response']['return_data'][0]; |
|
|
|
this.router.navigate(['/admin/company/company-detail'], { |
|
|
|
} else { |
|
|
|
queryParams: { |
|
|
|
this.validateForm.value.img = this.imgFile[0].name; |
|
|
|
companyId: id |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}).then(r => console.log(r)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (this.editFlag) { |
|
|
|
|
|
|
|
this.validateForm.value.id = this.id; |
|
|
|
handleOk(): void { |
|
|
|
this.config.updateBrand(this.validateForm.value, data => { |
|
|
|
// tslint:disable-next-line:forin
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
for (const i in this.validateForm.controls) { |
|
|
|
this.message.success('修改成功'); |
|
|
|
this.validateForm.controls[i].markAsDirty(); |
|
|
|
this.isVisible = false; |
|
|
|
this.validateForm.controls[i].updateValueAndValidity(); |
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
if (this.validateForm.controls[i].errors != null) { |
|
|
|
} else { |
|
|
|
this.message.error('必填项不能为空'); |
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
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) { |
|
|
|
} else { |
|
|
|
this.validateForm.value.id = this.id; |
|
|
|
this.config.insertBrand(this.validateForm.value, data => { |
|
|
|
this.config.updateBrand(this.validateForm.value, data => { |
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
this.message.success('添加成功'); |
|
|
|
this.isVisible = false; |
|
|
|
this.isVisible = false; |
|
|
|
this.message.success('修改成功'); |
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
console.log('123'); |
|
|
|
|
|
|
|
this.config.insertBrand(this.validateForm.value, data => { |
|
|
|
|
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
|
|
|
|
this.isVisible = false; |
|
|
|
|
|
|
|
this.message.success('添加成功'); |
|
|
|
|
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleCancel(): void { |
|
|
|
handleCancel(): void { |
|
|
|
this.isVisible = false; |
|
|
|
this.isVisible = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 對話框删除
|
|
|
|
// 對話框删除
|
|
|
|
showDeleteConfirm(id): void { |
|
|
|
showDeleteConfirm(id): void { |
|
|
|
this.modalService.confirm({ |
|
|
|
this.modalService.confirm({ |
|
|
|
nzTitle: '确定删除', |
|
|
|
nzTitle: '确定删除', |
|
|
|
nzOkText: '是', |
|
|
|
nzOkText: '是', |
|
|
|
nzOnOk: () => this.onDelete(id), |
|
|
|
nzOnOk: () => this.onDelete(id), |
|
|
|
nzCancelText: '否', |
|
|
|
nzCancelText: '否', |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onDelete(ids) { |
|
|
|
onDelete(ids) { |
|
|
|
this.config.getByDelete({ |
|
|
|
this.config.getByDelete({ |
|
|
|
id: ids |
|
|
|
id: ids |
|
|
|
}, data => { |
|
|
|
}, data => { |
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
if (data['return_code'] === '000000') { |
|
|
|
this.message.create('success', `删除成功!`); |
|
|
|
this.message.create('success', `删除成功!`); |
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
this.getRequest(true, this.searchForm.value); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
this.message.create('error', data['return_msg']); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|