index.jsx 8.68 KB
Newer Older
wuhao's avatar
wuhao committed
1
import AutoTable from "@/components/AutoTable";
wuhao's avatar
wuhao committed
2
import DraggableDialog from "@/components/DraggableDialog";
wuhao's avatar
wuhao committed
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 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
import ImportExcel from "@/components/ImportExcel";
import InitForm from "@/components/InitForm";
import PremButton from "@/components/PremButton";
import { doFetch } from "@/utils/doFetch";
import { Box, Container, Stack, Typography } from "@mui/material";
import { useRequest } from "ahooks";
import { message } from "antd";
import { useRef, useState } from "react";
import "./index.less";

const columns = [
    {
      title: "学校名称",
      dataIndex: "organizationName",
      key: "organizationName",
      colProps: {
        span: 24,
      },
      formItemProps: {
        rules: [
          {
            required: true,
            message: "此项为必填项",
          },
        ],
      },
    },
    {
      title: "省份",
      dataIndex: "provinceName",
      key: "provinceId",
      valueType: "select",
      options: { path: "/province/selection", params: {} },
      formItemProps: {
        rules: [
          {
            required: true,
            message: "此项为必填项",
          },
        ],
      },
    },
    {
      title: "城市",
      dataIndex: "cityName",
      key: "cityId",
      valueType: "select",
      options: { path: "/city/selection", linkParams: { provinceId: "" } },
      formItemProps: {
        rules: [
          {
            required: true,
            message: "此项为必填项",
          },
        ],
      },
    },
  ],
  columnes = [
    {
      title: "院系名称",
      dataIndex: "organizationName",
      key: "organizationName",
      colProps: {
        span: 24,
      },
      formItemProps: {
        rules: [
          {
            required: true,
            message: "此项为必填项",
          },
        ],
      },
    },
  ];
wuhao's avatar
wuhao committed
79 80

function Organization() {
wuhao's avatar
wuhao committed
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 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 184 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 226
  const actionRef = useRef();
  const [dialogprops, setdialogprops] = useState({
    open: false,
  });
  const [expandedRowKeys, onExpandedRowsChange] = useState([]);

  const handleClose = () => {
    setdialogprops({
      open: false,
    });
  };

  const { runAsync, loading } = useRequest(doFetch, {
    manual: true,
    onSuccess: (res, parames) => {
      let paramsall = parames[0] ?? {};
      let params = paramsall?.params;
      let url = paramsall?.url;
      if (res?.code == "0000") {
        handleClose();
        message.success("操作成功");
        if (url.indexOf("delete") !== -1) {
          return;
        }
        if (dialogprops?.title?.indexOf("院系") !== -1) {
          if (params?.parentId) {
            onExpandedRowsChange((s) => [...new Set([...s, params?.parentId])]);
          }
        } else {
          actionRef?.current?.reload();
        }
      }
    },
  });

  const add = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: "small",
          style: { color: "#000" },
          onClick: (e) => {
            e.stopPropagation();
            setdialogprops({
              open: true,
              defaultFormValue: {},
              title: "添加院系",
              parentId: row.id,
            });
          },
        }}
      >
        添加院系
      </PremButton>
    );
  };

  const edit = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: "small",
          variant: "text",
          onClick: () => {
            setdialogprops({
              open: true,
              defaultFormValue: { ...row },
              title: "编辑",
            });
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const remove = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: "是否删除该学校?",
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
              url: "/organization/delete",
              params: { id: row.id },
            });
            actionRef?.current?.reload();
          },
        }}
        btn={{
          size: "small",
          color: "error",
        }}
      >
        删除
      </PremButton>
    );
  };

  const edits = (text, row, _, action) => {
    return (
      <PremButton
        btn={{
          size: "small",
          variant: "text",
          onClick: () => {
            setdialogprops({
              open: true,
              defaultFormValue: { ...row },
              title: "编辑院系",
            });
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

  const removes = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: "是否删除该院系?",
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
              url: "/organization/delete",
              params: { id: row.id },
            });
          },
        }}
        btn={{
          size: "small",
          color: "error",
        }}
      >
        删除
      </PremButton>
    );
  };

