中化加油站项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

349 lines
12 KiB

import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ObjectsSimpleService } from 'src/app/service/objectsSimple.service';
import { NzMessageService } from 'ng-zorro-antd/message';
import * as moment from 'moment';
import Viewer from 'viewerjs';
import { Router, ActivatedRoute } from '@angular/router'
@Component({
selector: 'app-oil-station-info',
templateUrl: './oil-station-info.component.html',
styleUrls: ['./oil-station-info.component.scss']
})
export class OilStationInfoComponent implements OnInit {
validateForm!: FormGroup;
constructor(private router: Router, private fb: FormBuilder, private objectsSrv: ObjectsSimpleService, private http: HttpClient, private message: NzMessageService) { }
userdata: any
dateFormat = 'yyyy-MM-dd';
ngOnInit(): void {
this.userdata = JSON.parse(sessionStorage.getItem('userdata'))
this.validateForm = this.fb.group({
oilStation: this.fb.group({
organization: [this.userdata.organization.displayName],
startBusinessTime: [null, [Validators.required]],
oilStationType: [null],
laneNumber: [null],
address: [null],
// validityTime: [null, [Validators.required]],//营业执照有效期
locationName: [null],
companyName: [null],
leaderName: [null],
leaderContact: [null],
stationLevel: [null],
sellVariety: [null],
gasStationCount: [null],
tankVolume: [null],
}),
policeStation: this.fb.group({
name: [null],
address: [null],
distance: [null],
contactInformation: [null]
}),
hospital: this.fb.group({
name: [null],
address: [null],
distance: [null],
contactInformation: [null]
}),
fireBrigade: this.fb.group({
name: [null],
address: [null],
distance: [null],
contactInformation: [null]
}),
validityTime: this.fb.group({
businessLicensevalidityTime: [null],
businessLicensevalidityTimeDay: [null, [Validators.required]],
hazardousLicensevalidityTime: [null],
hazardousLicensevalidityTimeDay: [null, [Validators.required]],
oilLicensevalidityTime: [null],
oilLicensevalidityTimeDay: [null, [Validators.required]]
})
});
this.getInfo()
}
validityTime: any = []//营业执照有效期
businessLicensevalidityTime: any = []//营业执照有效期
hazardousLicensevalidityTime: any = []//危化品有效期
oilLicensevalidityTime: any = []//成品油有效期
//获取油站信息
gallery
gasStationId
getInfo() {
this.http.get('/api/services/app/GasStation/Get', {
params: {
organizationUnitId: this.userdata.organization.id
}
}).subscribe((data: any) => {
console.log('油站信息', data)
this.httpBody = data.result
this.gasStationId = data.result.id
if (!data.result.govUnitDetail) {
this.httpBody.govUnitDetail = {
policeStation: {},
hospital: {},
fireBrigade: {}
}
} else {
this.httpBody.govUnitDetail = JSON.parse(data.result.govUnitDetail)
console.log('走这里了', data.result.govUnitDetail)
this.policeStation = data.result.govUnitDetail.policeStation
this.hospital = data.result.govUnitDetail.hospital
this.fireBrigade = data.result.govUnitDetail.fireBrigade
}
this.httpBody.stationType = String(this.httpBody.stationType)
this.businessLicensevalidityTime[0] = data.result.validityStartTime
this.businessLicensevalidityTime[1] = data.result.validityEndTime
this.businessLicensevalidityTime = [...this.businessLicensevalidityTime]
this.hazardousLicensevalidityTime[0] = data.result.dangerousStartTime
this.hazardousLicensevalidityTime[1] = data.result.dangerousEndTime
this.hazardousLicensevalidityTime = [...this.hazardousLicensevalidityTime]
this.oilLicensevalidityTime[0] = data.result.sellLicenseStartTime
this.oilLicensevalidityTime[1] = data.result.sellLicenseEndTime
this.oilLicensevalidityTime = [...this.oilLicensevalidityTime]
// if (this.httpBody.govUnitDetail) {
// //
// } else {
// }
setTimeout(() => {
this.gallery = new Viewer(document.getElementById('images'), {
show: () => { // 动态加载图片后,更新实例
this.gallery.update();
},
});
}, 0);
}, err => {
console.log('油站错误信息', err.error.error.message)
})
}
exportExcel() {
const httpOptions = {
responseType: 'blob' as 'json'
};
this.http.get(`/api/services/app/GasStation/ExportExcelFile?gasStationId=${this.gasStationId}`, httpOptions).subscribe((data: any) => {
// console.log('导出成功')
// 文件名中有中文 则对文件名进行转码
const link = document.createElement('a');
const blob = new Blob([data], { type: 'application/vnd.ms-excel' });
link.setAttribute('href', window.URL.createObjectURL(blob));
link.setAttribute('download', this.httpBody.stationName + '基本信息' + '.xls');
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
this.message.create('success', '导出成功!');
}, err => {
this.message.create('error', '导出失败!');
})
}
policeStation = {
name: '',
address: '',
distance: '',
contactInformation: ''
}
hospital = {
name: '',
address: '',
distance: '',
contactInformation: ''
}
fireBrigade = {
name: '',
address: '',
distance: '',
contactInformation: ''
}
httpBody = {
id: null,
stationName: JSON.parse(sessionStorage.getItem('userdata')).organization.displayName,
organizationUnitId: JSON.parse(sessionStorage.getItem('userdata')).organization.id,
validityStartTime: '',
validityEndTime: '',
dangerousStartTime: '',
dangerousEndTime: '',
sellLicenseStartTime: '',
sellLicenseEndTime: '',
validityTermDays: null,
dangerousTermDays: null,
sellLicenseTermDays: null,
openTime: '',
stationType: '',
laneCount: '',
address: '',
locationName: '',
companyName: '',
leaderName: '',
leaderContact: '',
stationLevel: '',
sellVariety: '',
gasStationCount: '',
tankVolume: '',
govUnitDetail: {
policeStation: {},
hospital: {},
fireBrigade: {}
},
businessLicenseImage: '',
dangerousChemicalLicenseImage: '',
gasSellLicenseImage: ''
}
goback() {
this.router.navigate(['/warning/petrolStation'])
}
submitForm() {
// console.log(this.validateForm)
// console.log(this.httpBody)
if (this.validateForm.valid) {
this.isLoadingSave = true
this.httpBody.openTime = moment(this.httpBody.openTime).format('YYYY-MM-MM')//开业时间格式化
this.httpBody.validityStartTime = moment(this.businessLicensevalidityTime[0]).format('YYYY-MM-MM')//
this.httpBody.validityEndTime = moment(this.businessLicensevalidityTime[1]).format('YYYY-MM-MM')//
this.httpBody.dangerousStartTime = moment(this.hazardousLicensevalidityTime[0]).format('YYYY-MM-MM')//
this.httpBody.dangerousEndTime = moment(this.hazardousLicensevalidityTime[1]).format('YYYY-MM-MM')//
this.httpBody.sellLicenseStartTime = moment(this.oilLicensevalidityTime[0]).format('YYYY-MM-MM')//
this.httpBody.sellLicenseEndTime = moment(this.oilLicensevalidityTime[1]).format('YYYY-MM-MM')//
this.httpBody.govUnitDetail.policeStation = this.validateForm.value.policeStation
this.httpBody.govUnitDetail.hospital = this.validateForm.value.hospital
this.httpBody.govUnitDetail.fireBrigade = this.validateForm.value.fireBrigade
let body = JSON.parse(JSON.stringify(this.httpBody))
body.stationType
body.govUnitDetail = JSON.stringify(this.httpBody.govUnitDetail)
if (this.httpBody.id) {
this.http.put('/api/services/app/GasStation/Update', body).subscribe((data: any) => {
this.isLoadingSave = false
this.message.create('success', '保存成功!');
}, err => {
this.isLoadingSave = false
this.message.create('error', '保存失败!');
})
} else {
this.http.post('/api/services/app/GasStation/Create', body).subscribe((data: any) => {
this.httpBody.id = data.result.id
this.isLoadingSave = false
this.message.create('success', '保存成功!');
}, err => {
this.isLoadingSave = false
this.message.create('error', '保存失败!');
})
}
} else {
this.message.create('warning', '请填写完整!');
return false
}
}
isLoadingOne: boolean = false
isLoadingTwo: boolean = false
isLoadingThree: boolean = false
isLoadingSave: boolean = false
uploadType: string
filechange(e, type) {
let file = e.target.files[0] || null //获取上传的文件
this.uploadType = type
if (this.uploadType == 'businessLicense') {//营业执照
this.isLoadingOne = true
}
if (this.uploadType == 'dangerousChemical') {//危化品销售
this.isLoadingTwo = true
}
if (this.uploadType == 'retailOfRefinedOil') {//成品油零售
this.isLoadingThree = true
}
this.openFileSelect(file, `stationPhotos/${this.userdata.organization.id}/`)
}
//设置文件路径并上传
postFilePath
async openFileSelect(file: File, extensionPath: string) {
this.postFilePath = extensionPath;
let fileSize = file.size || null //上传文件的总大小
let shardSize = 5 * 1024 * 1024 //5MB 超过5MB要分块上传
if (fileSize >= shardSize) // 超过5MB要分块上传
{
await this.postFileByMul(file);
setTimeout(() => {
this.gallery.destroy()
this.gallery = new Viewer(document.getElementById('images'));
}, 0);
}
else //普通上传
{
await this.postFile(file);
setTimeout(() => {
this.gallery.destroy()
this.gallery = new Viewer(document.getElementById('images'));
}, 0);
}
}
//上传文件
async postFile(file: File) {
await new Promise((resolve, reject) => {
this.objectsSrv.postFile(this.postFilePath, file).subscribe(data => {
let dataObj = data as any;
let filePath: string = ObjectsSimpleService.baseUrl + dataObj.objectName;
if (this.uploadType == 'businessLicense') {//营业执照
this.httpBody.businessLicenseImage = filePath
this.isLoadingOne = false
}
if (this.uploadType == 'dangerousChemical') {//危化品
this.httpBody.dangerousChemicalLicenseImage = filePath
this.isLoadingTwo = false
}
if (this.uploadType == 'retailOfRefinedOil') {//成品油
this.httpBody.gasSellLicenseImage = filePath
this.isLoadingThree = false
}
resolve('success')
});
})
}
/**
* 分块上传
* @param file
*/
postFileByMul(file: File) {
this.objectsSrv.postFile_MultipartUpload(this.postFilePath, file).then((value) => {
let dataObj = value as any;
if (this.uploadType == 'businessLicense') {//营业执照
this.httpBody.businessLicenseImage = dataObj.filePath
this.isLoadingOne = false
}
if (this.uploadType == 'dangerousChemical') {//危化品
this.httpBody.dangerousChemicalLicenseImage = dataObj.filePath
this.isLoadingTwo = false
}
if (this.uploadType == 'retailOfRefinedOil') {//成品油
this.httpBody.gasSellLicenseImage = dataObj.filePath
this.isLoadingThree = false
}
});
}
}