spring
2026-07-03 081f242ea3c019f4eddd0fe342c5cf6189da1468
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
import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
import { h } from 'vue';
 
import { DICT_TYPE, MesAutoCodeRuleCode } from '#/packages/constants/src';
import { getDictOptions } from '#/packages/effects/hooks/src';
 
import { Button } from 'ant-design-vue';
 
import { generateAutoCode } from '#/api/mes/md/autocode/record';
import { isPdMockEnabled } from '#/api/mes/pd/mock/enabled';
import { mockNextCode } from '#/api/mes/pd/mock/utils';
 
export type VersionChangeFormType = 'create' | 'detail' | 'update';
 
export function useVersionChangeGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'code',
      label: '变更单号',
      component: 'Input',
      componentProps: { placeholder: '请输入变更单号' },
    },
    {
      fieldName: 'changeType',
      label: '变更类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.MES_PD_VERSION_CHANGE_TYPE, 'number'),
        placeholder: '请选择变更类型',
      },
    },
  ];
}
 
export function useVersionChangeGridColumns(
  showAction = true,
): VxeTableGridOptions['columns'] {
  const columns: VxeTableGridOptions['columns'] = [
    { field: 'code', title: '变更单号', minWidth: 130 },
    {
      field: 'changeType',
      title: '变更类型',
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MES_PD_VERSION_CHANGE_TYPE },
      },
    },
    { field: 'fromVersion', title: '原版本', minWidth: 90 },
    { field: 'toVersion', title: '新版本', minWidth: 90 },
    { field: 'applicantName', title: '申请人', minWidth: 100 },
    {
      field: 'createTime',
      title: '申请时间',
      minWidth: 160,
      formatter: 'formatDateTime',
    },
  ];
 
  if (showAction) {
    columns.push({
      field: 'action',
      title: '操作',
      width: 180,
      fixed: 'right',
      slots: { default: 'actions' },
    });
  }
 
  return columns;
}
 
export function useVersionChangeFormSchema(
  formType: VersionChangeFormType,
  formApi?: VbenFormApi,
): VbenFormSchema[] {
  const readonly = formType === 'detail';
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: { triggerFields: [''], show: () => false },
    },
    {
      fieldName: 'projectId',
      component: 'Input',
      dependencies: { triggerFields: [''], show: () => false },
    },
    {
      fieldName: 'code',
      label: '变更单号',
      component: 'Input',
      componentProps: { disabled: readonly, placeholder: '请输入变更单号' },
      rules: 'required',
      suffix:
        formType === 'detail'
          ? undefined
          : () =>
              h(
                Button,
                {
                  type: 'default',
                  onClick: async () => {
                    const code = isPdMockEnabled()
                      ? mockNextCode(
                          'VC-2026',
                          Math.floor(Date.now() % 10_000),
                        )
                      : await generateAutoCode(
                          MesAutoCodeRuleCode.PD_VERSION_CODE,
                        );
                    await formApi?.setFieldValue('code', code);
                  },
                },
                { default: () => '生成' },
              ),
    },
    {
      fieldName: 'changeType',
      label: '变更类型',
      component: 'Select',
      componentProps: {
        disabled: readonly,
        options: getDictOptions(DICT_TYPE.MES_PD_VERSION_CHANGE_TYPE, 'number'),
        placeholder: '请选择变更类型',
      },
      rules: 'selectRequired',
    },
    {
      fieldName: 'fromVersion',
      label: '原版本',
      component: 'Input',
      componentProps: { disabled: readonly, placeholder: '如 V1.0' },
      rules: 'required',
    },
    {
      fieldName: 'toVersion',
      label: '新版本',
      component: 'Input',
      componentProps: { disabled: readonly, placeholder: '如 V1.1' },
      rules: 'required',
    },
    {
      fieldName: 'changeReason',
      label: '变更原因',
      component: 'Textarea',
      componentProps: { disabled: readonly, placeholder: '请输入变更原因', rows: 2 },
      rules: 'required',
    },
    {
      fieldName: 'changeContent',
      label: '变更内容',
      component: 'Textarea',
      componentProps: { disabled: readonly, placeholder: '请输入变更内容', rows: 4 },
      rules: 'required',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: { disabled: readonly, placeholder: '请输入备注', rows: 2 },
    },
  ];
}