index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <div class="ele-border-lighter form-content">
  5. <!-- 查询区:与采购报表同一套查询面板;条件只有 2 个,操作按钮与条件同行右对齐 -->
  6. <el-form
  7. :inline="true"
  8. size="small"
  9. label-width="90px"
  10. class="report-search-form"
  11. @submit.native.prevent
  12. >
  13. <div class="report-search-form__fields">
  14. <el-form-item label="开始时间:">
  15. <el-date-picker
  16. v-model="queryForm.startCreateTime"
  17. type="date"
  18. value-format="yyyy-MM-dd"
  19. placeholder="请选择开始日期"
  20. clearable
  21. ></el-date-picker>
  22. </el-form-item>
  23. <el-form-item label="结束时间:">
  24. <el-date-picker
  25. v-model="queryForm.endCreateTime"
  26. type="date"
  27. value-format="yyyy-MM-dd"
  28. placeholder="请选择结束日期"
  29. clearable
  30. ></el-date-picker>
  31. </el-form-item>
  32. </div>
  33. <div class="report-search-form__actions">
  34. <el-button icon="el-icon-refresh-left" @click="handleReset">
  35. 重置
  36. </el-button>
  37. <el-button
  38. type="primary"
  39. icon="el-icon-search"
  40. class="ele-btn-icon"
  41. @click="handleSearch"
  42. >
  43. 查询
  44. </el-button>
  45. </div>
  46. </el-form>
  47. <!-- 数据表格 -->
  48. <ele-pro-table
  49. ref="table"
  50. :columns="columns"
  51. :datasource="datasource"
  52. height="calc(100vh - 405px)"
  53. full-height="calc(100vh - 116px)"
  54. tool-class="ele-toolbar-form"
  55. :page-size="20"
  56. >
  57. <!-- 表头工具栏 -->
  58. <template v-slot:toolbar>
  59. <el-button
  60. size="small"
  61. type="primary"
  62. icon="el-icon-download"
  63. class="ele-btn-icon"
  64. :loading="exportLoading"
  65. @click="handleExport"
  66. >
  67. 导出
  68. </el-button>
  69. </template>
  70. </ele-pro-table>
  71. </div>
  72. </el-card>
  73. </div>
  74. </template>
  75. <script>
  76. import { getSaleReportPage, exportSaleReport } from '@/api/reportForms/reportForms';
  77. import { download } from '@/utils/file';
  78. import { formatDate } from '@/utils/dateUtils';
  79. // 导出文件的 mime 类型
  80. const XLSX_TYPE =
  81. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
  82. // 空值统一展示为空,不显示 null / undefined
  83. function emptyFormatter(row, column, cellValue) {
  84. return cellValue === null || cellValue === undefined ? '' : cellValue;
  85. }
  86. // 查询区初始条件
  87. function initQueryForm() {
  88. return {
  89. startCreateTime: '',
  90. endCreateTime: ''
  91. };
  92. }
  93. export default {
  94. data() {
  95. return {
  96. exportLoading: false, // 导出中状态
  97. queryForm: initQueryForm(),
  98. // 当前已生效的查询条件(不含分页字段),导出使用它而不是当前页数据
  99. activeWhere: {},
  100. columns: [
  101. {
  102. prop: 'serialNumber',
  103. label: '序号',
  104. align: 'center',
  105. showOverflowTooltip: true,
  106. minWidth: 80,
  107. formatter: emptyFormatter
  108. },
  109. {
  110. prop: 'salesmanName',
  111. label: '销售人员',
  112. align: 'center',
  113. showOverflowTooltip: true,
  114. minWidth: 160,
  115. formatter: emptyFormatter
  116. },
  117. {
  118. prop: 'projectName',
  119. label: '项目名称',
  120. align: 'center',
  121. showOverflowTooltip: true,
  122. minWidth: 180,
  123. formatter: emptyFormatter
  124. },
  125. {
  126. prop: 'partaName',
  127. label: '客户名称',
  128. align: 'center',
  129. showOverflowTooltip: true,
  130. minWidth: 180,
  131. formatter: emptyFormatter
  132. },
  133. {
  134. prop: 'productName',
  135. label: '产品名称',
  136. align: 'center',
  137. showOverflowTooltip: true,
  138. minWidth: 160,
  139. formatter: emptyFormatter
  140. },
  141. {
  142. prop: 'modelType',
  143. label: '型号',
  144. align: 'center',
  145. showOverflowTooltip: true,
  146. minWidth: 160,
  147. formatter: emptyFormatter
  148. },
  149. {
  150. prop: 'specification',
  151. label: '规格',
  152. align: 'center',
  153. showOverflowTooltip: true,
  154. minWidth: 160,
  155. formatter: emptyFormatter
  156. },
  157. {
  158. prop: 'productBrand',
  159. label: '牌号',
  160. align: 'center',
  161. showOverflowTooltip: true,
  162. minWidth: 160,
  163. formatter: emptyFormatter
  164. },
  165. {
  166. prop: 'createTime',
  167. label: '发货日期',
  168. align: 'center',
  169. showOverflowTooltip: true,
  170. minWidth: 170,
  171. formatter: emptyFormatter
  172. },
  173. {
  174. prop: 'docNo',
  175. label: '发货单号',
  176. align: 'center',
  177. showOverflowTooltip: true,
  178. minWidth: 180,
  179. formatter: emptyFormatter
  180. },
  181. {
  182. prop: 'trayNum',
  183. label: '托盘数量',
  184. align: 'center',
  185. showOverflowTooltip: true,
  186. minWidth: 110,
  187. formatter: emptyFormatter
  188. },
  189. {
  190. prop: 'carCount',
  191. label: '装货车',
  192. align: 'center',
  193. showOverflowTooltip: true,
  194. minWidth: 110,
  195. formatter: emptyFormatter
  196. },
  197. {
  198. prop: 'carNo',
  199. label: '车牌号',
  200. align: 'center',
  201. showOverflowTooltip: true,
  202. minWidth: 160,
  203. formatter: emptyFormatter
  204. },
  205. {
  206. prop: 'saleCount',
  207. label: '发货数量',
  208. align: 'center',
  209. showOverflowTooltip: true,
  210. minWidth: 110,
  211. formatter: emptyFormatter
  212. },
  213. {
  214. prop: 'elementCount',
  215. label: '车数',
  216. align: 'center',
  217. showOverflowTooltip: true,
  218. minWidth: 110,
  219. formatter: emptyFormatter
  220. },
  221. ]
  222. };
  223. },
  224. methods: {
  225. /* 表格数据源 */
  226. datasource({ page, limit, where }) {
  227. // 记录当前生效的查询条件,导出时使用(不带 pageNum / pageSize)
  228. this.activeWhere = { ...where };
  229. return getSaleReportPage({
  230. ...where,
  231. pageNum: page,
  232. size: limit
  233. });
  234. },
  235. /* 组装查询条件,空值不提交 */
  236. buildWhere() {
  237. const where = {};
  238. Object.keys(this.queryForm).forEach((key) => {
  239. const value = this.queryForm[key];
  240. if (value !== '' && value !== null && value !== undefined) {
  241. where[key] = value;
  242. }
  243. });
  244. return where;
  245. },
  246. /* 查询 */
  247. handleSearch() {
  248. this.$refs.table.reload({ page: 1, where: this.buildWhere() });
  249. },
  250. /* 重置 */
  251. handleReset() {
  252. this.queryForm = initQueryForm();
  253. this.$refs.table.reload({ page: 1, where: {} });
  254. },
  255. /* 全量导出:按当前已生效的查询条件导出全部数据,不是当前页 */
  256. async handleExport() {
  257. if (this.exportLoading) {
  258. return;
  259. }
  260. this.exportLoading = true;
  261. try {
  262. const blob = await exportSaleReport(this.activeWhere);
  263. const name = `销售报表_${formatDate(
  264. new Date(),
  265. 'yyyyMMddHHmmss'
  266. )}.xlsx`;
  267. download(new Blob([blob], { type: XLSX_TYPE }), name);
  268. this.$message.success('导出成功');
  269. } catch (e) {
  270. this.$message.error(e && e.message ? e.message : '导出失败');
  271. } finally {
  272. this.exportLoading = false;
  273. }
  274. }
  275. }
  276. };
  277. </script>
  278. <style lang="scss" scoped>
  279. .report-search-form {
  280. display: flex;
  281. align-items: center;
  282. gap: 16px;
  283. margin-bottom: 12px;
  284. padding: 12px 12px 8px;
  285. background: #fafbfd;
  286. border: 1px solid #eef1f6;
  287. border-radius: 6px;
  288. /* 条件区:等宽栅格,列宽上限 360px,两个条件不会被拉成超宽输入框 */
  289. &__fields {
  290. flex: 1 1 auto;
  291. min-width: 0;
  292. display: grid;
  293. grid-template-columns: repeat(auto-fit, minmax(260px, 360px));
  294. gap: 10px 16px;
  295. }
  296. /* 操作区:与条件同一行右对齐,条件少时不再单独占一行 */
  297. &__actions {
  298. flex: 0 0 auto;
  299. display: flex;
  300. align-items: center;
  301. }
  302. /* element-ui 的 inline 模式让表单项收缩宽度(inline-block),
  303. 各控件按自身内容宽度渲染才会参差不齐;这里改成 flex:
  304. 标签定宽、控件撑满剩余宽度,输入框与日期框因此等宽等高 */
  305. :deep(.el-form-item) {
  306. display: flex;
  307. align-items: center;
  308. margin: 0;
  309. }
  310. :deep(.el-form-item__label) {
  311. flex: 0 0 auto;
  312. padding-right: 8px;
  313. line-height: 32px;
  314. }
  315. :deep(.el-form-item__content) {
  316. display: block;
  317. flex: 1 1 auto;
  318. min-width: 0;
  319. line-height: 32px;
  320. }
  321. :deep(.el-input),
  322. :deep(.el-date-editor.el-input) {
  323. width: 100%;
  324. }
  325. }
  326. </style>