Index.jsx 5.47 KB
Newer Older
wuhao's avatar
wuhao committed
1
import React, { useEffect, useRef, useReducer } from "react";
wuhao's avatar
wuhao committed
2
import { Button, Tooltip, Row, Divider, Drawer } from "antd";
wuhao's avatar
wuhao committed
3 4 5 6 7 8
import AutoTable from "@/components/AutoTable";
import getPrem from "@/utils/getPrem"; //权限判断fn
import { useRequest } from "umi";
import defaultFields from "./fields";
import { doFetch } from "@/utils/doFetch";
import DrawInitForm from "@/components/DrawInitForm";
wuhao's avatar
wuhao committed
9
import StoreApp from './store'
wuhao's avatar
wuhao committed
10
const initState = {
wuhao's avatar
wuhao committed
11 12 13 14 15 16 17
  vs: false,
  fields: {},
  iftype: {},
  curitem: {},
  detail: {
    dataSource: {},
    totalCard: [],
wuhao's avatar
wuhao committed
18
  },
wuhao's avatar
wuhao committed
19 20
  visible: false,
},
wuhao's avatar
wuhao committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  otherBasic = {
    productionLineName: "产线(加工中心)",
    sectionName: "工段",
    processLineName: "工艺路线",
    groupName: "班组",
    shiftName: "班次",
  };
function reducer(state, action) {
  let { type } = action,
    newState = {};
  switch (type) {
    case "add":
      newState = {
        ...state,
        vs: true,
        iftype: {
wuhao's avatar
wuhao committed
37
          title: "新增仓库",
wuhao's avatar
wuhao committed
38 39 40 41 42 43 44 45 46 47
          val: type,
        },
        fields: { ...action.fields },
      };
      break;
    case "edit":
      newState = {
        ...state,
        vs: true,
        iftype: {
wuhao's avatar
wuhao committed
48
          title: "编辑仓库",
wuhao's avatar
wuhao committed
49 50 51 52 53 54 55 56 57
          val: type,
        },
        fields: { ...action.fields },
        curitem: action.curitem,
      };
      break;
    case "see":
      newState = {
        ...state,
wuhao's avatar
wuhao committed
58
        curitem: action.curitem,
wuhao's avatar
wuhao committed
59 60 61 62 63
        visible: true,
      };
      break;
    case "close":
      newState = {
wuhao's avatar
wuhao committed
64
        ...state,
wuhao's avatar
wuhao committed
65
        curitem: {},
wuhao's avatar
wuhao committed
66
        vs: false,
wuhao's avatar
wuhao committed
67 68 69 70 71 72 73 74
        visible: false,
      };
      break;
  }

  return newState;
}

