/* * @Author: cclu * @Date: 2022-04-28 10:47:35 * @LastEditTime: 2024-09-03 11:09:26 * @LastEditors: cclu 1106109051@qq.com * @Description: 服务区门店管理模块 * @FilePath: \cloud-platform\src\pages\basicManage\ServerpartShop\index.tsx */ import ProCard from "@ant-design/pro-card"; import ProDescriptions from "@ant-design/pro-descriptions"; import SubMenu from "antd/lib/menu/SubMenu"; import ProTable from "@ant-design/pro-table"; import useRequest from "@ahooksjs/use-request"; import { getFieldEnum, getFieldEnumTree, getServerpartOption, getServerpartTree } from "@/services/options"; import { MenuFoldOutlined, PlusOutlined } from "@ant-design/icons"; import ProForm, { ModalForm, ProFormDatePicker, ProFormSelect, ProFormText } from "@ant-design/pro-form"; import { PageContainer } from "@ant-design/pro-layout"; import { Button, Tree, Col, Row, Drawer, message, Popconfirm, Space, Menu, Avatar, Form, TreeSelect, Modal } from "antd"; import type { ProDescriptionsItemProps } from "@ant-design/pro-descriptions"; import type { ActionType, ProColumns } from "@ant-design/pro-table"; import type { FormInstance } from "antd"; import type { ServerpartShopModel } from './data' import { useRef, useState } from "react"; import { getList, delServerpartShop, updateServerpartShop, handleSynchroServerpartShop, handleDeleteServerpartShop, handleSynchroRTSERVERPARTSHOP, handleModifyShopBusinessState } from "./service"; import './style.less' import type { ConnectState } from "@/models/connect"; import type { CurrentUser } from "umi"; import { connect } from "umi"; import FormDetail from "./component/formDetail"; import moment from 'moment' import session from "@/utils/session"; import ShopOperate from "./component/shopOperate"; import LogTable from "./component/logTable"; import Draggable from "react-draggable"; import React from "react"; import BusinessInforForm from "./component/businessInforForm"; import LeftSelectTree from "@/pages/reports/settlementAccount/component/leftSelectTree"; // 服务区门店组件主体 const ServerpartShopTable: React.FC<{ currentUser: CurrentUser }> = ({ currentUser }) => { const actionRef = useRef() const formRef = useRef() const updateShopStateModalFormRef = useRef() const BusinessInforFormRef = useRef() const ShopOperateRef = useRef() const formDetailRef = useRef() const [currentRow, setCurrentRow] = useState() const [showDetail, setShowDetail] = useState() const [currenMenu, setCurrenMenu] = useState(); // 当前选中的左侧菜单 const [modalVisible, handleModalVisible] = useState() const [serverpartId, setServerpartId] = useState() const [collapsible, setCollapsible] = useState(false) // 同步门店状态的悬浮框 const [updateShopStateModal, setUpdateShopStateModal] = useState(false) // 添加经营信息的悬浮框 const [showAddBusinessModal, setShowAddBusinessModal] = useState(false) const [bounds, setBounds] = useState<{ left: number, right: number, top: number, bottom: number }>() // 移动的位置 const [disabled, setDraggleDisabled] = useState() // 是否拖动 const draggleRef = React.createRef() // 选择的服务区 const [selectServerPartList, setSelectServerPartList] = useState() // 门店更新状态的loading const [updateShopStateLoading, setUpdateShopStateLoading] = useState() const businessStateList = session.get('businessStateList') const onDraggaleStart = (event, uiData) => { const { clientWidth, clientHeight } = window.document.documentElement; const targetRect = draggleRef.current?.getBoundingClientRect(); if (!targetRect) { return; } setBounds({ left: -targetRect.left + uiData.x, right: clientWidth - (targetRect.right - uiData.x), top: -targetRect.top + uiData.y, bottom: clientHeight - (targetRect.bottom - uiData.y), }); }; const { loading: severpartLoading, data: severpartTree = [] } = useRequest(() => { return getServerpartTree(currentUser?.ProvinceCode) }) const { data: shoptradeTree = [] } = useRequest(async () => { return await getFieldEnumTree({ FieldExplainField: 'BUSINESSTYPE', sessionName: 'BUSINESSTYPE' }) }) const { data: businessTypeTree = [] } = useRequest(async () => { return await getFieldEnumTree({ FieldExplainField: 'BUSINESS_TYPE', sessionName: 'BUSINESS_TYPE' }) }) const { data: businessStateTree = [] } = useRequest(async () => { return await getFieldEnumTree({ FieldExplainField: 'BUSINESSSTATE', sessionName: 'BUSINESSSTATE' }) }) const ServerpartIdsList = session.get('ServerpartIdsList') const columns: ProColumns[] = [ { dataIndex: 'SHOPNAME', title:
门店名称
, width: 200, ellipsis: true, hideInDescriptions: true, }, { dataIndex: 'SERVERPART_NAME', title: "服务区", align: 'center', width: 150, ellipsis: true, hideInSearch: true }, { dataIndex: 'SHOPREGION', title: '所属方位', valueType: 'select', width: 120, align: 'center', ellipsis: true, request: async () => { return await getFieldEnum({ FieldExplainField: 'SHOPREGION' }) }, hideInSearch: true }, { dataIndex: 'SHOPTRADE', title: '商品业态', hideInSearch: true, align: 'center', valueType: 'select', width: 120, ellipsis: true, request: async () => { return await getFieldEnum({ FieldExplainField: 'BUSINESSTYPE', sessionName: 'SHOPTRADE', notformate: true }) } }, { dataIndex: 'BUSINESS_TYPE', title: '经营模式', width: 120, align: 'center', ellipsis: true, valueType: 'select', request: async () => { return await getFieldEnumTree({ FieldExplainField: 'BUSINESS_TYPE', sessionName: 'BUSINESS_TYPE' }) } }, { dataIndex: 'BUSINESS_STATE', title: '经营状态', valueType: 'select', width: 120, ellipsis: true, align: 'center', initialValue: "1000", valueEnum: { "3000": { text: '关闭', status: 'error' }, "2000": { text: '暂停', status: 'warning' }, "1000": { text: '运营中', status: 'processing' }, "1010": { text: '待运营', status: 'default' } } }, { dataIndex: 'ISVALID', title: '有效状态', hideInTable: true, valueType: 'select', valueEnum: { "1": '有效', "0": "无效" }, initialValue: "1" }, { dataIndex: 'STAFF_NAME', title: '操作员', width: 120, align: 'center', ellipsis: true, hideInSearch: true }, { dataIndex: 'option', title: '操作', width: 120, align: 'center', valueType: 'option', hideInSearch: true, render: (_, record) => { return ( { console.log('record', record); setCurrentRow({ ...record }) handleModalVisible(true) }}>编辑 ) } } ] // 保存门店 const handleGetSaveShop = async () => { let req: any = {} let formRes: any = formDetailRef.current?.formRef.current?.getFieldsValue() // 老的查出的详情 let oldDetail: any = formDetailRef.current?.formDetailObj console.log('formRes', formRes); if (currentRow?.SERVERPARTSHOP_ID) { // 编辑 req = { ...oldDetail, ...formRes, BUSINESS_DATE: formRes?.BUSINESS_DATE ? moment(formRes?.BUSINESS_DATE).format('YYYY-MM-DD') : '', BUSINESS_ENDDATE: formRes?.BUSINESS_ENDDATE ? moment(formRes?.BUSINESS_ENDDATE).format('YYYY-MM-DD') : '', SERVERPART_NAME: formRes?.SERVERPART_ID ? ServerpartIdsList[formRes?.SERVERPART_ID] : '', STAFF_ID: currentUser?.ID, STAFF_NAME: currentUser?.Name, OPERATE_DATE: moment().format('YYYY-MM-DD HH:mm:ss'), } } else { // 新增 req = { ...formRes, BUSINESS_DATE: formRes?.BUSINESS_DATE ? moment(formRes?.BUSINESS_DATE).format('YYYY-MM-DD') : '', BUSINESS_ENDDATE: formRes?.BUSINESS_ENDDATE ? moment(formRes?.BUSINESS_ENDDATE).format('YYYY-MM-DD') : '', SERVERPART_NAME: formRes?.SERVERPART_ID ? ServerpartIdsList[formRes?.SERVERPART_ID] : '', STAFF_ID: currentUser?.ID, STAFF_NAME: currentUser?.Name, OPERATE_DATE: moment().format('YYYY-MM-DD HH:mm:ss'), OWNERUNIT_ID: currentUser?.OwnerUnitId, OWNERUNIT_NAME: currentUser?.OwnerUnitName, PROVINCE_CODE: currentUser?.ProvinceCode, } } console.log('req', req); const data = await handleSynchroServerpartShop(req) if (data.Result_Code === 100) { message.success(data.Result_Desc) handleModalVisible(false); setCurrentRow(undefined) actionRef.current?.reload() } else { message.error(data.Result_Desc) } } // 添加经营信息 const handleAddBusinessInfo = () => { BusinessInforFormRef.current?.formRef.current?.validateFields().then(async () => { let res: any = BusinessInforFormRef.current?.formRef.current?.getFieldsValue() console.log('res', res); const req: any = { ...res, SERVERPARTSHOP_ID: currentRow?.SERVERPARTSHOP_ID, SHOPNAME: currentRow?.SHOPSHORTNAME, BUSINESS_DATE: res?.BUSINESS_DATE ? moment(res?.BUSINESS_DATE).format('YYYY-MM-DD') : '', BUSINESS_ENDDATE: res?.BUSINESS_ENDDATE ? moment(res?.BUSINESS_ENDDATE).format('YYYY-MM-DD') : '', STAFF_ID: currentUser?.ID, STAFF_NAME: currentUser?.Name, OPERATE_DATE: moment().format('YYYY-MM-DD HH:mm:ss') } console.log('req', req); const data = await handleSynchroRTSERVERPARTSHOP(req) if (data.Result_Code === 100) { message.success(data.Result_Desc) ShopOperateRef.current?.actionRef.current?.reload() } else { message.error(data.Result_Desc) } setShowAddBusinessModal(false) }) } // 同步门店经营状态 const handleUpdateShopState = async (value: any) => { let list: any = [] if (selectServerPartList && selectServerPartList.length > 0) { selectServerPartList.forEach((item: any) => { list.push({ ServerPartShopId: item, BusinessState: value.BUSINESS_STATE.toString() }) }) } setUpdateShopStateLoading(true) const data = await handleModifyShopBusinessState({ list: list }) setUpdateShopStateLoading(false) if (data.Result_Code === 100) { message.success(data.Result_Desc) setSelectServerPartList([]) setUpdateShopStateModal(false) actionRef.current?.reload() } else { message.error(data.Result_Desc) } } return (
{ if (serverpartId && serverpartId.length > 0) { const data = await getList({ ...params, SERVERPART_IDS: serverpartId, current: 1, pageSize: 999999 }) return data } return { data: [], success: true } }} scroll={{ x: "100%", y: "calc(100vh - 450px)" }} actionRef={actionRef} search={{ span: 6 }} columns={columns} bordered toolbar={{ actions: [ , ] }} options={false} rowSelection={{ type: 'checkbox', selectedRowKeys: selectServerPartList, preserveSelectedRowKeys: true, onChange: (selectedRowKeys: any, selectedRows: any) => { console.log('selectedRowKeys', selectedRowKeys); setSelectServerPartList(selectedRowKeys) } }} />
{/* 同步门店状态的悬浮框 */} { setUpdateShopStateModal(false) }} confirmLoading={updateShopStateLoading} onOk={() => { updateShopStateModalFormRef.current?.validateFields().then((res: any) => { handleUpdateShopState(res) }) }} modalRender={(modal) => { return onDraggaleStart(event, uiData)} >
{modal}
}} >
{ handleModalVisible(false); setCurrentRow(undefined) }} bodyStyle={{ backgroundColor: "#fff", padding: 16 }} closable={false} destroyOnClose footer={
{ currentRow?.SERVERPARTSHOP_ID ? { const data = await handleDeleteServerpartShop({ ServerpartShopId: currentRow?.SERVERPARTSHOP_ID }) if (data.Result_Code === 100) { message.success(data.Result_Desc) handleModalVisible(false); setCurrentRow(undefined) actionRef.current?.reload() } else { message.error(data.Result_Desc) } }}> : '' }
} > {/* 表单 */} {/* 经营表格 */} {/* 日志表 */}
{/* 经营信息 */} { setShowAddBusinessModal(false) }} onOk={() => { handleAddBusinessInfo() }} modalRender={(modal) => { return onDraggaleStart(event, uiData)} >
{modal}
}} >
); } export default connect(({ user }: ConnectState) => ({ currentUser: user?.currentUser }))(ServerpartShopTable);