gaoluyang
昨天 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesProMpsApi } from '#/api/mes/pro/mps';
 
import { ref } from 'vue';
import { useRouter } from 'vue-router';
 
import { Page, useVbenModal } from '@vben/common-ui';
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
 
import { Button, message, Tag } from 'ant-design-vue';
 
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  cancelMps,
  deleteMps,
  exportMps,
  getMpsPage,
  issueMps,
  mergeIssueMps,
} from '#/api/mes/pro/mps';
import { $t } from '#/locales';
 
import { MpsStatusEnum, useGridColumns, useGridFormSchema } from './data';
import Form from './modules/form.vue';
 
/** MPS 生产主计划列表 */
defineOptions({ name: 'MesProMps' });
 
const router = useRouter();
 
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: Form,
  destroyOnClose: true,
});
 
const checkedIds = ref<number[]>([]);
const checkedRows = ref<MesProMpsApi.Mps[]>([]);
 
/** 刷新表格 */
function handleRefresh() {
  gridApi.query();
  checkedIds.value = [];
  checkedRows.value = [];
}
 
/** 新增 MPS */
function handleCreate() {
  formModalApi.setData({ formType: 'create' }).open();
}
 
/** 导出表格 */
async function handleExport() {
  const data = await exportMps(await gridApi.formApi.getValues());
  downloadFileFromBlobPart({ fileName: '生产主计划.xls', source: data });
}
 
/** 查看详情 */
function handleDetail(row: MesProMpsApi.Mps) {
  formModalApi.setData({ formType: 'detail', id: row.id }).open();
}
 
/** 编辑 */
function handleEdit(row: MesProMpsApi.Mps) {
  formModalApi.setData({ formType: 'edit', id: row.id }).open();
}
 
/** 删除 */
async function handleDelete(ids: number[]) {
  const hideLoading = message.loading({
    content: $t('ui.actionMessage.deleting'),
    duration: 0,
  });
  try {
    await deleteMps(ids);
    message.success($t('ui.actionMessage.deleteSuccess'));
    handleRefresh();
  } finally {
    hideLoading();
  }
}
 
/** 下发 MPS */
async function handleIssue(row: MesProMpsApi.Mps) {
  const hideLoading = message.loading({
    content: '下发中...',
    duration: 0,
  });
  try {
    await issueMps(row.id!);
    message.success('下发成功');
    handleRefresh();
  } finally {
    hideLoading();
  }
}
 
/** 合并下发 */
async function handleMergeIssue() {
  if (checkedIds.value.length < 2) {
    message.warning('请至少选择2条记录');
    return;
  }
  // 校验:相同产品、草稿状态
  const firstRow = checkedRows.value[0];
  const isSameProduct = checkedRows.value.every(
    (row) => row.productId === firstRow.productId,
  );
  if (!isSameProduct) {
    message.error('只能选择相同产品的MPS进行合并下发');
    return;
  }
  const isAllDraft = checkedRows.value.every(
    (row) => row.status === MpsStatusEnum.DRAFT,
  );
  if (!isAllDraft) {
    message.error('只能选择草稿状态的MPS进行合并下发');
    return;
  }
  const hideLoading = message.loading({
    content: '合并下发中...',
    duration: 0,
  });
  try {
    await mergeIssueMps(checkedIds.value);
    message.success('合并下发成功');
    handleRefresh();
  } finally {
    hideLoading();
  }
}
 
/** 取消 MPS */
async function handleCancel(row: MesProMpsApi.Mps) {
  const hideLoading = message.loading({
    content: '取消中...',
    duration: 0,
  });
  try {
    await cancelMps(row.id!);
    message.success('取消成功');
    handleRefresh();
  } finally {
    hideLoading();
  }
}
 
/** 跳转到生产工单 */
function handleGoToWorkOrder(row: MesProMpsApi.Mps) {
  if (row.workOrderId) {
    router.push({
      path: '/mes/pro/workorder',
      query: { id: row.workOrderId },
    });
  }
}
 
/** 行选择变化 */
function handleRowCheckboxChange({
  records,
}: {
  records: MesProMpsApi.Mps[];
}) {
  checkedIds.value = records.map((item) => item.id!);
  checkedRows.value = records;
}
 
