Ben Lin
2025-03-11 8e977a7ec92bc1845079eda2473e9c3fc4691c8d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button preIcon="OutR|svg" ghost color="success" @click="aoaToExcel"> 导出 </a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="[
          {
            icon: 'clarity:info-standard-line',
            tooltip: '查看单据详情',
            onClick: handleEdit.bind(null, record),
            name:''
          },
        ]" />
      </template>
    </BasicTable>
    <Loading :loading="compState.loading" :tip="compState.tip" />
    <!-- <WmsItemDrawer @register="registerDrawer" @success="handleSuccess" /> -->
  </div>
</template>
<script lang="ts" setup>
import { reactive } from 'vue';
import { aoaToSheetXlsx } from '/@/components/Excel';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
 
import { columns, searchFormSchema } from './wms_item_sum.data';
import { getWmsItemSumByPage } from '/@/api/tigerapi/wms/wms_item';
import { useGo } from '/@/hooks/web/usePage';
import { Loading } from '/@/components/Loading';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
 
const { t } = useI18n();
const { createMessage } = useMessage();
const go = useGo();
const compState = reactive({
  absolute: false,
  loading: false,
  tip: '加载中...',
});
const [registerTable,{getForm,getPaginationRef}] = useTable({
  title: '库存汇总',
  api: getWmsItemSumByPage,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
  },
  actionColumn: {
    width: 80,
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    fixed: 'right', //undefined,
  },
  ellipsis:true,
  useSearchForm: true,
  showTableSetting: false,
  bordered: true,
  showIndexColumn: false,
});
let arr: any[] = [];
function aoaToExcel() {
  const totals = getPaginationRef().total
  if (totals < 30000) {
    arr = [];
    compState.loading = true;
    const col = getForm().getFieldsValue()
    getWmsItemSumByPage(col).then((res) => {
      res.items.forEach(element => {
        arr.push({
          '仓库': element.WH_CODE,
          '物料代码': element.ITEM_CODE,
          '物料名称': element.ITEM_NAME,
          '数量': element.ZK_QTY,
          '单位': element.UNIT
        });
      });
      const arrHeader = columns.map((column) => column.title);
      const arrData = arr.map((item) => {
        return Object.keys(item).map((key) => item[key]);
      });
      // 保证data顺序与header一致
      if(arr.length<30000){
        aoaToSheetXlsx({
        data: arrData,
        header: arrHeader,
        filename: '汇总报表.xlsx',
      });
      }else{
        createMessage.error(t('导出数据不能超过三万条,如需要更多的请联系管理员'));
      }
      
      compState.loading = false;
 
    })
 
  } else {
    createMessage.error(t('导出数据不能超过三万条,如需要更多的请联系管理员'));
  }
 
 
}
//跳转到实时库存
function handleEdit(record: any) {
  go('/WmsItem/' + record.ITEM_CODE);
}
</script>