index.jsx 6.87 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
      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 155 156 157 158 159 160 161
        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 {
krysent's avatar
krysent committed
162 163
          message.destroy();
          message.warning("请添加列表数据!", 2);
krysent's avatar
krysent committed
164
        }
krysent's avatar
krysent committed
165 166 167 168
      });
    } else {
      saveAndPrint();
    }
krysent's avatar
krysent committed
169
    //新增&修改
krysent's avatar
krysent committed
170 171 172 173 174
    // let difrid = iftype.val == "edit" ? { id: curitem.id } : {};
    // run({
    //   url: "/ngic-auth/sysStation/save",
    //   params: { ...newfields, ...difrid },
    // });
krysent's avatar
krysent committed
175 176
  };

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

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

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