index.jsx 12.7 KB
Newer Older
wuhao's avatar
wuhao committed
1
import * as React from 'react';
TZW's avatar
TZW committed
2
import { useState, useMemo, useRef, useEffect } from 'react';
wuhao's avatar
wuhao committed
3 4 5 6 7 8 9 10 11
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 DetailPro from '@/components/DetailPro';
import EditTable from '@/components/InitForm/EditTable';
import { Button } from 'antd';
wuhao's avatar
wuhao committed
12

wuhao's avatar
wuhao committed
13
function Outstore(props) {
TZW's avatar
TZW committed
14
  let actionRef = useRef(),
wuhao's avatar
wuhao committed
15 16
    formRef = useRef();
  const [drawer, setdrawer] = useState({
左玲玲's avatar
左玲玲 committed
17 18
    open: false,
  }),
wuhao's avatar
wuhao committed
19 20
    [activeTabKey, setactiveTabKey] = useState('1');
  const [value, setvalue] = useState([]);
wuhao's avatar
wuhao committed
21

wuhao's avatar
wuhao committed
22 23 24 25 26 27 28 29 30
  const { run, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, params) => {
      if (res?.code == '0000') {
        actionRef?.current?.reload();
        setdrawer((s) => ({
          ...s,
          open: false,
        }));
wuhao's avatar
wuhao committed
31
        setvalue([]);
wuhao's avatar
wuhao committed
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
      }
    },
  });
  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: () => {
TZW's avatar
TZW committed
64
            actionRef.current.reload();
TZW's avatar
TZW committed
65 66 67 68 69 70 71 72 73 74 75 76 77
            doFetch({
              url: '/sparepart/outWarehouseTask/queryByBeforeOut',
              params: { id: row?.id },
            }).then((res) => {
              setdrawer((s) => ({
                ...s,
                open: true,
                item: row,
                title: '出库',
                val: 'only',
                submitdata: res?.data?.data?.taskSpareList ?? [],
              }));
            });
wuhao's avatar
wuhao committed
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 109
          },
        }}
      >
        出库
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: '是否关单?',
          okText: '确认',
          cancelText: '取消',
          onConfirm: () => {
            run({ url: '/sparepart/outWarehouseTask/shut', params: { id: row?.id } });
          },
        }}
        btn={{
          size: 'small',
          type: 'danger',
        }}
      >
        关单
      </PremButton>
    );
  };

  const columns = useMemo(() => {
    let defcolumn = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.columns;
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
TZW's avatar
TZW committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123
    if (activeTabKey == 1) {
      return defcolumn.concat({
        title: '操作',
        valueType: 'option',
        width: 150,
        render: (text, row, _, action) => [
          // defpath?.enabledetail && detail(text, row, _, action),
          defpath?.enableedit && edit(text, row, _, action),
          defpath?.enabledelete && remove(text, row, _, action),
        ],
      });
    } else {
      return defcolumn;
    }
wuhao's avatar
wuhao committed
124 125 126 127 128 129
  }, [activeTabKey]);

  const pathconfig = useMemo(() => {
    let defpath = getcolumns(setdrawer).filter((it) => it.key == activeTabKey)[0]?.pathconfig ?? {};
    return defpath;
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
130

wuhao's avatar
wuhao committed
131
  return (
左玲玲's avatar
左玲玲 committed
132
    <div>
wuhao's avatar
wuhao committed
133
      <AutoTable
TZW's avatar
1  
TZW committed
134
        pagetitle={<h3 className="page-title">出库管理</h3>}
wuhao's avatar
wuhao committed
135 136 137 138 139 140 141 142 143
        columns={columns}
        path={pathconfig?.list || '/ngic-auth/sysUser/query/page'}
        actionRef={actionRef}
        pageextra={pathconfig?.enableadd ? 'add' : null}
        resizeable={false}
        addconfig={{
          // access: 'sysDepartment_save',
          btn: {
            disabled: false,
wuhao's avatar
wuhao committed
144 145 146 147
            onClick: () => {
              setdrawer((s) => ({
                ...s,
                open: true,
TZW's avatar
TZW committed
148
                item: { outType: '2' },
wuhao's avatar
wuhao committed
149 150
                title: '新增',
                val: 'add',
wuhao's avatar
wuhao committed
151 152
              }));
            },
wuhao's avatar
wuhao committed
153 154 155 156 157 158 159 160
          },
        }}
        tabList={getcolumns()}
        activeTabKey={activeTabKey}
        onTabChange={(key) => {
          setactiveTabKey(key);
        }}
      />
wuhao's avatar
wuhao committed
161

wuhao's avatar
wuhao committed
162 163 164 165 166 167 168 169 170 171 172 173
      <DrawerPro
        fields={columns}
        detailpath={pathconfig?.detail || null}
        defaultFormValue={drawer?.item}
        params={{ id: drawer?.item?.id }}
        formRef={formRef}
        placement="right"
        onClose={() => {
          setdrawer((s) => ({
            ...s,
            open: false,
          }));
wuhao's avatar
wuhao committed
174
          setvalue([]);
wuhao's avatar
wuhao committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
        }}
        {...drawer}
        onFinish={(vals) => {
          const taskSpareList = vals?.taskSpareList?.map?.((it, i) => {
            return {
              spareStockId: it?.id,
              operateNum: it?.operateNum,
            };
          });
          if (drawer?.val == 'add') {
            run({ url: pathconfig?.add || '/add', params: { ...vals, taskSpareList } });
          } else if (drawer?.val == 'edit') {
            run({
              url: pathconfig?.edit || '/edit',
              params: { ...vals, id: drawer?.item?.id, taskSpareList },
            });
          }
        }}
      >
        {drawer?.val == 'only' && (
          <div>
            <DetailPro
              detailpath={pathconfig?.detail || null}
              params={{ id: drawer?.item?.id }}
              fields={columns?.filter(
                (it) => !['details', 'taskSpareList'].includes(it?.key) && it.valueType != 'option',
              )}
            />
            <AutoTable
              columns={[
                {
                  title: '备件料号',
                  dataIndex: 'sparePartNo',
                  key: 'sparePartNo',
                },
                {
                  title: '备件名称',
                  dataIndex: 'sparePartName',
                  key: 'sparePartName',
                },
                {
                  title: '库存单位',
                  dataIndex: 'unit',
                  key: 'unit',
                },
                {
                  title: '出库数量',
                  dataIndex: 'operateNum',
                  key: 'operateNum',
                },
                {
                  title: '未下架数量',
                  dataIndex: 'outNum',
                  key: 'outNum',
                },
              ]}
              pagetitle="备件信息"
TZW's avatar
TZW committed
232
              dataSource={drawer?.submitdata || []}
wuhao's avatar
wuhao committed
233 234 235
              expandable={{
                expandedRowRender: (record) => {
                  return (
TZW's avatar
TZW committed
236
                    <div>
wuhao's avatar
wuhao committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
                      <EditTable
                        resizeable={false}
                        alwaysShowAlert={false}
                        tableAlertRender={false}
                        tableAlertOptionRender={false}
                        columns={[
                          {
                            title: '供应商编号',
                            dataIndex: 'supplierNo',
                            key: 'supplierNo',
                            editable: false,
                          },
                          {
                            title: '供应商名称',
                            dataIndex: 'supplierName',
                            key: 'supplierName',
                            editable: false,
                          },
                          {
                            title: '库存数量',
                            dataIndex: 'actualStock',
                            key: 'actualStock',
                            editable: false,
                          },
                          {
                            title: '下架数量',
                            dataIndex: 'operateNum',
                            key: 'operateNum',
                            valueType: 'digit',
                            fieldProps: {
                              precision: 3,
                            },
                          },
                        ]}
                        dataSource={record?.spareSupplierStockList ?? []}
                        rowSelection={{
                          columnWidth: 44,
                          preserveSelectedRowKeys: true,
TZW's avatar
TZW committed
275 276
                          selectedRowKeys:
                            value && value.length > 0
TZW's avatar
TZW committed
277 278
                              ? value?.filter?.((it) => it?.id == record.id)[0]
                                ? value
左玲玲's avatar
左玲玲 committed
279 280
                                  ?.filter?.((it) => it?.id == record.id)[0]
                                  ?.taskSpareSupplierList?.map?.((it) => it?.spareSupplierStockId)
TZW's avatar
TZW committed
281
                                : []
TZW's avatar
TZW committed
282
                              : [],
wuhao's avatar
wuhao committed
283
                          onChange: (selectedKeys, selectedRows) => {
TZW's avatar
TZW committed
284
                            // debugger;
wuhao's avatar
wuhao committed
285 286 287
                            const curval =
                              value?.filter?.((it) => it?.id == record.id)[0]
                                ?.taskSpareSupplierList ?? [];
wuhao's avatar
wuhao committed
288

TZW's avatar
TZW committed
289 290 291 292
                            const rowkeylist =
                              curval && curval.length > 0
                                ? curval?.map((it) => it?.spareSupplierStockId)
                                : [];
wuhao's avatar
wuhao committed
293

wuhao's avatar
wuhao committed
294
                            const newValue = selectedRows?.map((its) => {
TZW's avatar
TZW committed
295 296
                              if (rowkeylist?.includes(its?.id)) {
                                return curval?.filter(
wuhao's avatar
wuhao committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
                                  (it) => it?.spareSupplierStockId == its?.id,
                                )[0];
                              } else {
                                return {
                                  spareSupplierStockId: its.id,
                                  operateNum: its.operateNum,
                                };
                              }
                            });
                            let nvalue = value ? [...value] : [];
                            if (value && value.some((it) => it.id == record?.id)) {
                              nvalue = value?.map((it, i) => {
                                if (it.id == record.id) {
                                  it.taskSpareSupplierList = newValue;
                                }
                                return it;
                              });
                            } else {
                              nvalue.push({
TZW's avatar
TZW committed
316
                                id: record?.id,
wuhao's avatar
wuhao committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
                                taskSpareSupplierList: newValue,
                              });
                            }
                            setvalue(nvalue);
                          },
                        }}
                        editable={{
                          onValuesChange: (rower, recordList) => {
                            const curval =
                              value?.filter?.((it) => it?.id == record.id)[0]
                                ?.taskSpareSupplierList ?? [];
                            const newValue = curval?.map((its) => {
                              if (its?.spareSupplierStockId == rower?.id) {
                                return {
                                  spareSupplierStockId: rower.id,
                                  operateNum: rower.operateNum,
                                };
                              } else {
                                return its;
                              }
                            });
                            let nvalue = value ? [...value] : [];
                            if (value && value.some((it) => it.id == record?.id)) {
                              nvalue = value?.map((it, i) => {
                                if (it.id == record.id) {
                                  it.taskSpareSupplierList = newValue;
                                }
                                return it;
                              });
                            } else {
                              nvalue.push({
                                id: record.id,
                                taskSpareSupplierList: newValue,
                              });
                            }
                            setvalue(nvalue);
                          },
                        }}
                      />
                    </div>
                  );
                },
              }}
            />
            <Button
              style={{ marginTop: 12 }}
              type="primary"
              onClick={() => {
                run({
                  url: '/sparepart/outWarehouseTask/OutWarehouse',
                  params: { id: drawer?.item?.id, taskSpareList: value },
                });
              }}
            >
              出库
            </Button>
          </div>
        )}
      </DrawerPro>
    </div>
  );
}
wuhao's avatar
wuhao committed
379

wuhao's avatar
wuhao committed
380
export default Outstore;