index.jsx 6.59 KB
Newer Older
krysent's avatar
krysent committed
1
import React, { useEffect, useRef, useReducer, useState, useMemo } from "react";
krysent's avatar
krysent committed
2 3 4 5 6 7 8 9 10 11
import {
  Button,
  Tooltip,
  Row,
  Divider,
  Drawer,
  Modal,
  Space,
  message,
} from "antd";
krysent's avatar
krysent committed
12 13
import AutoTable from "@/components/AutoTable";
import { useRequest } from "umi";
krysent's avatar
krysent committed
14
import { getColumns } from "./fields.js";
krysent's avatar
krysent committed
15
import { doFetch } from "@/utils/doFetch";
krysent's avatar
krysent committed
16
import InitForm from "@/components/NewInitForm";
krysent's avatar
krysent committed
17 18 19
import { start } from "@/utils/printHandle.js";
import { ExclamationCircleFilled } from "@ant-design/icons";
const { confirm } = Modal;
krysent's avatar
krysent committed
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

const Station = (props) => {
  let actionRef = useRef(),
    formRef = useRef(),
    ChildRef = null;
  function reload() {
    actionRef?.current?.reload();
    ChildRef?.onRefresh();
  }
  const { run, loading } = useRequest(doFetch, {
      manual: true,
      formatResult: (res) => res,
      onSuccess: (result, params) => {
        if (result.code == "0000") {
          reload();
          dispatch({ type: "close" });
        }
      },
    }),
    columns = [
      {
        title: "物料编码",
        dataIndex: "materieCode",
        key: "materieCode",
      },
      {
        title: "物料名称",
        dataIndex: "materieName",
        key: "materieName",
      },
      {
        title: "规格型号",
        dataIndex: "specificationModel",
        key: "specificationModel",
      },
      {
        title: "数量",
        dataIndex: "weight",
        key: "weight",
        search: false,
      },
      {
        title: "批号",
        dataIndex: "materieControlNo",
        key: "materieControlNo",
      },
      {
        title: "供应商",
        dataIndex: "supplierName",
        key: "supplierName",
        search: false,
      },
      {
        title: "宽度",
        dataIndex: "width",
        key: "width",
        search: false,
      },
      {
        title: "片厚",
        dataIndex: "sheetThickness",
        key: "sheetThickness",
        search: false,
      },
      {
        title: "铁损",
        dataIndex: "ironLoss",
        key: "ironLoss",
        search: false,
      },
      {
        title: "单边厚度",
        dataIndex: "unilateralThickness",
        key: "unilateralThickness",
        search: false,
      },
      {
        title: "创建人",
        dataIndex: "createUserName",
        key: "createUserName",
        search: false,
      },
      {
        title: "单据日期",
        dataIndex: "orderDate",
        key: "orderDate",
        search: false,
      },
    ];

  const [drawer, setDrawer] = useState({
    visible: false,
  });
krysent's avatar
krysent committed
113
  const [selectIds, setselectIds] = useState([]);
krysent's avatar
krysent committed
114

krysent's avatar
krysent committed
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
  const formFields = useMemo(() => {
    return getColumns(setDrawer, formRef);
  });
  const saveAndPrint = () => {
    confirm({
      title: `当前已完成信息填写,是否保存并立即打印?`,
      icon: <ExclamationCircleFilled />,
      width: 500,
      okText: '确定',
      cancelText:"取消",
      onOk() {
        formRef?.current?.validateFields().then((formData) => {
          start("/ngic-workmanship/wmsMaterieLabel/save", formData);
          setDrawer((v) => ({
            ...v,
            visible: false,
          }));
          message.success("保存成功!", 2);
        });
      },
      onCancel() {
        console.log("Cancel");
      },
    });
  };
krysent's avatar
krysent committed
140

krysent's avatar
krysent committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
  const saveData = (type) => {
    if (type === 1) {
      formRef?.current?.validateFields().then((formData) => {
        doFetch({
          url: "/ngic-workmanship/wmsMaterieLabel/save",
          params: formData,
        }).then((res) => {
          if (res?.code == "0000") {
            setDrawer((v) => ({
              ...v,
              visible: false,
            }));
          }
          message.success("保存成功!", 2);
        });
      });
    } else {
      saveAndPrint();
    }
krysent's avatar
krysent committed
160
    //新增&修改
krysent's avatar
krysent committed
161 162 163 164 165
    // let difrid = iftype.val == "edit" ? { id: curitem.id } : {};
    // run({
    //   url: "/ngic-auth/sysStation/save",
    //   params: { ...newfields, ...difrid },
    // });
krysent's avatar
krysent committed
166 167
  };

krysent's avatar
krysent committed
168 169 170 171 172
  const showConfirm = () => {
    confirm({
      title: `当前已选择 ${selectIds?.length} 条标签数据,是否全部打印?`,
      icon: <ExclamationCircleFilled />,
      width: 500,
krysent's avatar
krysent committed
173 174
      okText: '确定',
      cancelText:"取消",
krysent's avatar
krysent committed
175 176 177 178 179 180 181 182 183 184 185
      onOk() {
        start("/ngic-workmanship/wmsMaterieLabel/queryByIds", {
          ids: selectIds,
        });
      },
      onCancel() {
        console.log("Cancel");
      },
    });
  };

krysent's avatar
krysent committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
  const OptionsBtn = () => {
    return (
      <>
        <Button
          type="primary"
          style={{ marginRight: 8 }}
          onClick={() => {
            setDrawer((v) => ({ ...v, visible: true, title: " 卷料分卷打码" }));
          }}
        >
          卷料分卷打码
        </Button>
        <Button
          type="primary"
          onClick={() => {
krysent's avatar
krysent committed
201 202 203 204 205 206
            if (selectIds.length == 0) {
              message.destroy();
              message.warning("请选择数据!", 2);
              return;
            }
            showConfirm();
krysent's avatar
krysent committed
207 208 209 210 211 212 213 214
          }}
        >
          子卷补码
        </Button>
      </>
    );
  };

krysent's avatar
krysent committed
215 216 217 218 219
  const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
      console.log(selectedRowKeys, selectedRows);
      setselectIds(selectedRowKeys);
    },
