Ben Lin
2024-07-30 cc88111d61a350a4d24cf339b526d4357f934ddf
src/views/tigerprojects/system/lowcode/entityts/BAS_REASON.ts
@@ -1,56 +1,23 @@
/*
 * @Description: file content
 * @Description: 不良原因相关
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-22 00:58:43
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-25 18:30:43
 * @LastEditTime: 2024-07-04 11:21:56
 */
/*
 * @Description: 不良原因相关
 * @Author: Ben Lin
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-23 18:12:40
 */
import { Ref, h } from 'vue';
import { DeleteEntity, getEntity } from '/@/api/tigerapi/system';
import { ActionItem, BasicColumn } from '/@/components/Table';
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 { useDrawer } from '/@/components/Drawer';
import { EditOperation, Search, custDel } from '../data';
function _default() {
  /**
   * @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]();
        }
      });
    }
  }
  const ActionColumn: BasicColumn = {
    width: 80,
    title: '操作',
@@ -59,12 +26,16 @@
    fixed: undefined,
  };
  /**
   * @description: 一些自定义方法
   * @return {*}
   */
  const methods = {
    /**
     * @description: 获取新增按钮的行为
     * @return {*}
     */
    CreateAction: (fnName: string) => {
    CreateAction: (type: string) => {
      return {
        action: 'drawer', //drawer(打开左侧抽屉框) | go(跳转到新的页面)
      };
@@ -75,7 +46,7 @@
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      if (!isNullOrUnDef(data[1])) {
        data[1].popConfirm.confirm = rsnGrpDel.bind(null, args, params);
        data[1].popConfirm.confirm = custDel.bind(null, args, params);
      }
      return data;
    },
@@ -86,192 +57,36 @@
     * @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,
              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;
      }
    EditOperation: (data: Ref<any[]>, d, u, item) => {
       //更新
       var _data = data.value[item].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;
      });
      EditOperation(data,d, u, item, _data);
    },
    /**
     * @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',
        },
      ];
    GetBaseColumns: (type) => {
      return baseColumns[type];
    },
    GetSearchForm: () => {
      return [
        {
          field: 'RSN_CODE',
          label: '不良原因编码',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
        {
          label: '不良原因名称',
          field: 'RSN_NAME',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
      ];
    GetSearchForm: (type: string) => {
      return searchForms[type];
    },
    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,
        },
      ];
    GetCrudForm: (type: string) => {
      return crudForms[type];
    },
    GetBaseForm: () => {
      return [
@@ -323,9 +138,243 @@
        },
      ];
    },
    OthersValues: (val: string, id: string) => {
    /**
     * @description: 获取右侧边框use方法
     * @return {*}
     */
    GetUseDrawers: () => {
      return [
        {
          BAS_REASON: useDrawer(),
        },
      ];
    },
    /**
     * @description: 获取表格use列表
     * @param {string} type
     * @param {array} args
     * @return {*}
     */
    GetUseTables: (data: Ref<{}>, ...args) => {
      return {
        BAS_REASON: useTable({
          title: '列表信息',
          dataSource: data.value['BAS_REASON'],
          columns: baseColumns['BAS_REASON'],
          formConfig: {
            labelWidth: 140,
            schemas: searchForms['BAS_REASON'],
            submitFunc: () => Search('BAS_REASON', 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_REASON':
          data = d.data.value[d.type].filter(
            (item) =>
              item.RSN_CODE.includes(d.values.RSN_CODE) || item.RSN_NAME == d.values.RSN_NAME,
          );
          if (isNullOrEmpty(d.values.RSN_CODE) && isNullOrEmpty(d.values.RSN_NAME)) {
            data = d.data.value[d.type];
          }
          break;
      }
      return data;
    },
    KeyFieldValues: (val: string, id: string) => {
      return { RSNG_CODE: val };
    },
    /**
     * @description: 获取标题信息
     * @param {string} type
     * @return {*}
     */
    GetTitle: () => {
      return {
        pageTitle: '不良原因组管理',
        pageContent: '这里可以添加和修改不良原因组和不良代码。',
        tableTitle: {
          BAS_REASON: '不良原因管理',
        }
      };
    },
    GetUseForm: () => {
      return {};
    },
  };
  /* 以下是内部方法,不export,供上面的方法调用 */
  const baseColumns = {
    BAS_REASON: [
      {
        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',
      },
    ] as BasicColumn[],
  };
  const searchForms = {
    BAS_REASON: [
      {
        field: 'RSN_CODE',
        label: '不良原因编码',
        component: 'Input',
        colProps: {
          span: 8,
        },
      },
      {
        label: '不良原因名称',
        field: 'RSN_NAME',
        component: 'Input',
        colProps: {
          span: 8,
        },
      },
    ] as FormSchema[],
  };
  const crudForms = {
    BAS_REASON: [
      {
        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,
      },
    ] as FormSchema[],
  };
  return [methods, ActionColumn];