index.jsx 6.91 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

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,
      },
      {
krysent's avatar
krysent committed
62
        title: "批次号",
krysent's avatar
krysent committed
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
        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
      onOk() {
        formRef?.current?.validateFields().then((formData) => {
krysent's avatar
krysent committed
127 128 129 130 131 132 133 134 135 136 137
          start("/ngic-workmanship/wmsMaterieLabel/save", formData).then(
            (res) => {
              console.log(res);
              setDrawer((v) => ({
                ...v,
                visible: false,
              }));
              message.success("保存成功!", 2);
              reload();
            }
          );
krysent's avatar
krysent committed
138 139 140 141 142 143 144
        });
      },
      onCancel() {
        console.log("Cancel");
      },
    });
  };
krysent's avatar
krysent committed
145

krysent's avatar
krysent committed
146 147 148
  const saveData = (type) => {
    if (type === 1) {
      formRef?.current?.validateFields().then((formData) => {
krysent's avatar
krysent committed
149 150 151 152 153 154
        if (formData?.list && formData?.list.length > 0) {
          doFetch({
            url: "/ngic-workmanship/wmsMaterieLabel/save",
            params: formData,
          }).then((res) => {
            if (res?.code == "0000") {
krysent's avatar
krysent committed
155
              reload();
krysent's avatar
krysent committed
156 157 158 159 160 161 162
              setDrawer((v) => ({
                ...v,
                visible: false,
              }));
            }
          });
        } else {
krysent's avatar
krysent committed
163 164
          message.destroy();
          message.warning("请添加列表数据!", 2);
krysent's avatar
krysent committed
165
        }
krysent's avatar
krysent committed
166 167
      });
    } else {
krysent's avatar
krysent committed
168
      reload();
krysent's avatar
krysent committed
169 170
      saveAndPrint();
    }
krysent's avatar
krysent committed
171
    //新增&修改
krysent's avatar
krysent committed
172 173 174 175 176
    // let difrid = iftype.val == "edit" ? { id: curitem.id } : {};
    // run({
    //   url: "/ngic-auth/sysStation/save",
    //   params: { ...newfields, ...difrid },
    // });
krysent's avatar
krysent committed
177 178
  };

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

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

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