YangYuGang
2025-03-05 6cc2d85787171281c269f4a6c3290b4a0762bcb6
src/views/tigerprojects/system/lowcode/entityts/QMS_INS_ITEM.ts
@@ -4,18 +4,17 @@
 * @version:
 * @Date: 2024-06-19 20:34:27
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-06-26 03:07:40
 * @LastEditTime: 2024-07-04 11:22:58
 */
import { Ref, h, unref } from 'vue';
import { DeleteEntity, GetEnum, 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 { useLocale } from '/@/locales/useLocale';
import { useDrawer } from '/@/components/Drawer';
import { EditOperation, Search, custDel } from '../data';
const { getLocale } = useLocale();
function _default() {
@@ -27,43 +26,41 @@
    fixed: undefined,
  };
  /**
   * @description: 一些自定义方法
   * @return {*}
   */
  const methods = {
    EditOperation: ( data: Ref<any[]>, d, u) => {
      if (u.isUpdate) {
        //更新
        var _data = data.value.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;
        });
        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,
            INS_CODE: d.INS_CODE,
            INS_NAME: d.INS_NAME,
            STD_CODE: d.STD_CODE,
            CTGY_CODE: d.CTGY_CODE,
            IS_NECESSARY: d.IS_NECESSARY,
            IS_JUDGE: d.IS_JUDGE,
            INS_TOOL: d.INS_TOOL,
            QNTV_UNIT: d.QNTV_UNIT,
            QNTV_TIMES: d.QNTV_TIMES,
            QNTV_DEVIATION: d.QNTV_DEVIATION,
            QNTV_UPPER: d.QNTV_UPPER,
            QNTV_LOWER: d.QNTV_LOWER,
            QLTV_LIST: d.QLTV_LIST,
            REMARK: d.REMARK,
          };
        return item;
      });
      EditOperation(data,d, u, item, _data);
    },
    /**
     * @description: 获取新增按钮的行为
     * @return {*}
     */
    CreateAction: (fnName: string) => {
    CreateAction: (type: string) => {
      return {
        action: 'drawer', //drawer(打开左侧抽屉框) | go(跳转到新的页面)
      };
@@ -74,225 +71,26 @@
     */
    ActionItem: (params: Recordable<any>, data, ...args): ActionItem[] => {
      if (!isNullOrUnDef(data[1])) {
        data[1].popConfirm.confirm = Del.bind(null, args, params);
    }
        data[1].popConfirm.confirm = custDel.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: () => {
      return [
        {
          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',
        },
      ];
    GetBaseColumns: (type: string) => {
      return baseColumns[type];
    },
    GetSearchForm: () => {
      return [
        {
          field: 'INS_CODE',
          label: '检验项目编码',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
        {
          label: '检验项目名称',
          field: 'INS_NAME',
          component: 'Input',
          colProps: {
            span: 8,
          },
        },
      ];
    GetSearchForm: (type: string) => {
      return searchForms[type];
    },
    GetCrudForm: () => {
      return [
        {
          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,
        },
      ];
    GetCrudForm: (type: string) => {
      return crudForms[type];
    },
    GetBaseForm: () => {
      return [
@@ -360,8 +158,78 @@
        // { name: 'rotinfo', slots: ['add'], preIcons: { add: 'search|svg' }, title: '工艺信息' },
      ];
    },
    OthersValues: (val: string, id: string) => {
      return { TECH_STD: val };
    /**
     * @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: false,
          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;
    },
    /**
     * @description: 一些其他的字段值,一般是增删改是带入的关键字段值
     * @param {string} val
     * @param {string} id
     * @return {*}
     */
    KeyFieldValues: (val: string, id: string) => {
      return { STD_CODE: val };
    },
    /**
     * @description: 获取标题信息
@@ -372,36 +240,286 @@
      return {
        pageTitle: '检验标准管理',
        pageContent: '这里可以添加和修改检验标准和检验项目。',
        baseTableTitle: '检验项目管理',
        tableTitle: {
          QMS_INS_ITEM: '检验项目管理',
        },
      };
    },
    GetUseForm: () => {
      return {};
    },
  };
  /* 以下是内部方法,不export */
  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: 'STD_CODE',
      },
      {
        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[],
  };
  /**
   * @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 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: 'STD_CODE',
        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: 'IS_NECESSARY',
        component: 'Select',
        required: true,
        colProps: {
          span: 24,
        },
        componentProps: {
          options: [
            {
              label: '是',
              value: 'Y',
              key: 'Y',
            },
            {
              label: '否',
              value: 'N',
              key: 'N',
            },
          ],
        },
      },
      {
        label: '是否判定结果',
        field: 'IS_JUDGE',
        component: 'Select',
        required: true,
        colProps: {
          span: 24,
        },
        componentProps: {
          options: [
            {
              label: '是',
              value: 'Y',
              key: 'Y',
            },
            {
              label: '否',
              value: 'N',
              key: 'N',
            },
          ],
        },
      },
      {
        label: '技术要求',
        field: 'TECH_STD',
        component: 'Input',
        colProps: {
          span: 24,
        },
      },
      {
        label: '备注',
        field: 'REMARK',
        component: 'Input',
        colProps: {
          span: 24,
        },
      },
      {
        label: 'ID',
        field: 'ID',
        component: 'Input',
        colProps: {
          span: 24,
        },
        show: false,
      },
    ] as FormSchema[],
  };
  return [methods, ActionColumn];
}