feat: 采集采购页,采集与采购统一展示 (#19)
原来的采购任务页是骨架:var rows []gin.H 从不查库,页面永远为空; TODO 写的还是只查 task_type = 'purchase'。所以 #18 建出来的采集任务 在界面上哪儿都看不到——用户点完「创建采集任务」只能盯着 collect_status 猜。 模块名定为「采集采购」(用户指定),直接点出这页装的是哪两类任务, 比泛称「任务」更能让人一眼知道点进去看什么。路由 /tasks 不变, 改路由会让已有书签和文档链接全失效,没有收益。 列不按类型并列——两种任务字段完全不同,并列会让采集任务行一半是空列。 改成固定列 + 一列「目标」把业务信息概括成一句话: 采集 PDD 737116531267 采购 SO-001 · M/黑色 · 2件 · ≤¥42.00 拼接逻辑在 service 层,模板只负责显示。 统计和列表共用同一个筛选条件拼装函数。分开写的话总有一天会忘了 给统计也加条件,数字和表格对不上,操作员会以为页面坏了。 无主任务的客户端列显示「—」。#17 之后采集任务默认无主,这列会大量为空。 详情弹窗只读,采购专有字段(数量、价格上限、目标规格)在采集任务里 整段不出现,不显示空行。复用 #18 的弹窗机制,app.js 无需改动。 顺带清掉 PDD 页加进来之后一直没跟上的模块计数:多处「四个模块/四个页面」 改成五个。其中 06-quality-security.md 那两处是验证清单, 照着做的人只会测四个页面,PDD 页永远不在回归范围里。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+101
-14
@@ -4,9 +4,11 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"cmautobuy/admin/repository"
|
||||
"cmautobuy/admin/service"
|
||||
)
|
||||
|
||||
@@ -70,29 +72,114 @@ func (h *Handler) SybDelete(c *gin.Context) {
|
||||
fail(c, http.StatusNotImplemented, "删除功能尚未实现。")
|
||||
}
|
||||
|
||||
// ---------- 3. 采购任务 ----------
|
||||
|
||||
// TaskList 渲染采购任务列表页。
|
||||
// ---------- 3. 采集采购 ----------
|
||||
//
|
||||
// 注意颜色尺码显示的是 **PDD 侧**的规格(实际要买的),不是蝦皮的。
|
||||
// 价格上限显示成 ¥42.00,底层存的是整数分。
|
||||
// `tasks` 是一张表,用 task_type 区分采集和采购,这个模块把两种任务放在
|
||||
// 同一个列表里显示,靠「目标」一列概括各自的业务信息,见 #19。
|
||||
// 拼接和翻译逻辑全在 service/task.go,这里只做取参数 → 调 service → 渲染。
|
||||
|
||||
// TaskList 渲染「采集采购」列表页。
|
||||
func (h *Handler) TaskList(c *gin.Context) {
|
||||
keyword := c.Query("order_no")
|
||||
filter := repository.TaskFilter{
|
||||
Type: service.ParseTaskType(c.Query("type")),
|
||||
Status: service.ParseTaskStatus(c.Query("status")),
|
||||
Keyword: c.Query("q"),
|
||||
}
|
||||
|
||||
// TODO(骨架): 查 tasks,task_type = 'purchase'
|
||||
var rows []gin.H
|
||||
result, err := service.ListTasksView(h.db, filter)
|
||||
if err != nil {
|
||||
fail(c, http.StatusInternalServerError,
|
||||
"读取任务列表失败,数据没有被改动。刷新页面重试;一直失败请把这句话报给维护者。")
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "task/list", page(c, "tasks", "采购任务", gin.H{
|
||||
"Keyword": keyword,
|
||||
"Rows": rows,
|
||||
"Status": "尚未实现:创建任务后这里显示执行进度",
|
||||
// 底部状态条平时显示统计,刚做完删除操作时先显示操作结果,
|
||||
// 跳转带过来的 msg 参数,见 h.taskRedirect。
|
||||
statusLine := result.StatusLine()
|
||||
if msg := c.Query("msg"); msg != "" {
|
||||
statusLine = msg + " · " + statusLine
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "task/list", page(c, "tasks", "采集采购", gin.H{
|
||||
"Rows": result.Rows,
|
||||
"Keyword": filter.Keyword,
|
||||
"Status": statusLine,
|
||||
"TypeFilter": string(filter.Type),
|
||||
"StatusFilter": string(filter.Status),
|
||||
"TypeOptions": service.TaskTypeOptions(),
|
||||
"StatusOptions": service.TaskStatusOptions(),
|
||||
"IsFiltered": result.IsFiltered,
|
||||
}))
|
||||
}
|
||||
|
||||
// TaskDetail 渲染双击行弹出的只读详情弹窗内容(不是整页)。
|
||||
//
|
||||
// `[必须]` 只读。改派 / 重试 / 取消是后续工单的范围,这里不提供入口。
|
||||
// 弹窗机制复用 #18 已有的那套(static/js/app.js 的 setupRowDetail),
|
||||
// 不新造一套。
|
||||
func (h *Handler) TaskDetail(c *gin.Context) {
|
||||
taskID := c.Query("id")
|
||||
if taskID == "" {
|
||||
fail(c, http.StatusBadRequest, "任务编号不对,请刷新页面后重试。")
|
||||
return
|
||||
}
|
||||
|
||||
detail, err := service.GetTaskDetail(h.db, taskID)
|
||||
if err != nil {
|
||||
fail(c, http.StatusInternalServerError, "读取任务详情失败,数据没有被改动。")
|
||||
return
|
||||
}
|
||||
if detail == nil {
|
||||
fail(c, http.StatusNotFound, "这个任务不存在,请刷新页面。")
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "task/detail_modal", gin.H{"D": detail})
|
||||
}
|
||||
|
||||
// TaskDelete 批量删除任务。
|
||||
//
|
||||
// `tasks` 表没有软删除列——加一列是数据库结构变更,不在本工单范围内,
|
||||
// 见 repository.DeleteTasks 的注释。二次确认在前端做(data-confirm-delete)。
|
||||
func (h *Handler) TaskDelete(c *gin.Context) {
|
||||
// TODO(骨架)
|
||||
fail(c, http.StatusNotImplemented, "删除功能尚未实现。")
|
||||
ids := c.PostFormArray("ids")
|
||||
if len(ids) == 0 {
|
||||
h.taskRedirect(c, "没有勾选任何任务,没有删除")
|
||||
return
|
||||
}
|
||||
|
||||
n, err := service.DeleteTasks(h.db, ids)
|
||||
if err != nil {
|
||||
fail(c, http.StatusInternalServerError,
|
||||
"删除失败:"+err.Error()+"。没有删除任何记录。")
|
||||
return
|
||||
}
|
||||
h.taskRedirect(c, fmt.Sprintf("已删除 %d 条", n))
|
||||
}
|
||||
|
||||
// taskRedirect 处理完写操作后跳回列表页,带上当前筛选条件,
|
||||
// 免得操作员每做一次删除就要重新筛一遍。用 303 而不是直接渲染,
|
||||
// 是为了让浏览器地址栏变成 GET /tasks——按 F5 不会重复提交刚才的删除。
|
||||
func (h *Handler) taskRedirect(c *gin.Context, msg string) {
|
||||
params := url.Values{}
|
||||
if t := c.PostForm("type"); t != "" {
|
||||
params.Set("type", t)
|
||||
}
|
||||
if s := c.PostForm("status"); s != "" {
|
||||
params.Set("status", s)
|
||||
}
|
||||
if q := c.PostForm("q"); q != "" {
|
||||
params.Set("q", q)
|
||||
}
|
||||
if msg != "" {
|
||||
params.Set("msg", msg)
|
||||
}
|
||||
|
||||
target := "/tasks"
|
||||
if len(params) > 0 {
|
||||
target += "?" + params.Encode()
|
||||
}
|
||||
c.Redirect(http.StatusSeeOther, target)
|
||||
}
|
||||
|
||||
// ---------- 4. 客户端列表 ----------
|
||||
|
||||
@@ -64,8 +64,9 @@ func Register(r *gin.Engine, db *sql.DB, onlineThreshold time.Duration) {
|
||||
pages.POST("/syb/create-task", h.SybCreateTask)
|
||||
pages.POST("/syb/delete", h.SybDelete)
|
||||
|
||||
// 4. 采购任务
|
||||
// 4. 采集采购
|
||||
pages.GET("/tasks", h.TaskList)
|
||||
pages.GET("/tasks/detail", h.TaskDetail) // 双击行时前端来取弹窗内容
|
||||
pages.POST("/tasks/delete", h.TaskDelete)
|
||||
|
||||
// 5. 客户端列表
|
||||
|
||||
Reference in New Issue
Block a user