add:需求单预览打印、导出EXCEL

This commit is contained in:
zhaoyf
2026-10-12 17:54:32 +08:00
parent 8e2d609631
commit fe598f54a4
7 changed files with 165 additions and 8 deletions

View File

@@ -31,6 +31,12 @@ public class PmDemandController {
return ResponseData.build(pmDemandService.queryPage(query, page), HttpStatus.OK);
}
@GetMapping("/exportList")
@Log("导出需求单")
public ResponseEntity<Object> exportList(PmDemandQuery query) {
return ResponseData.build(pmDemandService.queryExportList(query), HttpStatus.OK);
}
@PostMapping
@Log("新增需求单")
public ResponseEntity<Object> create(@Valid @RequestBody PmDemandParam param) {

View File

@@ -16,6 +16,8 @@ public interface IPmDemandService extends IService<PmDemand> {
Page<PmDemandDto> queryPage(PmDemandQuery query, PageQuery pageQuery);
List<PmDemandDto> queryExportList(PmDemandQuery query);
void create(PmDemandParam param);
void batchCreate(List<PmDemandParam> param);

View File

@@ -10,5 +10,7 @@ import java.util.List;
public interface PmDemandMapper extends BaseMapper<PmDemand> {
List<PmDemandDto> queryExportList(@Param("query") PmDemandQuery query);
List<PmDemandDto> queryPage(@Param("query") PmDemandQuery query);
}

View File

@@ -66,4 +66,44 @@
</if>
order by d.create_time desc,d.work_order,d.priority desc
</select>
<select id="queryExportList" resultMap="DemandDtoMap">
select d.*
from pm_demand d
where 1 = 1
<if test="query.status == 90">
and d.is_deleted = 1
</if>
<if test="query.status != 90">
and d.is_deleted = 0
</if>
<if test="query.id != null and query.id != ''">
and d.id = #{query.id}
</if>
<if test="query.creator != null and query.creator != ''">
and d.creator like concat('%', #{query.creator}, '%')
</if>
<if test="query.status != null">
and d.status = #{query.status}
</if>
<if test="query.workOrder != null and query.workOrder != ''">
and d.work_order like concat('%', #{query.workOrder}, '%')
</if>
<if test="query.skuCode != null and query.skuCode != ''">
and (d.sku_code like concat('%', #{query.skuCode}, '%') or d.sku_name like concat('%', #{query.skuCode}, '%'))
</if>
<if test="query.productionLine != null and query.productionLine != ''">
and d.production_line like concat('%', #{query.productionLine}, '%')
</if>
<if test="query.targetArea != null and query.targetArea != ''">
and d.target_area like concat('%', #{query.targetArea}, '%')
</if>
<if test="query.startTime != null and query.startTime != ''">
and d.create_time &gt;= #{query.startTime}
</if>
<if test="query.endTime != null and query.endTime != ''">
and d.create_time &lt;= #{query.endTime}
</if>
order by d.create_time desc, d.work_order, d.priority desc
</select>
</mapper>

View File

@@ -123,6 +123,12 @@ public class PmDemandServiceImpl extends ServiceImpl<PmDemandMapper, PmDemand> i
return dtoPage;
}
@Override
public List<PmDemandDto> queryExportList(PmDemandQuery query) {
trimStringFields(query);
return baseMapper.queryExportList(query);
}
@Override
public void create(PmDemandParam param) {
PmDemand demand = new PmDemand();

View File

@@ -67,4 +67,12 @@ export function batchAllcation(data) {
data
})
}
export default { add, edit, del, queryInventory, batchAllocate, allocate, push, issueReturnBill }
export function queryExportList(params) {
return request({
url: 'api/pmDemand/exportList',
method: 'get',
params
})
}
export default { add, edit, del, queryInventory, batchAllocate, allocate, push, issueReturnBill, queryExportList }

View File

@@ -26,6 +26,8 @@
<el-button slot="right" class="filter-item" type="success" icon="el-icon-s-promotion" size="mini" :disabled="isPushDisabled()" @click="handleBatchPush">下推出库</el-button>
<el-button slot="right" class="filter-item" type="warning" icon="el-icon-house" size="mini" :disabled="isBatchAllocateDisabled()" @click="openBatchAllocateDialog">批量分配</el-button>
<el-button slot="right" class="filter-item" type="success" icon="el-icon-s-promotion" size="mini" :disabled="isBatchAllocateDisabled()" @click="handleBatchAllocation">自动分配</el-button>
<el-button slot="right" class="filter-item" type="primary" icon="el-icon-printer" size="mini" :disabled="!multipleSelection.length" @click="printDemand">预览打印</el-button>
<el-button slot="right" class="filter-item" type="success" icon="el-icon-download" size="mini" :loading="exporting" @click="exportDemand">导出 Excel</el-button>
</crudOperation>
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="900px">
<el-form ref="form" :model="form" :rules="rules" size="mini" label-width="110px" label-suffix=":" style="border: 1px solid #cfe0df;margin-top: 10px;padding: 10px;">
@@ -128,18 +130,26 @@
</el-table-column>
</el-table>
<pagination />
<el-dialog :close-on-click-modal="false" title="打印预览" :visible.sync="printPreviewVisible" width="800px" @close="closePrintPreview">
<iframe ref="printIframe" src="about:blank" style="width: 100%; height: 500px; border: 1px solid #ddd;" />
<div slot="footer" class="dialog-footer">
<el-button type="info" @click="printPreviewVisible = false">取消</el-button>
<el-button type="primary" @click="doPrint">打印</el-button>
</div>
</el-dialog>
</div>
</div>
</template>
<script>
import crudDemand, { del, queryInventory, allocate, batchAllocate, push, batchAllcation } from './demand'
import crudDemand, { del, queryInventory, allocate, batchAllocate, push, batchAllcation, queryExportList } from './demand'
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import rrOperation from '@crud/RR.operation.vue'
import pagination from '@crud/Pagination.vue'
import crudPurchase from '@/views/wms/pm_manage/allocationOut/purchase'
import XLSX from 'xlsx'
const createDefaultForm = () => ({ id: null, creator: '', createTime: '', priority: 0, status: 0, workOrder: '', skuCode: '', skuName: '', qty: undefined, unit: '', targetArea: '', productionLine: '', sn: '' })
@@ -177,6 +187,8 @@ export default {
],
audit_flag: true,
batchDeleting: false,
exporting: false,
printPreviewVisible: false,
allocateVisible: false,
inventoryLoading: false,
allocateSaving: false,
@@ -224,11 +236,90 @@ export default {
},
handleSelectionChange(val, row) {
this.multipleSelection = val
if (val.length === 0 && (val[0].status === '10' || val[0].status === '20')) {
this.audit_flag = true
} else {
this.audit_flag = false
this.audit_flag = val.length === 0
},
getExportQuery() {
const params = { ...this.query }
if (params.datepick && params.datepick.length) {
params.startTime = params.datepick[0]
params.endTime = params.datepick.length > 1 ? params.datepick[1] : params.datepick[0]
}
delete params.datepick
Object.keys(params).forEach(key => {
if (params[key] === null || params[key] === '') delete params[key]
})
return params
},
exportDemand() {
this.exporting = true
queryExportList(this.getExportQuery()).then(res => {
const list = res.data || []
if (!list.length) {
this.$message.info('当前筛选条件下没有可导出的需求单')
return
}
this.$confirm(`当前筛选条件下共有 ${list.length} 条需求单,确认导出吗?`, '导出确认', {
confirmButtonText: '确认导出',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const sheet = XLSX.utils.aoa_to_sheet([
['需求单编号', '物料编码', '物料名称', '数量'],
...list.map(item => [item.workOrder, item.skuCode, item.skuName, item.qty])
])
sheet['!cols'] = [{ wch: 24 }, { wch: 20 }, { wch: 30 }, { wch: 12 }]
const workbook = XLSX.utils.book_new()
XLSX.utils.book_append_sheet(workbook, sheet, '需求单')
XLSX.writeFile(workbook, '需求单_' + this.formatFileTime(new Date()) + '.xlsx')
}).catch(() => {})
}).catch(() => {
this.$message.error('查询导出数据失败')
}).finally(() => {
this.exporting = false
})
},
formatFileTime(date) {
const pad = value => String(value).padStart(2, '0')
return date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) + '_' + pad(date.getHours()) + pad(date.getMinutes()) + pad(date.getSeconds())
},
printDemand() {
if (!this.multipleSelection.length) {
this.$message.warning('请至少勾选一条需求单')
return
}
this.printPreviewVisible = true
this.$nextTick(() => this.renderPrintContent(this.multipleSelection))
},
renderPrintContent(list) {
const iframe = this.$refs.printIframe
if (!iframe) return
const doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document)
if (!doc) {
setTimeout(() => this.renderPrintContent(list), 100)
return
}
const escapeHtml = value => String(value === null || value === undefined ? '' : value)
.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;')
let html = '<!DOCTYPE html><html><head><meta charset="utf-8"><style>'
html += '*{box-sizing:border-box}body{font-family:"Microsoft YaHei",Arial,sans-serif;padding:15px;color:#222}'
html += 'h3{text-align:center;margin:0 0 12px;font-size:18px}table{width:100%;border-collapse:collapse}th,td{border:1px solid #333;padding:8px;font-size:14px;text-align:left}th{text-align:center;background:#f5f5f5}@media print{@page{size:auto;margin:8mm}}'
html += '</style></head><body><h3>需求单</h3><table><thead><tr><th>物料编码</th><th>物料名称</th><th>数量</th><th>目标库存地点</th></tr></thead><tbody>'
list.forEach(item => {
html += '<tr><td>' + escapeHtml(item.skuCode) + '</td><td>' + escapeHtml(item.skuName) + '</td><td>' + escapeHtml(item.qty) + '</td><td>' + escapeHtml(item.targetArea) + '</td></tr>'
})
html += '</tbody></table></body></html>'
doc.open()
doc.write(html)
doc.close()
},
doPrint() {
const iframe = this.$refs.printIframe
if (!iframe) return
iframe.contentWindow.focus()
iframe.contentWindow.print()
},
closePrintPreview() {
this.printPreviewVisible = false
},
issueReturnBill() {
const selections = this.multipleSelection
@@ -304,7 +395,9 @@ export default {
})
}
})
} catch (e) { }
} catch (e) {
// Ignore malformed saved allocation data.
}
}
}).finally(() => {
this.inventoryLoading = false