gaoluyang
9 天以前 86966ec9a83b93decbd93fc8ce2be1882d4c9775
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
<script lang="ts" setup>
import type { FormType } from '../data';
 
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesProRouteProcessApi } from '#/api/mes/pro/route/process';
 
import { ref, watch } from 'vue';
 
import { useVbenModal } from '@vben/common-ui';
 
import { message } from 'ant-design-vue';
 
import { TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
import {
  deleteRouteProcess,
  getRouteProcessListByRoute,
} from '#/api/mes/pro/route/process';
import { $t } from '#/locales';
 
import { useRouteProcessGridColumns } from '../data';
import ProcessForm from './process-form.vue';
 
const props = defineProps<{
  formType: FormType;
  routeId: number;
}>();
 
const isEditable = ref(props.formType !== 'detail'); // 是否可编辑
const list = ref<MesProRouteProcessApi.RouteProcess[]>([]); // 工艺路线工序列表
 
const [ProcessFormModal, processFormModalApi] = useVbenModal({
  connectedComponent: ProcessForm,
  destroyOnClose: true,
});
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    autoResize: true,
    border: true,
    columns: useRouteProcessGridColumns(),
    data: list.value,
    minHeight: 240,
    pagerConfig: { enabled: false },
    rowConfig: { isHover: true, keyField: 'id' },
    showOverflow: true,
    toolbarConfig: { enabled: false },
  } as VxeTableGridOptions<MesProRouteProcessApi.RouteProcess>,
});
 
/** 加载工艺路线工序列表 */
async function getList() {
  gridApi.setLoading(true);
  try {
    list.value = await getRouteProcessListByRoute(props.routeId);
    gridApi.setGridOptions({ data: list.value });
  } finally {
    gridApi.setLoading(false);
  }
}
 
/** 新增工艺路线工序 */
function handleCreate() {
  const maxSort = Math.max(0, ...list.value.map((item) => item.sort || 0));
  processFormModalApi.setData({ maxSort, routeId: props.routeId }).open();
}
 
/** 编辑工艺路线工序 */
function handleEdit(row: MesProRouteProcessApi.RouteProcess) {
  processFormModalApi.setData({ id: row.id, routeId: props.routeId }).open();
}
 
/** 删除工艺路线工序 */
async function handleDelete(row: MesProRouteProcessApi.RouteProcess) {
  await deleteRouteProcess(row.id!);
  message.success($t('ui.actionMessage.deleteSuccess', ['工艺路线工序']));
  await getList();
}
 
watch(
  () => props.routeId,
  (value) => {
    if (value) {
      getList();
    }
  },
  { immediate: true },
);
</script>
 
<template>
  <ProcessFormModal @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 #colorCode="{ row }">
      <div v-if="row.colorCode" class="flex items-center justify-center gap-1">
        <div
          class="h-4 w-4 rounded"
          :style="{ backgroundColor: row.colorCode }"
        ></div>
        <span>{{ row.colorCode }}</span>
      </div>
    </template>
    <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>