Ben Lin
2024-05-27 62f0e403c98fb76d39b8f1150d2bf2f026423b85
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
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button color="primary" @click="addTool" preIcon="add_02|svg"> 新增 </a-button>
        <a-button ghost color="success" @click="aoaToExcel" preIcon="excel-export|svg">
          导出
        </a-button>
        <a-button ghost color="success" @click="ExcelToaoa" preIcon="excel-import|svg">
          导入
        </a-button>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              tooltip: '修改',
              onClick: handleEdit.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              tooltip: '删除',
              popConfirm: {
                title: '是否确认删除?',
                placement: 'left',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <Loading :loading="compState.loading" :tip="compState.tip" />
    <!-- <WmsItemDrawer @register="registerDrawer" @success="handleSuccess" /> -->
    <SmttableDrawer @register="registerDrawer" @success="handleSuccess" />
    <SmttableModal @register="registerSmttable" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup>
  import { reactive, unref } from 'vue';
  import { aoaToSheetXlsx } from '/@/components/Excel';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import SmttableDrawer from './SmttableDrawer.vue';
  import SmttableModal from './SmttableModal.vue';
  import { useDrawer } from '/@/components/Drawer';
  import { columns, searchFormSchema } from './smttbale.data';
  import { getSmttableListByPage, DeleteSmttable } from '/@/api/tigerapi/mes/smt/smttable';
  import { useGo } from '/@/hooks/web/usePage';
  import { Loading } from '/@/components/Loading';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useModal } from '/@/components/Modal';
 
  const { t } = useI18n();
  const { createMessage } = useMessage();
  const [registerDrawer, { openDrawer }] = useDrawer();
  const go = useGo();
 
  const compState = reactive({
    absolute: false,
    loading: false,
    tip: '加载中...',
  });
  const [registerSmttable, { openModal: openSmttableModal }] = useModal();
  const [registerTable, { getForm, getPaginationRef, reload }] = useTable({
    title: '工单料站表',
    api: getSmttableListByPage,
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right', //undefined,
    },
    ellipsis: true,
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    showIndexColumn: false,
  });
  let arr: any[] = [];
  //导出
  function aoaToExcel() {
    const totals = getPaginationRef().total;
    if (totals < 30000) {
      arr = [];
      compState.loading = true;
      const col = getForm().getFieldsValue();
      getSmttableListByPage(col).then((res) => {
        res.items.forEach((element) => {
          arr.push({
            关联工单号: element.WORK_ORDER,
            产品编码: element.PROD_CODE,
            物料编码: element.ITEM_CODE,
            替代料: element.SUBITEM_CODE,
            单位: element.UNIT,
            单位用量: element.UNIT_QTY,
            产线编码: element.LINE_CODE,
            贴片机编码: element.SMT_CODE,
            钢网编码: element.SMT_STENCIL,
            站位号: element.SLOT_NO,
            贴片位置: element.LOCATION,
            飞达编码: element.FEEDER_CODE,
            飞达类型: element.FEEDER_TYPE,
            加工面: element.PCB_SURFACE,
            上料顺序: element.LOAD_SEQ,
            创建人: element.CREATE_USER,
            创建时间: element.CREATE_TIME,
          });
        });
        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 ExcelToaoa() {
    openSmttableModal(true, {
      data: 'content',
      info: 'Info',
    });
  }
  //添加
  function addTool() {
    openDrawer(true, {
      isUpdate: false,
    });
  }
  //编辑
  function handleEdit(record: any) {
    openDrawer(true, {
      isUpdate: true,
      record,
    });
  }
  function handleSuccess() {
    reload();
  }
  //删除
  function handleDelete(record: any) {
    const apiAction = DeleteSmttable(record.ID);
    apiAction.then((action) => {
      if (action.IsSuccessed) {
        createMessage.success(t('已删除'));
        reload();
      } else {
        createMessage.success(t('删除操作失败'));
      }
    });
  }
</script>