index.jsx 2.42 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-16 16:42:47
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 16
const App = ({
  setDrawer,
  onFinish,
  drawer,
TZW's avatar
TZW committed
17
  formRef,
TZW's avatar
TZW committed
18 19 20 21
  columns,
  urlParams,
  formId,
  defaultFormValue,
TZW's avatar
TZW committed
22
  onValuesChange,
TZW's avatar
TZW committed
23
}) => {
TZW's avatar
TZW committed
24 25
  const [value, setValue] = useState('');
  const [fieldscolumns, setfieldscolumns] = useState(columns);
TZW's avatar
TZW committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
  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',
TZW's avatar
TZW committed
45 46 47 48
          fieldProps: {
            placeholder: '请选择',
            mode: 'multiple',
          },
TZW's avatar
TZW committed
49 50 51 52 53 54 55 56 57 58 59 60
          options,
        };
      default:
        break;
    }
  };

  useEffect(() => {
    const fn = async () => {
      let res = await doFetch({
        url: '/base/paFormField/queryList',
        params: {
TZW's avatar
TZW committed
61
          formId: formId,
TZW's avatar
TZW committed
62 63 64
        },
      });
      if (res?.data?.dataList) {
TZW's avatar
TZW committed
65 66 67 68 69 70
        let column = [
          {
            title: '扩展字段',
            valueType: 'split',
          },
        ];
wuhao's avatar
wuhao committed
71
        res?.data?.dataList?.forEach?.((el) => {
TZW's avatar
TZW committed
72
          column.push({
TZW's avatar
TZW committed
73
            ...selectValueType(el.fieldChar, el.valueList),
TZW's avatar
TZW committed
74
            title: el.fieldName,
TZW's avatar
TZW committed
75
            dataIndex: el.fieldName,
TZW's avatar
TZW committed
76 77 78
            key: el.id,
          });
        });
TZW's avatar
TZW committed
79
        setfieldscolumns(fieldscolumns.concat(column));
TZW's avatar
TZW committed
80 81 82 83 84
      }
    };
    fn();
  }, []);

TZW's avatar
TZW committed
85 86 87 88 89 90 91 92 93 94 95 96
  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
97 98
  return (
    <>
TZW's avatar
TZW committed
99
      <InitForm
TZW's avatar
TZW committed
100
        formRef={formRef}
TZW's avatar
TZW committed
101
        defaultFormValue={defaultFormValue}
TZW's avatar
TZW committed
102
        extendField={selectextendField(formId)}
TZW's avatar
TZW committed
103 104
        detailpath={urlParams?.detail || null}
        params={{ id: drawer?.item?.id || null }}
TZW's avatar
TZW committed
105 106
        fields={fieldscolumns}
        onFinish={onFinish}
TZW's avatar
TZW committed
107
        onValuesChange={onValuesChange}
TZW's avatar
TZW committed
108
      />
TZW's avatar
TZW committed
109 110 111
    </>
  );
};
TZW's avatar
TZW committed
112 113

export default App;