jiateng_ws/ui/order_query_dialog_ui.py

355 lines
12 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from PySide6.QtWidgets import (
QDialog, QLabel, QLineEdit, QComboBox, QPushButton,
QVBoxLayout, QHBoxLayout, QFrame, QTableWidget, QTableWidgetItem,
QHeaderView, QDateEdit, QApplication
)
from PySide6.QtCore import Qt, QDate
from PySide6.QtGui import QFont
class OrderQueryDialogUI(QDialog):
def __init__(self):
super().__init__()
self.setWindowTitle("订单查询")
self.resize(1400, 700) # 增加宽度和高度
# 设置字体
self.normal_font = QFont("微软雅黑", 10)
self.title_font = QFont("微软雅黑", 10, QFont.Bold)
# 初始化UI
self.init_ui()
def init_ui(self):
"""初始化UI"""
# 主布局
self.main_layout = QVBoxLayout(self)
self.main_layout.setContentsMargins(20, 20, 20, 20)
self.main_layout.setSpacing(10)
# 创建查询条件区域
self.create_query_frame()
# 创建结果表格
self.create_result_table()
# 创建按钮
self.create_buttons()
def create_query_frame(self):
"""创建查询条件区域"""
# 创建一个带边框的容器
query_frame = QFrame()
query_frame.setStyleSheet("""
QFrame {
border: 1px solid #e0e0e0;
background-color: white;
border-radius: 4px;
}
""")
# 容器的垂直布局
query_layout = QVBoxLayout(query_frame)
query_layout.setContentsMargins(15, 15, 15, 15)
query_layout.setSpacing(10)
# 第一行日期范围和订单Mo
row1 = QHBoxLayout()
# 日期标签
date_label = QLabel("日期:")
date_label.setFont(self.normal_font)
date_label.setFixedWidth(40)
# 开始日期
self.start_date = QDateEdit()
self.start_date.setFont(self.normal_font)
self.start_date.setCalendarPopup(True)
self.start_date.setDate(QDate.currentDate().addDays(-7))
self.start_date.setFixedWidth(120)
self.start_date.setStyleSheet("""
QDateEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
""")
# 至标签
to_label = QLabel("至:")
to_label.setFont(self.normal_font)
to_label.setFixedWidth(20)
# 结束日期
self.end_date = QDateEdit()
self.end_date.setFont(self.normal_font)
self.end_date.setCalendarPopup(True)
self.end_date.setDate(QDate.currentDate())
self.end_date.setFixedWidth(120)
self.end_date.setStyleSheet("""
QDateEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
""")
# 订单Mo标签
order_mo_label = QLabel("订单Mo:")
order_mo_label.setFont(self.normal_font)
order_mo_label.setFixedWidth(60)
# 订单Mo输入框
self.order_mo_input = QLineEdit()
self.order_mo_input.setFont(self.normal_font)
self.order_mo_input.setStyleSheet("""
QLineEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
QLineEdit:focus {
border: 1px solid #66afe9;
}
""")
# 材质标签
material_label = QLabel("材质")
material_label.setFont(self.normal_font)
material_label.setFixedWidth(40)
# 材质下拉框
self.material_combo = QComboBox()
self.material_combo.setFont(self.normal_font)
self.material_combo.addItem("全部")
self.material_combo.setStyleSheet("""
QComboBox {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
width: 20px;
border-left: 1px solid #e0e0e0;
}
""")
# 规格标签
spec_label = QLabel("规格")
spec_label.setFont(self.normal_font)
spec_label.setFixedWidth(40)
# 规格输入框
self.spec_input = QLineEdit()
self.spec_input.setFont(self.normal_font)
self.spec_input.setStyleSheet("""
QLineEdit {
border: 1px solid #e0e0e0;
padding: 4px;
border-radius: 4px;
}
QLineEdit:focus {
border: 1px solid #66afe9;
}
""")
# 查询按钮
self.query_button = QPushButton("查询")
self.query_button.setFont(self.normal_font)
self.query_button.setStyleSheet("""
QPushButton {
background-color: #0078d4;
color: white;
border: none;
border-radius: 4px;
padding: 6px 16px;
}
QPushButton:hover {
background-color: #106ebe;
}
QPushButton:pressed {
background-color: #005a9e;
}
""")
self.query_button.setFixedWidth(80)
# 添加组件到第一行布局
row1.addWidget(date_label)
row1.addWidget(self.start_date)
row1.addWidget(to_label)
row1.addWidget(self.end_date)
row1.addSpacing(20)
row1.addWidget(order_mo_label)
row1.addWidget(self.order_mo_input, 1)
row1.addSpacing(20)
row1.addWidget(material_label)
row1.addWidget(self.material_combo, 1)
row1.addSpacing(20)
row1.addWidget(spec_label)
row1.addWidget(self.spec_input, 1)
row1.addSpacing(20)
row1.addWidget(self.query_button)
# 添加第一行到查询布局
query_layout.addLayout(row1)
# 将查询框架添加到主布局
self.main_layout.addWidget(query_frame)
def create_result_table(self):
"""创建结果表格"""
# 创建表格
self.result_table = QTableWidget()
self.result_table.setFont(self.normal_font)
# 设置表头样式
header = self.result_table.horizontalHeader()
header.setStyleSheet("""
QHeaderView::section {
background-color: #f5f5f5;
color: #333333;
padding: 5px;
border: 1px solid #e0e0e0;
font-weight: bold;
}
""")
# 设置表格样式
self.result_table.setStyleSheet("""
QTableWidget {
border: 1px solid #e0e0e0;
gridline-color: #e0e0e0;
selection-background-color: #0078d4;
selection-color: white;
}
QTableWidget::item {
padding: 5px;
border-bottom: 1px solid #e0e0e0;
}
""")
# 启用水平滚动条
self.result_table.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
# 设置表头自适应宽度
header.setSectionResizeMode(QHeaderView.Interactive)
# 设置默认列宽 - 常用列宽一些,不常用列窄一些
self.result_table.setColumnWidth(0, 60) # 序号
self.result_table.setColumnWidth(1, 100) # 日期
self.result_table.setColumnWidth(2, 120) # 订单号
self.result_table.setColumnWidth(3, 120) # 订单明细
self.result_table.setColumnWidth(4, 120) # 客户
self.result_table.setColumnWidth(5, 120) # 客户实际订单号
self.result_table.setColumnWidth(6, 100) # 订单类别
self.result_table.setColumnWidth(7, 100) # 客户交期
self.result_table.setColumnWidth(8, 100) # 编码
self.result_table.setColumnWidth(9, 100) # 产品类别
self.result_table.setColumnWidth(10, 80) # 材质
self.result_table.setColumnWidth(11, 80) # 规格
self.result_table.setColumnWidth(12, 80) # 产地
self.result_table.setColumnWidth(13, 80) # 最大入库量
self.result_table.setColumnWidth(14, 100) # 托盘号
self.result_table.setColumnWidth(15, 100) # 轴型
self.result_table.setColumnWidth(16, 80) # 轴型code
self.result_table.setColumnWidth(17, 80) # 轴型重量
# 其他列使用默认宽度
# 设置表格可以选择整行
self.result_table.setSelectionBehavior(QTableWidget.SelectRows)
# 设置表格只能单选
self.result_table.setSelectionMode(QTableWidget.SingleSelection)
# 添加表格到主布局
self.main_layout.addWidget(self.result_table, 1) # 1表示拉伸因子让表格占据更多空间
def create_buttons(self):
"""创建底部按钮"""
button_layout = QHBoxLayout()
# 分页控件(示例)
page_layout = QHBoxLayout()
# 添加分页按钮(示例)
self.first_page_btn = QPushButton("<<")
self.prev_page_btn = QPushButton("<")
self.page_label = QLabel("1 / 1")
self.next_page_btn = QPushButton(">")
self.last_page_btn = QPushButton(">>")
page_style = """
QPushButton {
border: 1px solid #e0e0e0;
background-color: white;
padding: 4px 8px;
}
QPushButton:hover {
background-color: #f5f5f5;
}
QLabel {
padding: 0 10px;
}
"""
self.first_page_btn.setStyleSheet(page_style)
self.prev_page_btn.setStyleSheet(page_style)
self.next_page_btn.setStyleSheet(page_style)
self.last_page_btn.setStyleSheet(page_style)
page_layout.addWidget(self.first_page_btn)
page_layout.addWidget(self.prev_page_btn)
page_layout.addWidget(self.page_label)
page_layout.addWidget(self.next_page_btn)
page_layout.addWidget(self.last_page_btn)
# 确认和取消按钮
self.confirm_button = QPushButton("确认")
self.confirm_button.setFont(self.normal_font)
self.confirm_button.setStyleSheet("""
QPushButton {
background-color: #0078d4;
color: white;
border: none;
border-radius: 4px;
padding: 8px 16px;
}
QPushButton:hover {
background-color: #106ebe;
}
QPushButton:pressed {
background-color: #005a9e;
}
""")
self.confirm_button.setFixedSize(100, 35)
self.cancel_button = QPushButton("取消")
self.cancel_button.setFont(self.normal_font)
self.cancel_button.setStyleSheet("""
QPushButton {
background-color: white;
color: #333333;
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 8px 16px;
}
QPushButton:hover {
background-color: #f5f5f5;
}
QPushButton:pressed {
background-color: #e0e0e0;
}
""")
self.cancel_button.setFixedSize(100, 35)
# 添加分页控件和按钮到布局
button_layout.addLayout(page_layout)
button_layout.addStretch()
button_layout.addWidget(self.confirm_button)
button_layout.addSpacing(20)
button_layout.addWidget(self.cancel_button)
# 添加按钮布局到主布局
self.main_layout.addLayout(button_layout)