const [Grid, gridApi] = useVbenVxeGrid({
  formOptions: {
    schema: useGridFormSchema(),
  },
  gridOptions: {
    columns: useGridColumns(),
    height: 'auto',
    keepSource: true,
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) => {
          return await getMpsPage({
            pageNo: page.currentPage,
            pageSize: page.pageSize,
            ...formValues,
          });
        },
      },
    },
    rowConfig: {
      keyField: 'id',
      isHover: true,
    },
    toolbarConfig: {
      refresh: true,
      search: true,
    },
  } as VxeTableGridOptions<MesProMpsApi.Mps>,
  gridEvents: {
    checkboxAll: handleRowCheckboxChange,
    checkboxChange: handleRowCheckboxChange,
  },
});
</script>
 
<template>
  <Page auto-content-height>
    <FormModal @success="handleRefresh" />
    <Grid table-title="生产主计划(MPS)列表">
      <template #toolbar-tools>
        <TableAction
          :actions="[
            {
              label: $t('ui.actionTitle.create', ['MPS']),
              type: 'primary',
              icon: ACTION_ICON.ADD,
              auth: ['mes:pro-mps:create'],
              onClick: handleCreate,
            },
            {
              label: $t('ui.actionTitle.export'),
              type: 'primary',
              icon: ACTION_ICON.DOWNLOAD,
              auth: ['mes:pro-mps:export'],
              onClick: handleExport,
            },
            {
              label: '合并下发',
              type: 'primary',
              disabled: isEmpty(checkedIds) || checkedIds.length < 2,
              icon: ACTION_ICON.AUDIT,
              auth: ['mes:pro-mps:merge-issue'],
              popConfirm: {
                title: '确认合并下发选中的MPS吗?',
                confirm: handleMergeIssue,
              },
            },
          ]"
        />
      </template>
      <template #code="{ row }">
        <Button type="link" @click="handleDetail(row)">
          {{ row.code }}
        </Button>
      </template>
      <template #status="{ row }">
        <Tag v-if="row.status === 0" color="blue">草稿</Tag>
        <Tag v-else-if="row.status === 1" color="success">已下发</Tag>
        <Tag v-else-if="row.status === 2" color="purple">已完成</Tag>
        <Tag v-else-if="row.status === 3" color="red">已取消</Tag>
      </template>
      <template #workOrderCode="{ row }">
        <Button
          v-if="row.workOrderCode"
          type="link"
          @click="handleGoToWorkOrder(row)"
        >
          {{ row.workOrderCode }}
        </Button>
        <span v-else>-</span>
      </template>
      <template #mergeFlag="{ row }">
        <Tag v-if="row.mergeFlag === 1" color="success">是</Tag>
        <Tag v-else color="default">否</Tag>
      </template>
      <template #actions="{ row }">
        <TableAction
          :actions="[
            {
              label: $t('common.detail'),
              type: 'link',
              icon: ACTION_ICON.VIEW,
              auth: ['mes:pro-mps:query'],
              onClick: handleDetail.bind(null, row),
            },
            {
              label: $t('common.edit'),
              type: 'link',
              icon: ACTION_ICON.EDIT,
              auth: ['mes:pro-mps:update'],
              ifShow: () => row.status === MpsStatusEnum.DRAFT,
              onClick: handleEdit.bind(null, row),
            },
            {
              label: '下发',
              type: 'link',
              icon: ACTION_ICON.AUDIT,
              auth: ['mes:pro-mps:issue'],
              ifShow: () => row.status === MpsStatusEnum.DRAFT,
              popConfirm: {
                title: `确认下发${row.code}吗?`,
                confirm: handleIssue.bind(null, row),
              },
            },
            {
              label: '取消',
              type: 'link',
              danger: true,
              icon: 'ant-design:stop-outlined',
              auth: ['mes:pro-mps:cancel'],
              ifShow: () => row.status === MpsStatusEnum.ISSUED,
              popConfirm: {
                title: `确认取消${row.code}吗?`,
                confirm: handleCancel.bind(null, row),
              },
            },
            {
              label: $t('common.delete'),
              type: 'link',
              danger: true,
              icon: ACTION_ICON.DELETE,
              auth: ['mes:pro-mps:delete'],
              ifShow: () => row.status === MpsStatusEnum.DRAFT,
              popConfirm: {
                title: $t('ui.actionMessage.deleteConfirm', [row.code]),
                confirm: handleDelete.bind(null, [row.id!]),
              },
            },
          ]"
        />
      </template>
    </Grid>
  </Page>
</template>