index.jsx 4.78 KB
Newer Older
1 2 3 4 5 6 7 8
import * as React from 'react';
import { useState, useMemo, useRef } from 'react';
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
9
import Project from './Project';
10
function Standard(props) {
TZW's avatar
TZW committed
11
  let actionRef = useRef(),
12 13 14 15 16 17 18 19
    formRef = useRef();
  const [drawer, setdrawer] = useState({
    open: false,
  });
  const pathconfig = useMemo(() => {
    let pathconf = getcolumns(setdrawer)?.pathconfig ?? {};
    return pathconf;
  }, []);
左玲玲's avatar
左玲玲 committed
20
  const { run, loading, runAsync } = useRequest(doFetch, {
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
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });

  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '详情',
              val: 'detail',
              title: '详细信息',
            }));
          },
        }}
      >
        详情
      </PremButton>
    );
  };

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '编辑',
              val: 'edit',
TZW's avatar
TZW committed
68
              id: row?.id,
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };
  const project = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              open: true,
              item: row,
              title: '点检项目',
              val: 'detailaddon',
TZW's avatar
TZW committed
89
              id: row?.id,
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
            }));
          },
        }}
      >
        项目明细
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否删除?',
          okText: '确认',
          cancelText: '取消',
左玲玲's avatar
左玲玲 committed
106 107
          onConfirm: async () => {
            await runAsync({ url: pathconfig?.delete || '/delete', params: { id: row?.id } });
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

  const columns = useMemo(() => {
    let defcolumn = getcolumns(drawer?.id)?.columns;
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
      render: (text, row, _, action) => [
        project(text, row, _, action),
        pathconfig?.enabledetail && detail(text, row, _, action),
        pathconfig?.enableedit && edit(text, row, _, action),
        pathconfig?.enabledelete && remove(text, row, _, action),
      ],
    });
  }, [drawer?.id]);

  return (
左玲玲's avatar
左玲玲 committed
136
    <div>
137
      <AutoTable
TZW's avatar
TZW committed
138
        pagetitle={<h3 className="page-title">点检标准</h3>}
139 140 141 142 143 144 145 146
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
        resizeable={false}
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
左玲玲's avatar
左玲玲 committed
147
            type: 'primary',
148 149 150 151 152 153 154 155
            disabled: false,
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
                item: null,
                title: '新增',
                val: 'add',
TZW's avatar
TZW committed
156
                id: null,
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
              }));
            },
          },
        }}
      />

      <DrawerPro
        fields={columns}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        detailpath={pathconfig?.detail || null}
        detailData={drawer?.item}
        defaultFormValue={drawer?.item}
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
          }));
        }}
        {...drawer}
左玲玲's avatar
左玲玲 committed
178
        onFinish={async (vals) => {
179
          if (drawer?.val == 'add') {
左玲玲's avatar
左玲玲 committed
180
            await runAsync({ url: pathconfig?.add || '/add', params: { ...vals } });
181
          } else if (drawer?.val == 'edit') {
TZW's avatar
TZW committed
182 183 184 185
            await runAsync({
              url: pathconfig?.edit || '/edit',
              params: { ...vals, id: drawer?.item?.id },
            });
186 187 188 189 190 191 192 193 194
          }
        }}
      >
        <Project equipmentCheckStandardId={drawer.id} />
      </DrawerPro>
    </div>
  );
}

TZW's avatar
TZW committed
195
export default Standard;