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

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

krysent's avatar
krysent committed
44 45 46
  

function Outstore(props) {
krysent's avatar
krysent committed
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 109 110 111 112 113 114 115 116
  const { initialState, setInitialState } = useModel("@@initialState");
  const [activeTabKey, onTabChange] = useState("1");
  const [selectKeys, setSelectKeys] = useState([]);

  let [drawprops, setdrawprops] = useState({
      title: "",
      visible: false,
      onClose: () => {
        setdrawprops((s) => ({
          ...s,
          visible: false,
          fields: {},
        }));
      },
      fields: {},
      width: 1200,
    }),
    actionRef = useRef(),
    ChildRef = null,
    printRef = useRef(),
    mutiPrintRef = useRef();

  //操作完成后刷新
  function reload() {
    actionRef.current.reload();
    ChildRef?.onRefresh();
    message.success("操作成功");
    setdrawprops((s) => ({
      ...s,
      visible: false,
      fields: {},
    }));
  }

  const handlePrint = useReactToPrint({
    content: () => printRef.current.dom.current,
  });

  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]);

  const columns = useMemo(() => {
    if (activeTabKey == "1") {
      return [
        {
          title: "入库单号",
          dataIndex: "materieInstoreNo",
          key: "materieInstoreNo",
          render: (dom, record) => {
            return (
              <a
krysent's avatar
krysent committed
117
                onClick={() => {
krysent's avatar
krysent committed
118 119 120 121 122 123 124 125 126 127 128 129
                  const detail = defaultFields.detail(
                    setSelectKeys,
                    PrintButton
                  );
                  setdrawprops((s) => ({
                    ...s,
                    visible: true,
                    //查看详情 props
                    val: "detail",
                    title: `查看详情`,
                    ...detail,
                    totalPath:
krysent's avatar
krysent committed
130
                      "/ngic-workmanship/wmsMaterieInstore/getInStoreInfoById",
krysent's avatar
krysent committed
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
                    totalParams: { id: record.id },
                    extra: (
                      <Button
                        onClick={async () => {
                          handlePrint();
                        }}
                      >
                        打印
                      </Button>
                    ),
                  }));
                }}
              >
                {dom}
              </a>
            );
          },
        },
        {
          title: "入库类型",
          dataIndex: "instoreTypeName",
          key: "instoreType",
          valueType: "select",
          options: [
            {
krysent's avatar
krysent committed
156
              label: "来料入库",
krysent's avatar
krysent committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
              value: "2",
            },
            {
              label: "退料入库",
              value: "3",
            },
            {
              label: "其他入库",
              value: "4",
            },
          ],
        },
        {
          title: "入库仓库",
          dataIndex: "storeName",
krysent's avatar
krysent committed
172
          search: false,
krysent's avatar
krysent committed
173 174 175 176 177 178 179 180 181
          key: "storeId",
          fieldProps: {
            allowClear: true,
            showSearch: true,
          },
        },
        {
          title: "备注",
          dataIndex: "remark",
krysent's avatar
krysent committed
182
          search: false,
krysent's avatar
krysent committed
183 184 185 186 187 188 189
          key: "remark",
          search: false,
        },
        {
          title: "创建人",
          dataIndex: "createUserName",
          key: "createUserName",
krysent's avatar
krysent committed
190
          search: false,
krysent's avatar
krysent committed
191 192 193 194
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
krysent's avatar
krysent committed
195
          key: "createTimeList",
krysent's avatar
krysent committed
196 197 198 199 200 201 202 203 204 205 206 207
          valueType: "dateRange",
          formItemProps: {
            name: "createTimeList",
          },
        },
        {
          title: "状态",
          dataIndex: "statusName",
          key: "status",
          valueType: "select",
          options: [
            {
krysent's avatar
krysent committed
208
              label: "待下架",
krysent's avatar
krysent committed
209 210 211
              value: "0",
            },
            {
krysent's avatar
krysent committed
212 213 214 215 216 217 218 219 220 221
              label: "下架中",
              value: "2",
            },
            {
              label: "待分配",
              value: "5",
            },
            {
              label: "待执行",
              value: "6",
krysent's avatar
krysent committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235
            },
          ],
        },
      ];
    } else {
      return [
        {
          title: "入库单号",
          dataIndex: "materieInstoreNo",
          key: "materieInstoreNo",
          render: (dom, record) => {
            return (
              <a
                onClick={() => {
krysent's avatar
krysent committed
236 237 238 239
                  const detail = defaultFields.detail(
                    setSelectKeys,
                    PrintButton
                  );
krysent's avatar
krysent committed
240 241 242 243 244 245
                  setdrawprops((s) => ({
                    ...s,
                    visible: true,
                    //查看详情 props
                    val: "detail",
                    title: `查看详情`,
krysent's avatar
krysent committed
246
                    ...detail,
krysent's avatar
krysent committed
247
                    totalPath:
krysent's avatar
krysent committed
248
                      "/ngic-workmanship/wmsMaterieInstoreHis/getInStoreInfoById",
krysent's avatar
krysent committed
249
                    totalParams: { id: record.id },
krysent's avatar
krysent committed
250 251 252 253 254 255 256 257 258
                    extra: (
                      <Button
                        onClick={async () => {
                          handlePrint();
                        }}
                      >
                        打印
                      </Button>
                    ),
krysent's avatar
krysent committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
                  }));
                }}
              >
                {dom}
              </a>
            );
          },
        },
        {
          title: "入库类型",
          dataIndex: "instoreTypeName",
          key: "instoreType",
          valueType: "select",
          options: [
            {
krysent's avatar
krysent committed
274
              label: "来料入库",
krysent's avatar
krysent committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
              value: "2",
            },
            {
              label: "退料入库",
              value: "3",
            },
            {
              label: "其他入库",
              value: "4",
            },
          ],
        },
        {
          title: "入库仓库",
          dataIndex: "storeName",
krysent's avatar
krysent committed
290
          search: false,
krysent's avatar
krysent committed
291 292 293 294 295 296 297 298 299
          key: "storeId",
          fieldProps: {
            allowClear: true,
            showSearch: true,
          },
        },
        {
          title: "备注",
          dataIndex: "remark",
krysent's avatar
krysent committed
300
          search: false,
krysent's avatar
krysent committed
301 302 303 304 305 306 307
          key: "remark",
          search: false,
        },
        {
          title: "创建人",
          dataIndex: "createUserName",
          key: "createUserName",
krysent's avatar
krysent committed
308
          search: false,
krysent's avatar
krysent committed
309 310 311 312
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
krysent's avatar
krysent committed
313
          key: "createTimeList",
krysent's avatar
krysent committed
314 315 316 317 318 319 320 321
          valueType: "dateRange",
          formItemProps: {
            name: "createTimeList",
          },
        },
        {
          title: "完成时间",
          dataIndex: "finishTime",
krysent's avatar
krysent committed
322
          search: false,
krysent's avatar
krysent committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
          key: "finishTime",
          valueType: "dateRange",
          formItemProps: {
            name: "finishTimeList",
          },
        },
        {
          title: "状态",
          dataIndex: "statusName",
          key: "status",
          valueType: "select",
          options: [
            {
              label: "已关单",
              value: "4",
            },
krysent's avatar
krysent committed
339 340 341 342
            {
              label: "已完成",
              value: "8",
            },
krysent's avatar
krysent committed
343 344 345 346 347 348 349 350
          ],
        },
      ];
    }
  }, [activeTabKey]);

  const tableprops = {
    ...props,
krysent's avatar
krysent committed
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
    // 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"
    //   ),
krysent's avatar
krysent committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
    tabList: [
      {
        tab: "未完成",
        key: "1",
      },
      {
        tab: "已完成",
        key: "2",
      },
    ],
    activeTabKey,
    onTabChange,
    columns,
    path:
      activeTabKey == "1"
        ? "/ngic-workmanship/wmsMaterieInstore/queryList"
        : "/ngic-workmanship/wmsMaterieInstoreHis/queryList",
  };

  return (
    <div>
krysent's avatar
krysent committed
398
      <div style={{ position: "fixed", bottom: -100000 }}>
krysent's avatar
krysent committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412
        <PrintDom ref={printRef} {...drawprops} />
      </div>
      <div style={{ display: "none" }}>
        <PrintQrCode ref={mutiPrintRef} selectedItems={selectKeys} />
      </div>
      <AutoTable
        {...tableprops}
        actionRef={actionRef}
        onRef={(node) => (ChildRef = node)}
      ></AutoTable>
      <DrawInitForm
        {...drawprops}
        submitData={async (value) => {
          if (drawprops.val == "add") {
krysent's avatar
krysent committed
413 414 415 416 417 418
            let newfileds = JSON.parse(JSON.stringify(value));
            newfileds.materialList = newfileds?.materialList?.map((it) => {
              delete it.usableNum;
              delete it.id;
              return it;
            });
krysent's avatar
krysent committed
419
            let res = await doFetch({
krysent's avatar
krysent committed
420 421
              url: "/ngic-workmanship/wmsMaterieOutstore/saveOutStore",
              params: { ...newfileds, outstoreType: drawprops.outstoreType },
krysent's avatar
krysent committed
422 423 424 425 426 427
            });
            if (res.code == "0000") {
              reload();
            }
          }
        }}
krysent's avatar
krysent committed
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 466 467 468 469 470 471 472 473 474 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 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
        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];
                }
                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: {
                      allowClear: true,
                      showSearch: true,
                      options,
                    },
                    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",
                    fieldProps: {
                      precision: 3,
                    },
                    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,
                };
              });
            }
          }
        }}
krysent's avatar
krysent committed
534 535 536 537 538 539
        reload={reload}
      />
    </div>
  );
}

krysent's avatar
krysent committed
540
export default Outstore;