// 经营品牌管理 import { connect } from "umi"; import type { CurrentUser } from "umi"; import type { ConnectState } from "@/models/connect"; import React, { useEffect, useRef, useState } from "react"; import ProCard from "@ant-design/pro-card"; import { MenuFoldOutlined } from "@ant-design/icons"; import type { FormInstance } from "antd"; import { Avatar, Button, Col, Form, message, Popconfirm, Row, Space, Spin, Tree, TreeSelect } from "antd"; import useRequest from "@ahooksjs/use-request"; import { getServerpartTree } from "@/services/options"; import type { ActionType } from "@ant-design/pro-table"; import ProTable from "@ant-design/pro-table"; import ReactHTMLTableToExcel from "react-html-table-to-excel"; import LeftSelectTree from "@/pages/reports/settlementAccount/component/leftSelectTree"; import PageTitleBox from "@/components/PageTitleBox"; import { getBusniessBrandTree } from "../service"; import { initial } from "lodash"; import { ModalForm, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from "@ant-design/pro-form"; import { getList } from "../BusinessTrade/service"; import { handleAddUpdate, handleDelete } from "./service"; const operatingBrand: React.FC<{ currentUser: CurrentUser }> = (props) => { const { currentUser } = props const downloadBtnRef = useRef() const actionRef = useRef(); const formRef = useRef(); const [reqDetailList, setReqDetailList] = useState(); // 合计项数据源 const [printOut, setPrintOut] = useState(); // 打印数据的内容 const [collapsible, setCollapsible] = useState(false) const [treeView, setTreeView] = useState() const [printIndex, setPrintIndex] = useState(new Date().getTime()) const [currentRow, setCurrentRow] = useState();// 当前选中行数据 // 树相关的属性和方法 const [selectedId, setSelectedId] = useState() // 导出的加载效果 const [showLoading, setShowLoading] = useState(false) // 是否显示打印的表格 const [showExportTable, setShowExportTable] = useState(false) // 查询的条件 const [searchParams, setSearchParams] = useState() // 导出数据 const [exportData, setExportData] = useState() const [createModalVisible, handleModalVisible] = useState(false); // 新建窗口的弹窗 const [treeSelectOption, setTreeSelectOption] = useState(); // 可选择项 const columns: any = [ // { // title:
品牌图标
, // dataIndex: 'BusinessTrade_ICO', // align: 'right', // hideInSearch: true, // }, { title: "图标", dataIndex: 'BusinessTrade_ICO', width: 120, align: 'center', hideInSearch: true, hideInDescriptions: true, render: (_, record) => { return record?.BusinessTrade_ICO || record?.Brand_ICO ? : {record.BusinessTrade_Name ? record.BusinessTrade_Name.substring(0, 1) : record?.Brand_Name ? record.Brand_Name.substring(0, 1) : ''} } }, { title: "有效状态", width: 120, align: 'center', dataIndex: "BrandState", valueType: "select", fieldProps: { options: [{ label: "有效", value: 1 }, { label: "无效", value: 0 }] }, initialValue: 1, }, { title:
业态/品牌名称
, dataIndex: 'BusinessTrade_Name', align: 'center', hideInSearch: true, render: (_, record) => { return record?.Brand_Name || record?.BusinessTrade_Name } }, { title: '操作', width: 120, dataIndex: 'option', valueType: 'option', align: 'center', hideInDescriptions: true, render: (_, record) => record?.Brand_ID ? [ { setCurrentRow(record); handleModalVisible(true); }} > 编辑 , { const sucesse = await handleDelete({ BrandId: record.Brand_ID }) if (sucesse && actionRef.current) { actionRef.current.reload() } }}> 删除 ] : "" } ] const exportColumns: any = [ { title:
经营业态
, dataIndex: 'Business_Format', align: 'center', hideInSearch: true, }, { title:
品牌名称
, dataIndex: 'BusinessTrade_Name', align: 'center', hideInSearch: true, }, ] const exportTable = (e) => { e.stopPropagation(); // 防止Collapse组件收起 const main = document.getElementsByClassName(`saleReportHideBox${printIndex}`)[0] const thead = main.querySelector('thead').cloneNode(true); // 深克隆DOM节点 const tbody = main.querySelector('tbody').cloneNode(true); // 深克隆DOM节点 const container = document.querySelector('#hiddenBox'); const tempTable = document.createElement('table'); tempTable.appendChild(thead); tempTable.appendChild(tbody); tempTable.setAttribute('id', 'table-to-xls-operatingBrand'); // 给table添加id,值与按钮上的table字段对应 container.appendChild(tempTable); // 把创建的节点添加到页面容器中 setShowLoading(false) downloadBtnRef.current.handleDownload(); setShowExportTable(false) tempTable.remove() // 防止重复打印一个内容 } useEffect(async () => { const data: any = await getList({ BusinessTradeModelPID: -1, BusinessTradeState: 1 }) setTreeSelectOption([{ AUTOSTATISTICS_NAME: '默认', AUTOSTATISTICS_ID: -1, children: [...data.data] }]) }, []) const normalizeTreeChildren = (list: any[]): any[] => { return list.map((node: any) => { // 复制节点,防止修改原始数据 const newNode = { ...node }; // 可能存在两种字段:BrandTreeList / children const subList = newNode.children || newNode.BrandTreeList; if (Array.isArray(subList) && subList.length > 0) { // 递归处理子节点 newNode.children = normalizeTreeChildren(subList); } else { // ✅ 空数组改为 null newNode.children = null; } // 删除旧字段 delete newNode.BrandTreeList; return newNode; }); }; return (
{ // 打印报表 if (!reqDetailList || reqDetailList.length === 0) return; setPrintOut(el); }} > { showLoading ?
数据导出中...
: '' }
{ showExportTable && exportData && exportData.length > 0 ? : '' }
{ return `${record?.BusinessTrade_Id}` }} bordered expandable={{ expandRowByClick: true }} scroll={{ x: "100%", y: "calc(100vh - 410px)" }} headerTitle={} // 列表表头 search={{ span: 6 }} request={async (params) => { const req: any = { ProvinceCode: currentUser?.ProvinceCode, BrandState: 1 } setSearchParams(params) const data = await getBusniessBrandTree(req) if (data && data.length > 0) { let exportData: any = [] data.forEach((item: any) => { exportData.push({ Business_Format: item.BusinessTrade_Name, BusinessTrade_Name: "" }) if (item.children && item.children.length > 0) { item.children.forEach((subItem: any) => { exportData.push({ Business_Format: item.BusinessTrade_Name, BusinessTrade_Name: subItem.BusinessTrade_Name, }) }) } }) setExportData(exportData) console.log('datadatadata', data); let res: any = normalizeTreeChildren(data) console.log(res, 'res'); return { data: res, success: true } } return { data: [], success: true } }} toolbar={{ actions: [ , , ] }} />
{ /* 更新 信息弹出框 */} { handleModalVisible(value) if (!value) { formRef.current?.resetFields(); setCurrentRow(undefined); } else { formRef.current?.setFieldsValue(currentRow || { AUTOSTATISTICS_TYPE: 2000 }) } }} onFinish={async (values) => { let newValue: any = { ...values } if (currentRow) { // 编辑数据 newValue = { ...currentRow, ...newValue } } newValue.AUTOSTATISTICS_STATE = values.AUTOSTATISTICS_STATE ? 1 : 0 newValue.AUTOSTATISTICS_TYPE = currentRow?.AUTOSTATISTICS_TYPE || 2000 const success = await handleAddUpdate(newValue); if (success) { if (actionRef.current) { actionRef.current.reload(); } return true } return false }} >
) } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser }))(operatingBrand);