index.jsx 10.7 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-30 13:56:38
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';
TZW's avatar
TZW committed
18
import { message } from 'antd';
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
    const gzmcref = useRef();
TZW's avatar
TZW committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 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
    const remove = (text, row, _, action) => {
      return (
        <PremButton
          pop={{
            title: '是否删除?',
            okText: '确认',
            cancelText: '取消',
            onConfirm: async () => {
              let res = await doFetch({
                url: '/repair/umFaultSettingDetail/deleteById',
                params: { id: row.id },
              });
              if (res.code === '0000') {
                message.success('删除成功!');
                setdrawergz((s) => ({
                  ...s,
                  open: false,
                }));
                actionRef.current.reload();
              }
            },
          }}
          btn={{
            size: 'small',
            type: 'danger',
          }}
        >
          删除
        </PremButton>
      );
    };
    const edit = (text, row, _, action) => {
      return (
        <PremButton
          btn={{
            size: 'small',
            onClick: () => {
              setdrawergz((s) => ({
                ...s,
                open: true,
                title: '编辑',
                val: 'edit',
                detailpath: '/repair/umFaultSettingDetail/queryById',
                params: { id: row.id },
                onFinish: async (vals) => {
                  //console.log(1);
                  let params = {
                    ...vals,
                    faultSettingId: drawer?.item.id,
                    id: row.id,
                  };
                  let res = await doFetch({
                    url: '/repair/umFaultSettingDetail/save',
                    params,
                  });
                  if (res.code === '0000') {
                    message.success('编辑成功!');
                    setdrawergz((s) => ({
                      ...s,
                      open: false,
                    }));
                    actionRef.current.reload();
                  }
                },
              }));
            },
          }}
        >
          编辑
        </PremButton>
      );
    };

TZW's avatar
TZW committed
212 213 214 215 216 217
    const columns = useMemo(() => {
      return [
        {
          title: '故障名称',
          dataIndex: 'faultDetailName',
          key: 'faultDetailName',
TZW's avatar
TZW committed
218 219 220 221 222 223 224 225
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
TZW's avatar
TZW committed
226 227
        },
        {
TZW's avatar
TZW committed
228
          title: '故障名称代码',
TZW's avatar
TZW committed
229 230 231 232 233 234 235
          dataIndex: 'faultDetailCode',
          key: 'faultDetailCode',
        },
        {
          title: '故障描述',
          dataIndex: 'faultPhenomenon',
          key: 'faultPhenomenon',
TZW's avatar
TZW committed
236
          valueType: 'textarea',
TZW's avatar
TZW committed
237 238 239 240 241
        },
        {
          title: '解决方案',
          dataIndex: 'faultSolution',
          key: 'faultSolution',
TZW's avatar
TZW committed
242
          valueType: 'textarea',
TZW's avatar
TZW committed
243 244
          search: false,
        },
TZW's avatar
TZW committed
245 246 247 248 249 250 251 252 253
        {
          title: '操作',
          valueType: 'option',
          width: 150,
          render: (text, row, _, action) => [
            edit(text, row, _, action),
            remove(text, row, _, action),
          ],
        },
TZW's avatar
TZW committed
254 255
      ];
    }, []);
TZW's avatar
TZW committed
256 257
    const renderRef = useRef(true);

TZW's avatar
TZW committed
258 259
    return (
      <>
TZW's avatar
TZW committed
260
        <ProDescriptions
TZW's avatar
TZW committed
261
          dataSource={drawer?.item}
TZW's avatar
TZW committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
          columns={[
            {
              title: '故障类型',
              dataIndex: 'faultType',
              key: 'faultType',
              formItemProps: {
                rules: [
                  {
                    required: true,
                    message: '此项为必填项',
                  },
                ],
              },
            },
            {
TZW's avatar
TZW committed
277
              title: '故障类型代码',
TZW's avatar
TZW committed
278 279 280 281 282 283 284 285 286 287
              dataIndex: 'faultCode',
              key: 'faultCode',
            },
            {
              title: '设备类型',
              dataIndex: 'equipmentTypeName',
              key: 'equipmentTypeId',
            },
          ]}
        />
TZW's avatar
TZW committed
288
        <AutoTable
TZW's avatar
TZW committed
289
          columns={columns}
TZW's avatar
TZW committed
290
          formRef={gzmcref}
TZW's avatar
TZW committed
291 292
          path="/repair/umFaultSettingDetail/queryList"
          extraparams={{ faultSettingId: drawer?.item.id }}
TZW's avatar
TZW committed
293
          pageextra={'add'}
TZW's avatar
TZW committed
294
          resizeable={false}
TZW's avatar
TZW committed
295 296 297 298 299 300 301 302 303
          addconfig={{
            // access: 'sysDepartment_save',
            btn: {
              disabled: false,
              type: 'primary',
              onClick: () => {
                setdrawergz((s) => ({
                  ...s,
                  open: true,
TZW's avatar
TZW committed
304
                  title: '新建故障名称',
TZW's avatar
TZW committed
305
                  val: 'add',
TZW's avatar
TZW committed
306 307 308
                  onFinish: async (vals) => {
                    let params = {
                      ...vals,
TZW's avatar
TZW committed
309
                      faultSettingId: drawer?.item.id,
TZW's avatar
TZW committed
310 311 312 313 314 315 316 317 318 319 320 321 322 323
                    };
                    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
324 325 326 327 328
                }));
              },
            },
          }}
        />
TZW's avatar
TZW committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
        <DrawerPro
          placement="right"
          fields={columns}
          actionRef={gzmcref}
          style={{ transform: 'translateX(180px)' }}
          defaultFormValue={drawergz?.item}
          onClose={() => {
            setdrawergz((s) => ({
              ...s,
              open: false,
              type: null,
              item: null,
            }));
          }}
          {...drawergz}
        />
TZW's avatar
TZW committed
345 346 347
      </>
    );
  };
TZW's avatar
TZW committed
348

TZW's avatar
TZW committed
349 350 351 352 353 354 355 356
  function selectType(type) {
    switch (type) {
      case 'gzmc':
        return <FaultName />;
      default:
        break;
    }
  }
TZW's avatar
TZW committed
357 358 359
  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
360
        pagetitle={<h3 className="page-title">故障设置</h3>}
TZW's avatar
TZW committed
361 362 363 364
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
365
        resizeable={false}
TZW's avatar
TZW committed
366 367 368 369
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
370
            type: 'primary',
wuhao's avatar
wuhao committed
371 372 373 374
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
TZW's avatar
TZW committed
375 376 377
                item: null,
                title: '新增',
                val: 'add',
wuhao's avatar
wuhao committed
378 379
              }));
            },
TZW's avatar
TZW committed
380 381 382
          },
        }}
      />
wuhao's avatar
wuhao committed
383

TZW's avatar
TZW committed
384 385
      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
386
        // params={{ id: drawer?.item?.id }}
TZW's avatar
TZW committed
387 388
        formRef={formRef}
        placement="right"
TZW's avatar
TZW committed
389
        // detailpath={pathconfig?.detail || null}
TZW's avatar
TZW committed
390 391 392 393 394 395
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
TZW's avatar
TZW committed
396 397
            type: null,
            item: null,
TZW's avatar
TZW committed
398 399 400 401 402 403 404 405 406 407
          }));
        }}
        {...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
408 409 410
      >
        {selectType(drawer?.type)}
      </DrawerPro>
TZW's avatar
TZW committed
411 412 413
    </div>
  );
}
wuhao's avatar
wuhao committed
414

TZW's avatar
TZW committed
415
export default Fault;