调令导出

master
xy 1 year ago
parent f6b36bd48e
commit 8e9e483ab3

@ -12,7 +12,7 @@
<header-content :auths="auths_auth_mixin">
<template #search>
<div style="display: flex">
<el-date-picker type="daterange" v-model="selectDate" size="small" :clearable="false" style="width: 220px;" @change="getTransfer"></el-date-picker>
<el-date-picker type="daterange" v-model="selectDate" size="small" :clearable="false" style="width: 220px;" @change="search"></el-date-picker>
<!-- <Button-->
<!-- style="margin-left: 10px"-->
<!-- type="primary"-->
@ -28,41 +28,39 @@
</div>
</div>
<el-card id="docx-content">
<div class="title">{{ selectDate[0] ? $moment(selectDate[0]).format('YYYY-MM-DD') : "-" }} ~ {{ selectDate[1] ? $moment(selectDate[1]).format('YYYY-MM-DD') : "-" }}调度指令执行情况</div>
<el-card id="docx-content" v-loading="loading"
element-loading-spinner="el-icon-loading"
element-loading-text="拼命加载中"
element-loading-background="rgba(0, 0, 0, 0.8)">
<div v-for="(value, date) in showData" :key="date" v-if="Object.keys(value).length > 0">
<div class="title">{{ date }}调度指令执行情况</div>
<p class="weather">{{ weather[date] ? weather[date].weather : '' }}</p>
<p style="text-indent: 30px;line-height: 1.2;padding: 20px 0;">{{ weather.weather }}</p>
<div v-for="(area, areaId) in value" :key="areaId">
<div class="area">{{ area.area ? area.area.key : '暂无区域' }}</div>
<div v-for="(item, index) in showData.filter(i => i._data.size > 0)" :key="item.value">
<div class="item" v-if="item._data.size > 0">
<div class="sub-title">{{ numberToChinese(index+1) }}. {{ item.key }}</div>
<div v-for="(item1, index1) in Array.from(item._data)" :key="item1[0]">
<div class="name">
{{index1+1}}.{{ item1[1][0].equipment_id_equipments_id_relation ? item1[1][0].equipment_id_equipments_id_relation.name : '' }}
<div v-for="(transfer, index) in area._data" :key="transfer.id" class="transfer">
<div class="transfer__name">{{ numberToChinese(++index) }}. {{ transfer.xuhao }} {{ transfer.equipment_id_equipments_id_relation ? transfer.equipment_id_equipments_id_relation.name: '' }}</div>
<div class="transfer__type">
{{ diaolingleixing.get(transfer.diaolingleixing) }}{{ type(transfer.leibie) }}
</div>
<div v-for="(item2, index2) in item1[1].sort((a,b) => new Date(a.act_start_time).valueOf() - new Date(b.act_start_time).valueOf())" :key="item2.id" style="display: flex;">
<div style="text-indent: 60px;">{{index1+1}}.{{index2+1}}</div>
<div>
<div>
{{ diaolingleixing.get(item2.diaolingleixing) }}{{ type(item2.leibie) }}
</div>
<div class="time">
<span>时间</span>
<span>{{ item2.act_start_time ? $moment(item2.act_start_time).format('YYYY-MM-DD HH:mm') : "-" }} ~ {{ item2.act_end_time ? $moment(item2.act_end_time).format('HH:mm') : "-" }}</span>
</div>
<div class="content">
<span>内容</span>
<span>{{ item2.to_transfer_id ? "[调整]" : "" }}{{ item2.content }}</span>
</div>
<div class="content" v-if="item2.diaolingleixing === 4">
<p v-for="log in item2.id_logs_transfer_id_relation">{{ $moment(log.created_at).format('HH:mm') }} {{ log.content }}</p>
</div>
</div>
<div class="transfer__plantime">
<span>计划时间</span>
<span>{{ $moment(transfer.start_time).format('YYYY-MM-DD HH:mm') }} ~ {{ $moment(transfer.end_time).format('YYYY-MM-DD HH:mm') }}</span>
</div>
<div class="transfer__acttime">
<span>实际时间</span>
<span>{{ $moment(transfer.act_start_time).format('YYYY-MM-DD HH:mm') }} ~ {{ $moment(transfer.act_end_time).format('YYYY-MM-DD HH:mm') }}</span>
</div>
<div class="transfer__content">
<span>调令内容</span>
<span>{{ transfer.to_transfer_id ? "[调整]" : "" }}{{ transfer.content }}</span>
</div>
</div>
</div>
</div>
<el-empty v-if="transfers.length === 0" description="暂无完成调令"></el-empty>
</el-card>
</div>
</template>
@ -92,11 +90,12 @@ export default {
mixins: [authMixin],
data() {
return {
loading: false,
types: [],
areas: [],
weather: {},
transfers: [],
showData: [],
showData: {},
selectDate: [new Date(),new Date()],
diaolingleixing: new Map([
[1,"水环境调令"],
@ -107,6 +106,12 @@ export default {
}
},
methods: {
search () {
if (this.loading) return;
this.loading = true;
Promise.all([this.getTransfer(),this.getWeather()]).then(_ => this.loading = false).catch(_ => this.loading = false)
},
async getWeatherInfo () {
try {
let infoObj = {
@ -142,17 +147,24 @@ export default {
filter: [
{
key: 'date',
op: 'eq',
value: this.$moment().format('YYYY-MM-DD')
op: 'range',
value: `${this.$moment(this.selectDate[0]||new Date()).startOf('days').format('YYYY-MM-DD HH:mm:ss')},${this.$moment(this.selectDate[1]||new Date()).endOf('days').format('YYYY-MM-DD HH:mm:ss')}`
}
]
},false)).data[0]
},false)).data
if (!res) {
await this.getWeatherInfo()
} else {
this.weather = res
let pickDateArr = [];
let startDay = this.$moment(this.selectDate[0]||new Date()).startOf('days')
while (startDay.isBefore(this.$moment(this.selectDate[1]||new Date()).endOf('days')) || (startDay.valueOf() === this.$moment(this.selectDate[1]||new Date()).endOf('days').valueOf())) {
pickDateArr.push(startDay.format('YYYY-MM-DD'))
startDay = startDay.add(1,'day')
}
this.weather = {};
pickDateArr.forEach(date => {
this.weather[date] = res.find(i => i.date === date)
})
console.log(this.weather)
},
numberToChinese (num) {
@ -224,7 +236,7 @@ export default {
table_name: "transfers",
page: 1,
page_size: 999,
sort_name: "equipment_id",
sort_name: "start_time",
filter: [
{
key: 'start_time',
@ -239,138 +251,267 @@ export default {
]
})).data
this.showData = this.areas.map(i => {
return {
...i,
_data: new Map()
}
let pickDateArr = [];
let startDay = this.$moment(this.selectDate[0]||new Date()).startOf('days')
while (startDay.isBefore(this.$moment(this.selectDate[1]||new Date()).endOf('days')) || (startDay.valueOf() === this.$moment(this.selectDate[1]||new Date()).endOf('days').valueOf())) {
pickDateArr.push(startDay.format('YYYY-MM-DD'))
startDay = startDay.add(1,'day')
}
this.showData = {}
pickDateArr.forEach(date => {
this.showData[date] = {}
})
this.transfers.forEach(item => {
let filterData = this.showData.find(i => i.value === item.equipment_id_equipments_id_relation.area)
if (filterData) {
if (filterData._data.has(item.equipment_id)) {
filterData._data.get(item.equipment_id).push(item)
if (item.start_time && item.equipment_id_equipments_id_relation.area) {
let myDate = this.$moment(item.start_time).format('YYYY-MM-DD');
let dateObj = this.showData[myDate];
if (dateObj.hasOwnProperty(item.equipment_id_equipments_id_relation.area)) {
dateObj[item.equipment_id_equipments_id_relation.area]._data.push(item)
} else {
filterData._data.set(item.equipment_id, [item])
dateObj[item.equipment_id_equipments_id_relation.area] = {
_data: [item],
area: this.areas.find(k => k.value === item.equipment_id_equipments_id_relation.area)
}
}
}
})
// this.showData = this.areas.map(i => {
// return {
// ...i,
// _data: new Map()
// }
// })
// this.transfers.forEach(item => {
// let filterData = this.showData.find(i => i.value === item.equipment_id_equipments_id_relation.area)
// if (filterData) {
// if (filterData._data.has(item.equipment_id)) {
// filterData._data.get(item.equipment_id).push(item)
// } else {
// filterData._data.set(item.equipment_id, [item])
// }
// }
// })
} catch (e) {
}
this.showData = Object.assign({}, this.showData)
console.log(this.showData)
},
async exportDocx () {
// const innerHTML = document.querySelector("#docx-content").innerHTML;
// const exportHTML = `<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head><meta charset='utf-8'><title></title></head><body>${innerHTML}</body></html>`
// let blob = new Blob(["\ufeff", exportHTML], {
// type: "application/msword",
// })
if (this.loading) return;
if (this.transfers.length <=0 ) {
this.$message({
type: "warning",
message: "暂无完成调令"
})
}
const document = new Document({
sections: [
{
children: [
new Paragraph({
text: `${this.selectDate[0] ? this.$moment(this.selectDate[0]).format('YYYY年MM月DD日') : "-"} ~ ${this.selectDate[1] ? this.$moment(this.selectDate[1]).format('YYYY年MM月DD日') : "-"}调度指令执行情况`,
heading: HeadingLevel.HEADING_1,
alignment: AlignmentType.CENTER,
spacing: {
after: 400
}
}),
new Paragraph({
indent: {
firstLine: convertInchesToTwip(0.5)
},
spacing: {
before: 200,
line: 500
},
children: [
new TextRun({
text: this.weather.weather,
size: 18,
})
]
}),
...this.showData.filter(i => (i._data && i._data.size>0)).map((i, index) => (
[
new Paragraph({
title: `${this.selectDate[0] ? this.$moment(this.selectDate[0]).format('YYYY年MM月DD日') : "-"} ~ ${this.selectDate[1] ? this.$moment(this.selectDate[1]).format('YYYY年MM月DD日') : "-"}调度指令执行情况`,
sections: (() => {
let sections = [];
for (let date in this.showData) {
let value = this.showData[date];
if (Object.keys(value).length > 0) {
let sectionChildren = [
new Paragraph({
text: `${this.$moment(date).format('YYYY年MM月DD日')}调度指令执行情况`,
heading: HeadingLevel.HEADING_2,
alignment: AlignmentType.CENTER,
spacing: {
after: 300
}
}),
new Paragraph({
text: this.weather[date]?.weather,
heading: HeadingLevel.HEADING_4,
alignment: AlignmentType.CENTER,
spacing: {
after: 200
}
}),
]
for (let areaId in value) {
let area = value[areaId];
sectionChildren.push(new Paragraph({
indent: {
firstLine: convertInchesToTwip(0.5)
},
spacing: {
after: 100,
before: 100
},
children: [
new TextRun({
text: area?.area.key || "暂无区域",
size: 24,
bold: true
})
]
}))
for (let index in area._data) {
let transfer = area._data[index];
sectionChildren.push(new Paragraph({
text: `${ this.numberToChinese(++index) }. ${ transfer?.xuhao || ' ' } ${ transfer?.equipment_id_equipments_id_relation?.name }`,
indent: {
firstLine: convertInchesToTwip(0.8)
},
spacing: {
before: 200,
line: 400
after: 50
},
children: [
new TextRun({
text: `${this.numberToChinese(index+1)}${i.key}`,
size: 28,
bold: true,
}),
]
}),
...Array.from(i._data).map((i1, index1) => (
[
new Paragraph({
spacing: {
before: 200,
line: 300
},
indent: {
left: 200
},
children: [
new TextRun({
text: `${index1+1}. ${i1[1][0].equipment_id_equipments_id_relation ? i1[1][0].equipment_id_equipments_id_relation.name : ''}`,
size: 24,
}),
]
}),
...i1[1].sort((a,b) => new Date(a.act_start_time).valueOf() - new Date(b.act_start_time).valueOf()).map((i2, index2) => {
return new Paragraph({
indent: {
left: 400
},
alignment: AlignmentType.LEFT,
children: [
new TextRun({
text: `${index1+1}.${index2+1}${ this.diaolingleixing.get(i2.diaolingleixing) }${ this.type(i2.leibie) }`,
size: 20,
break: 1,
}),
new TextRun({
text: `时间: ${i2.act_start_time ? this.$moment(i2.act_start_time).format('YYYY-MM-DD HH:mm') : "-" } ~ ${ i2.act_end_time ? this.$moment(i2.act_end_time).format('HH:mm') : "-" }`,
size: 18,
break: 1,
}),
new TextRun({
text: `${ i2.to_transfer_id ? "[调整]" : "" }内容:${i2.content || ''}`,
size: 18,
break: 1,
}),
...(() => {
if (i2.diaolingleixing === 4) {
return i2.id_logs_transfer_id_relation.map(log => new TextRun({
text: `${this.$moment(log.created_at).format('HH:mm')} ${log.content}`,
size: 18,
break: 1,
}))
} else {
return []
}
})()
]
})
})
]
)).flat()
]
)).flat()
]
},
]
}))
sectionChildren.push(new Paragraph({
text: `${ this.diaolingleixing.get(transfer.diaolingleixing) }${this.type(transfer.leibie)}`,
indent: {
firstLine: convertInchesToTwip(1)
},
spacing: {
after: 50
},
}))
sectionChildren.push(new Paragraph({
text: `计划时间:${ this.$moment(transfer.start_time).format('YYYY-MM-DD HH:mm') } ~ ${ this.$moment(transfer.end_time).format('YYYY-MM-DD HH:mm') }`,
indent: {
firstLine: convertInchesToTwip(1)
},
spacing: {
after: 50
},
}))
sectionChildren.push(new Paragraph({
text: `实际时间:${ this.$moment(transfer.act_start_time).format('YYYY-MM-DD HH:mm') } ~ ${ this.$moment(transfer.act_end_time).format('YYYY-MM-DD HH:mm') }`,
indent: {
firstLine: convertInchesToTwip(1)
},
spacing: {
after: 50
},
}))
sectionChildren.push(new Paragraph({
text: `${ transfer.to_transfer_id ? '[调整]' : '' }内容:${ transfer.content || ' ' }`,
indent: {
firstLine: convertInchesToTwip(1)
},
spacing: {
after: 50
},
}))
}
}
sections.push({
children: sectionChildren
})
}
}
return sections;
})()
})
// const document = new Document({
// sections: [
// {
// children: [
// new Paragraph({
// text: `${this.selectDate[0] ? this.$moment(this.selectDate[0]).format('YYYYMMDD') : "-"} ~ ${this.selectDate[1] ? this.$moment(this.selectDate[1]).format('YYYYMMDD') : "-"}`,
// heading: HeadingLevel.HEADING_1,
// alignment: AlignmentType.CENTER,
// spacing: {
// after: 400
// }
// }),
// new Paragraph({
// indent: {
// firstLine: convertInchesToTwip(0.5)
// },
// spacing: {
// before: 200,
// line: 500
// },
// children: [
// new TextRun({
// text: this.weather.weather,
// size: 18,
// })
// ]
// }),
// ...this.showData.filter(i => (i._data && i._data.size>0)).map((i, index) => (
// [
// new Paragraph({
// spacing: {
// before: 200,
// line: 400
// },
// children: [
// new TextRun({
// text: `${this.numberToChinese(index+1)}${i.key}`,
// size: 28,
// bold: true,
// }),
// ]
// }),
// ...Array.from(i._data).map((i1, index1) => (
// [
// new Paragraph({
// spacing: {
// before: 200,
// line: 300
// },
// indent: {
// left: 200
// },
// children: [
// new TextRun({
// text: `${index1+1}. ${i1[1][0].equipment_id_equipments_id_relation ? i1[1][0].equipment_id_equipments_id_relation.name : ''}`,
// size: 24,
// }),
// ]
// }),
// ...i1[1].sort((a,b) => new Date(a.act_start_time).valueOf() - new Date(b.act_start_time).valueOf()).map((i2, index2) => {
// return new Paragraph({
// indent: {
// left: 400
// },
// alignment: AlignmentType.LEFT,
// children: [
// new TextRun({
// text: `${index1+1}.${index2+1} ${ this.diaolingleixing.get(i2.diaolingleixing) }${ this.type(i2.leibie) }`,
// size: 20,
//
// break: 1,
// }),
// new TextRun({
// text: ` ${i2.act_start_time ? this.$moment(i2.act_start_time).format('YYYY-MM-DD HH:mm') : "-" } ~ ${ i2.act_end_time ? this.$moment(i2.act_end_time).format('HH:mm') : "-" }`,
// size: 18,
// break: 1,
// }),
// new TextRun({
// text: `${ i2.to_transfer_id ? "[]" : "" }${i2.content || ''}`,
// size: 18,
// break: 1,
// }),
// ...(() => {
// if (i2.diaolingleixing === 4) {
// return i2.id_logs_transfer_id_relation.map(log => new TextRun({
// text: `${this.$moment(log.created_at).format('HH:mm')} ${log.content}`,
// size: 18,
// break: 1,
// }))
// } else {
// return []
// }
// })()
// ]
// })
// })
// ]
// )).flat()
// ]
// )).flat()
// ]
// },
// ]
// })
const blob = await Packer.toBlob(document)
saveAs(blob, `${this.selectDate[0] ? this.$moment(this.selectDate[0]).format('YYYY年MM月DD日') : "-"} ~ ${this.selectDate[1] ? this.$moment(this.selectDate[1]).format('YYYY年MM月DD日') : "-"}调度指令执行情况.docx`)
@ -391,43 +532,42 @@ export default {
created() {
this.getType()
this.getArea()
this.getTransfer()
this.getWeather()
this.search()
}
}
</script>
<style scoped lang="scss">
#docx-content {
min-height: 300px;
}
.title {
font-weight: bolder;
font-size: 19px;
text-align: center;
padding: 10px 0;
}
.sub-title {
font-weight: bold;
font-size: 16px;
padding: 8px 0;
line-height: 3;
}
.name {
text-indent: 30px;
.weather {
font-size: 15px;
text-align: center;
line-height: 1.5;
padding: 6px 0;
}
.time {
text-indent: 10px;
line-height: 1.5;
.area {
font-weight: 600;
font-size: 15px;
line-height: 3;
}
.content {
text-indent: 10px;
line-height: 1.5;
.transfer {
line-height: 1.75;
text-indent: 20px;
& > div:nth-child(n+2) {
text-indent: 40px;
}
&__type {
}
.item + .item {
margin-top: 20px;
}
&__name {
}
}
</style>

@ -110,6 +110,7 @@ export default {
op,
select: {
table_name: "",
sort_name: 'equipment_id',
filter: [
{
key: "content",

Loading…
Cancel
Save