优化款号管理界面功能
- 修复删除类目时删除错误行的问题 - 移除"快速添加标准类目"功能 - 统一界面文案:"自定义类目"改为"选择类目" - 简化按钮文案:"新增/编辑款号"改为"新增款号" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ class GarmentLibraryDialog(QDialog):
|
|||||||
self.search_input.textChanged.connect(self.load_garments)
|
self.search_input.textChanged.connect(self.load_garments)
|
||||||
op_layout.addWidget(self.search_input)
|
op_layout.addWidget(self.search_input)
|
||||||
|
|
||||||
add_btn = QPushButton("新增/编辑款号")
|
add_btn = QPushButton("新增款号")
|
||||||
add_btn.clicked.connect(self.edit_garment)
|
add_btn.clicked.connect(self.edit_garment)
|
||||||
op_layout.addWidget(add_btn)
|
op_layout.addWidget(add_btn)
|
||||||
|
|
||||||
@@ -254,11 +254,7 @@ class GarmentEditDialog(QDialog):
|
|||||||
|
|
||||||
# 按钮区域
|
# 按钮区域
|
||||||
btn_layout = QHBoxLayout()
|
btn_layout = QHBoxLayout()
|
||||||
add_default_btn = QPushButton("快速添加标准类目")
|
add_custom_btn = QPushButton("添加类目")
|
||||||
add_default_btn.clicked.connect(self.add_default_categories)
|
|
||||||
btn_layout.addWidget(add_default_btn)
|
|
||||||
|
|
||||||
add_custom_btn = QPushButton("添加自定义类目")
|
|
||||||
add_custom_btn.clicked.connect(lambda: self.add_material_row())
|
add_custom_btn.clicked.connect(lambda: self.add_material_row())
|
||||||
btn_layout.addWidget(add_custom_btn)
|
btn_layout.addWidget(add_custom_btn)
|
||||||
|
|
||||||
@@ -327,13 +323,6 @@ class GarmentEditDialog(QDialog):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
QMessageBox.critical(self, "错误", "加载材料失败: " + str(e))
|
QMessageBox.critical(self, "错误", "加载材料失败: " + str(e))
|
||||||
|
|
||||||
def add_default_categories(self):
|
|
||||||
"""添加默认类目"""
|
|
||||||
defaults = [("A料", "", "米"), ("B料", "", "米"), ("C料", "", "米"), ("D料", "", "米"),
|
|
||||||
("花边", "", "码"), ("胸杯", "", "一对"), ("拉链", "", "个"), ("辅料", "", "个")]
|
|
||||||
for cat, fabric_type, unit in defaults:
|
|
||||||
self.add_material_row(cat, fabric_type, 0, unit)
|
|
||||||
|
|
||||||
def add_material_row(self, category="", fabric_type="", usage=0.0, unit="米", model=""):
|
def add_material_row(self, category="", fabric_type="", usage=0.0, unit="米", model=""):
|
||||||
"""添加材料行"""
|
"""添加材料行"""
|
||||||
print("add_material_row", category, fabric_type, usage, unit, model)
|
print("add_material_row", category, fabric_type, usage, unit, model)
|
||||||
@@ -344,7 +333,7 @@ class GarmentEditDialog(QDialog):
|
|||||||
cat_combo = QComboBox()
|
cat_combo = QComboBox()
|
||||||
cat_combo.setEditable(False)
|
cat_combo.setEditable(False)
|
||||||
# 最后添加自定义选项
|
# 最后添加自定义选项
|
||||||
cat_combo.addItem("—— 自定义类目 ——")
|
cat_combo.addItem("—— 选择类目 ——")
|
||||||
|
|
||||||
# 先添加所有类目选项
|
# 先添加所有类目选项
|
||||||
try:
|
try:
|
||||||
@@ -371,8 +360,8 @@ class GarmentEditDialog(QDialog):
|
|||||||
if category:
|
if category:
|
||||||
cat_combo.setCurrentText(category)
|
cat_combo.setCurrentText(category)
|
||||||
else:
|
else:
|
||||||
# 如果没有指定类目,默认选择"—— 自定义类目 ——"(索引0)
|
# 如果没有指定类目,默认选择"—— 选择类目 ——"(索引0)
|
||||||
print("没有指定类目,默认选择'—— 自定义类目 ——'(索引0)")
|
print("没有指定类目,默认选择'—— 选择类目 ——'(索引0)")
|
||||||
print(cat_combo.count())
|
print(cat_combo.count())
|
||||||
print(cat_combo.currentIndex())
|
print(cat_combo.currentIndex())
|
||||||
# 打印所有选项
|
# 打印所有选项
|
||||||
@@ -444,14 +433,14 @@ class GarmentEditDialog(QDialog):
|
|||||||
|
|
||||||
# 列5: 删除按钮
|
# 列5: 删除按钮
|
||||||
del_btn = QPushButton("删除")
|
del_btn = QPushButton("删除")
|
||||||
del_btn.clicked.connect(lambda _, r=row: self.material_table.removeRow(r))
|
del_btn.clicked.connect(lambda: self.delete_material_row(del_btn))
|
||||||
self.material_table.setCellWidget(row, 5, del_btn)
|
self.material_table.setCellWidget(row, 5, del_btn)
|
||||||
|
|
||||||
# 初始化类型和型号选项
|
# 初始化类型和型号选项
|
||||||
# self.on_category_changed(cat_combo.currentText(), row)
|
# self.on_category_changed(cat_combo.currentText(), row)
|
||||||
|
|
||||||
# 如果没有选择具体类目,初始化时显示全部型号
|
# 如果没有选择具体类目,初始化时显示全部型号
|
||||||
# if cat_combo.currentText() == "—— 自定义类目 ——":
|
# if cat_combo.currentText() == "—— 选择类目 ——":
|
||||||
# self.on_type_changed("—— 选择类型 ——", row)
|
# self.on_type_changed("—— 选择类型 ——", row)
|
||||||
|
|
||||||
# 如果有指定的型号,需要在初始化完成后设置
|
# 如果有指定的型号,需要在初始化完成后设置
|
||||||
@@ -477,6 +466,14 @@ class GarmentEditDialog(QDialog):
|
|||||||
type_combo.currentTextChanged.connect(lambda text, r=row: self.on_type_changed(text, r))
|
type_combo.currentTextChanged.connect(lambda text, r=row: self.on_type_changed(text, r))
|
||||||
# 当用户真正选择了某个型号(包括通过模糊搜索补全选择),再联动类目和类型
|
# 当用户真正选择了某个型号(包括通过模糊搜索补全选择),再联动类目和类型
|
||||||
model_combo.activated[str].connect(lambda text, r=row: self.on_model_selected(text, r))
|
model_combo.activated[str].connect(lambda text, r=row: self.on_model_selected(text, r))
|
||||||
|
|
||||||
|
def delete_material_row(self, button):
|
||||||
|
"""删除材料行 - 通过按钮找到实际行号"""
|
||||||
|
for row in range(self.material_table.rowCount()):
|
||||||
|
if self.material_table.cellWidget(row, 5) == button:
|
||||||
|
self.material_table.removeRow(row)
|
||||||
|
break
|
||||||
|
|
||||||
def update_model_combo_range(self, model_combo, row):
|
def update_model_combo_range(self, model_combo, row):
|
||||||
print("update_model_combo_range", model_combo, row)
|
print("update_model_combo_range", model_combo, row)
|
||||||
"""更新型号下拉框的搜索范围"""
|
"""更新型号下拉框的搜索范围"""
|
||||||
@@ -495,7 +492,7 @@ class GarmentEditDialog(QDialog):
|
|||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
# 根据类目和类型构建查询条件
|
# 根据类目和类型构建查询条件
|
||||||
if category_text and category_text != "—— 自定义类目 ——" and type_text and type_text != "—— 选择类型 ——":
|
if category_text and category_text != "—— 选择类目 ——" and type_text and type_text != "—— 选择类型 ——":
|
||||||
# 同时根据类目和类型过滤
|
# 同时根据类目和类型过滤
|
||||||
cursor = conn.execute("""
|
cursor = conn.execute("""
|
||||||
SELECT DISTINCT model, color, unit
|
SELECT DISTINCT model, color, unit
|
||||||
@@ -503,7 +500,7 @@ class GarmentEditDialog(QDialog):
|
|||||||
WHERE category = ? AND fabric_type = ?
|
WHERE category = ? AND fabric_type = ?
|
||||||
ORDER BY model
|
ORDER BY model
|
||||||
""", (category_text, type_text))
|
""", (category_text, type_text))
|
||||||
elif category_text and category_text != "—— 自定义类目 ——":
|
elif category_text and category_text != "—— 选择类目 ——":
|
||||||
# 只根据类目过滤
|
# 只根据类目过滤
|
||||||
cursor = conn.execute("""
|
cursor = conn.execute("""
|
||||||
SELECT DISTINCT model, color, unit
|
SELECT DISTINCT model, color, unit
|
||||||
@@ -573,7 +570,7 @@ class GarmentEditDialog(QDialog):
|
|||||||
try:
|
try:
|
||||||
with self.get_conn() as conn:
|
with self.get_conn() as conn:
|
||||||
# 加载所有类型
|
# 加载所有类型
|
||||||
if category_text and category_text != "—— 自定义类目 ——":
|
if category_text and category_text != "—— 选择类目 ——":
|
||||||
# 如果选择了具体类目,则过滤
|
# 如果选择了具体类目,则过滤
|
||||||
cursor = conn.execute("""
|
cursor = conn.execute("""
|
||||||
SELECT DISTINCT fabric_type
|
SELECT DISTINCT fabric_type
|
||||||
@@ -724,7 +721,7 @@ class GarmentEditDialog(QDialog):
|
|||||||
model = model_widget.currentText().strip()
|
model = model_widget.currentText().strip()
|
||||||
|
|
||||||
# 处理类目和类型
|
# 处理类目和类型
|
||||||
if category == "—— 自定义类目 ——":
|
if category == "—— 选择类目 ——":
|
||||||
category = ""
|
category = ""
|
||||||
if fabric_type == "—— 选择类型 ——":
|
if fabric_type == "—— 选择类型 ——":
|
||||||
fabric_type = ""
|
fabric_type = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user