import { connect } from "umi"; import type { CurrentUser } from "umi"; import type { ConnectState } from "@/models/connect"; import React, { useRef, useState } from "react"; import ProCard from "@ant-design/pro-card"; import { MenuFoldOutlined } from "@ant-design/icons"; import type { FormInstance } from "antd"; import { Button, message, Space, Spin, Tree } 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 moment from 'moment' import session from "@/utils/session"; import { handleCorrectShopCigarette, handleGetCigaretteReport } from "../../Finance/service"; import { formatTreeData, handleGetSumRow } from "@/utils/format"; import PageTitleBox from "@/components/PageTitleBox"; import { exportXlsxFromProColumnsExcelJS } from "@/utils/exportExcelFun"; const cigaretteReport: 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 [btnLoading, setBtnLoading] = useState(false) // 树相关的属性和方法 const [selectedId, setSelectedId] = useState() // 导出的加载效果 const [showLoading, setShowLoading] = useState(false) // 是否显示打印的表格 const [showExportTable, setShowExportTable] = useState(false) // 查询的条件 const [searchParams, setSearchParams] = useState() const serverpartObj: any = session.get('serverpartObj') const [columnsStateMap, setColumnsStateMap] = useState({ sumDifferent_Price_More: { show: false }, sumDifferent_Price_Less: { show: false }, ADifferent_Price_More: { show: false }, ADifferent_Price_Less: { show: false }, BDifferent_Price_More: { show: false }, BDifferent_Price_Less: { show: false }, sumCashPay_Amount: { show: false }, sumMobilePay_Amount: { show: false }, ACashPay_Amount: { show: false }, AMobilePay_Amount: { show: false }, BCashPay_Amount: { show: false }, BMobilePay_Amount: { show: false }, }); const columns: any = [ { title: '服务区', dataIndex: 'ServerpartIds', valueType: 'select', hideInTable: true, // valueEnum: serverpartObj, request: () => { const serverpartList: any = session.get('serverpartList') return serverpartList }, fieldProps: { showSearch: true, filterOption: (input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), } }, { title: '统计时间', dataIndex: 'search_date', valueType: 'dateRange', hideInTable: true, hideInDescriptions: true, search: { transform: (value) => { return { // format中的格式决定入参内容 StartDate: value[0], EndDate: value[1], }; }, }, initialValue: [moment().subtract(1, 'day').startOf('month'), moment().subtract(1, 'day')], fieldProps: { disabledDate: (current: any) => current > moment().subtract(1, 'days'), allowClear: false }, }, { title: '统计类型', dataIndex: 'DataSourceType', valueType: 'select', hideInTable: true, valueEnum: { "1": '日结', "2": "自然日" }, initialValue: "2", }, { title: '统计日期', width: 150, dataIndex: 'Statistics_Date', hideInSearch: true, align: 'center', sorter: (a, b) => new Date(a.Statistics_Date).getTime() - new Date(b.Statistics_Date).getTime(), defaultSortOrder: 'descend' }, { title: '合计', dataIndex: 'sum', hideInSearch: true, children: [ { title:
实收金额
, width: 120, dataIndex: 'sumRevenue_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
烟草营收
, width: 120, dataIndex: 'sumCigarette_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
长款
, width: 120, dataIndex: 'sumDifferent_Price_More', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
短款
, width: 120, dataIndex: 'sumDifferent_Price_Less', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
现金支付
, width: 120, dataIndex: 'sumCashPay_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
移动支付
, width: 120, dataIndex: 'sumMobilePay_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, ] }, { title:
{currentUser?.ProvinceCode === '340000' ? '东(南)区' : 'A区'}
, dataIndex: 'ARevenue', hideInSearch: true, children: [ { title:
实收金额
, width: 120, dataIndex: 'ARevenue_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
烟草营收
, width: 120, dataIndex: 'ACigarette_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
长款
, width: 120, dataIndex: 'ADifferent_Price_More', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
短款
, width: 120, dataIndex: 'ADifferent_Price_Less', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
现金支付
, width: 120, dataIndex: 'ACashPay_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
移动支付
, width: 120, dataIndex: 'AMobilePay_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, ] }, { title:
{currentUser?.ProvinceCode === '340000' ? '西(北)区' : 'B区'}
, dataIndex: 'BRevenue', hideInSearch: true, children: [ { title:
实收金额
, width: 120, dataIndex: 'BRevenue_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
烟草营收
, width: 120, dataIndex: 'BCigarette_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
长款
, width: 120, dataIndex: 'BDifferent_Price_More', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
短款
, width: 120, dataIndex: 'BDifferent_Price_Less', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
现金支付
, width: 120, dataIndex: 'BCashPay_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, { title:
移动支付
, width: 120, dataIndex: 'BMobilePay_Amount', hideInSearch: true, valueType: 'digit', align: 'right' }, ] } ] 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-cigaretteReport'); // 给table添加id,值与按钮上的table字段对应 container.appendChild(tempTable); // 把创建的节点添加到页面容器中 setShowLoading(false) downloadBtnRef.current.handleDownload(); setShowExportTable(false) tempTable.remove() // 防止重复打印一个内容 } return (
{ // 打印报表 if (!reqDetailList || reqDetailList.length === 0) return; setPrintOut(el); }} > { showLoading ?
数据导出中...
: '' }
{ showExportTable && reqDetailList && reqDetailList.length > 0 ? : '' }
} search={{ span: 6 }} request={async (params) => { if (!params?.ServerpartIds) { return } const req: any = { DataSourceType: params?.DataSourceType || '', StartDate: params?.StartDate ? moment(params?.StartDate).format('YYYY-MM-DD') : '', EndDate: params?.EndDate ? moment(params?.EndDate).format('YYYY-MM-DD') : '', ServerpartIds: params?.ServerpartIds } setSearchParams(params) const data = await handleGetCigaretteReport(req) if (data && data.length > 0) { let res: any = [] data.forEach((item: any) => { if (item.TotalRevenue) { item.sumCigarette_Amount = item.TotalRevenue.Cigarette_Amount item.sumDifferent_Price_More = item.TotalRevenue.Different_Price_More item.sumDifferent_Price_Less = item.TotalRevenue.Different_Price_Less item.sumCashPay_Amount = item.TotalRevenue.CashPay_Amount item.sumMobilePay_Amount = item.TotalRevenue.MobilePay_Amount item.sumRevenue_Amount = item.TotalRevenue.Revenue_Amount } if (item.RegionARevenue) { item.ACigarette_Amount = item.RegionARevenue.Cigarette_Amount item.ADifferent_Price_More = item.RegionARevenue.Different_Price_More item.ADifferent_Price_Less = item.RegionARevenue.Different_Price_Less item.ACashPay_Amount = item.RegionARevenue.CashPay_Amount item.AMobilePay_Amount = item.RegionARevenue.MobilePay_Amount item.ARevenue_Amount = item.RegionARevenue.Revenue_Amount } if (item.RegionBRevenue) { item.BCigarette_Amount = item.RegionBRevenue.Cigarette_Amount item.BDifferent_Price_More = item.RegionBRevenue.Different_Price_More item.BDifferent_Price_Less = item.RegionBRevenue.Different_Price_Less item.BCashPay_Amount = item.RegionBRevenue.CashPay_Amount item.BMobilePay_Amount = item.RegionBRevenue.MobilePay_Amount item.BRevenue_Amount = item.RegionBRevenue.Revenue_Amount } res.push(item) }) let result: any = handleGetSumRow(res, ['sumRevenue_Amount', 'sumCigarette_Amount', 'sumDifferent_Price_More', 'sumDifferent_Price_Less', 'sumCashPay_Amount', 'sumMobilePay_Amount', 'ARevenue_Amount', 'ACigarette_Amount', 'ADifferent_Price_More', 'ADifferent_Price_Less', 'ACashPay_Amount', 'AMobilePay_Amount', 'BRevenue_Amount', 'BCigarette_Amount', 'BDifferent_Price_More', 'BDifferent_Price_Less', 'BCashPay_Amount', 'BMobilePay_Amount'], 'Statistics_Date') let fieldData: any = [ "sumRevenue_Amount", "sumCigarette_Amount", "sumDifferent_Price_More", "sumDifferent_Price_Less", "sumCashPay_Amount", "sumMobilePay_Amount", "ARevenue_Amount", "ACigarette_Amount", "ADifferent_Price_More", "ADifferent_Price_Less", "ACashPay_Amount", "AMobilePay_Amount", "BRevenue_Amount", "BCigarette_Amount", "BDifferent_Price_More", "BDifferent_Price_Less", "BCashPay_Amount", "BMobilePay_Amount", ] let enumList: any = [] let newPrintData: any = formatTreeData(JSON.parse(JSON.stringify(result)), fieldData, enumList, [], []) setReqDetailList(newPrintData) return { data: result, success: true } } setReqDetailList([]) return { data: [], success: true } }} toolbar={{ actions: [ // // // , , ] }} columnsState={{ value: columnsStateMap, onChange: setColumnsStateMap, }} />
) } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser }))(cigaretteReport);