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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
| <template>
| <BasicModal
| width="1200px"
| :height="600"
| v-bind="$attrs"
| ok-text="保存"
| @register="register"
| :title="t(props.title)"
| @ok="handleSubmit"
| >
| <div class="high-form">
| <p style="color: red" v-text="err"></p>
| <BasicTable
| v-for="(table, index) in tableListRef"
| :key="index"
| :title="table.title"
| :columns="table.columns"
| :dataSource="table.dataSource"
| >
| <template #toolbar>
| <a-button @click="aoaToExcel" color="primary" preIcon="tmpDownload-white|svg">
| 模板
| </a-button>
| <ImpExcel @success="loadDataSuccess" dateFormat="YYYY-MM-DD">
| <a-button class="m-3" preIcon="excel-import|svg"> 导入Excel </a-button>
| </ImpExcel>
| </template>
| </BasicTable>
| </div>
| </BasicModal>
| </template>
| <script lang="ts" setup>
| import { ref, nextTick, unref, h } from 'vue';
| import { Tag, Tooltip, Card } from 'ant-design-vue';
| import { BasicModal, useModalInner } from '/@/components/Modal';
| import { SaveSmttable, ExportTable, SaveExportTable } from '/@/api/tigerapi/mes/smt/smttable';
| import { useI18n } from '/@/hooks/web/useI18n';
| import { aoaToSheetXlsx, ImpExcel, ExcelData } from '/@/components/Excel';
| import { useMessage } from '/@/hooks/web/useMessage';
| import { useLocale } from '/@/locales/useLocale';
| import { BasicTable, BasicColumn } from '/@/components/Table';
|
| const emit = defineEmits(['success', 'register', 'toExcel']);
| const props = defineProps({
| title: {
| type: String,
| default: '',
| },
| mtitle: {
| type: String,
| default: '',
| },
| arr: {
| type: Array,
| default: () => [1, 2, 3, 4],
| },
| });
| const ACard = Card;
| const { getLocale } = useLocale();
| const { t } = useI18n('');
| const { createMessage, createConfirm } = useMessage();
| const modelRef = ref({});
| const tableListRef = ref<
| {
| title: string;
| columns?: any[];
| dataSource?: any[];
| }[]
| >([]);
|
| const tableListRef2 = ref<
| {
| title: string;
| columns?: any[];
| dataSource?: any[];
| }[]
| >([]);
| const [register, { setModalProps, closeModal }] = useModalInner((data) => {
| setModalProps({ confirmLoading: false });
| tableListRef.value = [
| {
| title: '列表信息',
| columns: [
| {
| title: '字段1',
| dataIndex: 'field1',
| width: 200,
| sorter: true,
| resizable: true,
| },
| {
| title: '字段2',
| dataIndex: 'field2',
| width: 200,
| sorter: true,
| resizable: true,
| },
| ],
| dataSource: [],
| },
| ];
| });
| var err = ref('');
| async function loadDataSuccess(excelDataList: ExcelData[]) {
| tableListRef.value = [];
|
| for (const excelData of excelDataList) {
| const {
| header,
| results,
| meta: { sheetName },
| } = excelData;
| const columns: BasicColumn[] = [];
| columns.push({
| title: '处理方式',
| dataIndex: '处理方式',
| customRender: ({ record }) => {
| const status = record.处理方式;
| var text = '';
| var color = '';
| if (status == '数据异常') {
| color = 'red';
| text = status;
| } else if (status == '修改') {
| color = 'yellow';
| text = status;
| } else {
| text = status;
| }
| return h(Tooltip, { title: 'xxxxxx' }, () => h(Tag, { color: color }, () => text));
| },
| });
| columns.push({ title: '原因', dataIndex: '原因', width: 300, resizable: true });
| for (const title of header) {
| columns.push({ title, dataIndex: title });
| }
| tableListRef.value.push({ title: sheetName, dataSource: results, columns });
| }
| console.log('console.log(tableListRef.value);', tableListRef.value);
| var res = await ExportTable(tableListRef.value);
| if (res.IsSuccessed) {
| tableListRef.value[0].dataSource = res.Data;
| err.value = '';
| } else {
| tableListRef.value = [];
| createMessage.error('导入失败' + res.Message);
| err.value = res.Message;
| }
| }
|
| // function handleVisibleChange(v) {
| // v && props.userData && nextTick(() => onDataReceive(props.userData));
| // }
| //导出
| function aoaToExcel() {
| const arrHeader = [
| '关联工单号',
| '产品编码',
| '物料编码',
| '替代料',
| '单位',
| '单位用量',
| '产线编码',
| '贴片机编码',
| '贴片机编码',
| '钢网编码',
| '站位号',
| '贴片位置',
| '飞达编码',
| '飞达类型',
| '加工面',
| '上料顺序',
| '创建人',
| '创建时间',
| ];
| aoaToSheetXlsx({
| data: '',
| header: arrHeader,
| filename: '工单料站表信息.xlsx',
| });
| }
| async function handleSubmit() {
| try {
| const values = tableListRef.value;
| setModalProps({ confirmLoading: true });
| // TODO custom api
| //添加锡膏胶水记录
| createConfirm({
| iconType: 'warning',
| title: () => h('span', t('导入料站表信息')),
| content: () => h('span', t('确认有修改的数据是否正确,有异常的数据无法导入')),
| onOk: async () => {
| const apiAction = SaveExportTable(tableListRef.value);
| apiAction.then((action) => {
| if (action) {
| if (action.IsSuccessed) {
| closeModal();
| createMessage.success(t('导入成功'));
| emit('success', {
| isUpdate: unref(false),
| values: { ...values, id: 0 },
| });
| }
| } else {
| createMessage.error(t('导入失败,代码已使用'));
| }
| });
| },
| });
| } finally {
| setModalProps({ confirmLoading: false });
| }
| }
| </script>
| <style lang="less" scoped>
| .high-form {
| padding: 5px 10px 10px 10px;
| background: #f5f9fe;
| }
| </style>
|
|