|
@@ -0,0 +1,242 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <a-modal
|
|
|
|
|
+ title="批量下载保养记录PDF"
|
|
|
|
|
+ :width="580"
|
|
|
|
|
+ :visible="visible"
|
|
|
|
|
+ :maskClosable="false"
|
|
|
|
|
+ @cancel="handleCancel"
|
|
|
|
|
+ >
|
|
|
|
|
+ <a-form layout="vertical">
|
|
|
|
|
+ <a-form-item label="时间范围">
|
|
|
|
|
+ <a-radio-group v-model="rangeMode" button-style="solid" @change="onPresetChange">
|
|
|
|
|
+ <a-radio-button value="year">今年</a-radio-button>
|
|
|
|
|
+ <a-radio-button value="quarter">本季度</a-radio-button>
|
|
|
|
|
+ <a-radio-button value="lastQuarter">上季度</a-radio-button>
|
|
|
|
|
+ <a-radio-button value="month">本月</a-radio-button>
|
|
|
|
|
+ <a-radio-button value="custom">自定义</a-radio-button>
|
|
|
|
|
+ </a-radio-group>
|
|
|
|
|
+ </a-form-item>
|
|
|
|
|
+ <a-form-item label="起止日期">
|
|
|
|
|
+ <a-range-picker
|
|
|
|
|
+ v-model="dateRange"
|
|
|
|
|
+ style="width: 100%"
|
|
|
|
|
+ format="YYYY-MM-DD"
|
|
|
|
|
+ :allowClear="false"
|
|
|
|
|
+ @change="onDateChange"
|
|
|
|
|
+ />
|
|
|
|
|
+ </a-form-item>
|
|
|
|
|
+ <a-form-item label="部门/班组">
|
|
|
|
|
+ <a-tree-select
|
|
|
|
|
+ v-model="deptId"
|
|
|
|
|
+ style="width: 100%"
|
|
|
|
|
+ :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
|
|
|
|
|
+ :treeData="deptTree"
|
|
|
|
|
+ treeNodeFilterProp="title"
|
|
|
|
|
+ :showSearch="true"
|
|
|
|
|
+ allowClear
|
|
|
|
|
+ placeholder="不选则下载全部部门"
|
|
|
|
|
+ @change="loadCount"
|
|
|
|
|
+ />
|
|
|
|
|
+ <div class="batch-download-tip">
|
|
|
|
|
+ 按部门筛选时,会同时包含该部门(含所有下级)的班组任务,以及执行人属于该部门范围的非班组任务;不选部门则为全部。
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </a-form-item>
|
|
|
|
|
+ </a-form>
|
|
|
|
|
+
|
|
|
|
|
+ <a-alert :type="countType" show-icon>
|
|
|
|
|
+ <template slot="message">
|
|
|
|
|
+ <span v-if="countLoading">正在统计可下载数量...</span>
|
|
|
|
|
+ <span v-else-if="count > 0">
|
|
|
|
|
+ 将下载约 <b>{{ count }}</b> 条已完成保养记录({{ rangeText }})
|
|
|
|
|
+ </span>
|
|
|
|
|
+ <span v-else>当前条件下没有可下载的已完成保养记录({{ rangeText }})</span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </a-alert>
|
|
|
|
|
+
|
|
|
|
|
+ <template slot="footer">
|
|
|
|
|
+ <a-button @click="handleCancel">取消</a-button>
|
|
|
|
|
+ <a-button
|
|
|
|
|
+ type="primary"
|
|
|
|
|
+ icon="download"
|
|
|
|
|
+ :loading="downloading"
|
|
|
|
|
+ :disabled="count === 0 || countLoading"
|
|
|
|
|
+ @click="doDownload"
|
|
|
|
|
+ >下载PDF压缩包</a-button>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </a-modal>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script>
|
|
|
|
|
+import { getDeptTree } from '@/api/upms/dept'
|
|
|
|
|
+import { batchDownloadCheckJobPdf, countCheckJobDownloadPdf } from '@/api/check/checkjob'
|
|
|
|
|
+
|
|
|
|
|
+export default {
|
|
|
|
|
+ name: 'BatchDownloadModal',
|
|
|
|
|
+ props: {
|
|
|
|
|
+ // 检查类型:1-点检 2-保养,与列表页保持一致
|
|
|
|
|
+ checkType: {
|
|
|
|
|
+ type: Number,
|
|
|
|
|
+ default: null
|
|
|
|
|
+ },
|
|
|
|
|
+ // 数据权限过滤标识,透传给后端保证与列表可见范围一致
|
|
|
|
|
+ filter: {
|
|
|
|
|
+ type: Number,
|
|
|
|
|
+ default: null
|
|
|
|
|
+ },
|
|
|
|
|
+ // 任务状态,保养记录页固定为 3(已完成)
|
|
|
|
|
+ status: {
|
|
|
|
|
+ type: Number,
|
|
|
|
|
+ default: 3
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ data () {
|
|
|
|
|
+ return {
|
|
|
|
|
+ visible: false,
|
|
|
|
|
+ downloading: false,
|
|
|
|
|
+ countLoading: false,
|
|
|
|
|
+ count: 0,
|
|
|
|
|
+ rangeMode: 'year',
|
|
|
|
|
+ dateRange: [],
|
|
|
|
|
+ deptId: undefined,
|
|
|
|
|
+ deptTree: []
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ computed: {
|
|
|
|
|
+ countType () {
|
|
|
|
|
+ if (this.countLoading) {
|
|
|
|
|
+ return 'info'
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.count > 0 ? 'success' : 'warning'
|
|
|
|
|
+ },
|
|
|
|
|
+ rangeText () {
|
|
|
|
|
+ if (!this.dateRange || this.dateRange.length !== 2) {
|
|
|
|
|
+ return '未选择时间'
|
|
|
|
|
+ }
|
|
|
|
|
+ const start = this.dateRange[0].format('YYYY-MM-DD')
|
|
|
|
|
+ const end = this.dateRange[1].format('YYYY-MM-DD')
|
|
|
|
|
+ return start + ' ~ ' + end
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ base () {
|
|
|
|
|
+ this.visible = true
|
|
|
|
|
+ this.downloading = false
|
|
|
|
|
+ this.count = 0
|
|
|
|
|
+ this.deptId = undefined
|
|
|
|
|
+ this.rangeMode = 'year'
|
|
|
|
|
+ this.applyPreset('year')
|
|
|
|
|
+ this.loadDeptTree()
|
|
|
|
|
+ this.loadCount()
|
|
|
|
|
+ },
|
|
|
|
|
+ loadDeptTree () {
|
|
|
|
|
+ if (this.deptTree && this.deptTree.length > 0) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ getDeptTree({}).then((res) => {
|
|
|
|
|
+ this.deptTree = res.data || []
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ onPresetChange (e) {
|
|
|
|
|
+ const mode = e.target.value
|
|
|
|
|
+ if (mode === 'custom') {
|
|
|
|
|
+ // 自定义模式保留当前日期,由用户手动选择
|
|
|
|
|
+ this.loadCount()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.applyPreset(mode)
|
|
|
|
|
+ this.loadCount()
|
|
|
|
|
+ },
|
|
|
|
|
+ onDateChange (dates) {
|
|
|
|
|
+ this.dateRange = dates || []
|
|
|
|
|
+ this.rangeMode = 'custom'
|
|
|
|
|
+ this.loadCount()
|
|
|
|
|
+ },
|
|
|
|
|
+ applyPreset (mode) {
|
|
|
|
|
+ const m = this.BaseTool.Moment
|
|
|
|
|
+ const today = m()
|
|
|
|
|
+ let start
|
|
|
|
|
+ let end
|
|
|
|
|
+ if (mode === 'year') {
|
|
|
|
|
+ start = m(today).startOf('year')
|
|
|
|
|
+ end = m(today).endOf('year')
|
|
|
|
|
+ } else if (mode === 'quarter') {
|
|
|
|
|
+ start = m(today).startOf('quarter')
|
|
|
|
|
+ end = m(today).endOf('quarter')
|
|
|
|
|
+ } else if (mode === 'lastQuarter') {
|
|
|
|
|
+ start = m(today).subtract(1, 'quarters').startOf('quarter')
|
|
|
|
|
+ end = m(today).subtract(1, 'quarters').endOf('quarter')
|
|
|
|
|
+ } else if (mode === 'month') {
|
|
|
|
|
+ start = m(today).startOf('month')
|
|
|
|
|
+ end = m(today).endOf('month')
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.dateRange = [start, end]
|
|
|
|
|
+ },
|
|
|
|
|
+ buildParams () {
|
|
|
|
|
+ const params = {
|
|
|
|
|
+ status: this.status
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.checkType !== null && this.checkType !== undefined) {
|
|
|
|
|
+ params.type = this.checkType
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.filter !== null && this.filter !== undefined) {
|
|
|
|
|
+ params.filter = this.filter
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.dateRange && this.dateRange.length === 2) {
|
|
|
|
|
+ params.searchStartTime = this.dateRange[0].format('YYYY-MM-DD') + ' 00:00:00'
|
|
|
|
|
+ params.searchEndTime = this.dateRange[1].format('YYYY-MM-DD') + ' 23:59:59'
|
|
|
|
|
+ }
|
|
|
|
|
+ if (this.deptId) {
|
|
|
|
|
+ params.batchDeptId = this.deptId
|
|
|
|
|
+ }
|
|
|
|
|
+ return params
|
|
|
|
|
+ },
|
|
|
|
|
+ loadCount () {
|
|
|
|
|
+ if (!this.dateRange || this.dateRange.length !== 2) {
|
|
|
|
|
+ this.count = 0
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.countLoading = true
|
|
|
|
|
+ countCheckJobDownloadPdf(this.buildParams())
|
|
|
|
|
+ .then((res) => {
|
|
|
|
|
+ this.count = (res && res.data) || 0
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {
|
|
|
|
|
+ this.count = 0
|
|
|
|
|
+ })
|
|
|
|
|
+ .finally(() => {
|
|
|
|
|
+ this.countLoading = false
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ doDownload () {
|
|
|
|
|
+ this.downloading = true
|
|
|
|
|
+ this.$message.loading({ content: '正在打包保养记录PDF,请稍候...', key: 'batchPdf', duration: 0 })
|
|
|
|
|
+ batchDownloadCheckJobPdf(this.buildParams())
|
|
|
|
|
+ .then((file) => {
|
|
|
|
|
+ this.BaseTool.UPLOAD.downLoadExportExcel(file)
|
|
|
|
|
+ this.$message.success({ content: '打包下载成功', key: 'batchPdf', duration: 2 })
|
|
|
|
|
+ this.visible = false
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {
|
|
|
|
|
+ this.$message.error({ content: '没有可下载的保养记录PDF或下载失败', key: 'batchPdf', duration: 3 })
|
|
|
|
|
+ })
|
|
|
|
|
+ .finally(() => {
|
|
|
|
|
+ this.downloading = false
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ handleCancel () {
|
|
|
|
|
+ this.visible = false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style scoped>
|
|
|
|
|
+.batch-download-tip {
|
|
|
|
|
+ color: #888;
|
|
|
|
|
+ font-size: 12px;
|
|
|
|
|
+ line-height: 1.5;
|
|
|
|
|
+ margin-top: 4px;
|
|
|
|
|
+}
|
|
|
|
|
+</style>
|