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, Col, Descriptions, message, Modal, Row, Space, Spin, Table, Tree, Typography } 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 moment from "moment"; import Draggable from "react-draggable"; import ModalFooter from "@/pages/travelMember/scenicSpotConfig/component/modalFooter"; import ProForm, { ProFormDatePicker, ProFormDateTimePicker, ProFormDigit, ProFormMoney, ProFormSelect, ProFormText, ProFormTextArea } from "@ant-design/pro-form"; import session from "@/utils/session"; import { handleGetServiceShopList } from "@/pages/DataVerification/service"; import shop from "@/pages/BussinessProject/shop"; import { getMyShopList } from "@/pages/account/center/sevice"; import { handleGetRECEIVESERVERPARTList } from "../service"; import WarehouseInfo from "./components/warehouseInfo"; import { exportXlsxFromProColumnsExcelJS } from "@/utils/exportExcelFun"; import { formatTreeData } from "@/utils/format"; const { Text } = Typography; const shopProcurement: React.FC<{ currentUser: CurrentUser }> = (props) => { const { currentUser } = props const actionRef = useRef(); const formRef = useRef(); const downloadBtnRef = useRef() const modalFormRef = useRef(); // 查询的条件 const [searchParams, setSearchParams] = useState() // 显示申请的modal const [handleShowModal, setHandleShowModal] = useState(false) // 树相关的属性和方法 const [selectedId, setSelectedId] = useState() const [collapsible, setCollapsible] = useState(false) // 行数据 const [currentRow, setCurrentRow] = useState() const [disabled, setDraggleDisabled] = useState() // 是否拖动 const [confirmLoading, handleConfirmLoading] = useState(false) // 弹出框的内容表单是否在提交 // 弹出框拖动效果 const [bounds, setBounds] = useState<{ left: number, right: number, top: number, bottom: number }>() // 移动的位置 const draggleRef = React.createRef() // 门店列表 const [shopList, setShopList] = useState([]) const [printIndex, setPrintIndex] = useState(new Date().getTime()) // 导出的加载效果 const [showLoading, setShowLoading] = useState(false) // 是否显示打印的表格 const [showExportTable, setShowExportTable] = useState(false) const [reqDetailList, setReqDetailList] = useState(); // 合计项数据源 // 表格的合计值 const [tableSumObj, setTableSumObj] = useState(); // 表格加载效果 const [tableLoading, setTableLoading] = useState(false) 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 [currentShopList, setCurrentShopList] = useState() // 显示详情的悬浮框 const [showDetail, setShowDetail] = useState(false) const columns: any = [ // { // title: "服务区", // dataIndex: "servicePartId", // hideInTable: true, // valueType: 'select', // fieldProps: { // showSearch: true, // onChange: async (value: any, label: any) => { // formRef.current?.setFieldsValue({ serverpartShopId: undefined, InventoryTime: undefined }) // await handleGetShopList(value) // } // }, // request: async () => { // const list = session.get('ServerpartIdsTree') // return list || [] // }, // }, // { // title: "门店", // dataIndex: "serverpartShopId", // hideInTable: true, // valueType: 'select', // fieldProps: { // showSearch: true, // options: currentShopList, // } // }, { dataIndex: 'searchText', title: '查询内容', hideInTable: true, fieldProps: { placeholder: "请输入商品名称/商品条码" } }, { title: '查询时间', dataIndex: 'search_date', valueType: 'dateRange', hideInTable: true, hideInDescriptions: true, search: { transform: (value) => { return { RECEIVECENTER_DATE_Start: value[0], RECEIVECENTER_DATE_End: value[1], }; }, }, fieldProps: { ranges: { "本月": [moment().startOf('M'), moment()], "上月": [moment().subtract(1, 'M').startOf('M'), moment().subtract(1, 'M').endOf('M')], "近三月": [moment().subtract(3, 'M').startOf('M'), moment().endOf('M')], "近半年": [moment().subtract(6, 'M').startOf('M'), moment().endOf('M')], } }, initialValue: [moment().startOf('M'), moment()], }, { title: "序号", dataIndex: "index", valueType: 'index', align: 'center', width: 80, ellipsis: true, hideInSearch: true, }, { title:
服务区名
, dataIndex: "SERVERPART_NAME", align: 'left', width: 150, ellipsis: true, hideInSearch: true, }, { title:
门店方向
, dataIndex: "SHOPNAME", align: 'left', width: 150, ellipsis: true, hideInSearch: true, }, { title: '入库单号', dataIndex: "RECEIVECENTER_CODE", align: 'center', width: 150, ellipsis: true, hideInSearch: true, render: (_, record) => { return record?.RECEIVECENTER_CODE ? { setCurrentRow(record) setShowDetail(true) }}>{record?.RECEIVECENTER_CODE} : "-" } }, { title: "单据状态", dataIndex: "RECEIVECENTER_STATE", align: 'center', valueType: 'select', valueEnum: { "1000": "订单发起申请", "2000": "总部业务审核", "3000": "总部订单配送", "4000": "订单入库审核", "5000": "订单商品入库", }, width: 120, hideInSearch: true, ellipsis: true, }, { title:
采购说明
, dataIndex: "RECEIVESERVERPART_DESC", align: 'left', width: 200, ellipsis: true, hideInSearch: true, }, // { // title: '采购模式', // dataIndex: "PURCHASE_PATTERN", // align: 'center', // valueType: 'select', // valueEnum: { // "0": "铺货", // "1000": "订货", // "2000": "补货", // "3000": "退货", // }, // width: 120, // hideInSearch: true, // ellipsis: true, // }, { title:
入库总数
, dataIndex: "RECEIVE_TOTALCOUNT", align: 'right', valueType: 'digit', width: 120, sorter: true, // sorter: (a, b) => a.RECEIVE_TOTALCOUNT - b.RECEIVE_TOTALCOUNT, defaultSortOrder: 'descend', ellipsis: true, hideInSearch: true, }, { title:
入库金额
, dataIndex: "RECEIVE_TOTALPRICE", align: 'right', valueType: 'digit', width: 120, sorter: true, // sorter: (a, b) => a.RECEIVE_TOTALPRICE - b.RECEIVE_TOTALPRICE, ellipsis: true, hideInSearch: true, }, { title: '入库时间', dataIndex: "RECEIVECENTER_DATE", align: 'center', width: 150, sorter: true, // sorter: (a, b) => new Date(a?.RECEIVECENTER_DATE).getTime() - new Date(b?.RECEIVECENTER_DATE).getTime(), ellipsis: true, hideInSearch: true, }, // { // title: '单据类型', // dataIndex: "PURCHASE_TYPE", // align: 'center', // valueType: 'select', // valueEnum: { // "1000": "自采单", // "4000": "统配单" // }, // hideInSearch: true, // width: 150, // ellipsis: 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-shopProcurement'); // 给table添加id,值与按钮上的table字段对应 container.appendChild(tempTable); // 把创建的节点添加到页面容器中 setShowLoading(false) downloadBtnRef.current.handleDownload(); setShowExportTable(false) tempTable.remove() // 防止重复打印一个内容 } // 拿到服务区 对应的门店列表数据 const handleGetShopList = async (id: any) => { if (!id) { setCurrentShopList([]) return } const req: any = { // 调用的接口 里面 自己包了一层 // SearchParameter: { ISVALID: 1, SERVERPART_ID: id, INSALES_TYPE: 1, // }, PageIndex: 1, PageSize: 999999, SortStr: "SHOPTRADE,SHOPREGION,SHOPCODE" } const data = await getMyShopList(req) let list: any = [] if (data && data.length > 0) { data.forEach((item: any) => { list.push({ label: item.SHOPNAME, value: item.SERVERPARTSHOP_ID }) }) } setCurrentShopList(list) } // 关闭详情执行的方法 const handleGetClose = () => { setCurrentRow(null) setShowDetail(false) } return (
{ showLoading ?
数据导出中...
: '' }
{ showExportTable && reqDetailList && reqDetailList.length > 0 ? : '' }
} // 列表表头 search={{ span: 6, defaultCollapsed: false }} // 查询表单 request={async (params, sorter) => { if (!selectedId) { return } // 排序字段 const sortstr = Object.keys(sorter).map(n => { const value = sorter[n] return value ? `${n} ${value.replace('end', '')}` : '' }) const req: any = { SearchParameter: { SERVERPARTSHOP_IDS: selectedId, RECEIVECENTER_DATE_Start: params?.RECEIVECENTER_DATE_Start || "", RECEIVECENTER_DATE_End: params?.RECEIVECENTER_DATE_End || "", SearchOtherKeyName: "COMMODITY_NAME,COMMODITY_BARCODE", SearchOtherKeyValue: params?.searchText || '', }, // keyWord: { // Key: 'RECEIVECENTER_CODE', // Value: params?.searchText || '' // }, PageIndex: 1, PageSize: 999999, sortstr: sortstr.length ? sortstr.toString() : "", } setSearchParams(params) setTableLoading(true) const data = await handleGetRECEIVESERVERPARTList(req) setTableLoading(false) console.log('表格数据', data); let fieldData: any = [ "RECEIVE_TOTALCOUNT", "RECEIVE_TOTALPRICE", ] let enumList: any = [] let newPrintData: any = formatTreeData(JSON.parse(JSON.stringify(data)), fieldData, enumList, [], []) setReqDetailList(newPrintData) if (data && data.length > 0) { // 总数合计 let RECEIVE_TOTALCOUNTSUM: number = 0 // 金额合计 let RECEIVE_TOTALPRICESUM: number = 0 data.forEach((item: any) => { RECEIVE_TOTALCOUNTSUM += item.RECEIVE_TOTALCOUNT RECEIVE_TOTALPRICESUM += item.RECEIVE_TOTALPRICE }) setTableSumObj({ RECEIVE_TOTALCOUNT: Number(RECEIVE_TOTALCOUNTSUM.toFixed(2)), RECEIVE_TOTALPRICE: Number(RECEIVE_TOTALPRICESUM.toFixed(2)) }) return { data, success: true } } return { data: [], success: true } }} toolbar={{ actions: [ , // ] }} tableExtraRender={ (_, data) => { return
{tableSumObj?.RECEIVE_TOTALCOUNT ? tableSumObj?.RECEIVE_TOTALCOUNT.toLocaleString('zh-CN') : ""} {tableSumObj?.RECEIVE_TOTALPRICE ? tableSumObj?.RECEIVE_TOTALPRICE.toLocaleString('zh-CN') : ""}
} } summary={(pageData) => { // 总数合计 let RECEIVE_TOTALCOUNTSUM: number = 0 // 金额合计 let RECEIVE_TOTALPRICESUM: number = 0 if (pageData && pageData.length > 0) { pageData.forEach((item: any) => { RECEIVE_TOTALCOUNTSUM += item.RECEIVE_TOTALCOUNT RECEIVE_TOTALPRICESUM += item.RECEIVE_TOTALPRICE }) } return (
本页合计
{RECEIVE_TOTALCOUNTSUM ? Number(RECEIVE_TOTALCOUNTSUM.toFixed(2)).toLocaleString('zh-CN') : ''}
{RECEIVE_TOTALPRICESUM ? Number(RECEIVE_TOTALPRICESUM.toFixed(2)).toLocaleString('zh-CN') : ''}
) }} />
{/* 说是要里面高亮 查询的内容 那么就要传入 searchParams */}
) } export default connect(({ user }: ConnectState) => ({ currentUser: user.currentUser }))(shopProcurement);