index.jsx 8.71 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 故障设置
 * @Author: Li Hanlin
 * @Date: 2022-12-07 11:19:30
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2022-12-08 16:06:42
TZW's avatar
TZW committed
6 7
 */

wuhao's avatar
wuhao committed
8
import * as React from 'react';
TZW's avatar
TZW committed
9
import { useState, useMemo, useEffect, useRef } from 'react';
TZW's avatar
TZW committed
10 11 12 13 14 15
import DrawerPro from '@/components/DrawerPro';
import AutoTable from '@/components/AutoTable';
import PremButton from '@/components/PremButton';
import getcolumns from './columns';
import { useRequest } from 'ahooks';
import { doFetch } from '@/utils/doFetch';
TZW's avatar
TZW committed
16 17
import InitForm from '@/components/InitForm';
import { ProDescriptions } from '@ant-design/pro-components';
wuhao's avatar
wuhao committed
18

TZW's avatar
TZW committed
19 20 21 22 23 24 25 26 27 28
const pathconfig = {
  enableadd: true,
  enableedit: true,
  enabledelete: true,
  enabledetail: true,
  add: '/repair/umFaultSetting/save',
  edit: '/repair/umFaultSetting/save',
  list: '/repair/umFaultSetting/queryList',
  delete: '/repair/umFaultSetting/deleteById',
  detail: '',
wuhao's avatar
wuhao committed
29
};
wuhao's avatar
wuhao committed
30

TZW's avatar
TZW committed
31 32 33 34 35 36
function Fault(props) {
  const actionRef = useRef(),
    formRef = useRef();
  const [drawer, setdrawer] = useState({
    open: false,
  });
TZW's avatar
TZW committed
37 38 39
  const [drawergz, setdrawergz] = useState({
    open: false,
  });
TZW's avatar
TZW committed
40 41 42 43 44 45 46 47 48 49 50 51
  const { run, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });
wuhao's avatar
wuhao committed
52

TZW's avatar
TZW committed
53
  const gzmc = (text, row, _, action) => {
TZW's avatar
TZW committed
54 55 56 57 58 59 60 61 62 63
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '详情',
TZW's avatar
TZW committed
64 65
              val: 'only',
              type: 'gzmc',
TZW's avatar
TZW committed
66 67 68 69 70
              title: '详细信息',
            }));
          },
        }}
      >
TZW's avatar
TZW committed
71
        故障名称
TZW's avatar
TZW committed
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 103 104 105 106 107 108 109 110 111 112 113 114 115 116
      </PremButton>
    );
  };

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '编辑',
              val: 'edit',
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否删除?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
            run({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };
wuhao's avatar
wuhao committed
117

TZW's avatar
TZW committed
118 119
  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer);
TZW's avatar
TZW committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    if (drawer?.type == 'gzmc') {
      return defcolumn;
    } else {
      return defcolumn.concat({
        title: '操作',
        valueType: 'option',
        width: 150,
        render: (text, row, _, action) => [
          pathconfig?.enabledetail && gzmc(text, row, _, action),
          pathconfig?.enableedit && edit(text, row, _, action),
          pathconfig?.enabledelete && remove(text, row, _, action),
        ],
      });
    }
  }, [drawer?.type]);

