index.jsx 4.98 KB
Newer Older
wuhao's avatar
wuhao committed
1
import * as React from 'react';
wuhao's avatar
wuhao committed
2 3 4 5 6 7 8 9
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';
import { message } from 'antd';
wuhao's avatar
wuhao committed
10
import TreeRender from '@/components/TreeRender';
wuhao's avatar
wuhao committed
11

wuhao's avatar
wuhao committed
12
function Setting(props) {
TZW's avatar
TZW committed
13
  let actionRef = useRef(),
wuhao's avatar
wuhao committed
14 15 16 17 18 19 20 21
    formRef = useRef();
  const [drawer, setdrawer] = useState({
    open: false,
  });
  const pathconfig = useMemo(() => {
    let pathconf = getcolumns(setdrawer)?.pathconfig ?? {};
    return pathconf;
  }, []);
wuhao's avatar
wuhao committed
22
  const [sparePartTypeId, setsparePartTypeId] = useState();
wuhao's avatar
wuhao committed
23 24 25 26 27 28 29 30 31 32 33 34 35
  const { run, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        message.success('操作成功');
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
      }
    },
  });
wuhao's avatar
wuhao committed
36

wuhao's avatar
wuhao committed
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
  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',
            }));
          },
        }}
      >
        编辑
      </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
101

wuhao's avatar
wuhao committed
102 103 104 105 106 107 108
  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer)?.columns;
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
      render: (text, row, _, action) => [
TZW's avatar
TZW committed
109
        // pathconfig?.enabledetail && detail(text, row, _, action),
wuhao's avatar
wuhao committed
110 111 112 113 114 115 116 117 118
        pathconfig?.enableedit && edit(text, row, _, action),
        pathconfig?.enabledelete && remove(text, row, _, action),
      ],
    });
  }, []);

  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
1  
TZW committed
119
        pagetitle={<h3 className="page-title">备件设置</h3>}
wuhao's avatar
wuhao committed
120 121 122 123
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
TZW's avatar
TZW committed
124
        childposition="left"
wuhao's avatar
wuhao committed
125 126 127 128 129
        resizeable={false}
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
wuhao's avatar
wuhao committed
130 131 132 133
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
TZW's avatar
TZW committed
134
                item: { isLife: 1 },
wuhao's avatar
wuhao committed
135 136
                title: '新增',
                val: 'add',
wuhao's avatar
wuhao committed
137 138
              }));
            },
wuhao's avatar
wuhao committed
139 140
          },
        }}
wuhao's avatar
wuhao committed
141 142 143 144 145 146 147 148
        extraparams={{ sparePartTypeId }}
      >
        <TreeRender
          url="/sparepart/sparePartType/queryTreeList"
          deleteurl="/sparepart/sparePartType/deleteById"
          saveurl="/sparepart/sparePartType/save"
          submitKey="sparePartTypeName"
          onselected={(vals) => {
TZW's avatar
TZW committed
149
            console.log(vals);
wuhao's avatar
wuhao committed
150 151 152 153
            setsparePartTypeId(vals[0] ?? '');
          }}
        />
      </AutoTable>
wuhao's avatar
wuhao committed
154

wuhao's avatar
wuhao committed
155 156 157 158 159 160
      <DrawerPro
        fields={columns}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        detailpath={pathconfig?.detail || null}
wuhao's avatar
wuhao committed
161
        defaultFormValue={{ sparePartTypeId }}
wuhao's avatar
wuhao committed
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
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
          }));
        }}
        {...drawer}
        onFinish={(vals) => {
          const relationSupplierList = vals?.relationSupplierList?.map?.((it, i) => {
            return {
              supplierId: it?.id,
              qualityGuarantee: it?.qualityGuarantee,
              value: it?.value,
            };
          });
          if (drawer?.val == 'add') {
            run({ url: pathconfig?.add || '/add', params: { ...vals, relationSupplierList } });
          } else if (drawer?.val == 'edit') {
            run({
              url: pathconfig?.edit || '/edit',
              params: { ...vals, id: drawer?.item?.id, relationSupplierList },
            });
          }
        }}
      />
    </div>
  );
}
wuhao's avatar
wuhao committed
190

wuhao's avatar
wuhao committed
191
export default Setting;