diff --git a/src/views/order/orderSummary.vue b/src/views/order/orderSummary.vue index 94adb94..28df9cd 100644 --- a/src/views/order/orderSummary.vue +++ b/src/views/order/orderSummary.vue @@ -12,7 +12,7 @@ @@ -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 = `调令内容${innerHTML}` - // 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('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({ + // 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() } } diff --git a/src/views/order/today.vue b/src/views/order/today.vue index ea60ce7..757003e 100644 --- a/src/views/order/today.vue +++ b/src/views/order/today.vue @@ -110,6 +110,7 @@ export default { op, select: { table_name: "", + sort_name: 'equipment_id', filter: [ { key: "content",