TZW's avatar
TZW committed
136
  const FaultName = (props) => {
TZW's avatar
TZW committed
137
    const [request, setrequest] = useState();
TZW's avatar
TZW committed
138 139 140 141 142 143 144
    const gzmcref = useRef();
    const columns = useMemo(() => {
      return [
        {
          title: '故障名称',
          dataIndex: 'faultDetailName',
          key: 'faultDetailName',
TZW's avatar
TZW committed
145 146 147 148 149 150 151 152
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
TZW's avatar
TZW committed
153 154 155 156 157 158 159 160 161 162
        },
        {
          title: '故障代码',
          dataIndex: 'faultDetailCode',
          key: 'faultDetailCode',
        },
        {
          title: '故障描述',
          dataIndex: 'faultPhenomenon',
          key: 'faultPhenomenon',
TZW's avatar
TZW committed
163
          valueType: 'textarea',
TZW's avatar
TZW committed
164 165 166 167 168
        },
        {
          title: '解决方案',
          dataIndex: 'faultSolution',
          key: 'faultSolution',
TZW's avatar
TZW committed
169
          valueType: 'textarea',
TZW's avatar
TZW committed
170 171 172 173
          search: false,
        },
      ];
    }, []);
TZW's avatar
TZW committed
174 175 176 177 178 179 180 181 182 183
    useEffect(() => {
      const fn = async () => {
        let params = { id: drawer?.item?.id };
        let res = await doFetch({ url: '/repair/umFaultSetting/queryById', params });
        setrequest(res?.data.data);
      };
      fn();
    }, []);
    return (
      <>
TZW's avatar
TZW committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        <ProDescriptions
          dataSource={request}
          columns={[
            {
              title: '故障类型',
              dataIndex: 'faultType',
              key: 'faultType',
              formItemProps: {
                rules: [
                  {
                    required: true,
                    message: '此项为必填项',
                  },
                ],
              },
            },
            {
              title: '故障代码',
              dataIndex: 'faultCode',
              key: 'faultCode',
            },
            {
              title: '设备类型',
              dataIndex: 'equipmentTypeName',
              key: 'equipmentTypeId',
              valueType: 'treeSelect',
              options: {
                path: '/asset/equipmentType/queryTreeList',
                params: {},
              },
            },
          ]}
        />
TZW's avatar
TZW committed
217
        <AutoTable
TZW's avatar
TZW committed
218
          columns={columns}
TZW's avatar
TZW committed
219
          formRef={gzmcref}
TZW's avatar
TZW committed
220 221 222 223 224 225 226 227 228 229 230 231
          path="/repair/umFaultSettingDetail/queryById"
          params={{ id: drawer?.item.id }}
          pageextra={'add'}
          addconfig={{
            // access: 'sysDepartment_save',
            btn: {
              disabled: false,
              type: 'primary',
              onClick: () => {
                setdrawergz((s) => ({
                  ...s,
                  open: true,
TZW's avatar
TZW committed
232
                  title: '新建故障名称',
TZW's avatar
TZW committed
233
                  val: 'add',
TZW's avatar
TZW committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
                  onFinish: async (vals) => {
                    let params = {
                      ...vals,
                      id: drawer?.item.id,
                    };
                    let res = await doFetch({
                      url: '/repair/umFaultSettingDetail/save',
                      params,
                    });
                    if (res.code === '0000') {
                      message.success('新增成功!');
                      setdrawergz((s) => ({
                        ...s,
                        open: false,
                      }));
                      gzmcref.current.reload();
                    }
                  },
TZW's avatar
TZW committed
252 253 254 255 256
                }));
              },
            },
          }}
        />
TZW's avatar
TZW committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
        <DrawerPro
          placement="right"
          fields={columns}
          actionRef={gzmcref}
          style={{ transform: 'translateX(180px)' }}
          width={'100%'}
          defaultFormValue={drawergz?.item}
          onClose={() => {
            setdrawergz((s) => ({
              ...s,
              open: false,
              type: null,
              item: null,
            }));
          }}
          {...drawergz}
        />
TZW's avatar
TZW committed
274 275 276
      </>
    );
  };
TZW's avatar
TZW committed
277

TZW's avatar
TZW committed
278 279 280 281 282 283 284 285
  function selectType(type) {
    switch (type) {
      case 'gzmc':
        return <FaultName />;
      default:
        break;
    }
  }
TZW's avatar
TZW committed
286 287 288
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
289
        pagetitle={<h3 className="page-title">故障设置</h3>}
TZW's avatar
TZW committed
290 291 292 293
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
294
        resizeable={false}
TZW's avatar
TZW committed
295 296 297 298
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
wuhao's avatar
wuhao committed
299 300 301 302
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
TZW's avatar
TZW committed
303 304 305
                item: null,
                title: '新增',
                val: 'add',
wuhao's avatar
wuhao committed
306 307
              }));
            },
TZW's avatar
TZW committed
308 309 310
          },
        }}
      />
wuhao's avatar
wuhao committed
311

TZW's avatar
TZW committed
312 313
      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
314
        // params={{ id: drawer?.item?.id }}
TZW's avatar
TZW committed
315 316
        formRef={formRef}
        placement="right"
TZW's avatar
TZW committed
317
        // detailpath={pathconfig?.detail || null}
TZW's avatar
TZW committed
318 319 320 321 322 323
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
TZW's avatar
TZW committed
324 325
            type: null,
            item: null,
TZW's avatar
TZW committed
326 327 328 329 330 331 332 333 334 335
          }));
        }}
        {...drawer}
        onFinish={(vals) => {
          if (drawer?.val == 'add') {
            run({ url: pathconfig?.add || '/add', params: { ...vals } });
          } else if (drawer?.val == 'edit') {
            run({ url: pathconfig?.edit || '/edit', params: { ...vals, id: drawer?.item?.id } });
          }
        }}
TZW's avatar
TZW committed
336 337 338
      >
        {selectType(drawer?.type)}
      </DrawerPro>
TZW's avatar
TZW committed
339 340 341
    </div>
  );
}
wuhao's avatar
wuhao committed
342

TZW's avatar
TZW committed
343
export default Fault;