index.jsx 5.42 KB
Newer Older
krysent's avatar
krysent committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import React, { useEffect, useRef, useReducer } from "react";
import { Button, Tooltip, Row, Divider, Drawer } from "antd";
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";
import StoreApp from './store'
const initState = {
  vs: false,
  fields: {},
  iftype: {},
  curitem: {},
  detail: {
    dataSource: {},
    totalCard: [],
  },
  visible: false,
},
  otherBasic = {
    productionLineName: "产线(加工中心)",
    sectionName: "工段",
    processLineName: "工艺路线",
    groupName: "班组",
    shiftName: "班次",
  };
function reducer(state, action) {
  let { type } = action,
    newState = {};
  switch (type) {
    case "add":
      newState = {
        ...state,
        vs: true,
        iftype: {
krysent's avatar
krysent committed
37
          title: "新增库区",
krysent's avatar
krysent committed
38 39 40 41 42 43 44 45 46 47
          val: type,
        },
        fields: { ...action.fields },
      };
      break;
    case "edit":
      newState = {
        ...state,
        vs: true,
        iftype: {
krysent's avatar
krysent committed
48
          title: "编辑库区",
krysent's avatar
krysent committed
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
          val: type,
        },
        fields: { ...action.fields },
        curitem: action.curitem,
      };
      break;
    case "see":
      newState = {
        ...state,
        curitem: action.curitem,
        visible: true,
      };
      break;
    case "close":
      newState = {
        ...state,
        curitem: {},
        vs: false,
        visible: false,
      };
      break;
  }

  return newState;
}

const Store = (props) => {
  let actionRef = 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" });
      }
    },
  }),
    [state, dispatch] = useReducer(reducer, initState),
    { vs, fields, iftype, curitem, detail, visible } = state,
    columns = [
      {
krysent's avatar
krysent committed
96 97 98
        "title": "库区名称",
        "dataIndex": "storeAreaName",
        "key": "storeAreaName"
krysent's avatar
krysent committed
99 100
      },
      {
krysent's avatar
krysent committed
101 102 103
        "title": "所属工厂",
        "dataIndex": "factoryName",
        "key": "factoryName"
krysent's avatar
krysent committed
104 105
      },
      {
krysent's avatar
krysent committed
106 107 108
        "title": "所属仓库",
        "dataIndex": "storeName",
        "key": "storeName",
krysent's avatar
krysent committed
109 110 111 112 113
        // "valueType": "select",
        // "options": {
        //   database: () => doFetch({ url: "/ngic-base-business/sysDic/queryStoreTypeSelect", params: {} }),
        //   params: {}
        // }
krysent's avatar
krysent committed
114 115
      },
      {
krysent's avatar
krysent committed
116 117 118 119
        "title": "描述",
        "dataIndex": "remark",
        "key": "remark",
        "valueType": "textarea",
krysent's avatar
krysent committed
120
        search:false
krysent's avatar
krysent committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
      },
      {
        title: "操作",
        dataIndex: "option_dataindex",
        key: "option_dataindex",
        valueType: "option",
        width: 135,
        render: (text, row, _, action) => extraAction(text, row, _, action),
      },
    ];

  function extraAction(text, record, _, action) {
    return [
      getPrem("sysDepartment_save", action, "修改", () => {
        for (let i in defaultFields) {
          defaultFields[i].value = record[i];
        }
        dispatch({ type: "edit", fields: defaultFields, curitem: record });
      }),
      getPrem("sysDepartment_deleteById", action, "删除", null, {
krysent's avatar
krysent committed
141
        title: "确认删除该库区?",
krysent's avatar
krysent committed
142 143
        onConfirm: () => {
          run({
krysent's avatar
krysent committed
144
            url: "/ngic-auth/sysStoreArea/deleteById",
krysent's avatar
krysent committed
145 146 147 148 149 150 151 152 153 154 155 156
            params: { id: record.id },
          });
        },
      }),
    ];
  }

  let saveData = (values, fn) => {
    let newfields = JSON.parse(JSON.stringify(values));
    //新增&修改
    let difrid = iftype.val == "edit" ? { id: curitem.id } : {};
    run({
krysent's avatar
krysent committed
157
      url: "/ngic-auth/sysStoreArea/save",
krysent's avatar
krysent committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
      params: { ...newfields, ...difrid },
    });
  };

  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>,
  ];

  return (
    <div>
      <AutoTable
        pagetitle={props.route.name} //页面标题
        pageextra={extrarender} //页面操作 新增or批量删除
        columns={columns}
krysent's avatar
krysent committed
184
        path="/ngic-auth/sysStoreArea/page"
krysent's avatar
krysent committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
        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>

      <Drawer
        visible={visible}
        onClose={() => dispatch({ type: "close" })}
        title="库位列表"
        footer={false}
        destroyOnClose={true}
        width={"100%"}
        getContainer={false}
        style={{ position: "absolute" }}
      >
        
        <StoreApp curitem={curitem}></StoreApp>
      </Drawer>


    </div>
  );
};
export default Store;