index.jsx 5.21 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 工段管理
 * @Author: Li Hanlin
 * @Date: 2022-11-09 14:43:54
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2022-12-20 10:48:14
TZW's avatar
TZW committed
6 7
 */

wuhao's avatar
wuhao committed
8 9 10 11 12 13
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';
TZW's avatar
TZW committed
14 15
import { doFetch } from '@/utils/doFetch';
import { message } from 'antd';
wuhao's avatar
wuhao committed
16

TZW's avatar
TZW committed
17
function Section(props) {
TZW's avatar
TZW committed
18
  let actionRef = useRef(),
wuhao's avatar
wuhao committed
19 20 21 22 23
    formRef = useRef();
  const [drawer, setdrawer] = useState({
    visible: false,
  });

TZW's avatar
TZW committed
24
  const urlParams = {
TZW's avatar
TZW committed
25 26 27 28
    save: '/auth/sysSection/saveOrUpdate',
    remove: '/auth/sysSection/delete',
    list: '/auth/sysSection/queryPage',
    detail: '/auth/sysSection/getById',
TZW's avatar
TZW committed
29 30
  };

wuhao's avatar
wuhao committed
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
  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
            setdrawer((s) => ({
              ...s,
              visible: true,
              item: row,
              title: '详情',
              val: 'detail',
              title: row.userName + '的详细信息',
            }));
          },
        }}
      >
        详情
      </PremButton>
    );
  };

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
TZW's avatar
TZW committed
59 60 61 62 63
          onClick: async () => {
            let { data } = await doFetch({
              url: '/auth/sysSection/checkSectionRelation',
              params: { id: drawer?.id },
            });
wuhao's avatar
wuhao committed
64 65 66 67
            setdrawer((s) => ({
              ...s,
              visible: true,
              title: '编辑',
TZW's avatar
TZW committed
68
              params: { id: row.id },
TZW's avatar
TZW committed
69
              fields: getcolumns(data?.data),
TZW's avatar
TZW committed
70
              detailpath: '/auth/sysSection/getById',
wuhao's avatar
wuhao committed
71
              val: 'edit',
TZW's avatar
TZW committed
72 73 74
              onFinish: async (vals) => {
                let params = {
                  ...vals,
TZW's avatar
TZW committed
75
                  id: row.id,
TZW's avatar
TZW committed
76 77 78 79 80 81
                };
                let res = await doFetch({
                  url: urlParams.save,
                  params,
                });
                if (res.code === '0000') {
TZW's avatar
TZW committed
82
                  message.success('编辑成功!');
TZW's avatar
TZW committed
83 84 85 86 87 88 89
                  setdrawer((s) => ({
                    ...s,
                    visible: false,
                  }));
                  actionRef.current.reload();
                }
              },
wuhao's avatar
wuhao committed
90 91 92 93 94 95 96 97 98 99 100 101 102
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
TZW's avatar
TZW committed
103
          title: '是否删除该工段?',
wuhao's avatar
wuhao committed
104 105
          okText: '确认',
          cancelText: '取消',
TZW's avatar
TZW committed
106 107 108 109
          onConfirm: async () => {
            let res = await doFetch({ url: urlParams.remove, params: { id: row.id } });
            if (res.code === '0000') {
              message.success('删除成功!');
TZW's avatar
TZW committed
110
              setdrawer((s) => ({
TZW's avatar
TZW committed
111 112 113 114 115
                ...s,
                visible: false,
              }));
              actionRef.current.reload();
            }
wuhao's avatar
wuhao committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        删除
      </PremButton>
    );
  };

  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer);
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
TZW's avatar
TZW committed
134
      render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
wuhao's avatar
wuhao committed
135 136 137 138 139 140
    });
  }, []);

  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
141
        pagetitle={<h3 className="page-title">工段管理</h3>}
wuhao's avatar
wuhao committed
142
        columns={columns}
TZW's avatar
TZW committed
143
        path={urlParams.list}
wuhao's avatar
wuhao committed
144 145
        actionRef={actionRef}
        pageextra={'add'}
TZW's avatar
TZW committed
146
        resizeable={false}
wuhao's avatar
wuhao committed
147 148 149
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
TZW's avatar
TZW committed
150
            type: 'primary',
wuhao's avatar
wuhao committed
151 152 153 154 155 156
            disabled: false,
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                visible: true,
                item: null,
TZW's avatar
TZW committed
157
                detailpath: null,
wuhao's avatar
wuhao committed
158
                title: '新增',
TZW's avatar
TZW committed
159
                fields: getcolumns(false),
wuhao's avatar
wuhao committed
160
                val: 'add',
TZW's avatar
TZW committed
161 162 163 164 165 166 167 168 169 170
                onFinish: async (vals) => {
                  let params = {
                    ...vals,
                  };
                  let res = await doFetch({
                    url: urlParams.save,
                    params,
                  });
                  if (res.code === '0000') {
                    message.success('新增成功!');
TZW's avatar
TZW committed
171
                    setdrawer((s) => ({
TZW's avatar
TZW committed
172 173 174 175 176 177
                      ...s,
                      visible: false,
                    }));
                    actionRef.current.reload();
                  }
                },
wuhao's avatar
wuhao committed
178 179 180 181 182 183 184
              }));
            },
          },
        }}
      />

      <DrawerPro
TZW's avatar
TZW committed
185 186 187
        // detailpath={urlParams.detail}
        // params={{ id: drawer?.item?.id }}
        defaultFormValue={drawer?.item ?? {}}
wuhao's avatar
wuhao committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            visible: false,
          }));
        }}
        {...drawer}
      />
    </div>
  );
}

TZW's avatar
TZW committed
202
export default Section;