gaoluyang
2026-06-24 bfdc0e0e6d5e47aa501f9b6fadd143d9c97cf00a
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
<script lang="ts" setup>
import type { FormType } from '../data';
 
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesProProcessContentApi } from '#/api/mes/pro/process/content';
 
import { ref, watch } from 'vue';
 
import { useVbenModal } from '../../../../../packages/effects/common-ui/src';
 
import { message } from 'ant-design-vue';
 
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  deleteProcessContent,
  getProcessContentListByProcessId,
} from '#/api/mes/pro/process/content';
import { $t } from '#/locales';
 
import { useContentGridColumns } from '../data';
import ContentForm from './content-form.vue';
 
const props = defineProps<{
  formType: FormType;
  processId: number;
}>();
 
const isEditable = ref(props.formType !== 'detail'); // 是否可编辑
const list = ref<MesProProcessContentApi.ProcessContent[]>([]);
 
const [ContentFormModal, contentFormModalApi] = useVbenModal({
  connectedComponent: ContentForm,
  destroyOnClose: true,
});
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    autoResize: true,
    border: true,
    columns: useContentGridColumns(),
    data: list.value,
    minHeight: 240,
    pagerConfig: { enabled: false },
    rowConfig: {
      isHover: true,
      keyField: 'id',
    },
    showOverflow: true,
    toolbarConfig: { enabled: false },
  } as VxeTableGridOptions<MesProProcessContentApi.ProcessContent>,
});
 
/** 加载工序内容列表 */
async function getList() {
  gridApi.setLoading(true);
  try {
    list.value = await getProcessContentListByProcessId(props.processId);
    gridApi.setGridOptions({ data: list.value });
  } finally {
    gridApi.setLoading(false);
  }
}
 
/** 新增工序步骤 */
function handleCreate() {
  const maxSort = Math.max(0, ...list.value.map((item) => item.sort || 0));
  contentFormModalApi.setData({ maxSort, processId: props.processId }).open();
}
 
/** 编辑工序步骤 */
function handleEdit(row: MesProProcessContentApi.ProcessContent) {
  contentFormModalApi
    .setData({ id: row.id, processId: props.processId })
    .open();
}
 
/** 删除工序步骤 */
async function handleDelete(row: MesProProcessContentApi.ProcessContent) {
  await deleteProcessContent(row.id!);
  message.success($t('ui.actionMessage.deleteSuccess', ['工序步骤']));
  await getList();
}
 
watch(
  () => props.processId,
  (value) => {
    if (value) {
      getList();
    }
  },
  { immediate: true },
);
</script>
 
<template>
  <ContentFormModal @success="getList" />
  <div v-if="isEditable" class="mb-3 flex items-center justify-start">
    <TableAction
      :actions="[
        {
          label: $t('ui.actionTitle.create', ['步骤']),
          type: 'primary',
          onClick: handleCreate,
        },
      ]"
    />
  </div>
  <Grid class="w-full" table-title="工序操作步骤">
    <template #actions="{ row }">
      <TableAction
        :actions="[
          {
            label: $t('common.edit'),
            type: 'link',
            ifShow: () => isEditable,
            onClick: handleEdit.bind(null, row),
          },
          {
            label: $t('common.delete'),
            type: 'link',
            danger: true,
            ifShow: () => isEditable,
            popConfirm: {
              title: $t('ui.actionMessage.deleteConfirm', ['工序步骤']),
              confirm: handleDelete.bind(null, row),
            },
          },
        ]"
      />
    </template>
  </Grid>
</template>