index.jsx 6.74 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
  const formFields = useMemo(() => {
    return getColumns(setDrawer, formRef);
  });
  const saveAndPrint = () => {
    confirm({
      title: `当前已完成信息填写,是否保存并立即打印?`,
      icon: <ExclamationCircleFilled />,
      width: 500,
krysent's avatar
krysent committed
123 124
      okText: "确定",
      cancelText: "取消",
krysent's avatar
krysent committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
      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
  const saveData = (type) => {
    if (type === 1) {
      formRef?.current?.validateFields().then((formData) => {
krysent's avatar
krysent committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        if (formData?.list && formData?.list.length > 0) {
          doFetch({
            url: "/ngic-workmanship/wmsMaterieLabel/save",
            params: formData,
          }).then((res) => {
            if (res?.code == "0000") {
              setDrawer((v) => ({
                ...v,
                visible: false,
              }));
            }
          });
        } else {
          message.destroy()
          message.warning("请添加列表数据!",2);
        }
krysent's avatar
krysent committed
160 161 162 163
      });
    } else {
      saveAndPrint();
    }
krysent's avatar
krysent committed
164
    //新增&修改
krysent's avatar
krysent committed
165 166 167 168 169
    // let difrid = iftype.val == "edit" ? { id: curitem.id } : {};
    // run({
    //   url: "/ngic-auth/sysStation/save",
    //   params: { ...newfields, ...difrid },
    // });
krysent's avatar
krysent committed
170 171
  };

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

krysent's avatar
krysent committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  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
205 206 207 208 209 210
            if (selectIds.length == 0) {
              message.destroy();
              message.warning("请选择数据!", 2);
              return;
            }
            showConfirm();
krysent's avatar
krysent committed
211 212 213 214 215 216 217 218
          }}
        >
          子卷补码
        </Button>
      </>
    );
  };

krysent's avatar
krysent committed
219 220 221 222 223
  const rowSelection = {
    onChange: (selectedRowKeys, selectedRows) => {
      console.log(selectedRowKeys, selectedRows);
      setselectIds(selectedRowKeys);
    },
krysent's avatar
krysent committed
224
    preserveSelectedRowKeys: true,
krysent's avatar
krysent committed
225
  };
krysent's avatar
krysent committed
226 227 228 229 230 231 232 233 234
  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
235 236 237 238
        rowSelection={{
          type: "checkbox",
          ...rowSelection,
        }}
krysent's avatar
krysent committed
239 240 241
      ></AutoTable>
      <Drawer
        title={drawer?.title}
krysent's avatar
krysent committed
242
        open={drawer?.visible}
krysent's avatar
krysent committed
243 244 245 246 247 248 249 250 251
        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
252
          fields={formFields}
krysent's avatar
krysent committed
253 254 255 256
          onChange={(changedValues, allValues) => {}}
          actions={() => {
            return null;
          }}
krysent's avatar
krysent committed
257
          submitter={false}
krysent's avatar
krysent committed
258 259 260
        ></InitForm>
        <Button
          type="primary"
krysent's avatar
krysent committed
261
          //   loading={loading || !vs}
krysent's avatar
krysent committed
262
          style={{ marginRight: 16 }}
krysent's avatar
krysent committed
263
          onClick={() => saveData(1)}
krysent's avatar
krysent committed
264 265 266 267 268
        >
          保存
        </Button>
        <Button
          type="primary"
krysent's avatar
krysent committed
269
          //   loading={loading || !vs}
krysent's avatar
krysent committed
270
          onClick={() => saveData(2)}
krysent's avatar
krysent committed
271 272 273 274 275 276 277 278
        >
          保存并打印
        </Button>
      </Drawer>
    </div>
  );
};
export default Station;