Ben Lin
2024-07-02 2069d53e9be24adec3c8d6717fd7317555bd9a52
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/*
 * @Description: 检验项目相关
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-02 19:43:08
 */
 
import { Ref, h, unref } from 'vue';
import { DeleteEntity, GetEnum, getEntity } from '/@/api/tigerapi/system';
import { ActionItem, BasicColumn, FormSchema, useTable } 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';
import { useLocale } from '/@/locales/useLocale';
import { useDrawer } from '/@/components/Drawer';
import { EditOperation, Search } from '../data';
 
const { getLocale } = useLocale();
function _default() {
  const ActionColumn: BasicColumn = {
    width: 80,
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    fixed: undefined,
  };
 
  /**
   * @description: 一些自定义方法
   * @return {*}
   */
  const methods = {
    EditOperation: (data: Ref<any[]>, d, u, item) => {
      //更新
      var _data = data.value[item].map((item) => {
        if (item['ID'] == d.ID)
          return {
            ...item,
            STD_CODE: d.STD_CODE,
            STD_NAME: d.STD_NAME,
            STD_TYPE: d.STD_TYPE,
            REMARK: d.REMARK,
          };
        return item;
      });
      EditOperation(data,d, u, item, _data);
    },
    /**
     * @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 = Del.bind(null, args, params);
      }
      return data;
    },
    /**
     * @description: 高级表单和详情页面返回主页面的url
     * @return {*}
     */
    GetHomeUrl: () => {
      const param = { ID: 'QMS_INS_STD', colSlots: [], crudColSlots: [] };
      return `/QMS_INS_STD/LC/${encodeURI(JSON.stringify(param))}`;
    },
    GetBaseColumns: (type: string) => {
      return baseColumns[type];
    },
    GetSearchForm: (type: string) => {
      return searchForms[type];
    },
    GetCrudForm: (type: string) => {
      return crudForms[type];
    },
    GetBaseForm: () => {
      return [
        {
          field: 'STD_CODE',
          label: '检验标准编码',
          component: 'Input',
          required: true,
          colProps: {
            span: 8,
          },
        },
        {
          label: '检验标准名称',
          field: 'STD_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,
        },
        {
          label: 'TECH_STD',
          field: 'TECH_STD',
          component: 'Input',
          colProps: {
            span: 8,
          },
          show: false,
        },
      ];
    },
    GetBaseCards: () => {
      return [
        {
          name: 'BaseForm',
          slots: [],
          preIcons: {},
          title: '检验标准',
          entityName: 'QMS_INS_STD',
        },
        // {
        //   name: 'prodinfo',
        //   slots: ['addRot', 'setRot'],
        //   preIcons: { addRot: 'search|svg', setRot: 'config|svg' },
        //   title: '产品信息',
        // },
        // { name: 'rotinfo', slots: ['add'], preIcons: { add: 'search|svg' }, title: '工艺信息' },
      ];
    },
    /**
     * @description: 获取右侧边框use方法
     * @return {*}
     */
    GetUseDrawers: () => {
      return [
        {
          QMS_INS_ITEM: useDrawer(),
        },
      ];
    },
    /**
     * @description: 获取表格use列表
     * @param {string} type
     * @param {array} args
     * @return {*}
     */
    GetUseTables: (data: Ref<{}>, ...args) => {
      return {
        QMS_INS_ITEM: useTable({
          title: '列表信息',
          dataSource: data.value['QMS_INS_ITEM'],
          columns: baseColumns['QMS_INS_ITEM'],
          formConfig: {
            labelWidth: 140,
            schemas: searchForms['QMS_INS_ITEM'],
            submitFunc: () => Search('QMS_INS_ITEM', data, args[0]), //自定义查询提交按钮的方法,触发查询提交事件
          },
          useSearchForm: true,
          showTableSetting: true,
          bordered: true,
          canResize: true,
          showIndexColumn: false,
          actionColumn: {
            width: 130,
            title: '操作',
            dataIndex: 'action',
            slots: { customRender: 'action' },
            fixed: 'right',
          }, //自定义操作列
        }),
        MES_SHIFT_PRD: useTable(),
      };
    },
    /**
     * @description: 表格查询回调,父组件中通过子组件触发的事件获取传入的值,做具体的查询逻辑实现
     * @param {*} d
     * @return {*}
     */
    FormSearch: (d) => {
      let data = {} as any;
      switch (d.type) {
        case 'QMS_INS_ITEM':
          data = d.data.value[d.type].filter(
            (item) =>
              item.INS_CODE.includes(d.values.INS_CODE) || item.INS_NAME == d.values.INS_NAME,
          );
          if (isNullOrEmpty(d.values.INS_CODE) && isNullOrEmpty(d.values.INS_NAME)) {
            data = d.data.value[d.type];
          }
          break;
      }
      return data;
    },
    OthersValues: (val: string, id: string) => {
      return { TECH_STD: val };
    },
    /**
     * @description: 获取标题信息
     * @param {string} type
     * @return {*}
     */
    GetTitle: () => {
      return {
        pageTitle: '检验标准管理',
        pageContent: '这里可以添加和修改检验标准和检验项目。',
        tableTitle: {
          QMS_INS_ITEM: '检验项目管理',
        },
      };
    },
  };
 
  /**
   * @description: 自定义删除方法
   * @param {Fn} args
   * @param {*} params
   * @return {*}
   */
  function Del(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]();
        }
      });
    }
  }
 
  const baseColumns = {
    QMS_INS_ITEM: [
      {
        title: '检验项目编码',
        dataIndex: 'INS_CODE',
        // ifShow: false,
        width: 180,
      },
      {
        title: '检验项目名称',
        dataIndex: 'INS_NAME',
      },
      {
        title: '检验类别编码',
        dataIndex: 'CTGY_CODE',
      },
      {
        title: '检验方式',
        dataIndex: 'INS_MODE',
        customRender: ({ record }) => {
          const type = record.INS_MODE;
          var text = '';
          var color = 'green';
          switch (type) {
            case 0:
              text = '定量检测';
              break;
            case 1:
              color = 'blue';
              text = '定性检测';
              break;
          }
          return h(Tag, { color: color }, () => text);
        },
      },
      {
        title: '检验标准编码',
        dataIndex: 'TECH_STD',
      },
      {
        title: '是否必检',
        dataIndex: 'IS_NECESSARY',
        customRender: ({ record }) => {
          const type = record.IS_NECESSARY;
          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: 'IS_JUDGE',
        customRender: ({ record }) => {
          const type = record.IS_JUDGE;
          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: 'INS_TOOL',
      },
      {
        title: '测试值单位',
        dataIndex: 'QNTV_UNIT',
      },
      {
        title: '测试次数',
        dataIndex: 'QNTV_TIMES',
      },
      {
        title: '偏差值',
        dataIndex: 'QNTV_DEVIATION',
      },
      {
        title: '备注',
        dataIndex: 'REMARK',
      },
      {
        title: '更新时间',
        dataIndex: 'UPDATE_TIME',
      },
      {
        title: '更新人',
        dataIndex: 'UPDATE_USER',
      },
    ] as BasicColumn[],
  };
 
  const searchForms = {
    QMS_INS_ITEM: [
      {
        field: 'INS_CODE',
        label: '检验项目编码',
        component: 'Input',
        colProps: {
          span: 8,
        },
      },
      {
        label: '检验项目名称',
        field: 'INS_NAME',
        component: 'Input',
        colProps: {
          span: 8,
        },
      },
    ] as FormSchema[],
  };
 
  const crudForms = {
    QMS_INS_ITEM: [
      {
        field: 'INS_CODE',
        label: '检验项目编码',
        component: 'Input',
        required: true,
        colProps: {
          span: 24,
        },
      },
      {
        label: '检验项目名称',
        field: 'INS_NAME',
        component: 'Input',
        required: true,
        colProps: {
          span: 24,
        },
      },
      {
        label: '检验类别编码',
        field: 'CTGY_CODE',
        component: 'Input',
        colProps: {
          span: 24,
        },
      },
      {
        label: '检验标准',
        field: 'TECH_STD',
        component: 'ApiSelect',
        colProps: {
          span: 24,
        },
        componentProps: {
          api: getEntity,
          params: { entityName: 'QMS_INS_STD', sqlcmd: ' 1=1 ' },
          resultField: 'Data.Items',
          labelField: 'STD_NAME',
          valueField: 'STD_CODE',
        },
        dynamicDisabled: ({ values }) => {
          return true;
        },
      },
      {
        label: '检验方式',
        field: 'INS_MODE',
        component: 'ApiSelect',
        required: true,
        colProps: {
          span: 24,
        },
        componentProps: {
          api: GetEnum,
          params: { name: 'QMS_INS_ITEM+INS_MODEs' },
          resultField: 'Data',
          labelField: unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name',
          valueField: 'Value',
        },
      },
      {
        label: '备注',
        field: 'REMARK',
        component: 'Input',
        colProps: {
          span: 24,
        },
      },
      {
        label: 'ID',
        field: 'ID',
        component: 'Input',
        colProps: {
          span: 24,
        },
        show: false,
      },
    ] as FormSchema[],
  };
 
  return [methods, ActionColumn];
}
 
export default _default;