index.jsx 3.4 KB
Newer Older
TZW's avatar
TZW committed
1
import { useState, useEffect, useRef } from 'react';
TZW's avatar
TZW committed
2
import InitForm from '@/components/InitForm';
TZW's avatar
TZW committed
3 4
import { message } from 'antd';
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
5

TZW's avatar
TZW committed
6
const App = ({ url, actionRef, setdrawer,drawer }) => {
TZW's avatar
TZW committed
7 8 9 10 11 12 13 14 15 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  const columns = [
    {
      title: '选择设备',
      dataIndex: 'equipmentId',
      key: 'equipmentId',
      valueType: 'select',
      options: { path: '/asset/equipment/selection/user/shop', params: {} },
      formItemProps: {
        rules: [
          {
            required: true,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '是否停机',
      dataIndex: 'isShutdown',
      key: 'isShutdown',
      valueType: 'radio',
      options: [
        {
          value: 1,
          label: '是',
        },
        {
          value: 2,
          label: '否',
        },
      ],
      formItemProps: {
        rules: [
          {
            required: true,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '故障类型',
      dataIndex: 'faultSettingId',
      key: 'faultSettingId',
      valueType: 'select',
      options: {
        path: '/repair/umFaultSetting/selected/queryList',
        linkParams: {
          equipmentId: '',
        },
      },
    },
    {
      title: '故障名称',
      dataIndex: 'faultDetailId',
      key: 'faultDetailId',
      valueType: 'select',
      options: {
        path: '/repair/umFaultSettingDetail/selected/queryList',
        linkParams: {
          faultSettingId: '',
        },
      },
    },
    {
      title: '故障描述',
      dataIndex: 'faultDescription',
      key: 'faultDescription',
      valueType: 'textarea',
      formItemProps: {
        rules: [
          {
            required: true,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '故障图片',
      dataIndex: 'picList',
      key: 'picList',
      valueType: 'uploadImage',
      fieldProps: {
        limit: 5,
      },
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
    },
  ];
TZW's avatar
TZW committed
103 104 105

  const formRef = useRef();

TZW's avatar
TZW committed
106 107
  return (
    <>
TZW's avatar
TZW committed
108 109 110
      <InitForm
        formRef={formRef}
        fields={columns}
TZW's avatar
TZW committed
111
        defaultFormValue={drawer?.item}
TZW's avatar
TZW committed
112
        onValuesChange={(changedValues, allValues) => {
TZW's avatar
TZW committed
113
          //console.log(changedValues, allValues);
TZW's avatar
TZW committed
114 115 116 117 118 119 120
          if (Object.keys(changedValues)[0] == 'faultDetailId') {
            doFetch({
              url: '/repair/umFaultSettingDetail/queryById',
              params: {
                id: changedValues?.faultDetailId,
              },
            }).then((res) => {
TZW's avatar
TZW committed
121
              //console.log(res);
TZW's avatar
TZW committed
122 123 124 125 126 127 128
              formRef?.current?.setFieldsValue({
                faultDescription: res?.data?.data.faultPhenomenon,
              });
            });
          }
        }}
        onFinish={async (vals) => {
TZW's avatar
TZW committed
129
          //console.log(vals);
TZW's avatar
TZW committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
          let params = {
            ...vals,
          };
          let res = await doFetch({
            url,
            params,
          });
          if (res.code === '0000') {
            message.success('新建成功!');
            setdrawer((s) => ({
              ...s,
              open: false,
            }));
            actionRef.current.reload();
          }
        }}
      />
TZW's avatar
TZW committed
147 148 149 150 151
    </>
  );
};

export default App;