index.jsx 16.7 KB
Newer Older
wuhao's avatar
wuhao committed
1
import React, { useEffect, useMemo, useRef, useState } from "react";
wuhao's avatar
wuhao committed
2
import { Dropdown, Menu, Button, message } from "antd";
wuhao's avatar
wuhao committed
3 4 5 6
import AutoTable from "@/components/AutoTable";
import defaultFields from "./fields";
import { doFetch } from "@/utils/doFetch";
import DrawInitForm from "@/components/DrawInitForm";
wuhao's avatar
wuhao committed
7 8 9
import getPrem from "@/utils/getPrem"; //权限判断fn
import { useReactToPrint } from "react-to-print";
import { useModel } from "umi";
wuhao's avatar
wuhao committed
10
import PrintDom from "./printdom";
wuhao's avatar
wuhao committed
11
import { PrintQrCode } from "@/components/PrintCode";
wuhao's avatar
wuhao committed
12 13

const keytoval = {
wuhao's avatar
wuhao committed
14 15 16 17 18 19
    one: 1,
    two: 2,
    three: 3,
    four: 4,
  },
  items = [
wuhao's avatar
wuhao committed
20
    {
wuhao's avatar
wuhao committed
21 22
      key: "one",
      label: <a>生产领料出库</a>,
wuhao's avatar
wuhao committed
23 24
    },
    {
wuhao's avatar
wuhao committed
25 26
      key: "two",
      label: <a>销售出库</a>,
wuhao's avatar
wuhao committed
27 28
    },
    {
wuhao's avatar
wuhao committed
29 30
      key: "three",
      label: <a>报废出库</a>,
wuhao's avatar
wuhao committed
31 32
    },
    {
wuhao's avatar
wuhao committed
33 34
      key: "four",
      label: <a>其他出库</a>,
wuhao's avatar
wuhao committed
35
    },
wuhao's avatar
wuhao committed
36 37 38 39 40 41 42
  ],
  itemz = {
    one: "生产领料出库",
    two: "销售出库",
    three: "报废出库",
    four: "其他出库",
  };
wuhao's avatar
wuhao committed
43