krysent's avatar
krysent committed
220
    preserveSelectedRowKeys: true,
krysent's avatar
krysent committed
221
  };
krysent's avatar
krysent committed
222 223 224 225 226 227 228 229 230
  return (
    <div>
      <AutoTable
        pagetitle={props.route.name} //页面标题
        pageextra={OptionsBtn()} //页面操作 新增or批量删除
        columns={columns}
        path="/ngic-workmanship/wmsMaterieLabel/page"
        actionRef={actionRef}
        onRef={(node) => (ChildRef = node)}
krysent's avatar
krysent committed
231 232 233 234
        rowSelection={{
          type: "checkbox",
          ...rowSelection,
        }}
krysent's avatar
krysent committed
235 236 237
      ></AutoTable>
      <Drawer
        title={drawer?.title}
krysent's avatar
krysent committed
238
        open={drawer?.visible}
krysent's avatar
krysent committed
239 240 241 242 243 244 245 246 247
        onClose={() => setDrawer((v) => ({ ...v, visible: false }))}
        footer={false}
        destroyOnClose={true}
        getContainer={false}
        style={{ position: "absolute" }}
        width={"100%"}
      >
        <InitForm
          formRef={formRef}
krysent's avatar
krysent committed
248
          fields={formFields}
krysent's avatar
krysent committed
249 250 251 252
          onChange={(changedValues, allValues) => {}}
          actions={() => {
            return null;
          }}
krysent's avatar
krysent committed
253
          submitter={false}
krysent's avatar
krysent committed
254 255 256
        ></InitForm>
        <Button
          type="primary"
krysent's avatar
krysent committed
257
          //   loading={loading || !vs}
krysent's avatar
krysent committed
258
          style={{ marginRight: 16 }}
krysent's avatar
krysent committed
259
          onClick={() => saveData(1)}
krysent's avatar
krysent committed
260 261 262 263 264
        >
          保存
        </Button>
        <Button
          type="primary"
krysent's avatar
krysent committed
265
          //   loading={loading || !vs}
krysent's avatar
krysent committed
266
          onClick={() => saveData(2)}
krysent's avatar
krysent committed
267 268 269 270 271 272 273 274
        >
          保存并打印
        </Button>
      </Drawer>
    </div>
  );
};
export default Station;