printdom.jsx 4.6 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 22 23 24 25 26 27 28 29 30 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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 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 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
import { doFetch } from "@/utils/doFetch";
import React, {
  useState,
  useImperativeHandle,
  forwardRef,
  useRef,
} from "react";
import { useEffect } from "react";
import { ScrollBoard } from "@jiaminghi/data-view-react";
import { useWindowSize } from "@/utils/windowsize";
const pageStyle = `
@media all {
    .page-break {
    display: none;
    }
}

@media print {
    html, body {
    height: initial !important;
    overflow: initial !important;
    position:relative;
    -webkit-print-color-adjust: exact;
    word-break: break-all;
    }

}

@media print {
    .page-break {
    margin-top:0;
    display: block;
    page-break-before: auto;
    }
}

@media print {
    .page-noprint {
        display: none !important;
    }
}

@page {
    size: auto;
    margin: 0px;
}
`;

let columns = [
  {
    title: "物料编码 - 名称",
    dataIndex: "materieName",
    key: "materieName",
    search: false,
    render: (dom, row) => {
      return (row.materieCode ?? "") + " - " + (row.materieName ?? "");
    },
  },
  {
    title: "出库数量",
    dataIndex: "outstroeNum",
    key: "outstroeNum",
    search: false,
  },
  {
    title: "库存单位",
    dataIndex: "productionUnitName",
    key: "productionUnitName",
    search: false,
    width: 60,
  },
];

function PrintDom({ totalPath, val, totalParams, totalCard }, ref) {
  console.log(totalCard);
  let printRef = useRef();
  const [data, setdata] = useState({});
  useImperativeHandle(ref, () => ({
    dom: printRef,
  }));

  useEffect(() => {
    if (val == "detail") {
      doFetch({ url: totalPath, params: totalParams }).then((res) => {
        if (res.code == "0000") {
          setdata(res?.data?.data);
        }
      });
    } else {
    }
  }, [val]);

  let datas = data?.materialList
    ? data?.materialList.map((it) => {
        return columns.map((item) => {
          if (item.render) {
            return item.render(it, it);
          } else {
            return it[item.dataIndex];
          }
        });
      })
    : [];

  return (
    <>
      <style type="text/css" media="print">
        {pageStyle}
      </style>
      {val == "detail" && (
        <div
          ref={printRef}
          style={{
            width: "100%",
            minHeight: "100%",
            overflow: "inherit",
            position: "relative",
          }}
        >
          <div
            style={{
              display: "flex",
              justifyContent: "space-between",
              alignItems: "center",
              padding: "0 2%",
              paddingBottom: 12,
            }}
          >
            <h1
              style={{
                width: "100%",
                fontSize: 40,
                marginTop: "-6px",
              }}
            >
              出库工单
            </h1>
            <img
              style={{
                width: 300,
                height: "auto",
              }}
              src={data?.qrCodeUrl}
              alt=""
            />
          </div>
          <div
            style={{
              display: "flex",
              flexWrap: "wrap",
              paddingLeft: "2%",
              marginTop: 24,
            }}
          >
            {totalCard &&
              totalCard[0].itemData
                .filter((it) => !(it.noshow === true))
                .map((it) => {
                  return (
                    <div
                      style={{
                        width: it.noshow ?? "32%",
                        backgroundColor: "#f9f9f9",
                        marginRight: "1%",
                        marginBottom: 10,
                        padding: "4px",
                        fontSize: 20,
                        overflow: "hidden",
                      }}
                    >
                      <b>{it.title}: </b>
                      <span>{data[it.key] || "-"}</span>
                    </div>
                  );
                })}
          </div>
          <div
            style={{
              padding: "4px 2%",
              position: "relative",
              width: "100%",
              overflow: "hidden",
            }}
            id="large"
          >
            <div
              style={{
                marginBottom: 18,
              }}
            >
              <b>{totalCard && totalCard[1].cardTitle}</b>
            </div>

            <ScrollBoard
              config={{
                header: columns.map((it) => it.title),
                data: datas,
                rowNum: datas.length,
                hoverPause: false,
              }}
            />
          </div>
        </div>
      )}
    </>
  );
}

export default forwardRef(PrintDom);