// 经营品牌管理 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, handleGetBrandList } from "./service"; import { getList as handleGetTradeList } from '../BusinessTrade/service' import { exportXlsxFromProColumnsExcelJS } from "@/utils/exportExcelFun"; import { formatTreeData } from "@/utils/format"; import moment from 'moment' 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 [businessBrand, setBusinessBrand] = useState(); // 业态品牌 // 所有业态最里层的数据 const [extractLeafIdsList, setExtractLeafIdsList] = useState([]); const columns: any = [ { title: "品牌图标", dataIndex: 'BRAND_INTRO', width: 120, align: 'center', hideInSearch: true, hideInDescriptions: true, render: (_, record) => { return record?.BRAND_INTRO ? : {record.BRAND_NAME ? record.BRAND_NAME.substring(0, 1) : ''} } }, { title: "品牌索引", dataIndex: "BRAND_INDEX", width: 120, align: 'center', hideInSearch: true, ellipisis: true, }, { title: "品牌名称", dataIndex: "BRAND_NAME", width: 120, align: 'center', hideInSearch: true, ellipisis: true, }, { title: "经营业态名称", dataIndex: "BUSINESSTRADE_NAME", width: 120, align: 'center', hideInSearch: true, ellipisis: true, }, { title: "有效状态", width: 120, align: 'center', dataIndex: "BRAND_STATE", valueType: "select", fieldProps: { options: [{ label: "有效", value: 1 }, { label: "无效", value: 0 }] }, initialValue: 1, }, { 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 () => { // 拿到经营品牌数据 await handleGetBusinessTrade(); }, []) 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; }); }; // 拿到经营业态的数据 const handleGetBusinessTrade = async () => { const data: any = await handleGetTradeList({ BusinessTradeModelPID: -1, BusinessTradeState: 1 }) console.log('handleGetBusinessTradehandleGetBusinessTrade', data); setBusinessBrand(data.data) setExtractLeafIdsList(extractLeafIds(data.data)) setTreeSelectOption(markNonLeafDisabled([{ AUTOSTATISTICS_NAME: '默认', AUTOSTATISTICS_ID: -1, children: [...data.data] }])) } // 拿到全部最里层的 业态值 const extractLeafIds = (data: any) => { const result: any = []; const traverse = (list: any) => { list.forEach((item: any) => { if (!item.children || item.children.length === 0) { // 没有 children,就是最里层节点 result.push(item.AUTOSTATISTICS_ID); } else { // 有 children,继续递归 traverse(item.children); } }); } traverse(data); return result; } // 不是没有children 都禁用 const markNonLeafDisabled = (list: any) => { return list.map((node: any) => { const hasChildren = Array.isArray(node.children) && node.children.length > 0; // 复制原节点,添加 disabled 字段(只有非叶子节点 disabled) const newNode = { ...node, // 如果你更喜欢使用 selectable 而不是 disabled,可用: selectable: !hasChildren disabled: hasChildren ? true : undefined, }; if (hasChildren) { newNode.children = markNonLeafDisabled(node.children); } return newNode; }); } return (
{ // 打印报表 if (!reqDetailList || reqDetailList.length === 0) return; setPrintOut(el); }} > { showLoading ?
数据导出中...
: '' }
{ showExportTable && exportData && exportData.length > 0 ? : '' }
{ setCollapsible(!collapsible); }} />} colSpan={!collapsible ? "300px" : "60px"} title={!collapsible ? "请选择业态" : ""} headerBordered collapsed={collapsible} > {businessBrand && businessBrand.length > 0 ? { let res: any = [] if (checkedKeys && checkedKeys.length > 0) { if (extractLeafIdsList && extractLeafIdsList.length > 0) { checkedKeys.forEach((item: any) => { if (extractLeafIdsList.indexOf(item) > -1) { res.push(item); } }) } } setSelectedId(res) }} fieldNames={{ title: "AUTOSTATISTICS_NAME", key: "AUTOSTATISTICS_ID" }} /> : ''}
{ return `${record?.BusinessTrade_Id}` }} bordered expandable={{ expandRowByClick: true }} scroll={{ x: "100%", y: "calc(100vh - 410px)" }} headerTitle={} // 列表表头 search={{ span: 6 }} request={async (params) => { if (!selectedId) { return { data: [], success: true } } const req: any = { SearchParameter: { BRAND_CATEGORY: 1000, BRAND_INDUSTRYS: selectedId && selectedId.length > 0 ? selectedId.toString() : '', BRAND_STATE: params.BRAND_STATE || "", }, PageIndex: 1, PageSize: 999999 } const data = await handleGetBrandList(req) console.log('handleGetBrandListhandleGetBrandList', data); if (data && data.length > 0) { let fieldData: any = [] let enumList: any = ["BRAND_STATE",] let newPrintData: any = formatTreeData(JSON.parse(JSON.stringify(data)), fieldData, enumList, [[{ label: "有效", value: 1 }, { label: "无效", value: 0 }]], []) setReqDetailList(newPrintData) return { data: data, success: true } } // 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 } // } setReqDetailList([]) 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 }} > String(node.AUTOSTATISTICS_NAME) .toLowerCase() .includes(String(input).toLowerCase()) } />
) } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser }))(operatingBrand);