wuhao's avatar
wuhao committed
227
  return (
wuhao's avatar
wuhao committed
228
    <Container maxWidth={false}>
wuhao's avatar
wuhao committed
229
      <DraggableDialog
wuhao's avatar
wuhao committed
230 231 232
        handleClose={handleClose}
        loading={loading}
        dialogprops={dialogprops}
wuhao's avatar
wuhao committed
233 234
      >
        <InitForm
wuhao's avatar
wuhao committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
          fields={
            dialogprops?.title?.indexOf?.("院系") !== -1 ? columnes : columns
          }
          defaultFormValue={dialogprops?.defaultFormValue}
          onFinish={(val, extra) => {
            let postdata = {};

            switch (dialogprops?.title) {
              case "编辑":
                postdata = { ...val, id: dialogprops?.defaultFormValue?.id };
                break;
              case "创建学校":
                postdata = val;
                break;
              case "添加院系":
                postdata = { ...val, parentId: dialogprops?.parentId };
                break;
              case "编辑院系":
                postdata = {
                  ...val,
                  parentId: dialogprops?.defaultFormValue?.parentId,
                  id: dialogprops?.defaultFormValue?.id,
                };
                break;
              default:
                break;
            }
            runAsync({
              url: "/organization/saveOrUpdate",
              params: postdata,
            });
          }}
wuhao's avatar
wuhao committed
267 268
        ></InitForm>
      </DraggableDialog>
wuhao's avatar
wuhao committed
269 270 271 272 273 274 275 276 277 278

      <Box
        display={"flex"}
        justifyContent={"space-between"}
        alignItems={"center"}
        sx={{ mb: 2.5 }}
        mt={0}
      >
        <Typography variant="h5">组织管理</Typography>
        <Stack spacing={2} direction="row">
wuhao's avatar
wuhao committed
279 280 281 282 283 284 285
          <ImportExcel
            importurl="/organization/dataImport"
            downloadurl="/download/组织架构导入模板.xlsx"
            refresh={()=>{
              actionRef?.current?.reload();
            }}
          ></ImportExcel>
wuhao's avatar
wuhao committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
          <PremButton
            btn={{
              variant: "contained",
              onClick: (e) => {
                e.stopPropagation();
                setdialogprops({
                  open: true,
                  defaultFormValue: {},
                  title: "创建学校",
                });
              },
            }}
          >
            创建学校
          </PremButton>
        </Stack>
      </Box>

wuhao's avatar
wuhao committed
304 305
      <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2}>
        <AutoTable
wuhao's avatar
wuhao committed
306
          actionRef={actionRef}
wuhao's avatar
wuhao committed
307
          columns={[
wuhao's avatar
wuhao committed
308
            ...columns,
wuhao's avatar
wuhao committed
309
            {
wuhao's avatar
wuhao committed
310 311 312 313 314 315 316 317
              title: "操作",
              valueType: "option",
              width: 200,
              render: (text, row, _, action) => [
                add(text, row, _, action),
                edit(text, row, _, action),
                remove(text, row, _, action),
              ],
wuhao's avatar
wuhao committed
318 319
            },
          ]}
wuhao's avatar
wuhao committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
          path="/organization/page"
          expandable={{
            columnWidth: "60px",
            expandedRowKeys,
            onExpandedRowsChange,
            expandedRowRender: (record) => (
              <div className="white">
                <AutoTable
                  pagination={false}
                  path="/organization/childrenList"
                  columns={[
                    ...columnes,
                    {
                      title: "操作",
                      valueType: "option",
                      width: 180,
                      render: (text, row, _, action) => [
                        edits(text, row, _, action),
                        removes(text, row, _, action),
                      ],
                    },
                  ]}
                  extraparams={{ parentId: record?.id }}
                ></AutoTable>
              </div>
            ),
          }}
wuhao's avatar
wuhao committed
347 348 349 350
        ></AutoTable>
      </Box>
    </Container>
  );
wuhao's avatar
wuhao committed
351 352
}

wuhao's avatar
wuhao committed
353
export default Organization;