diff --git a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/api.ts b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/api.ts index 86e94d3..5a473e0 100644 --- a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/api.ts +++ b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/api.ts @@ -29,11 +29,11 @@ export interface ListResult { } // 机修组员工信息 -interface Staff { +export interface Staff { id?: string; // 配置id staffId: string; // 组员id staffName: string; // 组员名称 - manHoursProp?: string; // 工时分成占比(以小数表示,如0.5表示50%,全部组员相加为1) + manHoursProp: number; // 工时分成占比(以小数表示,如0.5表示50%,全部组员相加为1) } /** 工时分成配置列表 */ @@ -41,77 +41,18 @@ export function getListApi(params: ListParam): PromisePageResp { return request.get(`${CAS_HOST}/erp/team/setting/list`, { params }); } -/** 机修施工组 */ -export interface RepairGroup { - id: number; // 小组id - name: string; // 小组名称 - groupId: number; // 集团id - shopId: number; // 门店id - shopName: string; // 门店名称 - roIeCode: string; // 角色编码 - roIeName: string; // 角色名称 - remark: string; // 备注 - staffList: Staff[]; // 组员 -} - -/** 门店机修施工组:列表 */ -export function getShopRepairGroupsApi(shopId: number): PromisePageResp { - return request.get(`${CAS_HOST}/erp/team/setting/team/list`, { params: { shopId } }); -} - export interface SaveParams { shopId: number; // 门店id shopName: string; // 门店名称 - teamId: string; // 小组id + teamId: number; // 小组id teamName: string; // 小组名称 - userId?: string; // 用户id + userId?: number; // 用户id userName?: string; // 用户名称 - groupId?: string; // 集团id + groupId?: number; // 集团id userInfoVOS?: Staff[]; // 各组员分成比例配置 } -/** 保存/修改配置 */ +/** 修改配置 */ export function saveApi(params: SaveParams) { return request.post(`${CAS_HOST}/erp/team/setting/save`, params); } - -export interface DeleteParams { - groupId?: string; // 集团id - shopId?: number; // 门店id - userId?: string; // 用户id - userName?: string; // 用户名称 - current?: number; - pageSize?: number; - id: number; // 配置id -} - -/** 删除配置 */ -export function deleteApi(params: DeleteParams) { - return request.post(`${CAS_HOST}/erp/team/setting/delete`, params); -} - -/** 删除 */ -export function endApi(id?: number): http.PromiseResp { - return request.post(`${CAS_HOST}/erp/help/part/setting/delete`, { id }); -} - -/** - * 查询领辅料角色 - */ - -export interface User { - id: string; - name: string; -} - -export function getUserListApi(): http.PromiseResp { - return request.get(`${CAS_HOST}/erp/help/part/setting/role/list`); -} - -/** - * 查询辅料类型 - */ - -export function getTypeListApi(): http.PromiseResp { - return request.get(`${CAS_HOST}/erp/help/part/setting/type/list`); -} 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/components/Filter.tsx b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/Filter.tsx deleted file mode 100644 index 67207c8..0000000 --- a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/Filter.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { Row, Select } from "antd"; -import { LabeledValue } from "antd/lib/select"; - -const Option = Select.Option; - -const userData = [ - { value: 7, label: "工作车辆" }, - { value: 8, label: "员工车辆" }, - { value: 9, label: "大客户" }, -]; - -export interface FilterPara { - discountType?: number; - discountTypeName?: string; - [key: string]: any; -} - -interface Props { - onChange: Function; - filterParam: FilterPara; -} - -export default function Filter({ onChange, filterParam}: Props) { - const [type, setType] = useState(); - - useEffect(() => { - if (filterParam) { - filterParam.discountType && filterParam.discountTypeName - ? setType({ - key: `${filterParam.discountType}`, - value: filterParam.discountType, - label: filterParam.discountTypeName, - }) - : null; - } - }, [filterParam]); - - function onTypeChange(value: LabeledValue) { - const _value = value || ({} as LabeledValue); - const { key, label } = _value; - onChange && - onChange( - { discountType: key || undefined, current: 1, discountTypeName: label }, - true - ); - } - - return ( - - 客户类型: - - - ); -} diff --git a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/Modal.tsx b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/Modal.tsx deleted file mode 100644 index 27a4f1b..0000000 --- a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/components/Modal.tsx +++ /dev/null @@ -1,98 +0,0 @@ -import React, { useState, useEffect } from "react"; -import "@ant-design/compatible/assets/index.css"; -import { Select, Modal, Form, message } from "antd"; -import * as api from "../api"; -import { ListResult, SaveParams, saveApi, getShopRepairGroupsApi, ShopGroup } from "../api"; -import useInitial from "@/hooks/useInitail"; - -const FormItem = Form.Item; -const { Option } = Select; -const maxFormProps = { - labelCol: { span: 5 }, - wrapperCol: { span: 15 }, -}; - -interface Props { - visible: boolean; - onCancel: () => any; - shopId?: number; - detail?: ListResult; -} - -export default function SaveModal({ visible, onCancel, shopId, detail }: Props) { - const isNew = !detail.id; - - const [form] = Form.useForm(); - - const [confirmLoading, setConfirmLoading] = useState(false); - const [userData, setUserData] = useState([]); - - const { data: userList } = useInitial(getShopRepairGroupsApi, [], { shopId }); - - useEffect(() => { - if (detail.id) { - console.log(detail); - // form.setFieldsValue({ ..._item }); - } else { - form.resetFields(); - } - }, [visible]); - - function save(fieldsValue: any) { - console.log(fieldsValue); - setConfirmLoading(true); - const datas = { - id: detail.id || undefined, - roleCode: fieldsValue.roleCode.value, - partTypes: (fieldsValue.partTypes || []).map((e: any) => e.value), - }; - api - .saveApi(datas) - .then(() => { - message.success("操作成功!"); - setConfirmLoading(false); - onCancel(); - }) - .catch((e) => { - setConfirmLoading(false); - message.error(e.message); - }); - } - - return ( - form.submit()} - onCancel={onCancel} - > -
- - - - - - -
-
- ); -} diff --git a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/index.tsx b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/index.tsx index b16e2b1..027b571 100644 --- a/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/index.tsx +++ b/src/pages/cas/afterSaleConfiguration/manhoursProportionConfig/index.tsx @@ -1,109 +1,97 @@ -import React, { useState } from "react"; -import { Card, ConfigProvider, Table, Button, Popconfirm, message } from "antd"; +import React, { useState, useEffect } from "react"; +import { Card, Table, Button, Tag, message, Select, Input } from "antd"; import { PageHeaderWrapper } from "@ant-design/pro-layout"; -import zhCN from "antd/lib/locale-provider/zh_CN"; import usePagination from "@/hooks/usePagination"; -// import useInitial from "@/hooks/useInitail"; -import { getListApi, ListResult, deleteApi } from "./api"; +import { getShopApi } from "@/common/api"; +import { getListApi, ListResult, Staff } from "./api"; -// import Filter from "./components/Filter"; -import CreateModal from "./components/Modal"; +import ConfigModal from "./components/ConfigModal"; +const { Option } = Select; const { Column } = Table; export default function ManhoursProportionConfig() { - // const { data, loading, setLoading } = useInitial(getListApi, [], {}); - const { loading, setLoading, list, paginationConfig } = usePagination(getListApi, {}); + const { loading, setLoading, list, paginationConfig, setParams } = usePagination(getListApi, {}); + const [shops, setShops] = useState([]); const [visible, setVisible] = useState(false); const [detail, setDetail] = useState({}); - function handleDelete(row: ListResult) { - const deleteParams = { - id: row.teamId, - }; - deleteApi(deleteParams) + useEffect(() => { + getShopApi({}) .then((res) => { - message.success("删除成功"); - setLoading(true); + const { data = [] } = res; + setShops(data); }) .catch((e) => { - message.error(`删除失败:${e.message}`); + message.error(e.message); }); - } + }, []); return ( -
- {/* */} - -
- - - + + + setParams({ keywords: value }, true)} + /> + - ( - <> - - handleDelete(row)}> - - - - )} - /> -
-
+ + + + { + return users.map((user) => ( + + {user.staffName}:{user.manHoursProp} + + )); + }} + /> + ( + + )} + /> +
- {