index.jsx 5.51 KB
Newer Older
TZW's avatar
TZW committed
1 2 3 4
/* 设备供应商
 * @Author: Li Hanlin
 * @Date: 2022-11-09 14:44:44
 * @Last Modified by: Li Hanlin
TZW's avatar
TZW committed
5
 * @Last Modified time: 2022-11-14 10:39:38
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 17 18 19

function Supplier(props) {
  const actionRef = useRef(),
    formRef = useRef();
TZW's avatar
TZW committed
20
  const [drawer, setDrawer] = useState({
wuhao's avatar
wuhao committed
21 22 23
    visible: false,
  });

TZW's avatar
TZW committed
24 25 26 27 28 29 30 31
  const urlParams = {
    save: '/asset/equipmentSupplier/save',
    remove: '/asset/equipmentSupplier/deleteById',
    list: '/asset/equipmentSupplier/queryList',
    detail: '/asset/equipmentSupplier/query/detail',
    detail_nocp: '/asset/equipmentSupplier/queryById',
  };

wuhao's avatar
wuhao committed
32 33 34 35 36 37 38
  const detail = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: 'small',
          type: 'link',
          onClick: () => {
TZW's avatar
TZW committed
39
            setDrawer((s) => ({
wuhao's avatar
wuhao committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
              ...s,
              visible: true,
              item: row,
              title: '详情',
              val: 'detail',
              title: row.userName + '的详细信息',
            }));
          },
        }}
      >
        详情
      </PremButton>
    );
  };

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

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

  const columns = useMemo(() => {
TZW's avatar
TZW committed
126
    let defcolumn = getcolumns(setDrawer);
TZW's avatar
TZW committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    defcolumn[1].render = (text, row) => {
      return (
        <a
          onClick={() => {
            setDrawer((s) => ({
              ...s,
              visible: true,
              title: '查看详情',
              fields: columns,
              val: 'detail',
              detailpath: urlParams.detail,
              params: { id: row.id },
            }));
          }}
        >
          {row.supplierName}
        </a>
      );
    };
wuhao's avatar
wuhao committed
146 147 148 149
    return defcolumn.concat({
      title: '操作',
      valueType: 'option',
      width: 150,
TZW's avatar
TZW committed
150
      render: (text, row, _, action) => [edit(text, row, _, action), remove(text, row, _, action)],
wuhao's avatar
wuhao committed
151 152 153 154 155 156
    });
  }, []);

  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
TZW committed
157
        pagetitle={<h3 className="page-title">设备供应商</h3>}
wuhao's avatar
wuhao committed
158
        columns={columns}
TZW's avatar
TZW committed
159
        path={urlParams.list}
wuhao's avatar
wuhao committed
160 161
        actionRef={actionRef}
        pageextra={'add'}
TZW's avatar
TZW committed
162
        resizeable={false}
wuhao's avatar
wuhao committed
163 164 165 166
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
TZW's avatar
TZW committed
167
            type: 'primary',
wuhao's avatar
wuhao committed
168
            onClick: () => {
TZW's avatar
TZW committed
169
              setDrawer((s) => ({
wuhao's avatar
wuhao committed
170 171
                ...s,
                visible: true,
TZW's avatar
TZW committed
172 173 174
                item: {
                  status: 1,
                },
wuhao's avatar
wuhao committed
175
                title: '新增',
TZW's avatar
TZW committed
176
                detailpath: null,
wuhao's avatar
wuhao committed
177
                val: 'add',
TZW's avatar
TZW committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
                onFinish: async (vals) => {
                  let params = {
                    ...vals,
                  };
                  let res = await doFetch({
                    url: urlParams.save,
                    params,
                  });
                  if (res.code === '0000') {
                    message.success('新增成功!');
                    setDrawer((s) => ({
                      ...s,
                      visible: false,
                    }));
                    actionRef.current.reload();
                  }
                },
wuhao's avatar
wuhao committed
195 196 197 198 199 200 201 202
              }));
            },
          },
        }}
      />

      <DrawerPro
        fields={columns}
TZW's avatar
TZW committed
203
        defaultFormValue={drawer?.item ?? {}}
wuhao's avatar
wuhao committed
204 205 206
        formRef={formRef}
        placement="right"
        onClose={() => {
TZW's avatar
TZW committed
207
          setDrawer((s) => ({
wuhao's avatar
wuhao committed
208 209 210 211 212 213 214 215 216 217
            ...s,
            visible: false,
          }));
        }}
        {...drawer}
      />
    </div>
  );
}

TZW's avatar
TZW committed
218
export default Supplier;