diff --git a/config/routers/cas.ts b/config/routers/cas.ts index 92f254c..370e471 100644 --- a/config/routers/cas.ts +++ b/config/routers/cas.ts @@ -246,6 +246,10 @@ export default [ path: '/cas/cassetting/manHoursDiscountConfig/create/:id/:brandId?', //工时减免规则配置 component: './cas/afterSaleConfiguration/manHoursDiscountConfig/subpages/ConfigCreate' }, + { + path: '/cas/cassetting/manhoursProportionConfig', // 机修组工时分成比例配置 + component: './cas/afterSaleConfiguration/manhoursProportionConfig' + }, // { // path: '/cas/part/plantype', // 备件计划类型 // component: './cas/spareParts/PlanType' diff --git a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/api.ts b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/api.ts new file mode 100644 index 0000000..5a473e0 --- /dev/null +++ b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/api.ts @@ -0,0 +1,58 @@ +import { http } from "@/typing/http"; +import request from "@/utils/request"; +import { CAS_HOST } from "@/utils/host"; + +type PromisePageResp = http.PromisePageResp; + +// 列表参数 +interface ListParam { + current?: number; + pageSize?: number; + keyword?: string; + shopId?: number; + groupId?: number; + userId?: number; + userName?: string; + teamId?: number; +} + +// 列表结果 +export interface ListResult { + groupId: number; // 集团id + shopId: number; // 门店id + shopName: string; // 门店名称 + roleCode: string; // 角色编码 + roleName: string; // 角色名称 + teamId: number; // 组id + teamName: string; // 组名 + userInfoVOS: Staff[]; // 组员工信息 +} + +// 机修组员工信息 +export interface Staff { + id?: string; // 配置id + staffId: string; // 组员id + staffName: string; // 组员名称 + manHoursProp: number; // 工时分成占比(以小数表示,如0.5表示50%,全部组员相加为1) +} + +/** 工时分成配置列表 */ +export function getListApi(params: ListParam): PromisePageResp { + return request.get(`${CAS_HOST}/erp/team/setting/list`, { params }); +} + +export interface SaveParams { + shopId: number; // 门店id + shopName: string; // 门店名称 + teamId: number; // 小组id + teamName: string; // 小组名称 + userId?: number; // 用户id + userName?: string; // 用户名称 + groupId?: number; // 集团id + userInfoVOS?: Staff[]; // 各组员分成比例配置 +} + +/** 修改配置 */ +export function saveApi(params: SaveParams) { + return request.post(`${CAS_HOST}/erp/team/setting/save`, params); +} diff --git a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/ConfigModal.tsx b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/ConfigModal.tsx new file mode 100644 index 0000000..928ee7d --- /dev/null +++ b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/ConfigModal.tsx @@ -0,0 +1,96 @@ +import React, { useState, useEffect } from "react"; +import "@ant-design/compatible/assets/index.css"; +import { Alert, Modal, Form, message, InputNumber } from "antd"; +import { ListResult, SaveParams, saveApi, Staff } from "../api"; + +const FormItem = Form.Item; +const maxFormProps = { + labelCol: { span: 6 }, + wrapperCol: { span: 14 }, +}; + +interface Props { + visible: boolean; + onCancel: () => any; + detail?: ListResult; +} + +export default function ConfigModal({ visible, onCancel, detail }: Props) { + const [form] = Form.useForm(); + console.log("detail", detail); + + const [confirmLoading, setConfirmLoading] = useState(false); + + useEffect(() => { + if (visible) { + form.resetFields(); + // init form values + const initialValues: any = {}; + detail?.userInfoVOS?.forEach((user: Staff) => { + initialValues[user.staffId] = user.manHoursProp; + }); + form.setFieldsValue(initialValues); + } + }, [visible]); + + function handleSubmit(fieldsValue: any) { + const configItems = detail!.userInfoVOS.map((user: Staff) => ({ + id: user.id, + staffId: user.staffId, + staffName: user.staffName, + manHoursProp: fieldsValue[user.staffId], + })); + const sum = configItems.reduce((acc: number, cur: Staff) => acc + cur.manHoursProp, 0); + if (sum !== 1) { + message.error("所有人员分成占比之和必须等于1"); + return; + } + + const params: SaveParams = { + shopId: detail!.shopId, + shopName: detail!.shopName, + teamId: detail!.teamId, + teamName: detail!.teamName, + userInfoVOS: configItems, + }; + + setConfirmLoading(true); + saveApi(params) + .then(() => { + message.success("配置成功!"); + setConfirmLoading(false); + onCancel(); + }) + .catch((e) => { + setConfirmLoading(false); + message.error(e.message); + }); + } + + return ( + form.submit()} + onCancel={onCancel} + > + + +
+ {detail?.userInfoVOS?.map((user: Staff) => ( + + + + ))} +
+
+ ); +} diff --git a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/index.tsx b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/index.tsx new file mode 100644 index 0000000..d80e78f --- /dev/null +++ b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/index.tsx @@ -0,0 +1,105 @@ +import React, { useState, useEffect } from "react"; +import { Card, Table, Button, Tag, message, Select, Input } from "antd"; +import { PageHeaderWrapper } from "@ant-design/pro-layout"; + +import usePagination from "@/hooks/usePagination"; +import { getShopApi } from "@/common/api"; +import { getListApi, ListResult, Staff } from "./api"; + +import ConfigModal from "./components/ConfigModal"; + +const { Option } = Select; +const { Column } = Table; + +export default function ManhoursProportionConfig() { + const { loading, setLoading, list, paginationConfig, setParams } = usePagination(getListApi, {}); + + const [shops, setShops] = useState([]); + const [visible, setVisible] = useState(false); + const [detail, setDetail] = useState({}); + + useEffect(() => { + getShopApi({}) + .then((res) => { + const { data = [] } = res; + setShops(data); + }) + .catch((e) => { + message.error(e.message); + }); + }, []); + + return ( + + +
+ + + setParams({ keyword: value }, true)} + /> +
+ + + + + { + return users.map((user) => ( + + {user.staffName}:{user.manHoursProp} + + )); + }} + /> + ( + + )} + /> +
+
+ + { + setVisible(false); + setDetail({}); + setLoading(true); + }} + /> +
+ ); +}