Ben Lin
2024-04-25 e404c076586d9682c3d782a4ecb0dc254f0bfd48
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<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:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              popConfirm: {
                title: '是否确认删除?',
              placement: 'left',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template> -->
    </BasicTable>
    <Loading :loading="compState.loading" :tip="compState.tip" />
    <!-- <WmsItemDrawer @register="registerDrawer" @success="handleSuccess" /> -->
  </div>
</template>
<script lang="ts" setup>
 
import { aoaToSheetXlsx } from '/@/components/Excel';
 
import { reactive } from 'vue';
 
import { BasicTable, useTable } from '/@/components/Table';
 
import { columns, searchFormSchema } from './wms_item.data';
import { getWmsItemHisListByPage } from '/@/api/tigerapi/wms/wms_item_his';
 
import { useTabs } from '/@/hooks/web/useTabs';
import { Loading } from '/@/components/Loading';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
 
const { t } = useI18n();
const { createMessage } = useMessage();
 
const compState = reactive({
  absolute: false,
  loading: false,
  tip: '加载中...',
});
const [registerTable, { reload, getForm, getPaginationRef }] = useTable({
  title: '追溯查询',
  api: getWmsItemHisListByPage,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
  },
  useSearchForm: true,
 
  showTableSetting: true,
  // canColDrag:true,
  ellipsis: true,
  //canResize:true,
 
  bordered: true,
  showIndexColumn: false,
  // actionColumn: {
  //   width: 80,
  //   title: '操作',
  //   dataIndex: 'action',
  //   slots: { customRender: 'action' },
  //   fixed: undefined,
  // },
});
const { setTitle } = useTabs();
//setTitle('实时库存' + (ItemCode.value==''?'':',料号:('+ItemCode.value+')'));
 
function handleSuccess() {
  reload();
}
 
let arr: any[] = [];
function aoaToExcel() {
  const totals = getPaginationRef().total
  if (totals < 30000) {
    arr = [];
    compState.loading = true;
    const col = getForm().getFieldsValue()
    const data = getWmsItemHisListByPage(col).then((res) => {
      res.items.forEach(element => {
 
        let result = ''
        switch (element.STATUS) {
          case 0:
            result = '不存在';
            break;
          case 10:
            result = '送货中';
            break;
          case 20:
            result = '待检验';
            break;
          case 30:
            result = '待入库';
            break;
          case 40:
            result = '在库中';
            break;
          case 50:
            result = '已下架';
            break;
          case 60:
            result = '已发料';
            break;
          case 70:
            result = '已上料';
            break;
          case 80:
            result = '已耗尽';
            break;
          case 90:
            result = '已退料';
            break;
          case 100:
            result = '已发货';
            break;
          default:
            break;
        }
        arr.push({
          '单据代码': element.TRANS_NO,
          '条码': element.SN,
          '物料代码': element.ITEM_CODE,
          '条码来源说明': element.TRACE_INFO,
          '数量': element.QTY,
          '原始箱号': element.CARTON_NO,
          '操作时间': element.CREATE_TIME,
          '储存状态': result,
          '仓库': element.WH_CODE,
          '储位': element.LOCATION_CODE,
          '单位': element.UNIT,
          '生产日期': element.PROD_DATE,
          '首次入库日期': element.FIRST_IN_DATE,
          '单据行号': element.TRANS_LINE,
          '供应商代码': element.SUPP_CODE,
          '供应商批次号': element.SUPP_LOTNO,
          '批次号': element.LOTNO,
          '箱号': element.CARTON_NO,
          '栈板号': element.PALLET_NO,
          '更新人': element.UPDATE_USER,
        });
      });
      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('导出数据不能超过三万条,如需要更多的请联系管理员'));
  }
 
 
}
</script>