| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- <template>
- <div class="ele-body">
- <el-card shadow="never">
- <div class="ele-border-lighter form-content">
- <!-- 查询区:与采购报表同一套查询面板;条件只有 2 个,操作按钮与条件同行右对齐 -->
- <el-form
- :inline="true"
- size="small"
- label-width="90px"
- class="report-search-form"
- @submit.native.prevent
- >
- <div class="report-search-form__fields">
- <el-form-item label="开始时间:">
- <el-date-picker
- v-model="queryForm.startCreateTime"
- type="date"
- value-format="yyyy-MM-dd"
- placeholder="请选择开始日期"
- clearable
- ></el-date-picker>
- </el-form-item>
- <el-form-item label="结束时间:">
- <el-date-picker
- v-model="queryForm.endCreateTime"
- type="date"
- value-format="yyyy-MM-dd"
- placeholder="请选择结束日期"
- clearable
- ></el-date-picker>
- </el-form-item>
- </div>
- <div class="report-search-form__actions">
- <el-button icon="el-icon-refresh-left" @click="handleReset">
- 重置
- </el-button>
- <el-button
- type="primary"
- icon="el-icon-search"
- class="ele-btn-icon"
- @click="handleSearch"
- >
- 查询
- </el-button>
- </div>
- </el-form>
- <!-- 数据表格 -->
- <ele-pro-table
- ref="table"
- :columns="columns"
- :datasource="datasource"
- height="calc(100vh - 405px)"
- full-height="calc(100vh - 116px)"
- tool-class="ele-toolbar-form"
- :page-size="20"
- >
- <!-- 表头工具栏 -->
- <template v-slot:toolbar>
- <el-button
- size="small"
- type="primary"
- icon="el-icon-download"
- class="ele-btn-icon"
- :loading="exportLoading"
- @click="handleExport"
- >
- 导出
- </el-button>
- </template>
- </ele-pro-table>
- </div>
- </el-card>
- </div>
- </template>
- <script>
- import { getSaleReportPage, exportSaleReport } from '@/api/reportForms/reportForms';
- import { download } from '@/utils/file';
- import { formatDate } from '@/utils/dateUtils';
- // 导出文件的 mime 类型
- const XLSX_TYPE =
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
- // 空值统一展示为空,不显示 null / undefined
- function emptyFormatter(row, column, cellValue) {
- return cellValue === null || cellValue === undefined ? '' : cellValue;
- }
- // 查询区初始条件
- function initQueryForm() {
- return {
- startCreateTime: '',
- endCreateTime: ''
- };
- }
- export default {
- data() {
- return {
- exportLoading: false, // 导出中状态
- queryForm: initQueryForm(),
- // 当前已生效的查询条件(不含分页字段),导出使用它而不是当前页数据
- activeWhere: {},
- columns: [
- {
- prop: 'serialNumber',
- label: '序号',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 80,
- formatter: emptyFormatter
- },
- {
- prop: 'salesmanName',
- label: '销售人员',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 160,
- formatter: emptyFormatter
- },
- {
- prop: 'projectName',
- label: '项目名称',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 180,
- formatter: emptyFormatter
- },
- {
- prop: 'partaName',
- label: '客户名称',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 180,
- formatter: emptyFormatter
- },
- {
- prop: 'productName',
- label: '产品名称',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 160,
- formatter: emptyFormatter
- },
- {
- prop: 'modelType',
- label: '型号',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 160,
- formatter: emptyFormatter
- },
- {
- prop: 'specification',
- label: '规格',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 160,
- formatter: emptyFormatter
- },
- {
- prop: 'productBrand',
- label: '牌号',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 160,
- formatter: emptyFormatter
- },
- {
- prop: 'createTime',
- label: '发货日期',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 170,
- formatter: emptyFormatter
- },
- {
- prop: 'docNo',
- label: '发货单号',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 180,
- formatter: emptyFormatter
- },
- {
- prop: 'trayNum',
- label: '托盘数量',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 110,
- formatter: emptyFormatter
- },
- {
- prop: 'carCount',
- label: '装货车',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 110,
- formatter: emptyFormatter
- },
- {
- prop: 'carNo',
- label: '车牌号',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 160,
- formatter: emptyFormatter
- },
- {
- prop: 'saleCount',
- label: '发货数量',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 110,
- formatter: emptyFormatter
- },
- {
- prop: 'elementCount',
- label: '车数',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 110,
- formatter: emptyFormatter
- },
- ]
- };
- },
- methods: {
- /* 表格数据源 */
- datasource({ page, limit, where }) {
- // 记录当前生效的查询条件,导出时使用(不带 pageNum / pageSize)
- this.activeWhere = { ...where };
- return getSaleReportPage({
- ...where,
- pageNum: page,
- size: limit
- });
- },
- /* 组装查询条件,空值不提交 */
- buildWhere() {
- const where = {};
- Object.keys(this.queryForm).forEach((key) => {
- const value = this.queryForm[key];
- if (value !== '' && value !== null && value !== undefined) {
- where[key] = value;
- }
- });
- return where;
- },
- /* 查询 */
- handleSearch() {
- this.$refs.table.reload({ page: 1, where: this.buildWhere() });
- },
- /* 重置 */
- handleReset() {
- this.queryForm = initQueryForm();
- this.$refs.table.reload({ page: 1, where: {} });
- },
- /* 全量导出:按当前已生效的查询条件导出全部数据,不是当前页 */
- async handleExport() {
- if (this.exportLoading) {
- return;
- }
- this.exportLoading = true;
- try {
- const blob = await exportSaleReport(this.activeWhere);
- const name = `销售报表_${formatDate(
- new Date(),
- 'yyyyMMddHHmmss'
- )}.xlsx`;
- download(new Blob([blob], { type: XLSX_TYPE }), name);
- this.$message.success('导出成功');
- } catch (e) {
- this.$message.error(e && e.message ? e.message : '导出失败');
- } finally {
- this.exportLoading = false;
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .report-search-form {
- display: flex;
- align-items: center;
- gap: 16px;
- margin-bottom: 12px;
- padding: 12px 12px 8px;
- background: #fafbfd;
- border: 1px solid #eef1f6;
- border-radius: 6px;
- /* 条件区:等宽栅格,列宽上限 360px,两个条件不会被拉成超宽输入框 */
- &__fields {
- flex: 1 1 auto;
- min-width: 0;
- display: grid;
- grid-template-columns: repeat(auto-fit, minmax(260px, 360px));
- gap: 10px 16px;
- }
- /* 操作区:与条件同一行右对齐,条件少时不再单独占一行 */
- &__actions {
- flex: 0 0 auto;
- display: flex;
- align-items: center;
- }
- /* element-ui 的 inline 模式让表单项收缩宽度(inline-block),
- 各控件按自身内容宽度渲染才会参差不齐;这里改成 flex:
- 标签定宽、控件撑满剩余宽度,输入框与日期框因此等宽等高 */
- :deep(.el-form-item) {
- display: flex;
- align-items: center;
- margin: 0;
- }
- :deep(.el-form-item__label) {
- flex: 0 0 auto;
- padding-right: 8px;
- line-height: 32px;
- }
- :deep(.el-form-item__content) {
- display: block;
- flex: 1 1 auto;
- min-width: 0;
- line-height: 32px;
- }
- :deep(.el-input),
- :deep(.el-date-editor.el-input) {
- width: 100%;
- }
- }
- </style>
|