Ben Lin
2024-06-30 943954bdcb3b672b89cfa097e53d2ac17a36a101
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
 * @Description: 不良原因相关
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-22 00:58:43
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-26 03:13:26
 */
import { Ref, h } from 'vue';
import { DeleteEntity, getEntity } from '/@/api/tigerapi/system';
import { ActionItem, BasicColumn } from '/@/components/Table';
import { isNullOrEmpty, isNullOrUnDef } from '/@/utils/is';
import { buildUUID } from '/@/utils/uuid';
import { useUserStore } from '/@/store/modules/user';
import { formatToDateTime } from '/@/utils/dateUtil';
import { Tag } from 'ant-design-vue';
 
function _default() {
  const ActionColumn: BasicColumn = {
    width: 80,
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    fixed: undefined,
  };
 
  /**
   * @description: 一些自定义方法
   * @return {*}
   */  
  const methods = {
    /**
     * @description: 获取新增按钮的行为
     * @return {*}
     */
    CreateAction: (fnName: string) => {
      return {
        action: 'drawer', //drawer(打开左侧抽屉框) | go(跳转到新的页面)
      };
    },
    /**
     * @description: 操作字段自定义按钮
     * @return {*}
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      if (!isNullOrUnDef(data[1])) {
        data[1].popConfirm.confirm = rsnGrpDel.bind(null, args, params);
      }
      return data;
    },
    /**
     * @description: 自定义明细表中编辑返回方法
     * @param {string} type
     * @param {*} d
     * @param {*} u
     * @return {*}
     */
    EditOperation: (data: Ref<any[]>, d, u) => {
      if (u.isUpdate) {
        //更新
        var _data = data.value.map((item) => {
          if (item['ID'] == d.ID)
            return {
              ...item,
              RSN_CODE: d.RSN_CODE,
              RSN_NAME: d.RSN_NAME,
              NEED_REPLACE: d.NEED_REPLACE,
              REMARK: d.REMARK,
            };
          return item;
        });
        data.value = _data;
      } else {
        //新增
        d.ID = buildUUID();
        d.CREATE_USER = useUserStore().getUserInfo.userId as string;
        d.UPDATE_TIME = formatToDateTime(new Date());
        d.UPDATE_USER = useUserStore().getUserInfo.userId as string;
        var _data2: any[] = [];
        if (!isNullOrEmpty(data.value)) {
          _data2 = data.value.map((item) => {
            return item;
          });
        }
        _data2.push(d);
        data.value = _data2;
      }
    },
    /**
     * @description: 高级表单和详情页面返回主页面的url
     * @return {*}
     */
    GetHomeUrl: () => {
      return `/BAS_REASON_GRP/LC/${encodeURI(JSON.stringify({ ID: 'BAS_REASON_GRP', colSlots: [], crudColSlots: [] }))}`;
    },
    GetBaseColumns: () => {
      return [
        {
          title: '不良原因编码',
          dataIndex: 'RSN_CODE',
          // ifShow: false,
          width: 180,
        },
        {
          title: '不良原因名称',
          dataIndex: 'RSN_NAME',
        },
        {
          title: '是否必须更换零件',
          dataIndex: 'NEED_REPLACE',
          customRender: ({ record }) => {
            const type = record.NEED_REPLACE;
            var text = '';
            var color = 'green';
            switch (type) {
              case 'Y':
                text = '更换';
                break;
              case 'N':
                color = 'blue';
                text = '不更换';
                break;
            }
            return h(Tag, { color: color }, () => text);
          },
        },
        {
          title: '不良原因组编码',
          dataIndex: 'RSNG_CODE',
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
        },
        {
          title: '更新时间',
          dataIndex: 'UPDATE_TIME',
        },
        {
          title: '更新人',
          dataIndex: 'UPDATE_USER',
        },
      ];
    },
    GetSearchForm: () => {
      return [
        {
          field: 'RSN_CODE',
          label: '不良原因编码',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
        {
          label: '不良原因名称',
          field: 'RSN_NAME',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
      ];
    },
    GetCrudForm: () => {
      return [
        {
          field: 'RSN_CODE',
          label: '不良原因编码',
          component: 'Input',
          required: true,
          colProps: {
            span: 24,
          },
        },
        {
          label: '不良原因名称',
          field: 'RSN_NAME',
          component: 'Input',
          required: true,
          colProps: {
            span: 24,
          },
        },
        {
          label: '不良原因组编码',
          field: 'RSNG_CODE',
          component: 'ApiSelect',
          colProps: {
            span: 24,
          },
          componentProps: {
            api: getEntity,
            params: { entityName: 'BAS_REASON_GRP', sqlcmd: ' 1=1 ' },
            resultField: 'Data.Items',
            labelField: 'RSNG_NAME',
            valueField: 'RSNG_CODE',
          },
          dynamicDisabled: ({ values }) => {
            return true;
          },
        },
        {
          label: '是否必须更换零件',
          field: 'NEED_REPLACE',
          component: 'Select',
          required: true,
          colProps: {
            span: 24,
          },
          componentProps: {
            options: [
              {
                label: '更换',
                value: 'Y',
                key: 'Y',
              },
              {
                label: '不更换',
                value: 'N',
                key: 'N',
              },
            ],
          },
        },
        {
          label: '备注',
          field: 'REMARK',
          component: 'Input',
          colProps: {
            span: 24,
          },
        },
        {
          label: 'ID',
          field: 'ID',
          component: 'Input',
          colProps: {
            span: 24,
          },
          show: false,
        },
      ];
    },
    GetBaseForm: () => {
      return [
        {
          field: 'RSNG_CODE',
          label: '不良原因组编码',
          component: 'Input',
          required: true,
          colProps: {
            span: 8,
          },
        },
        {
          label: '不良原因组名称',
          field: 'RSNG_NAME',
          required: true,
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
        {
          label: '备注',
          field: 'REMARK',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
        {
          label: 'ID',
          field: 'ID',
          component: 'Input',
          colProps: {
            span: 8,
          },
          show: false,
        },
      ];
    },
    GetBaseCards: () => {
      return [
        {
          name: 'BaseForm',
          slots: [],
          preIcons: {},
          title: '不良原因组信息',
          entityName: 'BAS_REASON_GRP',
        },
      ];
    },
    OthersValues: (val: string, id: string) => {
      return { RSNG_CODE: val };
    },
    /**
     * @description: 获取标题信息
     * @param {string} type
     * @return {*}
     */
    GetTitle: () => {
      return {
        pageTitle: '不良原因组管理',
        pageContent: '这里可以添加和修改不良原因组和不良代码。',
        baseTableTitle: '不良原因管理',
      };
    },
  };
 
  /* 以下是内部方法,不export,供上面的方法调用 */
 
  /**
   * @description: 自定义删除方法
   * @param {Fn} args
   * @param {*} params
   * @return {*}
   */
  function rsnGrpDel(args: Fn[], params: {}) {
    if (!isNullOrEmpty(params['data'])) {
      var _data = params['data'].value.filter((item) => item['ID'] != params['record']['ID']);
      params['data'].value = _data;
      args[6]({
        dataSource: [],
      });
      args[6]({
        dataSource: params['data'],
      });
      args[1]();
    } else {
      DeleteEntity(params['record'], params['entityName']).then((action) => {
        if (action.IsSuccessed) {
          args[1]();
        }
      });
    }
  }
 
  return [methods, ActionColumn];
}
 
export default _default;