mirror of
https://github.com/goldenfishs/MRobot.git
synced 2026-03-31 21:07:14 +08:00
添加了开发票
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QListWidget, QListWidgetItem)
|
||||
from PyQt5.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QListWidget, QListWidgetItem, QMessageBox, QScrollArea, QWidget)
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QIcon, QColor, QFont
|
||||
from qfluentwidgets import (BodyLabel, PushButton, PrimaryPushButton, LineEdit,
|
||||
InfoBar, InfoBarPosition)
|
||||
InfoBar, InfoBarPosition, SubtitleLabel, TitleLabel,
|
||||
HorizontalSeparator, CardWidget, FluentIcon, StrongBodyLabel, theme, Theme)
|
||||
from .tools.finance_manager import FinanceManager
|
||||
|
||||
|
||||
@@ -19,49 +21,119 @@ class CategoryManagementDialog(QDialog):
|
||||
self.finance_manager = finance_manager
|
||||
self.account_id = account_id
|
||||
self.setWindowTitle("分类管理")
|
||||
self.setGeometry(100, 100, 500, 400)
|
||||
self.setGeometry(100, 100, 650, 550)
|
||||
self.setMinimumWidth(600)
|
||||
self.setMinimumHeight(480)
|
||||
|
||||
# 设置背景色跟随主题
|
||||
if theme() == Theme.DARK:
|
||||
self.setStyleSheet("background-color: #232323;")
|
||||
else:
|
||||
self.setStyleSheet("background-color: #f7f9fc;")
|
||||
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
"""初始化UI"""
|
||||
main_layout = QVBoxLayout()
|
||||
main_layout.setContentsMargins(24, 24, 24, 24)
|
||||
main_layout.setSpacing(16)
|
||||
|
||||
# 标签
|
||||
title_label = BodyLabel("选择分类进行管理:")
|
||||
main_layout.addWidget(title_label)
|
||||
# 标题区域
|
||||
title_layout = QVBoxLayout()
|
||||
title_layout.setSpacing(6)
|
||||
|
||||
title_label = TitleLabel("分类管理")
|
||||
title_layout.addWidget(title_label)
|
||||
|
||||
desc_label = BodyLabel("新增、编辑或删除您的交易分类")
|
||||
title_layout.addWidget(desc_label)
|
||||
|
||||
main_layout.addLayout(title_layout)
|
||||
main_layout.addWidget(HorizontalSeparator())
|
||||
|
||||
# 内容区域(分类列表)
|
||||
content_layout = QHBoxLayout()
|
||||
content_layout.setSpacing(16)
|
||||
|
||||
# 左侧:分类列表卡片
|
||||
list_card = CardWidget()
|
||||
list_card_layout = QVBoxLayout()
|
||||
list_card_layout.setContentsMargins(0, 0, 0, 0)
|
||||
list_card_layout.setSpacing(0)
|
||||
|
||||
list_label = StrongBodyLabel("现有分类")
|
||||
list_label.setStyleSheet("padding: 12px 16px; border-bottom: 1px solid var(--border-color);")
|
||||
list_card_layout.addWidget(list_label)
|
||||
|
||||
# 分类列表
|
||||
self.category_list = QListWidget()
|
||||
self.category_list.itemSelectionChanged.connect(self.on_category_selected)
|
||||
main_layout.addWidget(self.category_list)
|
||||
self.category_list.setStyleSheet("""
|
||||
QListWidget {
|
||||
border: none;
|
||||
background-color: transparent;
|
||||
}
|
||||
QListWidget::item {
|
||||
padding: 10px 12px;
|
||||
border-radius: 4px;
|
||||
margin: 2px 4px;
|
||||
}
|
||||
QListWidget::item:hover {
|
||||
background-color: rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
QListWidget::item:selected {
|
||||
background-color: var(--highlight-color);
|
||||
color: var(--highlight-text-color);
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
list_card_layout.addWidget(self.category_list, 1)
|
||||
list_card.setLayout(list_card_layout)
|
||||
list_card.setMinimumHeight(280)
|
||||
content_layout.addWidget(list_card, 1)
|
||||
|
||||
main_layout.addLayout(content_layout, 1)
|
||||
|
||||
# 加载分类
|
||||
self.load_categories()
|
||||
|
||||
# 按钮区域
|
||||
btn_layout = QHBoxLayout()
|
||||
btn_layout.addStretch()
|
||||
btn_layout.setSpacing(12)
|
||||
|
||||
# 新增按钮
|
||||
add_btn = PrimaryPushButton("新增")
|
||||
add_btn = PrimaryPushButton()
|
||||
add_btn.setIcon(FluentIcon.ADD)
|
||||
add_btn.setText("新增分类")
|
||||
add_btn.clicked.connect(self.on_add_category)
|
||||
add_btn.setMinimumWidth(120)
|
||||
btn_layout.addWidget(add_btn)
|
||||
|
||||
# 重命名按钮
|
||||
self.rename_btn = PushButton("重命名")
|
||||
self.rename_btn = PushButton()
|
||||
self.rename_btn.setIcon(FluentIcon.EDIT)
|
||||
self.rename_btn.setText("重命名")
|
||||
self.rename_btn.clicked.connect(self.on_rename_category)
|
||||
self.rename_btn.setEnabled(False)
|
||||
self.rename_btn.setMinimumWidth(110)
|
||||
btn_layout.addWidget(self.rename_btn)
|
||||
|
||||
# 删除按钮
|
||||
self.delete_btn = PushButton("删除")
|
||||
self.delete_btn = PushButton()
|
||||
self.delete_btn.setIcon(FluentIcon.DELETE)
|
||||
self.delete_btn.setText("删除")
|
||||
self.delete_btn.clicked.connect(self.on_delete_category)
|
||||
self.delete_btn.setEnabled(False)
|
||||
self.delete_btn.setMinimumWidth(110)
|
||||
btn_layout.addWidget(self.delete_btn)
|
||||
|
||||
btn_layout.addStretch()
|
||||
|
||||
# 关闭按钮
|
||||
close_btn = PushButton("关闭")
|
||||
close_btn.clicked.connect(self.accept)
|
||||
close_btn.setMinimumWidth(110)
|
||||
btn_layout.addWidget(close_btn)
|
||||
|
||||
main_layout.addLayout(btn_layout)
|
||||
@@ -88,17 +160,33 @@ class CategoryManagementDialog(QDialog):
|
||||
"""新增分类"""
|
||||
# 弹出输入对话框
|
||||
from PyQt5.QtWidgets import QDialog as QStdDialog
|
||||
from PyQt5.QtWidgets import QLabel
|
||||
|
||||
dialog = QStdDialog(self)
|
||||
dialog.setWindowTitle("新增分类")
|
||||
dialog.setGeometry(150, 150, 400, 150)
|
||||
dialog.setGeometry(150, 150, 450, 220)
|
||||
dialog.setStyleSheet("""
|
||||
QDialog {
|
||||
background-color: white;
|
||||
}
|
||||
""")
|
||||
|
||||
layout = QVBoxLayout(dialog)
|
||||
layout.addWidget(BodyLabel("分类名称:"))
|
||||
layout.setContentsMargins(24, 24, 24, 24)
|
||||
layout.setSpacing(16)
|
||||
|
||||
# 标题
|
||||
title = StrongBodyLabel("创建新分类")
|
||||
layout.addWidget(title)
|
||||
|
||||
# 说明文字
|
||||
desc = BodyLabel("请输入分类名称")
|
||||
desc.setStyleSheet("color: #606366;")
|
||||
layout.addWidget(desc)
|
||||
|
||||
# 输入框
|
||||
input_edit = LineEdit()
|
||||
input_edit.setPlaceholderText("例如:食品、交通、娱乐等")
|
||||
input_edit.setPlaceholderText("例如:食品、交通、娱乐、购物等")
|
||||
input_edit.setMinimumHeight(40)
|
||||
layout.addWidget(input_edit)
|
||||
|
||||
# 按钮
|
||||
@@ -140,14 +228,21 @@ class CategoryManagementDialog(QDialog):
|
||||
)
|
||||
|
||||
cancel_btn = PushButton("取消")
|
||||
cancel_btn.setMinimumWidth(100)
|
||||
cancel_btn.clicked.connect(dialog.reject)
|
||||
btn_layout.addWidget(cancel_btn)
|
||||
|
||||
create_btn = PrimaryPushButton("创建")
|
||||
create_btn.setMinimumWidth(100)
|
||||
create_btn.clicked.connect(on_create)
|
||||
btn_layout.addWidget(create_btn)
|
||||
|
||||
layout.addSpacing(12)
|
||||
layout.addLayout(btn_layout)
|
||||
|
||||
# 回车快速创建
|
||||
input_edit.returnPressed.connect(on_create)
|
||||
|
||||
dialog.exec()
|
||||
|
||||
def on_rename_category(self):
|
||||
@@ -163,15 +258,41 @@ class CategoryManagementDialog(QDialog):
|
||||
|
||||
dialog = QStdDialog(self)
|
||||
dialog.setWindowTitle("重命名分类")
|
||||
dialog.setGeometry(150, 150, 400, 150)
|
||||
dialog.setGeometry(150, 150, 450, 280)
|
||||
dialog.setStyleSheet("""
|
||||
QDialog {
|
||||
background-color: white;
|
||||
}
|
||||
""")
|
||||
|
||||
layout = QVBoxLayout(dialog)
|
||||
layout.addWidget(BodyLabel(f"原分类名: {old_name}"))
|
||||
layout.addWidget(BodyLabel("新分类名:"))
|
||||
layout.setContentsMargins(24, 24, 24, 24)
|
||||
layout.setSpacing(16)
|
||||
|
||||
# 标题
|
||||
title = StrongBodyLabel("重命名分类")
|
||||
layout.addWidget(title)
|
||||
|
||||
# 原名称显示
|
||||
old_info_layout = QHBoxLayout()
|
||||
old_label = BodyLabel("原分类名:")
|
||||
old_label.setMinimumWidth(80)
|
||||
old_value = StrongBodyLabel(old_name)
|
||||
old_value.setStyleSheet("color: #1976d2;")
|
||||
old_info_layout.addWidget(old_label)
|
||||
old_info_layout.addWidget(old_value)
|
||||
old_info_layout.addStretch()
|
||||
layout.addLayout(old_info_layout)
|
||||
|
||||
# 新名称输入
|
||||
new_label = BodyLabel("新分类名:")
|
||||
new_label.setMinimumWidth(80)
|
||||
layout.addWidget(new_label)
|
||||
|
||||
input_edit = LineEdit()
|
||||
input_edit.setText(old_name)
|
||||
input_edit.selectAll()
|
||||
input_edit.setMinimumHeight(40)
|
||||
layout.addWidget(input_edit)
|
||||
|
||||
# 按钮
|
||||
@@ -217,14 +338,21 @@ class CategoryManagementDialog(QDialog):
|
||||
)
|
||||
|
||||
cancel_btn = PushButton("取消")
|
||||
cancel_btn.setMinimumWidth(100)
|
||||
cancel_btn.clicked.connect(dialog.reject)
|
||||
btn_layout.addWidget(cancel_btn)
|
||||
|
||||
rename_btn = PrimaryPushButton("重命名")
|
||||
rename_btn.setMinimumWidth(100)
|
||||
rename_btn.clicked.connect(on_rename)
|
||||
btn_layout.addWidget(rename_btn)
|
||||
|
||||
layout.addSpacing(12)
|
||||
layout.addLayout(btn_layout)
|
||||
|
||||
# 回车快速重命名
|
||||
input_edit.returnPressed.connect(on_rename)
|
||||
|
||||
dialog.exec()
|
||||
|
||||
def on_delete_category(self):
|
||||
@@ -236,8 +364,6 @@ class CategoryManagementDialog(QDialog):
|
||||
category_name = current_item.text()
|
||||
|
||||
# 确认删除
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
|
||||
reply = QMessageBox.question(
|
||||
self,
|
||||
"确认删除",
|
||||
|
||||
Reference in New Issue
Block a user