Ben Lin
2024-06-18 ebbd788fbb2c0b45d4473798efc57eec8ba74a25
src/views/tigerprojects/system/lowcode/normal/basDefectGrp.ts
@@ -1,30 +1,392 @@
import { ActionItem, BasicColumn } from '/@/components/Table';
import { useMessage } from '/@/hooks/web/useMessage';
import { Ref, h, unref } from 'vue';
import { ActionItem, BasicColumn, FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { useLocale } from '/@/locales/useLocale';
import { Tag } from 'ant-design-vue';
import { DeleteEntity, GetEnum, getEntity } from '/@/api/tigerapi/system';
import { isNullOrEmpty } from '/@/utils/is';
import { buildUUID } from '/@/utils/uuid';
import { useUserStore } from '/@/store/modules/user';
import { formatToDateTime } from '/@/utils/dateUtil';
const { notification } = useMessage();
/* 自定义按钮方法 */
export function DftGrpRelease(reload: Fn, params: {}) {
const { t } = useI18n();
const { getLocale } = useLocale();
/**
 * @description: 自定义按钮方法
 * @param {Fn} args
 * @param {*} params
 * @return {*}
 */
export function DftGrpRelease(args: Fn[], params: {}) {
  console.log('点击了下发按钮');
  notification.success({
    message: '点击了下发按钮',
    description: `${params.entityName}`,
    duration: 3,
  // notification.success({
  //   message: '点击了下发按钮',
  //   description: `${params.entityName}`,
  //   duration: 3,
  // });
  // reload();
  // if (params.STATUS == 2) {
  //   createErrorModal({
  //     title: t('警告'),
  //     content: t('工单已经下发,不能再下发!'),
  //     getContainer: () => document.body,
  //   });
  //   return;
  // }
  params['dtlSlots'].value = [
    {
      name: 'forminfo',
      slots: ['add', 'set'],
      preIcons: { add: 'search|svg', set: 'config|svg' }, //如果是多个表单,增加多个插槽。slots是弹出框按钮的插槽,preIcons是插槽对应的按钮图标
      title: '下发配置',
    },
  ];
  args[2](true, {
    isUpdate: true, //是否更新操作
    ctype: params['cType'].value, //是哪个页面
    title: '工单下发', //标题
    width: '900px', //弹出框宽度
    formEl: params['useFormData'].value,
    formElName: ['forminfo'], //表单插槽名称
    RowKeys: { add: 'ROUTE_CODE', set: 'ROUTE_CODE' }, //插槽的弹出框选择的code
    fnName: { BIZ_MES_WO: 'SaveWoBatch' }, //保存方法名
    initFnName: {}, //初始化方法名
    values: params['record'], //表单记录
  });
  reload();
}
/**
 * @description: 自定义编辑方法
 * @param {Fn} args
 * @param {*} params
 * @return {*}
 */
export function DftGrpEdit(args: Fn[], params: {}) {
  const param = { CODE: params['record']['DFTG_CODE'], ID: params['record']['ID'], Name: 'BAS_DEFECT', Title: `编辑不良代码组:${params['record']['DFTG_CODE']}`, pCode: 'DFTG_CODE', IsID: false };
  args[5](`/BAS_DEFECT/High/${encodeURI(JSON.stringify(param))}`);
}
/**
 * @description: 自定义删除方法
 * @param {Fn} args
 * @param {*} params
 * @return {*}
 */
export function DftGrpDel(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]();
      }
    });
  }
}
/**
 * @description: 自定义明细表中编辑返回方法
 * @param {string} type
 * @param {*} d
 * @param {*} u
 * @return {*}
 */
