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

  const tableprops = {
    ...props,
krysent's avatar
krysent committed
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
    // 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
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
    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
385
      <div style={{ position: "fixed", bottom: -100000 }}>
krysent's avatar
krysent committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399
        <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
400 401 402 403 404 405
            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
406
            let res = await doFetch({
krysent's avatar
krysent committed
407 408
              url: "/ngic-workmanship/wmsMaterieOutstore/saveOutStore",
              params: { ...newfileds, outstoreType: drawprops.outstoreType },
krysent's avatar
krysent committed
409 410 411 412 413 414
            });
            if (res.code == "0000") {
              reload();
            }
          }
        }}
krysent's avatar
krysent committed
415 416 417 418 419 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
        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",
krysent's avatar
krysent committed
454
                    width:250,
krysent's avatar
krysent committed
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
                    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
522 523 524 525 526 527
        reload={reload}
      />
    </div>
  );
}

krysent's avatar
krysent committed
528
export default Outstore;