jiateng_ws/ui/report_dialog_ui.py

221 lines
7.6 KiB
Python
Raw Normal View History

2025-06-24 11:21:33 +08:00
from PySide6.QtWidgets import (
QDialog, QVBoxLayout, QHBoxLayout, QLabel,
QTableWidget, QTableWidgetItem, QHeaderView,
2025-08-16 13:37:42 +08:00
QPushButton, QComboBox, QFrame, QDateEdit,
QLineEdit
2025-06-24 11:21:33 +08:00
)
from PySide6.QtCore import Qt, QDate
from PySide6.QtGui import QFont
class ReportDialogUI(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("统计报表")
self.resize(1000, 600)
self.init_ui()
def init_ui(self):
# 设置字体
self.title_font = QFont("微软雅黑", 14, QFont.Bold)
self.normal_font = QFont("微软雅黑", 12)
# 主布局
self.main_layout = QVBoxLayout(self)
self.main_layout.setContentsMargins(10, 10, 10, 10)
self.main_layout.setSpacing(10)
# 创建筛选条件区域
self.create_filter_section()
# 创建报表内容区域
self.create_report_section()
# 创建按钮区域
self.create_button_section()
def create_filter_section(self):
"""创建筛选条件区域"""
# 筛选条件容器
self.filter_frame = QFrame()
self.filter_frame.setFrameShape(QFrame.StyledPanel)
2025-08-16 13:37:42 +08:00
self.filter_layout = QVBoxLayout(self.filter_frame)
2025-06-24 11:21:33 +08:00
2025-08-16 13:37:42 +08:00
# 第一行:日期选择
self.date_row = QHBoxLayout()
2025-06-24 11:21:33 +08:00
self.date_label = QLabel("日期范围:")
self.date_label.setFont(self.normal_font)
2025-08-16 13:37:42 +08:00
self.date_label.setFixedWidth(80)
2025-06-24 11:21:33 +08:00
self.start_date = QDateEdit()
self.start_date.setFont(self.normal_font)
self.start_date.setCalendarPopup(True)
2025-08-16 13:37:42 +08:00
self.start_date.setDate(QDate.currentDate().addMonths(-1)) # 默认开始日期为一个月前
2025-06-24 11:21:33 +08:00
self.date_separator = QLabel("-")
self.end_date = QDateEdit()
self.end_date.setFont(self.normal_font)
self.end_date.setCalendarPopup(True)
self.end_date.setDate(QDate.currentDate())
2025-08-16 13:37:42 +08:00
self.date_row.addWidget(self.date_label)
self.date_row.addWidget(self.start_date)
self.date_row.addWidget(self.date_separator)
self.date_row.addWidget(self.end_date)
self.date_row.addStretch()
# 第二行:客户、材质、规格
self.filter_row = QHBoxLayout()
# 客户输入
self.customer_label = QLabel("客户:")
self.customer_label.setFont(self.normal_font)
self.customer_label.setFixedWidth(80)
self.customer_edit = QLineEdit()
self.customer_edit.setFont(self.normal_font)
self.customer_edit.setPlaceholderText("输入客户名称")
# 材质输入
self.material_label = QLabel("材质:")
self.material_label.setFont(self.normal_font)
self.material_label.setFixedWidth(80)
self.material_edit = QLineEdit()
self.material_edit.setFont(self.normal_font)
self.material_edit.setPlaceholderText("输入材质")
# 规格输入
self.spec_label = QLabel("规格:")
self.spec_label.setFont(self.normal_font)
self.spec_label.setFixedWidth(80)
self.spec_edit = QLineEdit()
self.spec_edit.setFont(self.normal_font)
self.spec_edit.setPlaceholderText("输入规格")
self.filter_row.addWidget(self.customer_label)
self.filter_row.addWidget(self.customer_edit)
self.filter_row.addSpacing(10)
self.filter_row.addWidget(self.material_label)
self.filter_row.addWidget(self.material_edit)
self.filter_row.addSpacing(10)
self.filter_row.addWidget(self.spec_label)
self.filter_row.addWidget(self.spec_edit)
# 第三行:查询按钮
self.button_row = QHBoxLayout()
2025-06-24 11:21:33 +08:00
# 查询按钮
self.query_button = QPushButton("查询")
self.query_button.setFont(self.normal_font)
self.query_button.setStyleSheet("""
QPushButton {
padding: 8px 16px;
background-color: #1976D2;
color: white;
border-radius: 4px;
}
QPushButton:hover {
background-color: #1565C0;
}
""")
2025-08-16 13:37:42 +08:00
# 清空按钮
self.clear_button = QPushButton("清空条件")
self.clear_button.setFont(self.normal_font)
self.clear_button.setStyleSheet("""
QPushButton {
padding: 8px 16px;
background-color: #757575;
color: white;
border-radius: 4px;
}
QPushButton:hover {
background-color: #616161;
}
""")
self.button_row.addStretch()
self.button_row.addWidget(self.clear_button)
self.button_row.addWidget(self.query_button)
# 添加所有行到筛选布局
self.filter_layout.addLayout(self.date_row)
self.filter_layout.addLayout(self.filter_row)
self.filter_layout.addLayout(self.button_row)
2025-06-24 11:21:33 +08:00
# 添加到主布局
self.main_layout.addWidget(self.filter_frame)
def create_report_section(self):
"""创建报表内容区域"""
# 报表表格
self.report_table = QTableWidget()
self.report_table.setFont(self.normal_font)
2025-08-16 13:37:42 +08:00
# 设置列 - 根据SQL查询结果设置列
self.report_table.setColumnCount(7)
2025-06-24 11:21:33 +08:00
self.report_table.setHorizontalHeaderLabels([
2025-08-16 13:37:42 +08:00
"日期", "客户", "订单号", "轴数", "材质", "规格", "净重"
2025-06-24 11:21:33 +08:00
])
# 设置表格样式
self.report_table.setStyleSheet("""
QTableWidget {
border: 1px solid #ddd;
gridline-color: #ddd;
}
QHeaderView::section {
background-color: #f5f5f5;
padding: 5px;
border: 1px solid #ddd;
font-weight: bold;
}
""")
# 调整列宽
header = self.report_table.horizontalHeader()
2025-08-16 13:37:42 +08:00
for i in range(7):
2025-06-24 11:21:33 +08:00
header.setSectionResizeMode(i, QHeaderView.Stretch)
# 添加到主布局
self.main_layout.addWidget(self.report_table)
def create_button_section(self):
"""创建按钮区域"""
# 按钮容器
self.button_frame = QFrame()
self.button_layout = QHBoxLayout(self.button_frame)
# 导出按钮
self.export_button = QPushButton("导出Excel")
self.export_button.setFont(self.normal_font)
self.export_button.setStyleSheet("""
QPushButton {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border-radius: 4px;
}
QPushButton:hover {
background-color: #43A047;
}
""")
# 关闭按钮
self.close_button = QPushButton("关闭")
self.close_button.setFont(self.normal_font)
self.close_button.setStyleSheet("""
QPushButton {
padding: 8px 16px;
background-color: #FF5722;
color: white;
border-radius: 4px;
}
QPushButton:hover {
background-color: #F4511E;
}
""")
# 添加按钮到布局
self.button_layout.addStretch()
self.button_layout.addWidget(self.export_button)
self.button_layout.addWidget(self.close_button)
# 添加到主布局
self.main_layout.addWidget(self.button_frame)