wuhao's avatar
wuhao committed
75
const Store = (props) => {
wuhao's avatar
wuhao committed
76 77 78 79 80 81 82
  let actionRef = useRef(),
    ChildRef = null;
  function reload() {
    actionRef?.current?.reload();
    ChildRef?.onRefresh();
  }
  const { run, loading } = useRequest(doFetch, {
wuhao's avatar
wuhao committed
83 84 85 86 87 88 89 90 91
    manual: true,
    formatResult: (res) => res,
    onSuccess: (result, params) => {
      if (result.code == "0000") {
        reload();
        dispatch({ type: "close" });
      }
    },
  }),
wuhao's avatar
wuhao committed
92 93 94 95
    [state, dispatch] = useReducer(reducer, initState),
    { vs, fields, iftype, curitem, detail, visible } = state,
    columns = [
      {
wuhao's avatar
wuhao committed
96 97 98
        "title": "仓库编号",
        "dataIndex": "storeCode",
        "key": "storeCode"
wuhao's avatar
wuhao committed
99 100
      },
      {
wuhao's avatar
wuhao committed
101 102 103
        "title": "仓库名称",
        "dataIndex": "storeName",
        "key": "storeName"
wuhao's avatar
wuhao committed
104 105
      },
      {
wuhao's avatar
wuhao committed
106 107
        "title": "仓库类型",
        "dataIndex": "storeTypeName",
wuhao's avatar
wuhao committed
108
        "key": "storeType",
wuhao's avatar
wuhao committed
109
        "valueType": "select",
wuhao's avatar
wuhao committed
110 111 112 113
        "options": {
          database: () => doFetch({ url: "/ngic-base-business/sysDic/queryStoreTypeSelect", params: {} }),
          params: {}
        }
wuhao's avatar
wuhao committed
114 115
      },
      {
wuhao's avatar
wuhao committed
116 117 118
        "title": "工厂名",
        "dataIndex": "factoryName",
        "key": "factoryName"
wuhao's avatar
wuhao committed
119 120 121 122 123 124 125 126 127 128
      },
      {
        title: "操作",
        dataIndex: "option_dataindex",
        key: "option_dataindex",
        valueType: "option",
        width: 135,
        render: (text, row, _, action) => extraAction(text, row, _, action),
      },
    ];
wuhao's avatar
wuhao committed
129

wuhao's avatar
wuhao committed
130 131
  function extraAction(text, record, _, action) {
    return [
wuhao's avatar
wuhao committed
132 133 134
      getPrem("sysDepartment_save", action, "库位管理", () => {
        dispatch({ type: "see", curitem: record });
      }),
wuhao's avatar
wuhao committed
135
      getPrem("sysDepartment_save", action, "修改", () => {
wuhao's avatar
wuhao committed
136 137 138 139
        for (let i in defaultFields) {
          defaultFields[i].value = record[i];
        }
        dispatch({ type: "edit", fields: defaultFields, curitem: record });
wuhao's avatar
wuhao committed
140 141
      }),
      getPrem("sysDepartment_deleteById", action, "删除", null, {
wuhao's avatar
wuhao committed
142
        title: "确认删除该仓库?",
wuhao's avatar
wuhao committed
143 144
        onConfirm: () => {
          run({
wuhao's avatar
wuhao committed
145
            url: "/ngic-auth/sysStore/deleteById",
wuhao's avatar
wuhao committed
146 147 148 149 150 151
            params: { id: record.id },
          });
        },
      }),
    ];
  }
wuhao's avatar
wuhao committed
152

wuhao's avatar
wuhao committed
153 154 155 156 157
  let saveData = (values, fn) => {
    let newfields = JSON.parse(JSON.stringify(values));
    //新增&修改
    let difrid = iftype.val == "edit" ? { id: curitem.id } : {};
    run({
wuhao's avatar
wuhao committed
158
      url: "/ngic-auth/sysStore/save",
wuhao's avatar
wuhao committed
159 160 161
      params: { ...newfields, ...difrid },
    });
  };
wuhao's avatar
wuhao committed
162

wuhao's avatar
wuhao committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  let extrarender = [
    <Button
      disabled={!getPrem("sysDepartment_save", "ifs")}
      type="primary"
      onClick={() => {
        for (let i in defaultFields) {
          defaultFields[i].value = null;
          defaultFields[i].disabled = false;
        }
        dispatch({ type: "add", fields: defaultFields });
      }}
    >
      新增
    </Button>,
  ];
wuhao's avatar
wuhao committed
178

wuhao's avatar
wuhao committed
179 180 181 182 183 184
  return (
    <div>
      <AutoTable
        pagetitle={props.route.name} //页面标题
        pageextra={extrarender} //页面操作 新增or批量删除
        columns={columns}
wuhao's avatar
wuhao committed
185
        path="/ngic-auth/sysStore/queryList"
wuhao's avatar
wuhao committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
        actionRef={actionRef}
        onRef={(node) => (ChildRef = node)}
      ></AutoTable>

      <DrawInitForm
        title={iftype.title}
        visible={vs}
        onClose={() => dispatch({ type: "close" })}
        footer={false}
        destroyOnClose={true}
        fields={fields}
        submitData={(values) => {
          saveData(values);
        }}
        onChange={(changedValues, allValues) => {
          //联动操作
        }}
        submitting={loading || !vs}
        width={"60%"}
      >
      </DrawInitForm>
wuhao's avatar
wuhao committed
207 208

      <Drawer
wuhao's avatar
wuhao committed
209 210
        visible={visible}
        onClose={() => dispatch({ type: "close" })}
wuhao's avatar
wuhao committed
211
        title="库位列表"
wuhao's avatar
wuhao committed
212 213 214
        footer={false}
        destroyOnClose={true}
        width={"100%"}
wuhao's avatar
wuhao committed
215 216 217
        getContainer={false}
        style={{ position: "absolute" }}
      >
wuhao's avatar
wuhao committed
218
        
wuhao's avatar
wuhao committed
219 220 221 222
        <StoreApp curitem={curitem}></StoreApp>
      </Drawer>


wuhao's avatar
wuhao committed
223 224 225
    </div>
  );
};
wuhao's avatar
wuhao committed
226
export default Store;