Files
bbq/src/app/routes/supply-management/components/bulk-publish/bulk-publish.component.ts
wangshiming c5a15ed78d 车辆对接
2022-01-06 11:13:20 +08:00

853 lines
27 KiB
TypeScript

import { Component, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup,Validators,FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import {
SFComponent,
SFNumberWidgetSchema,
SFSchema,
SFSchemaEnum,
SFSelectWidgetSchema,
SFTextareaWidgetSchema,
SFUISchema
} from '@delon/form';
import { _HttpClient } from '@delon/theme';
import { AmapPoiPickerComponent, AmapService, ShipperBaseService } from '@shared';
import { NzModalService } from 'ng-zorro-antd/modal';
import { PublishGoodsChooseFamifiarComponent } from '../choose-famifiar/choose-famifiar.component';
import { SupplyManagementService} from '../../services/supply-management.service';
import { map } from 'rxjs/operators';
import { of } from 'rxjs';
import { PublishSuccessComponent } from '../onecar-publish/publish-success/publish-success.component';
import { PublishAddressListComponent } from '../onecar-publish/address-list/address-list.component';
@Component({
selector: 'app-publish-goods-bulk-publish',
templateUrl: './bulk-publish.component.html',
styleUrls: ['./bulk-publish.component.less']
})
export class SupplyManagementBulkPublishComponent implements OnInit {
validateForm1: FormGroup;
newTempchecked = false; //是否存入新模板
sf1data: any; // 货源单设置回显
sf3data: any; // 货源单设置回显
sf4data: any; // 货源单设置回显
sf5data: any; // 货源单设置回显
sf7data: any; // 货源单设置回显
creatTime: any; // 货源单设置回显
modifyTime: any; // 货源单设置回显
totalFees: any; // 总数信息
totalDistance = 0.0; //总里程
totalTime = 0.0; //路程总时间
currentGoodsTypeName: any;
enterpriseProjectIds: any;
id = this.route.snapshot.params.id;
// // 单位
unit1 = '吨';
unit2 = '方';
unit3 = '保价费金额';
startInfo: any = [];
endInfo: any = [];
PageStatus = '';
dataList: any;
constructor(
private http: _HttpClient,
fb: FormBuilder,
private router: Router,
private route: ActivatedRoute,
private modalService: NzModalService,
public service: SupplyManagementService,
private amapService: AmapService,
public shipperSrv: ShipperBaseService,) {
this.validateForm1 = fb.group({
createTime: [null, []],
modifyTime: [null, []],
loadAddress0: [null, [Validators.required]],
loadName0: [null, [Validators.required]],
loadPhone0: [null, [Validators.required]],
unloadAddress0: [null, [Validators.required]],
unloadName0: [null, [Validators.required]],
unloadPhone0: [null, [Validators.required]]
});
}
@ViewChild('sf1', { static: false }) sf1!: SFComponent;
schema1: SFSchema = {};
ui1!: SFUISchema;
@ViewChild('sf2', { static: false }) sf2!: SFComponent;
schema2: SFSchema = {};
ui2!: SFUISchema;
@ViewChild('sf3', { static: false }) sf3!: SFComponent;
schema3: SFSchema = {};
ui3!: SFUISchema;
@ViewChild('sf4', { static: false }) sf4!: SFComponent;
schema4: SFSchema = {};
ui4!: SFUISchema;
@ViewChild('sf7', { static: false }) sf7!: SFComponent;
schema7: SFSchema = {};
ui7!: SFUISchema;
ngOnInit(): void {
if(this.route.snapshot?.queryParams?.sta === '1') {
console.log('修改')
this.PageStatus = '整车修改';
} else if(this.route.snapshot?.queryParams?.sta === '2') {
this.PageStatus = '整车下一单';
} else if(this.route.snapshot?.queryParams?.sta === '3') {
this.PageStatus = '大宗修改';
} else if(this.route.snapshot?.queryParams?.sta === '4') {
this.PageStatus = '大宗下一单';
}
this.initSF1();
// this.initSF2();
this.initSF3();
this.initSF4();
this.initSF6();
this.initdata();
}
initSF1() {
this.schema1 = {
properties: {
shipperAppUserId: {
title: '货主',
type: 'string',
maxLength: 30,
ui: {
widget: 'select',
serverSearch: true,
searchDebounceTime: 300,
searchLoadingText: '搜索中...',
onSearch: (q: any) => {
if (!!q) {
return this.service
.request(this.service.$api_enterpriceList, { enterpriseName: q})
.pipe(map((res) => (res as any[]).map((i) => ({ label: i.enterpriseName, value: i.id } as SFSchemaEnum))))
.toPromise();
} else {
return of([]);
}
},
change: (q: any) => {
this.getRegionCode(q)
},
visibleIf: {
_$expand: (value: boolean) => value,
},
} as SFSelectWidgetSchema,
},
enterpriseProjectId: {
type: 'string',
title: '项目',
ui: {
widget: 'select',
placeholder: '请选择',
} as SFSelectWidgetSchema
},
enterpriseInfoName: {
type: 'string',
title: '网络货运人',
ui: {
widget: 'text'
},
},
deadlineTime: {
title: '截至日期',
type: 'string',
format: 'date-time',
ui: {
placeholder: '请输入',
format: 'yyyy-MM-dd HH:mm:ss'
}
},
dispatchId: {
type: 'string',
title: '调度员',
ui: {
widget: 'select',
placeholder: '请选择',
allowClear: true,
optionalHelp: '选择调度员,司机直接联系调度员 ; 不选择,司机直接联系您',
asyncData: () => this.shipperSrv.getStaffList2()
} as SFSelectWidgetSchema
}
},
require: ['deadlineTime']
};
this.ui1 = {
'*': {
spanLabelFixed: 120,
grid: { span: 8 }
}
};
}
// 获取城市列表
getRegionCode(regionCode: any) {
console.log(regionCode);
return this.service
.request(this.service.$api_get_enterprise_project, { id: regionCode })
.pipe(
map(res =>
res.map((item: any) => ({
label: item.projectName,
value: item.id
}))
)
)
.subscribe(res => {
this.sf1.getProperty('/enterpriseProjectId')!.schema.enum = res;
this.sf1.getProperty('/enterpriseProjectId')!.widget.reset(res);
console.log('12345645454545454=============')
console.log(this.enterpriseProjectIds)
console.log(res)
if(this.enterpriseProjectIds) {
this.sf1.setValue('/enterpriseProjectId', this.enterpriseProjectIds);
}
});
}
// initSF2() {
// this.schema2 = {
// properties: {
// name1: {
// type: 'string',
// title: '发货模板',
// ui: {
// widget: 'custom',
// placeholder: '请输入'
// }
// }
// }
// };
// this.ui2 = {
// '*': {
// spanLabelFixed: 90,
// grid: { span: 12 }
// }
// };
// }
initSF3() {
this.schema3 = {
properties: {
goodsTypeId: {
type: 'string',
title: '货物名称',
ui: {
widget: 'select',
placeholder: '请选择',
errors: { required: '请选择货物类型' },
asyncData: () =>
this.shipperSrv.loadConfigByKey('goods.name.config.type').pipe(
map((data: any) => {
return data[0].children?.map((m: any) => {
return { label: m.name, value: m.id };
});
})
),
change: (value, data: any) => {
this.changeGoodsType(value, data);
this.sf3.setValue('/goodsTypeName', data.label);
}
} as SFSelectWidgetSchema
},
goodsTypeName: {
type: 'string',
title: '',
ui: {
hidden: true
}
},
goodsNameId: {
type: 'string',
title: '',
ui: {
widget: 'select',
placeholder: '请选择',
errors: { required: '请填写货物名称' },
change: (value: any, data: any) => {
this.sf3.setValue('/goodsName', data.label);
},
visibleIf: {
goodsTypeName: (value: any) => value && value !== '其它'
}
}
},
goodsName: {
type: 'string',
title: '',
ui: {
hidden: true,
visibleIf: {
goodsTypeName: (value: any) => value && value !== '其它'
}
}
},
goodsName1: {
type: 'string',
title: '',
ui: {
errors: { required: '请填写货物名称' },
visibleIf: {
goodsTypeName: (value: any) => value && value === '其它'
}
}
}
},
required: ['goodsTypeId', 'goodsName', 'goodsNameId']
};
this.ui3 = {
'*': {
spanLabelFixed: 90,
grid: { span: 12 }
}
};
}
initSF4() {
this.schema4 = {
properties: {
freightPrice: {
type: 'string',
title: '运费单价',
ui: {
errors: { required: '请选择运费单价' },
widget: 'custom',
placeholder: '请输入'
}
},
freightType: {
type: 'string',
title: '',
ui: {
hidden: true
},
default: '1'
},
rule: {
type: 'string',
title: '',
ui: {
widget: 'custom',
errors: { required: '请选择运费取整规则' }
}
},
settlementBasis: {
type: 'string',
title: '',
enum: [
{ label: '以收货为准', value: '1' },
{ label: '以发货为准', value: '2' }
],
ui: {
widget: 'select',
placeholder: '结算依据',
errors: { required: '请选择结算依据' }
} as SFSelectWidgetSchema
},
weight: {
type: 'string',
title: '货物数量',
ui: {
widget: 'custom',
placeholder: '请输入',
errors: { required: '请填写总重量' }
}
},
volume: {
type: 'string',
title: '',
ui: {
widget: 'custom',
placeholder: '请输入'
}
},
number: {
type: 'string',
title: '',
ui: {
widget: 'custom',
placeholder: '请输入'
}
},
maxWeight: {
type: 'string',
title: '车型/车长',
ui: {
widget: 'dict-select',
params: { dictKey: 'car:model' },
mode: 'multiple',
placeholder: '请选择车型',
errors: { required: '请选择车型' }
}
},
maxCube: {
type: 'string',
title: '',
ui: {
widget: 'dict-select',
params: { dictKey: 'car:length' },
mode: 'multiple',
placeholder: '请选择车长',
errors: { required: '请选择车长' }
}
}
},
required: ['weight', 'maxWeight', 'maxCube', 'freightPrice', 'rule', 'settlementBasis']
};
this.ui4 = {
'*': {
spanLabelFixed: 90,
grid: { span: 24 }
},
$freightPrice: {
grid: { span: 8 }
},
$rule: {
grid: { span: 8 }
},
$settlementBasis: {
grid: { span: 8 }
},
$weight: {
grid: { span: 8 }
},
$volume: {
grid: { span: 8 }
},
$number: {
grid: { span: 8 }
},
$maxWeight: {
grid: { span: 12 }
},
$maxCube: {
grid: { span: 12 }
}
};
}
changeValue() {
this.totalFees = Number(this.sf7?.value?.appendFee) + Number(this.sf7?.value?.oilCardPay) + Number(this.sf7?.value?.prePay) + Number(this.sf7?.value?.receiptPay) + Number(this.sf7?.value?.toPay)
console.log(this.totalFees)
}
initSF6() {
this.schema7 = {
properties: {
paymentDays: {
type: 'string',
title: '到货后',
ui: {
widget: 'custom',
placeholder: '请输入',
errors: { required: '请输入付款承诺天数' }
}
},
remarks: {
type: 'string',
title: '备注',
maxLength: 200,
ui: {
widget: 'textarea',
placeholder: '请输入',
autosize: { minRows: 3, maxRows: 3 }
} as SFTextareaWidgetSchema
}
},
required: ['paymentDays']
};
this.ui7 = {
'*': {
spanLabelFixed: 90,
grid: { span: 24 }
}
};
}
addStartInfo(event: any) {
if (this.startInfo.length < 5) {
const controlId = this.startInfo.length;
this.startInfo.push({
detailedAddress: '',
appUserName: '',
contractTelephone: '',
latitude: '',
longitude: '',
province: '',
city: '',
area: '',
type: 1
});
this.validateForm1.addControl(`loadAddress${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`loadName${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`loadPhone${controlId}`, new FormControl(null, Validators.required));
}
}
subStartInfo(event: any, index: number, id?:any) {
console.log(event, index, id)
if(id) {
this.service.request(this.service.$api_delete_Wholedeletebatch, [id]).subscribe((res) => {
console.log(res)
})
}
this.startInfo.splice(index, 1);
this.validateForm1.removeControl(`loadAddress${index}`);
this.validateForm1.removeControl(`loadName${index}`);
this.validateForm1.removeControl(`loadPhone${index}`);
}
addEndInfo(event: any) {
if (this.addEndInfo.length < 5) {
const controlId = this.endInfo.length;
this.endInfo.push({
detailedAddress: '',
appUserName: '',
contractTelephone: '',
latitude: '',
longitude: '',
province: '',
city: '',
area: '',
type: 2
});
this.validateForm1.addControl(`unloadAddress${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`unloadName${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`unloadPhone${controlId}`, new FormControl(null, Validators.required));
}
}
subEndInfo(event: any, index: number, id?:any) {
if(id) {
this.service.request(this.service.$api_delete_Wholedeletebatch, [id]).subscribe((res) => {
console.log(res)
})
}
console.log(event, index, id)
this.endInfo.splice(index, 1);
this.validateForm1.removeControl(`unloadAddress${index}`);
this.validateForm1.removeControl(`unloadName${index}`);
this.validateForm1.removeControl(`unloadPhone${index}`);
}
//指派熟车
chooseFamifiar() {
this.modalService.create({
nzTitle: '指派熟车',
nzContent: PublishGoodsChooseFamifiarComponent,
nzWidth: 1300
});
}
submit(): void {
console.log(this.startInfo)
if(typeof(this.validateForm1.value.modifyTime) !== 'string' ) {
var c = new Date(this.validateForm1.value.modifyTime);
this.validateForm1.value.modifyTime = c.getFullYear() + '-' + (c.getMonth() + 1) + '-' + c.getDate() + ' ' + c.getHours() + ':' + c.getMinutes() + ':' + c.getSeconds()
}
if(typeof(this.validateForm1.value.createTime) !== 'string' ) {
var c = new Date(this.validateForm1.value.createTime);
this.validateForm1.value.createTime = c.getFullYear() + '-' + (c.getMonth() + 1) + '-' + c.getDate() + ' ' + c.getHours() + ':' + c.getMinutes() + ':' + c.getSeconds()
}
// if (this.validateForm1.invalid) {
// return;
// }
const params: any = {
...this.sf1.value,
...this.sf7.value,
unLoadingPlaceDTOList: [...this.startInfo, ...this.endInfo,],
goodsInfoDTOList: [
{
...this.sf4.value, ...this.sf3.value,
maxWeight: this.sf4.value.maxWeight.join(','),
maxCube: this.sf4.value.maxCube.join(',')
}
]
}
params.freightPrice = this.totalFees
console.log(this.sf7.value)
console.log(params)
if(this.PageStatus === '大宗修改') {
this.requests(this.service.$api_set_bulkModify, params);
} else if(this.PageStatus === '大宗下一单') {
this.requests(this.service.$api_set_saveAnotherBulkOrder, params);
}
}
requests(url: any, params: any) {
this.service.request(url, params).subscribe((res: any) => {
if (res) {
this.modalService.create({
nzTitle: '',
nzContent: PublishSuccessComponent,
nzWidth: 900,
nzFooter: null,
nzComponentParams: { type: 'onecar' }
});
} else {
this.service.msgSrv.error(res.msg);
}
});
}
changeGoodsType(value: string, data: any) {
if (data.label === '其它') return;
const params = {
pageIndex: 1,
pageSize: 100,
configId: value
};
this.service
.request(this.service.$api_get_config_item_page, params)
.pipe(
map(data => {
return data.records?.map((m: any) => {
return { label: m.name, value: m.id };
});
})
)
.subscribe(res => {
if (res) {
this.sf3.getProperty('/goodsNameId')!.schema.enum = res;
this.sf3.getProperty('/goodsNameId')!.widget.reset(res);
if(this.sf3data.goodsNameId){
this.sf3.setValue('/goodsNameId',this.sf3data.goodsNameId);
}
} else {
this.service.msgSrv.error(res.msg);
}
});
}
// 打开地图
openMap(type: string, index: number) {
const modalRef = this.modalService.create({
nzTitle: '',
nzContent: AmapPoiPickerComponent,
nzWidth: 900,
nzOnOk: item => {
const poi = item.poi;
const locList = poi.location.toString().split(',');
switch (type) {
case 'start':
this.startInfo[index].detailedAddress = poi.district + poi.name;
this.startInfo[index].longitude = locList[0];
this.startInfo[index].latitude = locList[1];
this.startInfo[index].province = poi.cityInfo.province;
this.startInfo[index].city = poi.cityInfo.city;
this.startInfo[index].area = poi.cityInfo.district;
this.startInfo[index].address = poi.name;
break;
case 'end':
this.endInfo[index].detailedAddress = poi.district + poi.name;
this.endInfo[index].longitude = locList[0];
this.endInfo[index].latitude = locList[1];
this.endInfo[index].province = poi.cityInfo.province;
this.endInfo[index].city = poi.cityInfo.city;
this.endInfo[index].area = poi.cityInfo.district;
this.endInfo[index].address = poi.name;
break;
default:
break;
}
if (this.startInfo[0]?.area && this.endInfo[0]?.area) {
this.amapService.drivingCompute([...this.startInfo], [...this.endInfo]).subscribe((res: any) => {
this.totalDistance = res.distance;
this.totalTime = res.time;
});
}
}
});
}
goBack() {
window.history.go(-1);
}
// 初始化信息
initdata() {
this.service.request(`${this.service.$api_get_getBulkDetail}`, {id:this.id}).subscribe((res) => {
this.dataR(res);
})
}
asds(i: any) {
console.log(i)
}
// 初始化信息
dataR (res: any) {
// this.dataList = res;
if (res?.shipperAppUserName) {
const List: any = [];
this.service.request(this.service.$api_enterpriceList, { enterpriseName: res?.shipperAppUserName }).subscribe(rs => {
rs?.forEach((element: any) => {
List.push({ label: element.enterpriseName, value: element.id });
});
this.sf1.getProperty('/shipperAppUserId')!.schema.enum = List;
this.sf1.getProperty('/shipperAppUserId')!.widget.reset(List);
if (res?.shipperAppUserId) {
this.sf1.setValue('/shipperAppUserId', res?.shipperAppUserId);
this.getRegionCode(res?.shipperAppUserId);
}
});
}
if(res?.enterpriseProjectId) {
this.enterpriseProjectIds = res.enterpriseProjectId
}
this.sf1data = {
// shipperAppUserName: res?.shipperAppUserName || '',
enterpriseProjectId: res?.enterpriseProjectId || '',
enterpriseInfoName: res?.enterpriseInfoName || '',
externalResourceCode: res?.externalResourceCode || '',
dispatchId: res?.dispatchId || '',
deadlineTime: res?.deadlineTime || '',
}
if(this.PageStatus === '大宗修改') {
this.sf1data.id = res?.id;
}
res?.unLoadingPlaceVOList.forEach((element: any) => {
if(element.type === 1 || element.type === '1') {
const controlId = this.startInfo.length;
if(this.PageStatus === '大宗修改') {
this.startInfo.push({
detailedAddress: element.detailedAddress,
appUserName: element.appUserName,
contractTelephone: element.contractTelephone,
latitude: element.latitude,
longitude: element.longitude,
province: element.province,
city: element.city,
area: element.area,
type: element.type,
id: element.id
})
} else {
this.startInfo.push({
detailedAddress: element.detailedAddress,
appUserName: element.appUserName,
contractTelephone: element.contractTelephone,
latitude: element.latitude,
longitude: element.longitude,
province: element.province,
city: element.city,
area: element.area,
type: element.type,
})
}
if(element.createTime) {
this.creatTime = element?.createTime
this.modifyTime = element?.modifyTime
}
this.validateForm1.addControl(`loadAddress${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`loadName${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`loadPhone${controlId}`, new FormControl(null, Validators.required));
} else if(element.type === 2 || element.type === '2') {
const controlId = this.endInfo.length;
if( this.PageStatus === '大宗修改') {
this.endInfo.push({
detailedAddress: element?.detailedAddress,
appUserName: element?.appUserName,
contractTelephone: element?.contractTelephone,
latitude: element.latitude,
longitude: element.longitude,
province: element.province,
city: element.city,
area: element.area,
type: element.type,
id: element.id
})
} else {
this.endInfo.push({
detailedAddress: element?.detailedAddress,
appUserName: element?.appUserName,
contractTelephone: element?.contractTelephone,
latitude: element.latitude,
longitude: element.longitude,
province: element.province,
city: element.city,
area: element.area,
type: element.type
})
}
this.validateForm1.addControl(`unloadAddress${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`unloadName${controlId}`, new FormControl(null, Validators.required));
this.validateForm1.addControl(`unloadPhone${controlId}`, new FormControl(null, Validators.required));
}
});
this.sf3data = {
goodsTypeId: res?.goodsInfoVOList[0]?.goodsTypeId || '',
goodsTypeName: res?.goodsInfoVOList[0]?.goodsTypeName || '',
goodsNameId: res?.goodsInfoVOList[0]?.goodsNameId || '',
goodsName: res?.goodsInfoVOList[0]?.goodsName || '',
};
if (this.sf3data.goodsTypeName === '其它') {
this.sf3data.goodsName1 = res?.goodsInfoVOList[0]?.goodsName || '';
}
this.changeGoodsType(this.sf3data.goodsTypeId, { label: this.sf3data.goodsTypeName, value: this.sf3data.goodsTypeId });
this.sf4data = {
freightPrice: res?.goodsInfoVOList[0]?.freightPrice || '',
freightType: res?.goodsInfoVOList[0]?.freightType || '',
rule: res?.goodsInfoVOList[0]?.rule || '',
settlementBasis: res?.goodsInfoVOList[0]?.settlementBasis || '',
weight: res?.goodsInfoVOList[0]?.weight || '',
volume: res?.goodsInfoVOList[0]?.volume || '',
number: res?.goodsInfoVOList[0]?.number || '',
maxWeight: res?.goodsInfoVOList[0]?.maxWeight?.split(',') || '',
maxCube: res?.goodsInfoVOList[0]?.maxCube?.split(',') || ''
}
if(this.PageStatus === '大宗修改') {
this.sf4data.id = res?.goodsInfoVOList[0]?.id;
}
this.totalFees = res?.freightPrice || '0';
this.sf7data = {
paymentDays: res?.paymentDays || '',
remarks: res?.remarks || ''
};
}
choose(){
window.history.go(-1);
}
chooseAddress(index: number, type: string) {
const modalRef = this.modalService.create({
nzTitle: '选择地址',
nzContent: PublishAddressListComponent,
nzWidth: 900,
nzComponentParams: { spuStatus: '1' },
nzOnOk: item => {
console.log(item)
console.log(type)
const data = item.seleteData;
if (JSON.stringify(data) === '{}') return;
switch (type) {
case 'start':
this.startInfo[index] = {
detailedAddress: data.detailedAddress,
appUserName: data.contactName,
contractTelephone: data.contactTelephone,
latitude: data.contactTelephone,
longitude: data.latitude,
province: data.province,
city: data.city,
area: data.area,
type: '1'
};
break;
case 'end':
this.endInfo[index] = {
detailedAddress: data.detailedAddress,
appUserName: data.contactName,
contractTelephone: data.contactTelephone,
latitude: data.contactTelephone,
longitude: data.latitude,
province: data.province,
city: data.city,
area: data.area,
type: '2'
};
break;
default:
break;
}
}
});
}
}