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 { Drawer } from "antd"; import { Select } from "antd"; import { Button, message, Space, Spin, Tree } from "antd"; import useRequest from "@ahooksjs/use-request"; import { getFieldEnum, getMoney, getServerpartTree, handleCallLogs } from "@/services/options"; import type { ActionType } from "@ant-design/pro-table"; import ProTable from "@ant-design/pro-table"; import { handleGetExamineList } from "@/pages/examine/examineList/service"; import moment from "moment"; import session from "@/utils/session"; import { handleGetGetTransactionCustomer, handleGetShopShortNames, handleGetTransactionCustomerByDate } from "@/pages/reports/BusinessAnalysis/transactionAnalysis/service"; import ReactHTMLTableToExcel from "react-html-table-to-excel"; import * as numeral from "numeral"; import { handleGetShopShortNamesGet } from "@/pages/reports/BusinessAnalysis/transactionAnalysis/service"; import { handleGetGetRevenueYOYQOQByDate } from "@/pages/reports/BusinessAnalysis/revenueYOYQOQReport/service"; import PageTitleBox from "@/components/PageTitleBox"; const transactionAnalysis: React.FC<{ currentUser: CurrentUser }> = (props) => { const { currentUser } = props const downloadBtnRef = useRef() const actionRef = useRef(); const actionByDateRef = useRef(); const formRef = useRef(); const formByDateRef = useRef(); const [reqDetailList, setReqDetailList] = useState(); // 合计项数据源 const [printOut, setPrintOut] = useState(); // 打印数据的内容 const [collapsible, setCollapsible] = useState(false) const [treeView, setTreeView] = useState() // 加载服务区树 const { loading: treeLoading, data: treeViews } = useRequest(async () => { const data = await getServerpartTree(currentUser?.ProvinceCode, currentUser?.CityAuthority, true, false, true) setTreeView(data) return data }) // 树相关的属性和方法 const [selectedId, setSelectedId] = useState() const businessTypeList = session.get("BUSINESSTYPEList") const businessTypeObj = session.get("BUSINESSTYPEObj") const BUSINESSTYPEObj = session.get('BUSINESSTYPEObj') // 判断是不是第一次进入页面 const [isFirst, setIsFirst] = useState(true) // 导出的加载效果 const [showLoading, setShowLoading] = useState(false) // 是否显示打印的表格 const [showExportTable, setShowExportTable] = useState(false) // 查询的条件 const [searchParams, setSearchParams] = useState() // 自营业态的选择列表 const [selfList, setSelfList] = useState() const [businessModel, setBusinessModel] = useState() // 经营模式 const [businessType, setBusinessType] = useState() // 展示自营业态 const [showSelfBusiness, setShowSelfBusiness] = useState(true) // 自营业态的选择列表 const [shopNamesList, setShopNamesList] = useState() const [printIndex, setPrintIndex] = useState(new Date().getTime()) // 显示每日流水抽屉 const [showDailyDrawer, setShowDailyDrawer] = useState(false) const [currentRow, setCurrentRow] = useState() const { loading: selfLoading, data: self } = useRequest(async () => { const data = await handleGetShopShortNames() if (data && data.length > 0) { const list: any = [] data.forEach((item: any) => { list.push({ label: item, value: item }) }) return list } }) const [columnsStateMap, setColumnsStateMap] = useState({ // Business_Type:{show:false}, ShopTrade: { show: false } }) const [columnsDailyStateMap, setColumnsDailyStateMap] = useState({ ShopTrade: { show: false } }) const columns: any = [ { title: '统计时间', dataIndex: 'search_date', valueType: 'dateRange', hideInTable: true, hideInDescriptions: true, initialValue: [moment().add(-1, 'day'), moment().add(-1, 'day')], search: { transform: (value) => { return { StartDate: value[0], EndDate: value[1], }; }, }, fieldProps: { disabledDate: (current: any) => current && current > moment().endOf('day') } }, { title: '经营模式', dataIndex: 'businessType', valueType: 'select', hideInTable: true, valueEnum: BUSINESSTYPEObj, fieldProps: { mode: "multiple", onChange: async (e) => { console.log('e', e) const flag = e.filter(item => item === '1000')?.toString() || '' console.log('flag', flag) if (flag) { setShowSelfBusiness(false) // handleGetShopNamesList(selectedId) } else { setShowSelfBusiness(true) // setShopNamesList({}) } } } }, { title: '自营业态', dataIndex: 'shopNames', hideInTable: true, hideInSearch: showSelfBusiness, valueType: 'select', valueEnum: shopNamesList, // request: async () => { // return await getFieldEnum({ FieldExplainField: 'BUSINESSTYPE' }) // }, fieldProps: { multiple: true, showSearch: true, filterOption: (input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase()), } }, { title: '外接系统', dataIndex: 'targetSystem', valueType: 'select', hideInTable: true, valueEnum: { "": '全部', 1: "是", 0: "否" }, initialValue: "" }, { title: '', dataIndex: 'SearchKeyValue', hideInTable: true, fieldProps: { placeholder: "请输入商户/品牌/门店/服务区" } }, { title: '服务区信息', dataIndex: '', hideInSearch: true, children: [ // { // title: '序号', // width: 120, // hideInSearch: true, // dataIndex: 'index' // }, { title: '门店名称', width: 200, hideInSearch: true, dataIndex: 'Name', ellipsis: true, render: (_, record) => { return showDailyDrawer ? record?.Name : { if (record?.Name === '合计') { let id: string = '' if (record?.children && record?.children.length > 0) { record?.children.forEach((item: any) => { if (item?.children && item?.children.length > 0) { item?.children.forEach((subItem: any) => { if (id) { id += `,${subItem.Id}` } else { id = subItem.Id } }) } }) } setCurrentRow({ ...record, Id: id }) } else if (record?.Name && record?.Name.indexOf('管理中心') !== -1) { let id: string = '' if (record?.children && record?.children.length > 0) { record?.children.forEach((item: any) => { if (id) { id += `,${item.Id}` } else { id = item.Id } }) } setCurrentRow({ ...record, Id: id, SpregiontypeName: record?.Name, ServerpartId: id }) } else if (record?.Name && record?.Name.indexOf('服务区') !== -1) { setCurrentRow({ ...record, ServerpartId: record?.Id, ServerpartName: record?.Name, }) } else { setCurrentRow(record) } setShowDailyDrawer(true) }}> {record?.Name} } }, { title: '门店数量', hideInSearch: true, valueType: 'digit', dataIndex: 'ShopCount' }, { title: '经营模式', width: 150, dataIndex: 'Business_Type', valueType: 'select', valueEnum: businessTypeObj, render: (_, record) => { return record.BusinessType ? businessTypeObj[record.BusinessType] : '-' } }, { title: '经营商户', width: 120, ellipsis: true, dataIndex: 'MERCHANTS_NAME', hideInSearch: true, }, { dataIndex: 'ShopTrade', title: '商品业态', align: 'center', width: 120, valueType: 'select', hideInSearch: true, request: async () => { // 这里要手动添加枚举字段(从下面这些字典中选择一个):商品业态[BUSINESSTYPE] const options = await getFieldEnum({ FieldExplainField: 'BUSINESSTYPE' }); return options; }, }, ] }, { title: '经营数据', dataIndex: '', hideInSearch: true, children: [ { title: '客单数量', hideInSearch: true, dataIndex: 'TicketCount', valueType: 'digit' }, { title: '销售数量', hideInSearch: true, valueType: 'digit', dataIndex: 'TotalCount' }, { title: '销售金额', hideInSearch: true, valueType: 'digit', dataIndex: 'TotalSellAmount' }, { title: '客单均量', hideInSearch: true, valueType: 'digit', dataIndex: 'AverageCount' }, { title: '客单均价', hideInSearch: true, valueType: 'digit', dataIndex: 'AverageAmount' }, { title: '商品均价', hideInSearch: true, valueType: 'digit', dataIndex: 'AverageCommodity' }, ] } ] const exportTable = (e) => { e.stopPropagation(); // 防止Collapse组件收起 const main = document.getElementsByClassName(`transactionAnalysisHideBox${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-transactionAnalysis'); // 给table添加id,值与按钮上的table字段对应 container.appendChild(tempTable); // 把创建的节点添加到页面容器中 setShowLoading(false) downloadBtnRef.current.handleDownload(); setShowExportTable(false) tempTable.remove() // 防止重复打印一个内容 } // 自营业态的选择的列表方法 const handleGetShopNamesList = async (id: any) => { const req: any = { ProvinceCode: currentUser?.USER_PROVINCE, BusinessType: 1000, ServerpartId: id || selectedId } const data = await handleGetShopShortNamesGet(req) console.log('data', data) if (data && data.length > 0) { const obj: any = {} if (data && data.length > 0) { data.forEach((item: any) => { obj[item] = item }) } setShopNamesList(obj) } } return (
{ // 打印报表 if (!reqDetailList || reqDetailList.length === 0) return; setPrintOut(el); }}> { showLoading ?
数据导出中...
: '' }
{ showExportTable && reqDetailList && reqDetailList.length > 0 ? : '' }
{ setCollapsible(!collapsible) }} />} colSpan={!collapsible ? "300px" : "60px"} title={!collapsible ? "请选择服务区" : ""} headerBordered collapsed={collapsible} > {treeView && treeView.length > 0 ? { const selectedIds = info.checkedNodes.filter(n => n?.type === 1) setSelectedId(selectedIds.map(n => n?.value)?.toString() || '') handleGetShopNamesList(selectedIds.map(n => n?.value)?.toString() || '') // actionRef?.current?.reload() // getData(selectedIds.map(n => n?.value)?.toString() || '') }} // switcherIcon={} /> : ''}
{ return `${record?.Id}-${record?.Name}-${record?.ServerpartId}` }} bordered headerTitle={} search={{ span: 6, defaultCollapsed: false, }} scroll={{ y: 'calc(100vh - 470px)' }} request={async (params) => { if (isFirst) { setIsFirst(false) return } if (!selectedId) { message.error('请选择服务区') return } console.log('params', params) handleCallLogs() setSearchParams(params) const req = { ServerpartIds: selectedId, startDate: params?.StartDate, endDate: params?.EndDate, businessType, // shopNames: businessModel, targetSystem: params.targetSystem || '', shopNames: params.shopNames || '', SearchKeyName: "MerchantName,Brand,Shop,Serverpart", SearchKeyValue: params?.SearchKeyValue || '' } const data = await handleGetGetTransactionCustomer(req) console.log('data', data) let list: any = [] if (data && data.length > 0) { list = JSON.parse(JSON.stringify(data)) // let ShopCountSum: number = 0 // let TicketCountSum: number = 0 // let TotalCountSum: number = 0 // let TotalSellAmountSum: number = 0 // let AverageCountSum: number = 0 // let AverageAmountSum: number = 0 // let AverageCommoditySum: number = 0 // // list.forEach((item: any, index: number) => { // item.index = index + 1 // ShopCountSum += item.ShopCount // TicketCountSum += item.TicketCount // TotalCountSum += item.TotalCount // TotalSellAmountSum += item.TotalSellAmount // AverageCountSum += item.AverageCount // AverageAmountSum += item.AverageAmount // AverageCommoditySum += item.AverageCommodity // // if (item.children && item.children.length > 0) { // item.children.forEach((subItem: any, subIndex: number) => { // subItem.index = `${index + 1}.${subIndex + 1}` // if (subItem.children && subItem.children.length > 0) { // subItem.children.forEach((thirdItem: any, thirdIndex: number) => { // thirdItem.index = `${index + 1}.${subIndex + 1}.${thirdIndex + 1}` // }) // } // }) // } // }) // list.unshift({ // Name: '合计', // ShopCount: getMoney(ShopCountSum), // TicketCount: getMoney(TicketCountSum), // TotalCount: getMoney(TotalCountSum), // TotalSellAmount: getMoney(TotalSellAmountSum), // AverageCount: getMoney(AverageCountSum), // AverageAmount: getMoney(AverageAmountSum), // AverageCommodity:getMoney(AverageCommoditySum), // }) } console.log('list', list) setReqDetailList(list) return { data: list, success: true } }} toolbar={{ actions: [ , ] }} columnsState={{ value: columnsStateMap, onChange: setColumnsStateMap, }} />
{ setCurrentRow(undefined); setShowDailyDrawer(false); }} bodyStyle={{ backgroundColor: "#f9f9f9", padding: 16 }} destroyOnClose closable={false} >
{ return `${record?.index}-${record?.Id}-${record?.Name}-${record?.SERVERPART_ID}` }} columns={columns} bordered search={false} options={false} pagination={false} headerTitle={currentRow?.Name === '合计' ? '合计' : `${currentRow?.SpregiontypeName}${currentRow?.ServerpartName ? `-${currentRow?.ServerpartName}` : ''}${currentRow?.SERVERPARTSHOP_NAME ? `-${currentRow?.SERVERPARTSHOP_NAME}` : ''}`} request={async (params) => { console.log('currentRow', currentRow) const req = { ServerpartIds: currentRow?.Name === '合计' ? selectedId : currentRow?.ServerpartId ? currentRow?.ServerpartId : '', ServerpartShopId: currentRow?.SERVERPARTSHOP_ID ? currentRow?.SERVERPARTSHOP_ID : '', startDate: searchParams?.StartDate, endDate: searchParams?.EndDate, businessType, shopNames: businessModel, targetSystem: searchParams?.targetSystem || '', } const data = await handleGetTransactionCustomerByDate(req) console.log('data22222', data) if (data && data.length > 0) { console.log('data', data) data.forEach((item: any, index: number) => { item.index = index + 1 if (item.children && item.children.length > 0) { item.children.forEach((subItem: any, subIndex: number) => { subItem.index = subIndex + 1 }) } }) return { data, success: true } } return { data: [], success: true } }} scroll={{ x: 1700 }} columnsState={{ value: columnsDailyStateMap, onChange: setColumnsDailyStateMap, }} />
) } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser }))(transactionAnalysis);