|
|
@@ -109,14 +109,7 @@ public class MainController {
|
|
|
@FXML private TableColumn<Book, Integer> myBookStockCol;
|
|
|
@FXML private TableColumn<Book, Void> myBookStatusCol;
|
|
|
@FXML private TableColumn<Book, Void> myBookActionCol;
|
|
|
- @FXML private TitledPane bookFormPane;
|
|
|
- @FXML private Button saveBookBtn;
|
|
|
- @FXML private TextField newTitle;
|
|
|
- @FXML private TextField newAuthor;
|
|
|
- @FXML private TextField newCategory;
|
|
|
- @FXML private TextField newOriginalPrice;
|
|
|
- @FXML private TextField newSellingPrice;
|
|
|
- @FXML private TextField newStock;
|
|
|
+
|
|
|
|
|
|
// Statistics tab
|
|
|
@FXML private Label statTotalAmount;
|
|
|
@@ -186,7 +179,6 @@ public class MainController {
|
|
|
private final StatisticsService statisticsService = new StatisticsService();
|
|
|
|
|
|
private Book selectedBook;
|
|
|
- private Book editingBook;
|
|
|
|
|
|
@FXML private Button prevPageBtn;
|
|
|
@FXML private Button nextPageBtn;
|
|
|
@@ -611,7 +603,7 @@ public class MainController {
|
|
|
delBtn.setStyle("-fx-padding: 4px 12px; -fx-font-size: 12px;");
|
|
|
editBtn.setOnAction(e -> {
|
|
|
Book b = getTableView().getItems().get(getIndex());
|
|
|
- editBook(b);
|
|
|
+ showBookDialog(b);
|
|
|
});
|
|
|
toggleBtn.setOnAction(e -> {
|
|
|
Book b = getTableView().getItems().get(getIndex());
|
|
|
@@ -672,77 +664,6 @@ public class MainController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void editBook(Book sel) {
|
|
|
- editingBook = sel;
|
|
|
- newTitle.setText(sel.getTitle());
|
|
|
- newAuthor.setText(sel.getAuthor());
|
|
|
- newCategory.setText(sel.getCategory());
|
|
|
- newOriginalPrice.setText(sel.getOriginalPrice().toString());
|
|
|
- newSellingPrice.setText(sel.getSellingPrice().toString());
|
|
|
- newStock.setText(String.valueOf(sel.getStock()));
|
|
|
- bookFormPane.setText("编辑书籍");
|
|
|
- saveBookBtn.setText("保存修改");
|
|
|
- bookFormPane.setExpanded(true);
|
|
|
- }
|
|
|
-
|
|
|
- @FXML
|
|
|
- private void handleEditBook() {
|
|
|
- Book sel = myBookTable.getSelectionModel().getSelectedItem();
|
|
|
- if (sel == null) {
|
|
|
- showAlert("请先选择要编辑的书籍");
|
|
|
- return;
|
|
|
- }
|
|
|
- editBook(sel);
|
|
|
- }
|
|
|
-
|
|
|
- @FXML
|
|
|
- private void handleAddBook() {
|
|
|
- try {
|
|
|
- String title = newTitle.getText().trim();
|
|
|
- String author = newAuthor.getText().trim();
|
|
|
- String category = newCategory.getText().trim();
|
|
|
- BigDecimal originalPrice = new BigDecimal(newOriginalPrice.getText().trim());
|
|
|
- BigDecimal sellingPrice = new BigDecimal(newSellingPrice.getText().trim());
|
|
|
- int stock = Integer.parseInt(newStock.getText().trim());
|
|
|
-
|
|
|
- if (editingBook != null) {
|
|
|
- editingBook.setTitle(title);
|
|
|
- editingBook.setAuthor(author);
|
|
|
- editingBook.setCategory(category);
|
|
|
- editingBook.setOriginalPrice(originalPrice);
|
|
|
- editingBook.setSellingPrice(sellingPrice);
|
|
|
- editingBook.setStock(stock);
|
|
|
- R<Book> result = bookService.update(editingBook.getBookId(), editingBook);
|
|
|
- if (result.getCode() == 200) {
|
|
|
- showInfo("书籍已更新!");
|
|
|
- clearBookForm();
|
|
|
- handleLoadMyBooks();
|
|
|
- } else {
|
|
|
- showAlert(result.getMessage());
|
|
|
- }
|
|
|
- } else {
|
|
|
- Book book = new Book();
|
|
|
- book.setSellerId(LoginUserHolder.get().getUserid());
|
|
|
- book.setTitle(title);
|
|
|
- book.setAuthor(author);
|
|
|
- book.setCategory(category);
|
|
|
- book.setOriginalPrice(originalPrice);
|
|
|
- book.setSellingPrice(sellingPrice);
|
|
|
- book.setStock(stock);
|
|
|
- R<Book> result = bookService.create(book);
|
|
|
- if (result.getCode() == 200) {
|
|
|
- showInfo("书籍已上架!");
|
|
|
- clearBookForm();
|
|
|
- handleLoadMyBooks();
|
|
|
- } else {
|
|
|
- showAlert(result.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- showAlert("输入无效:" + e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@FXML
|
|
|
private void handleDeleteBook() {
|
|
|
Book sel = myBookTable.getSelectionModel().getSelectedItem();
|
|
|
@@ -775,16 +696,120 @@ public class MainController {
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
|
- private void handleToggleBookForm() {
|
|
|
- bookFormPane.setExpanded(!bookFormPane.isExpanded());
|
|
|
- if (bookFormPane.isExpanded()) {
|
|
|
- clearBookForm();
|
|
|
- }
|
|
|
+ private void handleAddBookDialog() {
|
|
|
+ showBookDialog(null);
|
|
|
}
|
|
|
|
|
|
- @FXML
|
|
|
- private void handleCancelBookForm() {
|
|
|
- clearBookForm();
|
|
|
+ private void showBookDialog(Book existingBook) {
|
|
|
+ boolean isNew = (existingBook == null);
|
|
|
+ Dialog<Book> dialog = new Dialog<>();
|
|
|
+ dialog.setTitle(isNew ? "添加新书" : "编辑书籍");
|
|
|
+ dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
|
|
+ dialog.getDialogPane().setPrefWidth(480);
|
|
|
+
|
|
|
+ GridPane grid = new GridPane();
|
|
|
+ grid.setHgap(12);
|
|
|
+ grid.setVgap(10);
|
|
|
+ grid.setPadding(new javafx.geometry.Insets(20));
|
|
|
+ ColumnConstraints col1 = new ColumnConstraints(70);
|
|
|
+ ColumnConstraints col2 = new ColumnConstraints(300, 300, Double.MAX_VALUE);
|
|
|
+ grid.getColumnConstraints().addAll(col1, col2);
|
|
|
+
|
|
|
+ TextField titleField = new TextField();
|
|
|
+ titleField.setPromptText("请输入书名");
|
|
|
+ TextField authorField = new TextField();
|
|
|
+ authorField.setPromptText("请输入作者");
|
|
|
+ ComboBox<String> categoryCombo = new ComboBox<>();
|
|
|
+ // Same categories as browse page (excluding "全部")
|
|
|
+ categoryCombo.getItems().addAll("教材", "小说", "科技", "文学", "考试", "其他");
|
|
|
+ TextField origPriceField = new TextField();
|
|
|
+ origPriceField.setPromptText("请输入原价");
|
|
|
+ TextField sellPriceField = new TextField();
|
|
|
+ sellPriceField.setPromptText("请输入售价");
|
|
|
+ TextField stockField = new TextField();
|
|
|
+ stockField.setPromptText("请输入库存数量");
|
|
|
+
|
|
|
+ if (!isNew) {
|
|
|
+ titleField.setText(existingBook.getTitle());
|
|
|
+ authorField.setText(existingBook.getAuthor());
|
|
|
+ categoryCombo.getSelectionModel().select(existingBook.getCategory());
|
|
|
+ origPriceField.setText(existingBook.getOriginalPrice().toString());
|
|
|
+ sellPriceField.setText(existingBook.getSellingPrice().toString());
|
|
|
+ stockField.setText(String.valueOf(existingBook.getStock()));
|
|
|
+ } else {
|
|
|
+ categoryCombo.getSelectionModel().select(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ Label titleLbl = new Label("书名:");
|
|
|
+ Label authorLbl = new Label("作者:");
|
|
|
+ Label categoryLbl = new Label("分类:");
|
|
|
+ Label origPriceLbl = new Label("原价:");
|
|
|
+ Label sellPriceLbl = new Label("售价:");
|
|
|
+ Label stockLbl = new Label("库存:");
|
|
|
+
|
|
|
+ int row = 0;
|
|
|
+ grid.add(titleLbl, 0, row);
|
|
|
+ grid.add(titleField, 1, row++);
|
|
|
+ grid.add(authorLbl, 0, row);
|
|
|
+ grid.add(authorField, 1, row++);
|
|
|
+ grid.add(categoryLbl, 0, row);
|
|
|
+ grid.add(categoryCombo, 1, row++);
|
|
|
+ grid.add(origPriceLbl, 0, row);
|
|
|
+ grid.add(origPriceField, 1, row++);
|
|
|
+ grid.add(sellPriceLbl, 0, row);
|
|
|
+ grid.add(sellPriceField, 1, row++);
|
|
|
+ grid.add(stockLbl, 0, row);
|
|
|
+ grid.add(stockField, 1, row++);
|
|
|
+
|
|
|
+ dialog.getDialogPane().setContent(grid);
|
|
|
+
|
|
|
+ Node okBtn = dialog.getDialogPane().lookupButton(ButtonType.OK);
|
|
|
+ if (isNew) {
|
|
|
+ okBtn.setDisable(true);
|
|
|
+ titleField.textProperty().addListener((obs, old, val) ->
|
|
|
+ okBtn.setDisable(val.trim().isEmpty() || authorField.getText().trim().isEmpty()));
|
|
|
+ authorField.textProperty().addListener((obs, old, val) ->
|
|
|
+ okBtn.setDisable(val.trim().isEmpty() || titleField.getText().trim().isEmpty()));
|
|
|
+ }
|
|
|
+
|
|
|
+ dialog.setResultConverter(btn -> {
|
|
|
+ if (btn == ButtonType.OK) {
|
|
|
+ try {
|
|
|
+ Book book = isNew ? new Book() : existingBook;
|
|
|
+ book.setTitle(titleField.getText().trim());
|
|
|
+ book.setAuthor(authorField.getText().trim());
|
|
|
+ book.setCategory(categoryCombo.getSelectionModel().getSelectedItem());
|
|
|
+ book.setOriginalPrice(new BigDecimal(origPriceField.getText().trim()));
|
|
|
+ book.setSellingPrice(new BigDecimal(sellPriceField.getText().trim()));
|
|
|
+ book.setStock(Integer.parseInt(stockField.getText().trim()));
|
|
|
+ return book;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+
|
|
|
+ dialog.showAndWait().ifPresent(book -> {
|
|
|
+ if (isNew) {
|
|
|
+ book.setSellerId(LoginUserHolder.get().getUserid());
|
|
|
+ R<Book> result = bookService.create(book);
|
|
|
+ if (result.getCode() == 200) {
|
|
|
+ showInfo("书籍已上架!");
|
|
|
+ handleLoadMyBooks();
|
|
|
+ } else {
|
|
|
+ showAlert(result.getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ R<Book> result = bookService.update(book.getBookId(), book);
|
|
|
+ if (result.getCode() == 200) {
|
|
|
+ showInfo("书籍已更新!");
|
|
|
+ handleLoadMyBooks();
|
|
|
+ } else {
|
|
|
+ showAlert(result.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@FXML
|
|
|
@@ -1150,6 +1175,11 @@ public class MainController {
|
|
|
R<List<BookDetailDTO>> result = bookService.getPendingBooks();
|
|
|
if (result.getCode() == 200 && result.getData() != null) {
|
|
|
pendingBookTable.setItems(FXCollections.observableArrayList(result.getData()));
|
|
|
+ if (result.getData().isEmpty()) {
|
|
|
+ showInfo("暂无待审核书籍");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ showAlert(result.getMessage() != null ? result.getMessage() : "加载待审核书籍失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1268,19 +1298,6 @@ public class MainController {
|
|
|
|
|
|
// ── Helpers ──
|
|
|
|
|
|
- private void clearBookForm() {
|
|
|
- editingBook = null;
|
|
|
- newTitle.clear();
|
|
|
- newAuthor.clear();
|
|
|
- newCategory.clear();
|
|
|
- newOriginalPrice.clear();
|
|
|
- newSellingPrice.clear();
|
|
|
- newStock.clear();
|
|
|
- bookFormPane.setText("添加新书");
|
|
|
- saveBookBtn.setText("添加书籍");
|
|
|
- bookFormPane.setExpanded(false);
|
|
|
- }
|
|
|
-
|
|
|
private void showUserDialog(User user) {
|
|
|
boolean isNew = (user == null);
|
|
|
Dialog<User> dialog = new Dialog<>();
|