Ben Lin
2024-11-25 6e6fec028ffc9a27b3c8d30eb484cd361a119d76
src/views/tigerprojects/system/lowcode/entityts/BAS_DEFECT.ts
@@ -4,18 +4,20 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-23 18:41:06
 * @LastEditTime: 2024-07-04 11:21:28
 */
import { Ref, h, unref } from 'vue';
import { DeleteEntity, GetEnum, getEntity } from '/@/api/tigerapi/system';
import { ActionItem, BasicColumn } from '/@/components/Table';
import { isNullOrEmpty } from '/@/utils/is';
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, custDel } from '../data';
const { getLocale } = useLocale();
function _default() {
@@ -26,205 +28,47 @@
    slots: { customRender: 'action' },
    fixed: undefined,
  };
  /**
   * @description: 些自定义方法
   * @return {*}
   */
  const methods = {
    EditOperation: (type: string, 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;
      }
    },
    /**
     * @description: 获取新增按钮的行为
     * @return {*}
     */
    CreateAction: () => {
    CreateAction: (type: string) => {
      return {
        action: 'drawer', //drawer(打开左侧抽屉框) | go(跳转到新的页面)
      };
    },
    /**
     * @description: 产品绑定工艺路线操作字段自定义按钮
     * @description: 操作字段自定义按钮
     * @return {*}
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      data[1].popConfirm.confirm = DftGrpDel.bind(null, args, params);
      if (!isNullOrUnDef(data[1])) {
        data[1].popConfirm.confirm = custDel.bind(null, args, params);
      }
      return data;
    },
    /**
     * @description: 高级表单和详情页面返回主页面的url
     * @return {*}
     */
    GetHomeUrl: () => {
      const param = { ID: 'BAS_DEFECT_GRP', colSlots: [], crudColSlots: [] };
      return `/BAS_DEFECT_GRP/LC/${encodeURI(JSON.stringify(param))}`;
    },
    GetBaseColumns: () => {
      return [
        {
          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',
        },
      ];
    GetBaseColumns: (type: string) => {
      return baseColumns[type];
    },
    GetSearchForm: () => {
      return [
        {
          field: 'DFT_CODE',
          label: '不良代码编码',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
        {
          label: '不良代码名称',
          field: 'DFT_NAME',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
      ];
    GetSearchForm: (type: string) => {
      return searchForms[type];
    },
    GetCrudForm: () => {
      return [
        {
          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,
        },
      ];
    GetCrudForm: (type: string) => {
      return crudForms[type];
    },
    GetBaseForm: () => {
      return [
@@ -265,7 +109,11 @@
        },
      ];
    },
    GetBaseCards: () => {
    /**
     * @description: 获取卡片内配置列表,以循环显示多个卡片并配置多个插槽
     * @return {*}
     */
    GetBaseCards: (type: string) => {
      return [
        {
          name: 'BaseForm',
@@ -283,72 +131,259 @@
        // { name: 'rotinfo', slots: ['add'], preIcons: { add: 'search|svg' }, title: '工艺信息' },
      ];
    },
    OthersValues: (val: string, id: string) => {
    /**
     * @description: 获取右侧边框use方法
     * @return {*}
     */
    GetUseDrawers: () => {
      return [{
        'BAS_DEFECT': useDrawer(),
      }];
    },
    /**
     * @description: 获取表格use列表
     * @param {string} type
     * @param {array} args
     * @return {*}
     */
    GetUseTables: (data: Ref<{}>, ...args) => {
      return {
        BAS_DEFECT: useTable({
          title: '列表信息',
          dataSource: data.value['BAS_DEFECT'],
          columns: baseColumns['BAS_DEFECT'],
          formConfig: {
            labelWidth: 140,
            schemas: searchForms['BAS_DEFECT'],
            submitFunc: () => Search('BAS_DEFECT', data, args[0]), //自定义查询提交按钮的方法,触发查询提交事件
          },
          useSearchForm: true,
          showTableSetting: false,
          bordered: true,
          canResize: true,
          showIndexColumn: false,
          actionColumn: {
            width: 130,
            title: '操作',
            dataIndex: 'action',
            slots: { customRender: 'action' },
            fixed: 'right',
          }, //自定义操作列
        })
      };
    },
    /**
     * @description: 表格查询回调,父组件中通过子组件触发的事件获取传入的值,做具体的查询逻辑实现
     * @param {*} d
     * @return {*}
     */
    FormSearch: (d) => {
      let data = {} as any;
      switch (d.type) {
        case 'BAS_DEFECT':
          data = d.data.value[d.type].filter(
            (item) =>
              item.DFT_CODE.includes(d.values.DFT_CODE) || item.DFT_NAME == d.values.DFT_NAME,
          );
          if (isNullOrEmpty(d.values.DFT_CODE) && isNullOrEmpty(d.values.DFT_NAME)) {
            data = d.data.value[d.type];
          }
          break;
      }
      return data;
    },
    KeyFieldValues: (val: string, id: string) => {
      return { DFTG_CODE: val };
    },/**
    * @description: 自定义明细表中编辑返回方法
    * @param {string} type
    * @param {*} d
    * @param {*} u
    * @return {*}
    */
   EditeOperation:(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;
     }
   }
    } /**
     * @description: 自定义明细表中编辑返回方法
     * @param {string} type
     * @param {*} d
     * @param {*} u
     * @return {*}
     */,
    EditOperation: (data: Ref<any[]>, d, u, item) => {
      //更新
      var _data = data.value[item].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;
      });
      EditOperation(data,d, u, item, _data);
    },
    /**
     * @description: 获取标题信息
     * @param {string} type
     * @return {*}
     */
    GetTitle: () => {
      return {
        pageTitle: '不良代码组管理',
        pageContent: '这里可以添加和修改不良代码组和不良代码。',
        tableTitle: {
          BAS_DEFECT: '不良代码管理',
        }
      };
    },
    GetUseForm: () => {
      return {};
    },
  };
  /**
   * @description: 自定义删除方法
   * @param {Fn} args
   * @param {*} params
   * @return {*}
   */
  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]();
        }
      });
    }
  /* 以下是内部方法,不export,供上面的方法调用 */
  const baseColumns = {
    BAS_DEFECT: [
      {
        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',
      },
    ]
  }
  const searchForms = {
    BAS_DEFECT: [
      {
        field: 'DFT_CODE',
        label: '不良代码编码',
        component: 'Input',
        colProps: {
          span: 8,
        },
      },
      {
        label: '不良代码名称',
        field: 'DFT_NAME',
        component: 'Input',
        colProps: {
          span: 8,
        },
      },
    ] as FormSchema[],
  }
  const crudForms = {
    BAS_DEFECT: [
      {
        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,
      },
    ] as FormSchema[],
  }
  return [methods, ActionColumn];