index.jsx 5.13 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6
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';
wuhao's avatar
wuhao committed
7
import { useAsyncEffect, useRequest } from 'ahooks';
wuhao's avatar
wuhao committed
8
import { doFetch } from '@/utils/doFetch';
wuhao's avatar
wuhao committed
9
import extraColumns from '@/utils/extraColumns';
wuhao's avatar
wuhao committed
10
import { message } from 'antd';
wuhao's avatar
wuhao committed
11 12 13 14 15 16 17

function Supplier(props) {
  const actionRef = useRef(),
    formRef = useRef();
  const [drawer, setdrawer] = useState({
    open: false,
  });
wuhao's avatar
wuhao committed
18 19 20 21 22 23 24 25

  const [columns, setcolumns] = useState([
    {
      title: 'asd',
      key: 'ads',
    },
  ]);

wuhao's avatar
wuhao committed
26
  const pathconfig = useMemo(() => {
wuhao's avatar
wuhao committed
27
    let pathconf = getcolumns(changeState)?.pathconfig ?? {};
wuhao's avatar
wuhao committed
28 29
    return pathconf;
  }, []);
wuhao's avatar
wuhao committed
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 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 101 102 103 104 105 106 107 108
  const { run, loading } = useRequest(doFetch, {
    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',
            }));
          },
        }}
      >
        编辑
      </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
109 110 111 112 113 114 115 116 117
  function changeState(params) {
    doFetch({ url: '/sparepart/sparePartSupplier/stopAndStart', params }).then((res) => {
      if (res.code == '0000') {
        message.success('操作成功');
        actionRef?.current?.reload();
      }
    });
  }

wuhao's avatar
wuhao committed
118 119 120 121
  useAsyncEffect(async () => {
    let extracolumns = await extraColumns({
      url: '/base/paFormField/queryList',
      params: { formId: 4 },
wuhao's avatar
wuhao committed
122
    });
wuhao's avatar
wuhao committed
123
    let defcolumn = getcolumns(changeState)?.columns;
wuhao's avatar
wuhao committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137
    setcolumns([
      ...defcolumn,
      ...extracolumns,
      {
        title: '操作',
        valueType: 'option',
        width: 150,
        render: (text, row, _, action) => [
          pathconfig?.enabledetail && detail(text, row, _, action),
          pathconfig?.enableedit && edit(text, row, _, action),
          pathconfig?.enabledelete && remove(text, row, _, action),
        ],
      },
    ]);
wuhao's avatar
wuhao committed
138 139 140 141 142
  }, []);

  return (
    <div style={{ position: 'relative' }}>
      <AutoTable
TZW's avatar
1  
TZW committed
143
        pagetitle={<h3 className="page-title">备件供应商</h3>}
wuhao's avatar
wuhao committed
144 145 146 147
        columns={columns}
        actionRef={actionRef}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        pageextra={pathconfig?.enableadd ? 'add' : null}
wuhao's avatar
wuhao committed
148
        resizeable={false}
wuhao's avatar
wuhao committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
                item: null,
                title: '新增',
                val: 'add',
              }));
            },
          },
        }}
      />

      <DrawerPro
        fields={columns}
wuhao's avatar
wuhao committed
168
        extendField="supplierCharList"
wuhao's avatar
wuhao committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182
        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}
        onFinish={(vals) => {
wuhao's avatar
wuhao committed
183 184 185 186 187 188 189 190 191 192 193 194 195
          const newVals = JSON.parse(JSON.stringify(vals));
          const supplierCharReqList = [];
          for (let i in newVals) {
            if (!isNaN(i)) {
              supplierCharReqList.push({
                fieldId: i,
                fieldRealValue: newVals[i],
              });
              delete newVals[i];
            }
          }
          newVals.supplierCharReqList = supplierCharReqList;

wuhao's avatar
wuhao committed
196
          if (drawer?.val == 'add') {
wuhao's avatar
wuhao committed
197
            run({ url: pathconfig?.add || '/add', params: { ...newVals } });
wuhao's avatar
wuhao committed
198
          } else if (drawer?.val == 'edit') {
wuhao's avatar
wuhao committed
199
            run({ url: pathconfig?.edit || '/edit', params: { ...newVals, id: drawer?.item?.id } });
wuhao's avatar
wuhao committed
200 201 202 203 204 205 206 207
          }
        }}
      />
    </div>
  );
}

export default Supplier;