| | |
| | | <el-button type="primary" @click="fnPrint('是')">打印</el-button> |
| | | </el-form-item> |
| | | <el-form-item label=""> |
| | | <el-button type="success" @click="exportExcel">Excel导出</el-button> |
| | | </el-form-item> |
| | | <el-form-item label=""> |
| | | <el-button type="primary" @click="fnCanelPrint()">撤销生成</el-button> |
| | | </el-form-item> |
| | | <el-form-item label=""> |
| | |
| | | |
| | | } |
| | | |
| | | function dateFormat(fmt, date) { |
| | | let ret; |
| | | const opt = { |
| | | "Y+": date.getFullYear().toString(), |
| | | "m+": (date.getMonth() + 1).toString(), |
| | | "d+": date.getDate().toString(), |
| | | "H+": date.getHours().toString(), |
| | | "M+": date.getMinutes().toString(), |
| | | "S+": date.getSeconds().toString() |
| | | }; |
| | | for (let k in opt) { |
| | | ret = new RegExp("(" + k + ")").exec(fmt); |
| | | if (ret) { |
| | | fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) |
| | | } |
| | | } |
| | | return fmt; |
| | | } |
| | | |
| | | function exportExcel() { |
| | | if (selectList.value.length === 0) { |
| | | ElementPlus.ElMessage({ |
| | | message: "请先选择要导出的数据", |
| | | type: 'error' |
| | | }); |
| | | return; |
| | | } |
| | | const loading = ElementPlus.ElLoading.service({ |
| | | lock: true, |
| | | text: '导出中...', |
| | | background: 'rgba(0, 0, 0, 0.7)', |
| | | }); |
| | | $.ajax({ |
| | | url: "http://127.0.0.1:8133/mo/materialuse/print", |
| | | headers: { |
| | | 'token': localStorage.getItem('token') |
| | | }, |
| | | data: JSON.stringify({ |
| | | icmoDTOS: JSON.stringify(selectList.value), |
| | | izPrint: "否", |
| | | izRed: 0 |
| | | }), |
| | | dataType: 'json', |
| | | contentType: 'application/json;charset=UTF-8', |
| | | method: 'POST', |
| | | success: function(res) { |
| | | loading.close(); |
| | | if (res.code == 200) { |
| | | var tableHtml = CreateTable(res.data || []); |
| | | var planDate = ''; |
| | | if (tableSearchParam.value.fplancommitdate) { |
| | | planDate = tableSearchParam.value.fplancommitdate.toLocaleString('zh-CN', { |
| | | timeZone: 'Asia/Shanghai', |
| | | year: 'numeric', |
| | | month: '2-digit', |
| | | day: '2-digit', |
| | | hour12: false |
| | | }).slice(0, 10); |
| | | } |
| | | var html = |
| | | "<html><head><meta charset='utf-8' />" + |
| | | "<style>" + |
| | | "body{font-family:SimSun,Microsoft YaHei,sans-serif;padding:16px;}" + |
| | | ".title{text-align:center;font-size:28px;font-weight:700;margin-bottom:12px;}" + |
| | | ".meta{font-size:14px;margin-bottom:10px;display:flex;justify-content:space-between;}" + |
| | | ".meta span{display:inline-block;min-width:260px;}" + |
| | | "</style></head><body>" + |
| | | "<div class='title'>生成领料单</div>" + |
| | | "<div class='meta'><span>生产线:" + (depName.value || '') + "</span><span>计划开工日期:" + planDate + "</span></div>" + |
| | | tableHtml + |
| | | "</body></html>"; |
| | | var blob = new Blob(['\ufeff' + html], { type: 'application/vnd.ms-excel;charset=utf-8;' }); |
| | | var link = document.createElement('a'); |
| | | var url = URL.createObjectURL(blob); |
| | | link.href = url; |
| | | link.download = "生产领料单_" + dateFormat("YYYYmmddHHMMSS", new Date()) + ".xls"; |
| | | document.body.appendChild(link); |
| | | link.click(); |
| | | document.body.removeChild(link); |
| | | URL.revokeObjectURL(url); |
| | | ElementPlus.ElMessage({ |
| | | message: "Excel导出成功", |
| | | type: 'success' |
| | | }); |
| | | } else { |
| | | ElementPlus.ElMessage({ |
| | | message: res.msg || "导出失败", |
| | | type: 'error' |
| | | }); |
| | | } |
| | | }, |
| | | error: function() { |
| | | loading.close(); |
| | | ElementPlus.ElMessage({ |
| | | message: "导出请求失败,请稍后重试", |
| | | type: 'error' |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | function handleSizeChange(val) { |
| | |
| | | page, |
| | | fnPrint, |
| | | fnPrintView, |
| | | exportExcel, |
| | | fnCanelPrint, |
| | | fnCanelPrintRed, |
| | | fnPrintRed, |