index.jsx 2.14 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 扩展字段内容
 * @Author: Li Hanlin
 * @Date: 2022-11-29 14:03:07
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2022-12-01 11:06:20
TZW's avatar
TZW committed
6 7 8 9 10 11 12
 */

import { doFetch } from '@/utils/doFetch';
import { useRequest } from 'ahooks';
import { useState, useEffect } from 'react';
import InitForm from '../InitForm';

TZW's avatar
TZW committed
13 14 15
const App = ({ setDrawer, onFinish, drawer, actionRef, columns, urlParams, formId }) => {
  const [value, setValue] = useState('');
  const [fieldscolumns, setfieldscolumns] = useState(columns);
TZW's avatar
TZW committed
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
  const selectValueType = (type, options) => {
    switch (type) {
      case 1:
        return {
          valueType: 'input',
        };
      case 2:
        return {
          valueType: 'select',
          options,
        };
      case 3:
        return {
          valueType: 'radio',
          options,
        };
      case 4:
        return {
          valueType: 'select',
          options,
        };
      default:
        break;
    }
  };

  useEffect(() => {
    const fn = async () => {
      let res = await doFetch({
        url: '/base/paFormField/queryList',
        params: {
TZW's avatar
TZW committed
47
          formId: formId,
TZW's avatar
TZW committed
48 49 50
        },
      });
      if (res?.data?.dataList) {
TZW's avatar
TZW committed
51 52 53 54 55 56
        let column = [
          {
            title: '扩展字段',
            valueType: 'split',
          },
        ];
TZW's avatar
TZW committed
57 58
        res?.data?.dataList?.forEach((el) => {
          column.push({
TZW's avatar
TZW committed
59
            ...selectValueType(el.fieldChar, el.valueList),
TZW's avatar
TZW committed
60
            title: el.fieldName,
TZW's avatar
TZW committed
61
            dataIndex: el.fieldName,
TZW's avatar
TZW committed
62 63 64
            key: el.id,
          });
        });
TZW's avatar
TZW committed
65
        setfieldscolumns(fieldscolumns.concat(column));
TZW's avatar
TZW committed
66 67 68 69 70
      }
    };
    fn();
  }, []);

TZW's avatar
TZW committed
71 72 73 74 75 76 77 78 79 80 81 82
  const selectextendField = (type) => {
    switch (Number(type)) {
      case 1:
        return 'userCharList';
      case 2:
        return 'equipmentCharList';
      case 3:
        return 'equipmentSupplierCharList';
      default:
        break;
    }
  };
TZW's avatar
TZW committed
83 84
  return (
    <>
TZW's avatar
TZW committed
85 86 87 88 89 90 91
      <InitForm
        extendField={selectextendField(formId)}
        detailpath={urlParams.detail}
        params={{ id: drawer?.item?.id }}
        fields={fieldscolumns}
        onFinish={onFinish}
      />
TZW's avatar
TZW committed
92 93 94
    </>
  );
};
TZW's avatar
TZW committed
95 96

export default App;