Files
bbq/src/app/routes/supply-management/components/vehicle/vehicle.component.ts
Taric Xin 2181b8e5cb edit
2021-12-22 11:16:04 +08:00

463 lines
12 KiB
TypeScript

import { ActivatedRoute, Router } from '@angular/router';
import { Component, OnInit, ViewChild } from '@angular/core';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFComponent, SFSchema, SFSelectWidgetSchema, SFUISchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { NzModalService } from 'ng-zorro-antd/modal';
import { map } from 'rxjs/operators';
import { SupplyManagementService } from '../../services/supply-management.service';
import { SupplyManagementAssignedCarComponent } from '../assigned-car/assigned-car.component';
import { SupplyManagementUpdateExternalSnComponent } from '../update-external-sn/update-external-sn.component';
import { SupplyManagementUpdateFreightComponent } from '../update-freight/update-freight.component';
@Component({
selector: 'app-supply-management-vehicle',
templateUrl: './vehicle.component.html',
styleUrls: ['./vehicle.component.less']
})
export class SupplyManagementVehicleComponent implements OnInit {
ui2: SFUISchema = {};
schema: SFSchema = this.initSF();
freightSchema: SFSchema = {};
auditMany = false;
isVisible = false;
_$expand = false;
@ViewChild('st') private readonly st!: STComponent;
@ViewChild('sf', { static: false }) sf!: SFComponent;
@ViewChild('sfFre', { static: false }) sfFre!: SFComponent;
columns: STColumn[] = this.initST();
tabs = {
totalQuantity: 0,
cancelQuantity: 0,
receivedQuantity: 0,
stayQuantity: 0
};
resourceStatus: any;
constructor(public service: SupplyManagementService, private modal: NzModalService, private router: Router, private ar: ActivatedRoute) {}
/**
* 查询参数
*/
get reqParams() {
const a: any = {};
if (this.resourceStatus) {
a.resourceStatus = this.resourceStatus;
}
return {
...a,
...this.sf?.value
};
}
get selectedRows() {
return this.st?.list.filter(item => item.checked) || [];
}
ngOnInit(): void {
this.initSFFre();
this.getGoodsSourceStatistical();
}
/**
* 初始化查询表单
*/
initSFFre() {
this.freightSchema = {
properties: {
roleDescription: {
title: '备注',
type: 'string',
maxLength: 50,
ui: {
placeholder: '请输入备注',
widget: 'textarea'
}
}
}
};
this.ui2 = { '*': { spanLabelFixed: 120, grid: { span: 24 } } };
}
add(): void {
// this.modal
// .createStatic(FormEditComponent, { i: { id: 0 } })
// .subscribe(() => this.st.reload());
}
/**
* 伸缩查询条件
*/
expandToggle(): void {
this._$expand = !this._$expand;
this.sf?.setValue('/_$expand', this._$expand);
}
/**
* 重置表单
*/
resetSF(): void {
this.sf.reset();
this._$expand = false;
}
selectChange(e: number) {
this.resourceStatus = e;
setTimeout(() => {
this.st.load();
}, 500);
}
/**
* 编辑外部货源号
* @param item st当前行对象
*/
editEnternalSn(item: any) {
const modalRef = this.modal.create({
nzWidth: '400px',
nzContent: SupplyManagementUpdateExternalSnComponent,
nzComponentParams: {
orderObject: item
},
nzFooter: null,
nzClosable: false
});
}
/**
* 导入货源
*/
importGoodsSource() {}
/**
* 修改运费
*/
updateFreight(item: any) {
const modalRef = this.modal.create({
nzTitle: '修改运费',
nzWidth: '40%',
nzContent: SupplyManagementUpdateFreightComponent,
nzComponentParams: {
i: item
},
nzFooter: null
});
}
/**
* 重新指派
*/
assignedCar(item: any) {
const { resourceId } = item;
const modalRef = this.modal.create({
nzTitle: '指派熟车',
nzWidth: '1200px',
nzContent: SupplyManagementAssignedCarComponent,
nzComponentParams: {
i: item,
status: 'anew',
// url: this.service.$api_save_assign_vehicle,
params: { resourceId }
},
nzFooter: null
});
modalRef.afterClose.subscribe(result => {
if (result) {
this.st.reload();
}
});
}
/**
* 审核
*/
audit(value: any, status?: any) {
console.log(value);
console.log(status);
if (status === 2) {
this.auditMany = true;
} else {
this.auditMany = false;
}
this.isVisible = true;
}
/**
* 审核关闭弹窗
*/
handleCancel(type: any) {
this.isVisible = false;
}
/**
* 审核通过按钮
*/
handleOK() {}
/**
* 跳转修改货源
*/
amend(item: any) {
console.log(item);
this.router.navigate(['/supply-management/vehicle-amend', item.id], {
queryParams: {
sta: 1
}
});
}
nextOrder(item: any) {
this.router.navigate(['/supply-management/vehicle-amend', item.id], {
queryParams: {
sta: 2
}
});
}
/**
* 取消货源
*/
cancleGoodsSource(record: any) {
this.modal.confirm({
nzTitle: '<b>确定取消货源吗?</b>',
nzContent: `<b>取消后不可恢复,谨慎操作</b>`,
nzOnOk: () =>
this.service.request(this.service.$api_cancle_goods_source, [record.id]).subscribe(res => {
if (res === true) {
this.service.msgSrv.success('操作成功!');
this.st?.reload();
this.getGoodsSourceStatistical();
}
})
});
}
// 获取货源状态统计
getGoodsSourceStatistical() {
this.service.request(this.service.$api_get_goods_resource_statistical, { resourceType: 1 }).subscribe(res => {
if (res) {
console.log(res);
this.tabs = res;
}
});
}
private initSF(): SFSchema {
return {
properties: {
_$expand: { type: 'boolean', ui: { hidden: true } },
resourceCode: {
type: 'string',
title: '货源编号',
ui: { placeholder: '请输入' }
},
loadingPlace: {
type: 'string',
title: '装货地',
ui: {
placeholder: '请输入'
}
},
dischargePlace: {
type: 'string',
title: '卸货地',
ui: { placeholder: '请输入' }
},
shipperAppUserName: {
type: 'string',
title: '货主',
ui: {
visibleIf: {
_$expand: (value: boolean) => value
}
}
},
goodsName: {
title: '所属项目',
type: 'string',
default: '',
ui: {
widget: 'select',
visibleIf: {
_$expand: (value: boolean) => value
}
// asyncData: () =>[]
} as SFSelectWidgetSchema
},
serviceType: {
title: '服务类型',
type: 'string',
ui: {
widget: 'dict-select',
containsAllLable: true,
params: { dictKey: 'service:type' },
visibleIf: {
_$expand: (value: boolean) => value
}
} as SFSelectWidgetSchema
},
auditStatus: {
title: '审核状态',
type: 'string',
ui: {
widget: 'dict-select',
params: { dictKey: 'goodresource:audit:status' },
visibleIf: {
_$expand: (value: boolean) => value
}
} as SFSelectWidgetSchema
},
enterpriseInfoName: {
type: 'string',
title: '网络货运人',
ui: {
widget: 'select',
placeholder: '请选择',
visibleIf: {
_$expand: (value: boolean) => value
},
allowClear: true
// asyncData: () => this.getCatalogueMember(),
}
}
}
};
}
/**
* 初始化数据列表
*/
private initST(): STColumn[] {
return [
{ title: '', type: 'checkbox', width: '50px', className: 'text-center' },
{
title: '货源编号',
width: '100px',
className: 'text-center',
render: 'resourceCode'
},
// {
// title: '服务类型',
// index: 'serviceType',
// width: '120px',
// className: 'text-center',
// type: 'enum',
// enum: { '1': '抢单', '2': '指派' }
// },
{ title: '货主', index: 'shipperAppUserNmae', width: '120px' },
{
title: '项目名称',
index: 'enterpriseProjectName',
width: '120px'
},
{
title: '装货地',
index: 'loadingAddressArr',
width: '120px'
},
{
title: '卸货地',
index: 'unloadingAddressArr',
width: '120px'
},
{
title: '货物名称',
index: 'goodsName',
width: '120px'
},
{
title: '货物数量',
width: '120px',
index: 'goodsNumber',
format: item => item.goodsNumber.join('/')
},
{
title: '用车需求',
width: '120px',
format: (item: any) => `<p>车型: ${item.vehicleDemand?.maxWeight || ''}</p><p>车长: ${item.vehicleDemand?.maxCube || ''}米</p>`,
index: 'vehicleDemand'
},
{
title: '总费用',
className: 'text-center',
width: '120px',
index: 'totalAmount',
render: 'totalAmount'
},
{
title: '总运费',
className: 'text-center',
width: '120px',
index: '总运费'
},
{
title: '附加费',
className: 'text-center',
width: '120px',
index: 'surcharge',
format: item => `${item.surcharge}`
},
{
title: '货源状态',
className: 'text-center',
index: 'resourceStatus',
type: 'badge',
width: '120px',
badge: {
'1': { text: '待接单', color: 'warning' },
'2': { text: '已接单', color: 'success' }
}
},
{
title: '创建时间',
width: '170px',
index: 'createTime',
className: 'text-center',
type: 'date'
},
{
title: '审核状态',
className: 'text-center',
index: 'auditStatus',
type: 'badge',
width: '170px',
badge: {
'1': { text: '待审核', color: 'warning' },
'2': { text: '审核通过', color: 'success' },
'3': { text: '不通过', color: 'error' },
'4': { text: '已取消', color: 'default' }
}
},
{
title: '操作',
fixed: 'right',
width: '110px',
className: 'text-center',
buttons: [
{
text: '货源审核',
click: _record => this.audit(_record, 1),
iif: item => item.auditStatus === '1'
},
{
text: '修改货源',
click: _record => this.amend(_record),
iif: item => item.resourceStatus === '1'
},
{
text: '修改运费',
click: _record => this.updateFreight(_record),
iif: item => item.resourceStatus === '1' && item.serviceType === '2'
},
{
text: '取消货源',
click: _record => this.cancleGoodsSource(_record),
iif: item => item.resourceStatus === '1'
},
{
text: '再下一单',
click: _record => this.nextOrder(_record)
},
{
text: '重新指派',
click: _record => this.assignedCar(_record),
iif: item => item.resourceStatus === '1' && item.serviceType === '2'
}
]
}
];
}
}