export function dftEditeOperation(data: Ref<any[]>, d, u) {
  if (u.isUpdate) {
    //更新
    var _data = data.value.map((item) => {
      if (item['ID'] == d.ID)
        return {
          ...item,
          DFT_CODE: d.DFT_CODE,
          DFT_NAME: d.DFT_NAME,
          DFT_LEVEL: d.DFT_LEVEL,
          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;
  }
}
export const dftGrpactionColumn: BasicColumn = {
  width: 180,
  width: 100,
  title: '操作',
  dataIndex: 'action',
  slots: { customRender: 'action' },
  fixed: undefined,
  fixed: 'right',
};
export const dftGrpActionItem: ActionItem[] = [
// export const dftGrpActionItem: ActionItem[] =[
//   {
//     icon: 'clarity:note-edit-line',
//     onClick: () => {},
//   },
//   {
//     icon: 'ant-design:delete-outlined',
//     color: 'error',
//     popConfirm: {
//       title: '是否确认删除?',
//       placement: 'left',
//       confirm: () => {},
//     },
//   },
// ];
export function dftGrpGetSelectSuccess(d, u) {
  return {
    ITEM_CODE: d.values['val'],
  };
}
export function dftGrpOpenSelectItem(openItemModal: Fn) {
  openItemModal(true, {
    title: '物料列表',
    schemas: [
      {
        field: 'ITEM_CODE',
        component: 'Input',
        label: '物料编码',
        colProps: {
          span: 12,
        },
      },
    ],
    ItemColumns: [
      {
        title: t('物料编码'),
        dataIndex: 'ITEM_CODE',
        resizable: true,
        sorter: true,
        width: 200,
      },
      {
        title: t('物料名称'),
        dataIndex: 'ITEM_NAME',
        resizable: true,
        sorter: true,
        width: 180,
      },
    ],
    tableName: 'BAS_ITEM',
    rowKey: 'ITEM_CODE',
    searchInfo: {TABLE_NAME: 'BAS_ITEM'}
  });
}
/**
 * @description: 不良代码基本信息
 * @return {*}
 */
export const baseSchema: FormSchema[] = [
  {
    icon: 'release|svg',
    tooltip: '下发',
    onClick: () => {},
    field: 'DFTG_CODE',
    label: '不良代码组编码',
    component: 'Input',
    required: true,
    colProps: {
      span: 8,
    },
  },
  {
    label: '不良代码组名称',
    field: 'DFTG_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,
  },
];
export const searchSchema: FormSchema[] = [
  {
    field: 'DFT_CODE',
    label: '不良代码编码',
    component: 'Input',
    colProps: {
      span: 8,
    },
  },
  {
    label: '不良代码名称',
    field: 'DFT_NAME',
    component: 'Input',
    colProps: {
      span: 8,
    },
  },
];
/**
 * @description: 获取不良代码增删改表单
 * @return {*}
 */
export const crudSchema: FormSchema[] = [
  {
    field: 'DFT_CODE',
    label: '不良代码编码',
    component: 'Input',
    required: true,
    colProps: {
      span: 24,
    },
  },
  {
    label: '不良代码名称',
    field: 'DFT_NAME',
    component: 'Input',
    required: true,
    colProps: {
      span: 24,
    },
  },
  {
    label: '不良代码组编码',
    field: 'DFTG_CODE',
    component: 'ApiSelect',
    colProps: {
      span: 24,
    },
    componentProps: {
      api: getEntity,
      params: { entityName: 'BAS_DEFECT_GRP', sqlcmd: ' 1=1 ' },
      resultField: 'Data.Items',
      labelField: 'DFTG_NAME',
      valueField: 'DFTG_CODE',
    },
    dynamicDisabled: ({ values }) => {
      return true;
    },
  },
  {
    label: '缺陷等级',
    field: 'DFT_LEVEL',
    component: 'ApiSelect',
    required: true,
    colProps: {
      span: 24,
    },
    componentProps: {
      api: GetEnum,
      params: { name: 'BAS_DEFECT+DFT_LEVELs' },
      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,
  },
];
/**
 * @description: 不良代码表格列
 * @return {*}
 */
export const defectBaseColumn: BasicColumn[] = [
  {
    title: '不良代码编码',
    dataIndex: 'DFT_CODE',
    // ifShow: false,
    width: 180,
  },
  {
    title: '不良代码名称',
    dataIndex: 'DFT_NAME',
  },
  {
    title: '缺陷等级',
    dataIndex: 'DFT_LEVEL',
    customRender: ({ record }) => {
      const type = record.DFT_LEVEL;
      var text = '';
      var color = 'green';
      switch (type) {
        case 0:
          text = '轻微缺陷';
          break;
        case 1:
          color = 'blue';
          text = '严重缺陷';
          break;
        case 2:
          color = 'red';
          text = '致命缺陷';
          break;
      }
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '不良代码组编码',
    dataIndex: 'DFTG_CODE',
  },
  {
    title: '备注',
    dataIndex: 'REMARK',
  },
  {
    title: '更新时间',
    dataIndex: 'UPDATE_TIME',
  },
  {
    title: '更新人',
    dataIndex: 'UPDATE_USER',
  },
];