左玲玲's avatar
左玲玲 committed
44
function Outstore(props) {
wuhao's avatar
wuhao committed
45 46
  const { initialState, setInitialState } = useModel("@@initialState");
  const [activeTabKey, onTabChange] = useState("1");
wuhao's avatar
wuhao committed
47 48
  const [selectKeys, setSelectKeys] = useState([]);

wuhao's avatar
wuhao committed
49 50 51 52 53 54 55 56 57 58 59 60
  let [drawprops, setdrawprops] = useState({
      title: "",
      visible: false,
      onClose: () => {
        setdrawprops((s) => ({
          ...s,
          visible: false,
          fields: {},
        }));
      },
      fields: {},
      width: 1200,
wuhao's avatar
wuhao committed
61
    }),
wuhao's avatar
wuhao committed
62 63
    actionRef = useRef(),
    ChildRef = null,
wuhao's avatar
wuhao committed
64 65
    printRef = useRef(),
    mutiPrintRef = useRef();
wuhao's avatar
wuhao committed
66

wuhao's avatar
wuhao committed
67 68 69 70 71 72 73 74 75 76 77
  //操作完成后刷新
  function reload() {
    actionRef.current.reload();
    ChildRef?.onRefresh();
    message.success("操作成功");
    setdrawprops((s) => ({
      ...s,
      visible: false,
      fields: {},
    }));
  }
wuhao's avatar
wuhao committed
78

wuhao's avatar
wuhao committed
79
  const handlePrint = useReactToPrint({
wuhao's avatar
wuhao committed
80
    content: () => printRef.current.dom.current,
wuhao's avatar
wuhao committed
81
  });
wuhao's avatar
wuhao committed
82

wuhao's avatar
wuhao committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
  const mutiPrint = useReactToPrint({
    content: () => mutiPrintRef.current.dom.current,
  });
  const PrintButton = (
    <Button
      disabled={!selectKeys.length}
      onClick={() => {
        mutiPrint();
      }}
    >
      打印
    </Button>
  );

  useEffect(() => {
    const detail = defaultFields.detail(setSelectKeys, PrintButton);
    setdrawprops((s) => ({
      ...s,
      ...detail,
    }));
  }, [selectKeys]);

wuhao's avatar
wuhao committed
105 106 107 108 109 110 111 112 113 114 115
  const columns = useMemo(() => {
    if (activeTabKey == "1") {
      return [
        {
          title: "出库单号",
          dataIndex: "materieOutstoreNo",
          key: "materieOutstoreNo",
          render: (dom, record) => {
            return (
              <a
                onClick={() => {
wuhao's avatar
wuhao committed
116 117 118 119
                  const detail = defaultFields.detail(
                    setSelectKeys,
                    PrintButton
                  );
wuhao's avatar
wuhao committed
120 121 122 123 124 125
                  setdrawprops((s) => ({
                    ...s,
                    visible: true,
                    //查看详情 props
                    val: "detail",
                    title: `查看详情`,
wuhao's avatar
wuhao committed
126
                    ...detail,
wuhao's avatar
wuhao committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
                    totalPath:
                      "/ngic-workmanship/wmsMaterieOutstore/getOutStoreInfoById",
                    totalParams: { id: record.id },
                    extra: (
                      <Button
                        onClick={async () => {
                          handlePrint();
                        }}
                      >
                        打印
                      </Button>
                    ),
                  }));
                }}
              >
                {dom}
              </a>
            );
          },
        },
        {
          title: "出库类型",
          dataIndex: "outstoreTypeName",
          key: "outstoreType",
          valueType: "select",
          options: [
            {
              label: "生产领料出库",
              value: "1",
            },
            {
              label: "销售出库",
              value: "2",
            },
            {
              label: "报废出库",
              value: "3",
            },
            {
              label: "其他出库",
              value: "4",
            },
          ],
        },
        {
          title: "出库仓库",
          dataIndex: "storeName",
          key: "storeId",
wuhao's avatar
wuhao committed
175 176
          fieldProps: {
            allowClear: true,
wuhao's avatar
wuhao committed
177
            showSearch: true,
wuhao's avatar
wuhao committed
178
          },
wuhao's avatar
wuhao committed
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 232 233 234
          options: {
            database: () =>
              doFetch({
                url: "/ngic-auth/sysStore/selectionBox",
                params: { factoryIdList: [] },
              }),
            params: {},
          },
          valueType: "select",
        },
        {
          title: "相关单号",
          dataIndex: "businessNo",
          key: "businessNo",
        },
        {
          title: "备注",
          dataIndex: "remark",
          key: "remark",
          search: false,
        },
        {
          title: "创建人",
          dataIndex: "createUserName",
          key: "createUserName",
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
          key: "createTime",
          valueType: "dateRange",
          formItemProps: {
            name: "createTimeList",
          },
        },
        {
          title: "状态",
          dataIndex: "statusName",
          key: "status",
          valueType: "select",
          options: [
            {
              label: "待下架",
              value: "0",
            },
            {
              label: "下架中",
              value: "1",
            },
          ],
        },
        {
          title: "操作",
          valueType: "option",
          width: 240,
          render: (text, record, _, action) => {
wuhao's avatar
wuhao committed
235
            return [
wuhao's avatar
wuhao committed
236 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
              getPrem(
                "equipmentCustomer_save",
                action,
                "下架采集",
                async () => {
                  let extra = defaultFields.dooutside(
                    record.id,
                    record.storeId
                  );
                  setdrawprops((s) => ({
                    ...s,
                    visible: true,
                    //查看详情 props
                    val: "detail",
                    title: `下架采集`,
                    ...extra,
                    totalPath:
                      "/ngic-workmanship/wmsMaterieOutstore/getOutStoreInfoById",
                    totalParams: { id: record.id },
                    extra: null,
                  }));
                  setInitialState((s) => {
                    return {
                      ...s,
                      submits: {},
                    };
                  });
wuhao's avatar
wuhao committed
263
                }
wuhao's avatar
wuhao committed
264 265 266 267 268 269 270 271 272 273
              ),
              getPrem("equipmentCustomer_deleteById", action, "关单", null, {
                title: "确认关单?",
                onConfirm: () => {
                  doFetch({
                    url: "/ngic-workmanship/wmsMaterieOutstore/close",
                    params: { id: record.id },
                  }).then((res) => {
                    if (res.code == "0000") {
                      reload();
wuhao's avatar
wuhao committed
274
                    }
wuhao's avatar
wuhao committed
275
                  });
wuhao's avatar
wuhao committed
276
                },
wuhao's avatar
wuhao committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
              }),
              record.status == 0 &&
                getPrem("equipmentCustomer_deleteById", action, "删除", null, {
                  title: "确认删除?",
                  onConfirm: () => {
                    doFetch({
                      url: "/ngic-workmanship/wmsMaterieOutstore/deleteById",
                      params: { id: record.id },
                    }).then((res) => {
                      if (res.code == "0000") {
                        reload();
                      }
                    });
                  },
                }),
            ];
          },
        },
      ];
    } else {
      return [
        {
          title: "出库单号",
          dataIndex: "materieOutstoreNo",
          key: "materieOutstoreNo",
          render: (dom, record) => {
            return (
              <a
                onClick={() => {
                  setdrawprops((s) => ({
wuhao's avatar
wuhao committed
307 308
                    ...s,
                    visible: true,
wuhao's avatar
wuhao committed
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
                    //查看详情 props
                    val: "detail",
                    title: `查看详情`,
                    ...defaultFields?.detail,
                    totalPath:
                      "/ngic-workmanship/wmsMaterieOutstoreHis/getOutStoreInfoById",
                    totalParams: { id: record.id },
                  }));
                }}
              >
                {dom}
              </a>
            );
          },
        },
        {
          title: "出库类型",
          dataIndex: "outstoreTypeName",
          key: "outstoreType",
          valueType: "select",
          options: [
wuhao's avatar
wuhao committed
330
            {
wuhao's avatar
wuhao committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
              label: "生产领料出库",
              value: "1",
            },
            {
              label: "销售出库",
              value: "2",
            },
            {
              label: "报废出库",
              value: "3",
            },
            {
              label: "其他出库",
              value: "4",
            },
          ],
        },
        {
          title: "出库仓库",
          dataIndex: "storeName",
          key: "storeId",
wuhao's avatar
wuhao committed
352 353
          fieldProps: {
            allowClear: true,
wuhao's avatar
wuhao committed
354
            showSearch: true,
wuhao's avatar
wuhao committed
355
          },
wuhao's avatar
wuhao committed
356
          options: {
wuhao's avatar
wuhao committed
357 358 359 360 361
            database: () =>
              doFetch({
                url: "/ngic-auth/sysStore/selectionBox",
                params: { factoryIdList: [] },
              }),
wuhao's avatar
wuhao committed
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
            params: {},
          },
          valueType: "select",
        },
        {
          title: "相关单号",
          dataIndex: "businessNo",
          key: "businessNo",
        },
        {
          title: "备注",
          dataIndex: "remark",
          key: "remark",
          search: false,
        },
        {
          title: "创建人",
          dataIndex: "createUserName",
          key: "createUserName",
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
          key: "createTime",
          valueType: "dateRange",
          formItemProps: {
            name: "createTimeList",
          },
        },
        {
          title: "完成时间",
          dataIndex: "finishTime",
          key: "finishTime",
          valueType: "dateRange",
          formItemProps: {
            name: "finishTimeList",
          },
        },
        {
          title: "状态",
          dataIndex: "statusName",
          key: "status",
          valueType: "select",
          options: [
            {
              label: "已下架",
              value: "2",
            },
            {
              label: "已关单",
              value: "4",
            },
          ],
        },
      ];
wuhao's avatar
wuhao committed
417
    }
wuhao's avatar
wuhao committed
418
  }, [activeTabKey]);
wuhao's avatar
wuhao committed
419

wuhao's avatar
wuhao committed
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
  const tableprops = {
    ...props,
    pageextra:
      activeTabKey == "1" ? (
        <Dropdown
          placement="bottomRight"
          overlay={
            <Menu
              onClick={(e) => {
                setdrawprops((s) => ({
                  ...s,
                  visible: true,
                  title: "新增" + itemz[e.key],
                  fields: defaultFields[e.key],
                  outstoreType: keytoval[e.key],
                  val: "add", //类型
                  extra: null,
                }));
              }}
              items={items}
            />
          }
        >
          <Button type="primary">新增</Button>
        </Dropdown>
      ) : (
        "none"
      ),
    tabList: [
      {
        tab: "未完成",
        key: "1",
      },
      {
        tab: "已完成",
        key: "2",
      },
    ],
    activeTabKey,
    onTabChange,
    columns,
    path:
      activeTabKey == "1"
        ? "/ngic-workmanship/wmsMaterieOutstore/queryList"
        : "/ngic-workmanship/wmsMaterieOutstoreHis/queryList",
  };
wuhao's avatar
wuhao committed
466

wuhao's avatar
wuhao committed
467 468
  return (
    <div>
wuhao's avatar
wuhao committed
469
      <div style={{ position: "fixed", bottom: -100000 }}>
wuhao's avatar
wuhao committed
470 471
        <PrintDom ref={printRef} {...drawprops} />
      </div>
wuhao's avatar
wuhao committed
472 473 474
      <div style={{ display: "none" }}>
        <PrintQrCode ref={mutiPrintRef} selectedItems={selectKeys} />
      </div>
wuhao's avatar
wuhao committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
      <AutoTable
        {...tableprops}
        actionRef={actionRef}
        onRef={(node) => (ChildRef = node)}
      ></AutoTable>
      <DrawInitForm
        {...drawprops}
        submitData={async (value) => {
          if (drawprops.val == "add") {
            let newfileds = JSON.parse(JSON.stringify(value));
            newfileds.materialList = newfileds?.materialList?.map((it) => {
              delete it.usableNum;
              delete it.id;
              return it;
            });
            let res = await doFetch({
              url: "/ngic-workmanship/wmsMaterieOutstore/saveOutStore",
              params: { ...newfileds, outstoreType: drawprops.outstoreType },
            });
            if (res.code == "0000") {
              reload();
            }
          }
        }}
        onChange={async (changedValues, allValues) => {
          for (let i in changedValues) {
            if (i == "storeId") {
              let res = await doFetch({
                  url: "/ngic-workmanship/wmsMaterieStockStore/selectbox/usableStock",
                  params: { storeId: changedValues["storeId"] },
                }),
                options = res?.data?.dataList;
              setdrawprops((s) => {
                let fields = JSON.parse(JSON.stringify(s.fields));
                for (let i in fields) {
                  fields[i].value = allValues[i];
wuhao's avatar
wuhao committed
511
                }
wuhao's avatar
wuhao committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
                fields["materialList"].linkconfig = {
                  urlchangeval: {
                    //根据url接口 改变某个value
                    database: (params) =>
                      doFetch({
                        url: "/ngic-workmanship/wmsMaterieStockStore/queryStoreOne",
                        params,
                      }),
                    params: { materieId: "linked", storeId: changedValues[i] },
                    effectresult: {
                      productionUnit: "productionUnit", //key 为列表更新值  value为response 返回值
                      productionUnitName: "productionUnitName",
                      usableNum: "usableNum",
                      outstroeNum: "outstroeNum",
                    },
                  },
                };
                fields["materialList"].columns = [
                  {
                    title: (
                      <span>
                        物料编码-名称 <b style={{ color: "red" }}>*</b>
                      </span>
                    ),
                    dataIndex: "materieId",
                    key: "materieId",
                    valueType: "select",
                    fieldProps: {
wuhao's avatar
wuhao committed
540
                      allowClear: true,
wuhao's avatar
wuhao committed
541
                      showSearch: true,
wuhao's avatar
wuhao committed
542
                      options,
wuhao's avatar
wuhao committed
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
                    },
                    formItemProps: () => {
                      return {
                        rules: [{ required: true, message: "此项为必填项" }],
                      };
                    },
                    editable: true,
                  },
                  {
                    title: (
                      <span>
                        出库数量 <b style={{ color: "red" }}>*</b>
                      </span>
                    ),
                    dataIndex: "outstroeNum",
                    key: "outstroeNum",
                    formItemProps: () => {
                      return {
                        rules: [{ required: true, message: "此项为必填项" }],
                      };
                    },
                    valueType: "digit",
                    editable: true,
                  },
                  {
                    title: "可用库存",
                    dataIndex: "usableNum",
                    key: "usableNum",
                    readonly: "usableNum",
                  },
                  {
                    title: "库存单位",
                    dataIndex: "productionUnitName",
                    key: "productionUnitName",
                    readonly: "productionUnitName",
                  },
                  {
                    title: "操作",
                    valueType: "option",
                    width: 70,
                    render: (text, record, _, action) => [
                      <a key="delete" onClick={() => {}}>
                        删除
                      </a>,
                    ],
                  },
                ];
                fields["materialList"].value = undefined;
                let newfields = {
                  ...fields,
                };
                return {
                  ...s,
                  fields: newfields,
                };
              });
            }
          }
        }}
        reload={reload}
      />
    </div>
  );
wuhao's avatar
wuhao committed
606 607
}

wuhao's avatar
wuhao committed
608
export default Outstore;