Compare commits
44 Commits
b547844dca
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a79e21302 | |||
| 661e77416a | |||
| 0d323e8181 | |||
| e5e2a395e7 | |||
| 616638a6c8 | |||
| eb97c12bed | |||
| 58cb9a23ef | |||
| 0287003e93 | |||
| df42250725 | |||
| 7c7b72cadd | |||
| aad26b3d9e | |||
| c92e7bd931 | |||
| 8f0f725e26 | |||
| 67755c7847 | |||
| 57884d7baa | |||
| 8be06bcd43 | |||
| b2cfa3871e | |||
| e5bcde667b | |||
| ef9e5bbae5 | |||
| 9846dd6c8f | |||
| 3176bcde6f | |||
| 49c8707955 | |||
| 5f7b8e9394 | |||
| 1ba44d4b0a | |||
| 81e41bc38b | |||
| f4ff4b5ecb | |||
| bdc861cf8e | |||
| bcf1038f8a | |||
| 11f9f64dc6 | |||
| ff3de80c96 | |||
| 999f8c2f3e | |||
| eccf79b8d1 | |||
| da8db95141 | |||
| e183ea5583 | |||
| 34347dafb0 | |||
| a0bdce0359 | |||
| c0feab6be4 | |||
| eb52e2fd48 | |||
| f3fb000bda | |||
| b00ebd892f | |||
| ae720656b1 | |||
| 3b29bb0bd1 | |||
| c836944f92 | |||
| f665cf7e24 |
24
backend/alembic/versions/a7b8c9d0e1f2_add_task_type.py
Normal file
24
backend/alembic/versions/a7b8c9d0e1f2_add_task_type.py
Normal file
@ -0,0 +1,24 @@
|
||||
"""add_task_type
|
||||
|
||||
Revision ID: a7b8c9d0e1f2
|
||||
Revises: f6a7b8c9d0e1
|
||||
Create Date: 2026-08-06
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = "a7b8c9d0e1f2"
|
||||
down_revision: Union[str, None] = "f6a7b8c9d0e1"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column("tasks", sa.Column("task_type", sa.String(20), nullable=True, comment="派生类型: TRANSFER/SPAWN/RECOVERY"))
|
||||
# 刷老数据:parent_task_id 非空的默认为 TRANSFER
|
||||
op.execute("UPDATE tasks SET task_type = 'TRANSFER' WHERE parent_task_id IS NOT NULL AND task_type IS NULL")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column("tasks", "task_type")
|
||||
@ -121,6 +121,23 @@ async def end_task_endpoint(
|
||||
return await task_service.end_task(db, uuid.UUID(task_id), operator_id)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 核心业务 0.3:撤回转交 (PENDING → 删除 + 恢复父任务)
|
||||
# ============================================================
|
||||
|
||||
@router.post("/{task_id}/recall", response_model=TaskResponse)
|
||||
async def recall_task_endpoint(
|
||||
task_id: str,
|
||||
operator_id: str | None = Query(None),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
**撤回转交:删除 PENDING 子任务,恢复父任务为 WIP。**
|
||||
适用场景:转交后发现选错人,在对方接收前撤回。
|
||||
"""
|
||||
return await task_service.recall_task(db, uuid.UUID(task_id), operator_id)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 核心业务 0.5:并发派发协助分支 (WIP → 不改变状态,创建子任务)
|
||||
# ============================================================
|
||||
@ -154,16 +171,17 @@ async def receive_task_endpoint(
|
||||
task_id: str,
|
||||
operator_id: str | None = Query(None, description="操作人ID"),
|
||||
remark: str | None = Body(None, description="接收备注", embed=True),
|
||||
task_name: str | None = Body(None, description="接收人选定的工序名称", embed=True),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
**确认接收任务。**
|
||||
**确认接收任务。工人选定工序名称后接收。**
|
||||
|
||||
校验:只有状态为 PENDING 的任务可接收。
|
||||
动作:将状态改为 WIP,记录 received_at 为当前时间,写入 remark。
|
||||
动作:状态改为 WIP,记录 received_at,更新 task_name,同步产品宏观状态。
|
||||
"""
|
||||
return await task_service.receive_task(
|
||||
db, uuid.UUID(task_id), operator_id, remark
|
||||
db, uuid.UUID(task_id), operator_id, remark, task_name
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ class UserOption(BaseModel):
|
||||
id: str
|
||||
username: str
|
||||
full_name: str
|
||||
department: str = ""
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
@ -19,39 +20,49 @@ class UserOption(BaseModel):
|
||||
def list_users(
|
||||
keyword: str = Query("", description="按用户名/姓名模糊搜索"),
|
||||
limit: int = Query(100, ge=1, le=500),
|
||||
dept: str = Query("IRIS", description="部门过滤"),
|
||||
):
|
||||
"""获取 MOM 系统用户列表,供前端选人使用"""
|
||||
"""获取 MOM 系统用户列表,默认只返回 IRIS 部门"""
|
||||
db = MomSessionLocal()
|
||||
try:
|
||||
if keyword.strip():
|
||||
sql = text(
|
||||
"""
|
||||
# 尝试按部门过滤;若 sys_user 无 department 列则降级全量查询
|
||||
try:
|
||||
base_sql = """
|
||||
SELECT id, username,
|
||||
SPLIT_PART(username, '/', 1) AS full_name
|
||||
SPLIT_PART(username, '/', 1) AS full_name,
|
||||
COALESCE(department, '') AS department
|
||||
FROM sys_user
|
||||
WHERE username ILIKE :kw
|
||||
ORDER BY username
|
||||
LIMIT :lim
|
||||
"""
|
||||
)
|
||||
rows = db.execute(sql, {"kw": f"%{keyword.strip()}%", "lim": limit}).fetchall()
|
||||
else:
|
||||
sql = text(
|
||||
"""
|
||||
WHERE department = :dept
|
||||
"""
|
||||
params = {"dept": dept, "lim": limit}
|
||||
if keyword.strip():
|
||||
sql = text(base_sql + " AND username ILIKE :kw ORDER BY username LIMIT :lim")
|
||||
params["kw"] = f"%{keyword.strip()}%"
|
||||
else:
|
||||
sql = text(base_sql + " ORDER BY username LIMIT :lim")
|
||||
rows = db.execute(sql, params).fetchall()
|
||||
except Exception:
|
||||
# 降级:不使用 department 列过滤
|
||||
fallback_sql = """
|
||||
SELECT id, username,
|
||||
SPLIT_PART(username, '/', 1) AS full_name
|
||||
SPLIT_PART(username, '/', 1) AS full_name,
|
||||
'' AS department
|
||||
FROM sys_user
|
||||
ORDER BY username
|
||||
LIMIT :lim
|
||||
"""
|
||||
)
|
||||
rows = db.execute(sql, {"lim": limit}).fetchall()
|
||||
"""
|
||||
params = {"lim": limit}
|
||||
if keyword.strip():
|
||||
sql = text(fallback_sql + " WHERE username ILIKE :kw ORDER BY username LIMIT :lim")
|
||||
params["kw"] = f"%{keyword.strip()}%"
|
||||
else:
|
||||
sql = text(fallback_sql + " ORDER BY username LIMIT :lim")
|
||||
rows = db.execute(sql, params).fetchall()
|
||||
|
||||
return [
|
||||
UserOption(
|
||||
id=str(row.id),
|
||||
username=row.username.split("/")[-1] if "/" in row.username else row.username,
|
||||
full_name=row.full_name,
|
||||
department=row.department or "",
|
||||
)
|
||||
for row in rows
|
||||
]
|
||||
|
||||
@ -14,6 +14,7 @@ TASK_STATUS_WIP = "WIP" # 进行中
|
||||
TASK_STATUS_COMPLETED = "COMPLETED" # 已完成
|
||||
TASK_STATUS_REJECTED = "REJECTED" # 已驳回
|
||||
TASK_STATUS_ARCHIVED = "ARCHIVED" # 已入库
|
||||
TASK_STATUS_CANCELED = "CANCELED" # 已撤回/已作废
|
||||
|
||||
|
||||
class Task(Base):
|
||||
@ -69,6 +70,9 @@ class Task(Base):
|
||||
is_rework: Mapped[bool] = mapped_column(
|
||||
Boolean, default=False, comment="是否为返工任务",
|
||||
)
|
||||
task_type: Mapped[str | None] = mapped_column(
|
||||
String(20), nullable=True, comment="任务派生类型: TRANSFER/SPAWN/RECOVERY/null=历史数据",
|
||||
)
|
||||
remark: Mapped[str | None] = mapped_column(
|
||||
String(2000), nullable=True, comment="任务初始描述/交接备注",
|
||||
)
|
||||
|
||||
@ -131,6 +131,7 @@ class TaskResponse(BaseModel):
|
||||
status: str
|
||||
notify_parent_on_complete: bool
|
||||
is_rework: bool = False
|
||||
task_type: str | None = None
|
||||
remark: str | None = None
|
||||
reject_reason: str | None = None
|
||||
received_at: datetime | None = None
|
||||
|
||||
@ -15,11 +15,19 @@ from app.schemas.task import TaskSummaryResponse, TaskResponse, TaskRecordRespon
|
||||
|
||||
def _task_to_response(task: Task) -> TaskResponse:
|
||||
"""将 Task ORM 对象递归转为 TaskResponse(含子任务树)"""
|
||||
product_sn = ""
|
||||
product_material = ""
|
||||
try:
|
||||
if task.product:
|
||||
product_sn = task.product.serial_number or ""
|
||||
product_material = (task.product.material_name or task.product.material_id or "")
|
||||
except Exception:
|
||||
pass
|
||||
return TaskResponse(
|
||||
id=task.id,
|
||||
product_id=task.product_id,
|
||||
product_sn=task.product.serial_number if task.product else "",
|
||||
product_material=task.product.material_name or task.product.material_id or "" if task.product else "",
|
||||
product_sn=product_sn,
|
||||
product_material=product_material,
|
||||
parent_task_id=task.parent_task_id,
|
||||
task_name=task.task_name,
|
||||
assignee_id=task.assignee_id,
|
||||
|
||||
@ -2,11 +2,11 @@
|
||||
from __future__ import annotations
|
||||
import uuid
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import select, delete
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from app.models.task import Task, TaskRecord, TASK_STATUS_PENDING, TASK_STATUS_WIP, TASK_STATUS_COMPLETED, TASK_STATUS_REJECTED
|
||||
from app.models.task import Task, TaskRecord, TASK_STATUS_PENDING, TASK_STATUS_WIP, TASK_STATUS_COMPLETED, TASK_STATUS_REJECTED, TASK_STATUS_CANCELED, TASK_STATUS_ARCHIVED
|
||||
from app.core.time_utils import get_beijing_time
|
||||
from app.models.product import Product
|
||||
from app.models.task_log import TaskLog
|
||||
@ -91,19 +91,60 @@ async def _get_task_with_children_recursive(db: AsyncSession, task_id: uuid.UUID
|
||||
return task
|
||||
|
||||
|
||||
def _to_response(task: Task) -> TaskResponse:
|
||||
"""将 Task ORM 对象转为递归 TaskResponse"""
|
||||
def _to_flat_response(task: Task) -> TaskResponse:
|
||||
"""扁平序列化,不递归 children(避免 MissingGreenlet)"""
|
||||
product_sn = ""
|
||||
product_material = ""
|
||||
try:
|
||||
if task.product:
|
||||
product_sn = task.product.serial_number or ""
|
||||
product_material = (task.product.material_name or task.product.material_id or "")
|
||||
except Exception:
|
||||
pass
|
||||
return TaskResponse(
|
||||
id=task.id,
|
||||
product_id=task.product_id,
|
||||
product_sn=task.product.serial_number if task.product else "",
|
||||
product_material=task.product.material_name or task.product.material_id or "" if task.product else "",
|
||||
product_sn=product_sn,
|
||||
product_material=product_material,
|
||||
parent_task_id=task.parent_task_id,
|
||||
task_name=task.task_name,
|
||||
assignee_id=task.assignee_id,
|
||||
status=task.status,
|
||||
notify_parent_on_complete=task.notify_parent_on_complete,
|
||||
is_rework=task.is_rework,
|
||||
task_type=task.task_type,
|
||||
remark=task.remark,
|
||||
reject_reason=task.reject_reason,
|
||||
received_at=task.received_at,
|
||||
completed_at=task.completed_at,
|
||||
created_at=task.created_at,
|
||||
child_tasks=[],
|
||||
records=[TaskRecordResponse.model_validate(r) for r in (task.records or [])],
|
||||
)
|
||||
|
||||
|
||||
def _to_response(task: Task) -> TaskResponse:
|
||||
"""将 Task ORM 对象转为递归 TaskResponse"""
|
||||
product_sn = ""
|
||||
product_material = ""
|
||||
try:
|
||||
if task.product:
|
||||
product_sn = task.product.serial_number or ""
|
||||
product_material = (task.product.material_name or task.product.material_id or "")
|
||||
except Exception:
|
||||
pass
|
||||
return TaskResponse(
|
||||
id=task.id,
|
||||
product_id=task.product_id,
|
||||
product_sn=product_sn,
|
||||
product_material=product_material,
|
||||
parent_task_id=task.parent_task_id,
|
||||
task_name=task.task_name,
|
||||
assignee_id=task.assignee_id,
|
||||
status=task.status,
|
||||
notify_parent_on_complete=task.notify_parent_on_complete,
|
||||
is_rework=task.is_rework,
|
||||
task_type=task.task_type,
|
||||
remark=task.remark,
|
||||
reject_reason=task.reject_reason,
|
||||
received_at=task.received_at,
|
||||
@ -180,9 +221,20 @@ async def get_top_level_tasks(db: AsyncSession, product_id: uuid.UUID) -> list[T
|
||||
|
||||
|
||||
async def create_task(db: AsyncSession, data: TaskCreate) -> TaskResponse:
|
||||
"""创建任务"""
|
||||
"""创建任务,并同步产品宏观状态"""
|
||||
task = Task(**data.model_dump())
|
||||
db.add(task)
|
||||
|
||||
# 同步产品宏观状态 + 当前位置
|
||||
product_result = await db.execute(select(Product).where(Product.id == data.product_id))
|
||||
product = product_result.scalar_one_or_none()
|
||||
if product:
|
||||
if data.task_name:
|
||||
product.overall_status = "在库" if "virtual_warehouse" in data.task_name else data.task_name
|
||||
# 派发给人 → 产品离开仓库
|
||||
if data.assignee_id and data.assignee_id != VIRTUAL_WAREHOUSE:
|
||||
product.current_location_id = data.assignee_id
|
||||
|
||||
await db.commit()
|
||||
await db.refresh(task)
|
||||
return _to_response(task)
|
||||
@ -218,9 +270,9 @@ async def get_all_tasks(
|
||||
result = await db.execute(stmt)
|
||||
tasks = result.scalars().all()
|
||||
|
||||
# 返回所有匹配的任务(含子任务),不再过滤 parent_task_id
|
||||
all_tasks = [_to_response(t) for t in tasks]
|
||||
return TaskListResponse(tasks=all_tasks, total=len(all_tasks))
|
||||
# 返回扁平列表(不递归 children,避免 MissingGreenlet)
|
||||
flat_tasks = [_to_flat_response(t) for t in tasks]
|
||||
return TaskListResponse(tasks=flat_tasks, total=len(flat_tasks))
|
||||
|
||||
|
||||
# ============================================================
|
||||
@ -256,6 +308,57 @@ async def end_task(
|
||||
return _to_response(task)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 核心业务 0.3:撤回转交
|
||||
# ============================================================
|
||||
|
||||
async def recall_task(
|
||||
db: AsyncSession, task_id: uuid.UUID, operator_id: str | None = None
|
||||
) -> TaskResponse:
|
||||
"""撤回 PENDING 转交:标记为 CANCELED,以被撤回节点为父生成接力新任务给操作人。"""
|
||||
task = await _get_task_or_404(db, task_id)
|
||||
|
||||
if task.status != TASK_STATUS_PENDING:
|
||||
raise HTTPException(status_code=409, detail="只有待接收(PENDING)的任务可以撤回")
|
||||
|
||||
now = get_beijing_time()
|
||||
|
||||
# 1. 废掉当前待接收任务
|
||||
task.status = TASK_STATUS_CANCELED
|
||||
task.completed_at = now
|
||||
await _create_task_log(db, task_id, action_type="recall", operator_id=operator_id,
|
||||
remark=f"撤回转交「{task.task_name}」→ {task.assignee_id}")
|
||||
db.add(TaskRecord(task_id=task.id, remark=f"[撤回] 转交至 {task.assignee_id} 已撤回", images="[]"))
|
||||
|
||||
# 2. 生成接力新任务(以撤回节点为父,还给操作人)
|
||||
recovery = Task(
|
||||
product_id=task.product_id,
|
||||
parent_task_id=task.id,
|
||||
task_name=task.task_name,
|
||||
assignee_id=operator_id,
|
||||
status=TASK_STATUS_WIP,
|
||||
task_type="RECOVERY",
|
||||
notify_parent_on_complete=False,
|
||||
is_rework=False,
|
||||
remark=f"撤回「{task.task_name}」后重新接手",
|
||||
)
|
||||
db.add(recovery)
|
||||
await db.flush()
|
||||
await _create_task_log(db, recovery.id, action_type="create", operator_id=operator_id,
|
||||
remark=f"撤回接力:撤回「{task.task_name}」→ {task.assignee_id} 后重新指派给 {operator_id}")
|
||||
db.add(TaskRecord(task_id=recovery.id, remark=f"[重新接手] 撤回转交后系统自动生成接力节点", images="[]"))
|
||||
|
||||
# 3. 更新产品位置
|
||||
product_result = await db.execute(select(Product).where(Product.id == task.product_id))
|
||||
product = product_result.scalar_one_or_none()
|
||||
if product and operator_id:
|
||||
product.current_location_id = operator_id
|
||||
|
||||
await db.commit()
|
||||
await db.refresh(recovery)
|
||||
return _to_response(recovery)
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 核心业务 0.5:派发协助分支(不改变父任务状态)
|
||||
# ============================================================
|
||||
@ -277,6 +380,7 @@ async def spawn_subtask(
|
||||
task_name=data.task_name,
|
||||
assignee_id=data.assignee_id,
|
||||
status=TASK_STATUS_PENDING,
|
||||
task_type="SPAWN",
|
||||
notify_parent_on_complete=False,
|
||||
is_rework=False,
|
||||
remark=data.remark or None,
|
||||
@ -284,6 +388,9 @@ async def spawn_subtask(
|
||||
db.add(child)
|
||||
await db.flush()
|
||||
|
||||
# 协助分支不改变产品宏观状态(只有主分支影响 overall_status)
|
||||
db.add(TaskRecord(task_id=task.id, remark=data.remark or f"[派发协助] 分配给 {data.assignee_id}", images="[]"))
|
||||
|
||||
await _create_task_log(db, child.id, action_type="create", operator_id=operator_id,
|
||||
remark=f"协助分支(由「{task.task_name}」派发,分配给 {data.assignee_id})")
|
||||
await db.commit()
|
||||
@ -298,7 +405,7 @@ async def _check_children_done(db: AsyncSession, task_id: uuid.UUID):
|
||||
)
|
||||
children = result.scalars().all()
|
||||
incomplete = [c for c in children if c.status not in (
|
||||
TASK_STATUS_COMPLETED, TASK_STATUS_REJECTED, ARCHIVED_STATUS
|
||||
TASK_STATUS_COMPLETED, TASK_STATUS_REJECTED, TASK_STATUS_CANCELED, ARCHIVED_STATUS
|
||||
)]
|
||||
if incomplete:
|
||||
names = "、".join(c.task_name for c in incomplete)
|
||||
@ -318,13 +425,13 @@ ARCHIVED_STATUS = "ARCHIVED"
|
||||
|
||||
async def receive_task(
|
||||
db: AsyncSession, task_id: uuid.UUID, operator_id: str | None = None,
|
||||
remark: str | None = None,
|
||||
remark: str | None = None, task_name: str | None = None,
|
||||
) -> TaskResponse:
|
||||
"""
|
||||
操作员确认接收任务。
|
||||
操作员确认接收任务。工人选定工序名称后接收。
|
||||
|
||||
校验:只有状态为 PENDING 的任务可接收。
|
||||
动作:状态改为 WIP,记录 received_at,写入 remark。
|
||||
动作:状态改为 WIP,记录 received_at,更新 task_name,同步产品宏观状态。
|
||||
"""
|
||||
task = await _get_task_or_404(db, task_id)
|
||||
|
||||
@ -347,6 +454,8 @@ async def receive_task(
|
||||
task.received_at = now
|
||||
if remark:
|
||||
task.remark = remark
|
||||
if task_name:
|
||||
task.task_name = task_name
|
||||
|
||||
await _create_task_log(
|
||||
db, task_id,
|
||||
@ -354,6 +463,16 @@ async def receive_task(
|
||||
operator_id=operator_id,
|
||||
remark=remark or f"操作员确认接收任务「{task.task_name}」",
|
||||
)
|
||||
db.add(TaskRecord(task_id=task.id, remark=remark or f"[接收] 操作员已确认接收", images="[]"))
|
||||
|
||||
# 接收时同步产品位置到接收人 + 宏观状态同步
|
||||
product_result = await db.execute(select(Product).where(Product.id == task.product_id))
|
||||
product = product_result.scalar_one_or_none()
|
||||
if product:
|
||||
if task.assignee_id:
|
||||
product.current_location_id = task.assignee_id
|
||||
if task_name:
|
||||
product.overall_status = task_name
|
||||
|
||||
await db.commit()
|
||||
await db.refresh(task)
|
||||
@ -443,6 +562,7 @@ async def reject_task(
|
||||
task_name=task.task_name,
|
||||
assignee_id=rework_assignee_id,
|
||||
status=TASK_STATUS_PENDING,
|
||||
task_type="TRANSFER",
|
||||
notify_parent_on_complete=task.notify_parent_on_complete,
|
||||
is_rework=True,
|
||||
)
|
||||
@ -488,9 +608,6 @@ async def transfer_task(
|
||||
"""
|
||||
task = await _get_task_or_404(db, task_id)
|
||||
|
||||
# 校验:必须等待所有协助分支完成
|
||||
await _check_children_done(db, task_id)
|
||||
|
||||
# 校验:不能重复完成
|
||||
if task.status == TASK_STATUS_COMPLETED:
|
||||
raise HTTPException(
|
||||
@ -524,6 +641,7 @@ async def transfer_task(
|
||||
operator_id=operator_id,
|
||||
remark=request.note or f"完成任务「{task.task_name}」,转交至下一道工序",
|
||||
)
|
||||
db.add(TaskRecord(task_id=task.id, remark=request.note or f"[完工转交] 移交下一工序", images="[]"))
|
||||
|
||||
# --- 动作 2:解析下家 & 裂变 ---
|
||||
# 兼容新旧格式
|
||||
@ -553,7 +671,7 @@ async def transfer_task(
|
||||
elif is_child_task:
|
||||
new_parent_task_id = task.parent_task_id
|
||||
else:
|
||||
new_parent_task_id = None
|
||||
new_parent_task_id = task.id
|
||||
|
||||
new_task = Task(
|
||||
product_id=task.product_id,
|
||||
@ -561,6 +679,7 @@ async def transfer_task(
|
||||
task_name=task_name,
|
||||
assignee_id=assignee_id,
|
||||
status=TASK_STATUS_PENDING,
|
||||
task_type="TRANSFER",
|
||||
notify_parent_on_complete=False,
|
||||
is_rework=False,
|
||||
remark=request.note or None,
|
||||
@ -587,8 +706,10 @@ async def transfer_task(
|
||||
if product:
|
||||
if has_warehouse and not real_branches:
|
||||
product.current_location_id = VIRTUAL_WAREHOUSE
|
||||
product.overall_status = "在库"
|
||||
elif real_branches:
|
||||
product.current_location_id = real_branches[0][1]
|
||||
product.overall_status = real_branches[0][0]
|
||||
|
||||
await db.commit()
|
||||
|
||||
@ -599,7 +720,7 @@ async def transfer_task(
|
||||
await db.refresh(nt)
|
||||
created_task_responses.append(_to_response(nt))
|
||||
|
||||
assignee_list = ", ".join(real_assignees)
|
||||
assignee_list = ", ".join(a for _, a in real_branches) if real_branches else "仓库"
|
||||
location_info = ""
|
||||
if has_warehouse:
|
||||
location_info = ",产品已入库(virtual_warehouse)"
|
||||
|
||||
@ -284,6 +284,48 @@ export default function CreateProductDialog({ open, onClose, onCreated }: Props)
|
||||
};
|
||||
});
|
||||
|
||||
// ============================================================
|
||||
// 打印标签
|
||||
// ============================================================
|
||||
|
||||
function printCurrentQRCode() {
|
||||
const printArea = document.getElementById("label-print-area");
|
||||
if (!printArea) return;
|
||||
const printContent = printArea.innerHTML;
|
||||
|
||||
const styles = Array.from(document.querySelectorAll("style, link[rel=\"stylesheet\"]"))
|
||||
.map(el => el.outerHTML)
|
||||
.join("");
|
||||
|
||||
const iframe = document.createElement("iframe");
|
||||
iframe.style.position = "absolute";
|
||||
iframe.style.width = "0";
|
||||
iframe.style.height = "0";
|
||||
iframe.style.border = "none";
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
const doc = iframe.contentWindow!.document;
|
||||
doc.write(`
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title>打印标签</title>${styles}
|
||||
<style>
|
||||
@page { size: auto; margin: 0mm; }
|
||||
body { margin: 0; padding: 0; background: #fff; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
|
||||
</style>
|
||||
</head>
|
||||
<body><div style="width:100%;max-width:360px;margin:0 auto;padding:12px;box-sizing:border-box;background:#fff;font-family:monospace,'Helvetica Neue',sans-serif;">${printContent}</div></body>
|
||||
</html>
|
||||
`);
|
||||
doc.close();
|
||||
|
||||
iframe.contentWindow!.onload = () => {
|
||||
iframe.contentWindow!.focus();
|
||||
iframe.contentWindow!.print();
|
||||
setTimeout(() => { document.body.removeChild(iframe); }, 1000);
|
||||
};
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 渲染
|
||||
// ============================================================
|
||||
@ -299,23 +341,34 @@ export default function CreateProductDialog({ open, onClose, onCreated }: Props)
|
||||
>
|
||||
{createdSn ? (
|
||||
/* ---- 成功页 ---- */
|
||||
<div className="flex flex-col items-center py-6">
|
||||
<img
|
||||
src={`/api/v1/products/qrcode/${createdSn}`}
|
||||
alt={`QR-${createdSn}`}
|
||||
className="h-48 w-48 rounded-lg border"
|
||||
/>
|
||||
<p className="mt-3 font-mono text-lg font-bold tracking-widest text-gray-800">
|
||||
{createdSn}
|
||||
</p>
|
||||
<p className="mt-1 text-sm text-green-600">产品创建成功!</p>
|
||||
<Space className="mt-5">
|
||||
<Button onClick={() => window.open(`/api/v1/products/qrcode/${createdSn}`, "_blank")}>
|
||||
打开二维码
|
||||
</Button>
|
||||
<Button type="primary" onClick={() => setCreatedSn(null)}>
|
||||
继续创建
|
||||
</Button>
|
||||
<div className="py-4">
|
||||
<div id="label-print-area" style={{
|
||||
width: '100%', maxWidth: '360px', margin: '0 auto', padding: '12px',
|
||||
boxSizing: 'border-box', background: '#fff',
|
||||
fontFamily: 'monospace, "Helvetica Neue", Helvetica, sans-serif',
|
||||
border: '1px solid #e5e7eb'
|
||||
}}>
|
||||
<div style={{ width: '100%' }}>
|
||||
<div style={{ float: 'left', width: '110px', height: '110px', marginRight: '10px', marginBottom: '4px' }}>
|
||||
<img src={`/api/v1/products/qrcode/${createdSn}`} alt="QR"
|
||||
style={{ width: '100%', height: '100%', objectFit: 'contain', display: 'block' }} />
|
||||
</div>
|
||||
<div style={{ fontSize: '13px', fontWeight: 900, color: '#000', lineHeight: '1.4', wordBreak: 'break-all' }}>
|
||||
<div style={{ marginBottom: '4px' }}>名: {selected?.material_name ?? ""}</div>
|
||||
<div style={{ marginBottom: '4px' }}>规: {selected?.spec_model ?? ""}</div>
|
||||
<div style={{ marginBottom: '4px' }}>单: {orderNo || "—"}</div>
|
||||
</div>
|
||||
<div style={{ clear: 'both' }}></div>
|
||||
</div>
|
||||
<div style={{ width: '100%', marginTop: '8px', paddingTop: '8px', borderTop: '2px solid #000',
|
||||
textAlign: 'center', fontSize: '16px', fontWeight: 900, color: '#000', letterSpacing: '1px' }}>
|
||||
码: {createdSn}
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-2 text-center text-sm text-green-600">产品创建成功!</p>
|
||||
<Space className="mt-3 flex justify-center">
|
||||
<Button type="primary" onClick={printCurrentQRCode}>🖨️ 直接打印标签</Button>
|
||||
<Button onClick={() => setCreatedSn(null)}>继续创建</Button>
|
||||
</Space>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@ -13,13 +13,10 @@
|
||||
class="tree-movable-view"
|
||||
direction="all"
|
||||
:x="0" :y="0"
|
||||
:scale="true" :scale-min="0.5" :scale-max="2"
|
||||
:scale="true" :scale-min="0.3" :scale-max="2"
|
||||
:style="{ width: canvasWidth + 'px', height: canvasHeight + 'px' }"
|
||||
>
|
||||
<view class="canvas-inner">
|
||||
<!-- 连线层 -->
|
||||
<view v-for="line in treeLines" :key="line.key" class="canvas-line" :style="lineStyle(line)"></view>
|
||||
|
||||
<!-- 节点卡片层 -->
|
||||
<view v-for="node in treeNodes" :key="node.id"
|
||||
class="canvas-node" :class="statusColor(node.status)"
|
||||
@ -27,7 +24,7 @@
|
||||
@tap="node.records && node.records.length && $emit('viewRecords', node)">
|
||||
|
||||
<view class="cn-header">
|
||||
<text class="cn-name">{{ node.task_name }}</text>
|
||||
<text :class="node.parent_task_id ? 'badge-sub' : 'badge-main'">{{ node.parent_task_id ? branchLabelMap[node.id] || '分支' : '主分支' }}</text>
|
||||
<text :class="['cn-badge', statusColor(node.status)]">{{ statusLabel(node.status) }}</text>
|
||||
</view>
|
||||
|
||||
@ -60,80 +57,86 @@ export default {
|
||||
treeNodes() {
|
||||
if (!this.product || !this.product.task_tree) return [];
|
||||
|
||||
// 1. 拍平所有任务(无视后端的错误嵌套)
|
||||
const allTasks = [];
|
||||
const CARD_W = 320, CARD_H = 460, GAP_X = 80, GAP_Y = 120;
|
||||
const nodes = [];
|
||||
const rowMaxX = {};
|
||||
let currentMaxYIdx = -1;
|
||||
|
||||
const flatMap = {};
|
||||
const flatten = (tasks) => {
|
||||
if (!tasks) return;
|
||||
for (const t of tasks) { allTasks.push(t); flatten(t.child_tasks); }
|
||||
tasks.forEach(t => { flatMap[t.id] = t; flatten(t.child_tasks); });
|
||||
};
|
||||
flatten(this.product.task_tree);
|
||||
|
||||
// 2. 绝对时间轴排序(强制自上而下流转)
|
||||
allTasks.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime());
|
||||
const layoutNode = (t) => {
|
||||
if (t._visited) return;
|
||||
t._visited = true;
|
||||
|
||||
// 3. 智能分层(判定谁是同行裂变,谁是上下游)
|
||||
const levels = [];
|
||||
let currentLevel = [];
|
||||
let lastTime = null;
|
||||
|
||||
allTasks.forEach(t => {
|
||||
const tTime = new Date(t.created_at).getTime();
|
||||
if (lastTime === null) {
|
||||
currentLevel.push(t); lastTime = tTime;
|
||||
if (!t.parent_task_id) {
|
||||
// 规则A:根节点 → 新行 X=0
|
||||
currentMaxYIdx++;
|
||||
t._yIdx = currentMaxYIdx;
|
||||
t._xIdx = 0;
|
||||
} else {
|
||||
if (Math.abs(tTime - lastTime) < 2000 ||
|
||||
(t.parent_task_id && currentLevel.some(c => c.parent_task_id === t.parent_task_id))) {
|
||||
currentLevel.push(t);
|
||||
} else {
|
||||
levels.push(currentLevel);
|
||||
currentLevel = [t]; lastTime = tTime;
|
||||
const parent = flatMap[t.parent_task_id];
|
||||
if (parent && !parent._visited) layoutNode(parent);
|
||||
|
||||
const type = t.task_type || (parent && parent.status === 'CANCELED' ? 'RECOVERY' : 'SPAWN');
|
||||
|
||||
if (type === 'SPAWN') {
|
||||
t._yIdx = parent._yIdx;
|
||||
t._xIdx = (rowMaxX[t._yIdx] !== undefined ? rowMaxX[t._yIdx] : 0) + 1;
|
||||
} else if (type === 'TRANSFER' || type === 'MAIN') {
|
||||
currentMaxYIdx++;
|
||||
t._yIdx = currentMaxYIdx;
|
||||
t._xIdx = 0;
|
||||
} else if (type === 'RECOVERY') {
|
||||
currentMaxYIdx++;
|
||||
t._yIdx = currentMaxYIdx;
|
||||
t._xIdx = parent._xIdx;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (currentLevel.length > 0) levels.push(currentLevel);
|
||||
|
||||
// 4. 计算 X, Y 坐标
|
||||
const CARD_W = 240, CARD_H = 140, GAP_X = 60, GAP_Y = 80;
|
||||
const nodes = [];
|
||||
nodes._lines = [];
|
||||
rowMaxX[t._yIdx] = Math.max(rowMaxX[t._yIdx] || 0, t._xIdx);
|
||||
t.x = 40 + t._xIdx * (CARD_W + GAP_X);
|
||||
t.y = 20 + t._yIdx * (CARD_H + GAP_Y);
|
||||
nodes.push(t);
|
||||
|
||||
let maxCards = Math.max(...levels.map(l => l.length));
|
||||
const CENTER_X = (maxCards * CARD_W + (maxCards - 1) * GAP_X) / 2 + 60;
|
||||
if (t.child_tasks && t.child_tasks.length) {
|
||||
t.child_tasks
|
||||
.sort((a, b) => (a.task_type === 'TRANSFER' ? -1 : 1))
|
||||
.forEach(child => layoutNode(child));
|
||||
}
|
||||
};
|
||||
|
||||
levels.forEach((lvlTasks, depth) => {
|
||||
const y = 40 + depth * (CARD_H + GAP_Y);
|
||||
const lvlWidth = lvlTasks.length * CARD_W + (lvlTasks.length - 1) * GAP_X;
|
||||
const startX = CENTER_X - lvlWidth / 2;
|
||||
lvlTasks.forEach((t, i) => {
|
||||
nodes.push({ ...t, x: startX + i * (CARD_W + GAP_X), y, _depth: depth });
|
||||
});
|
||||
});
|
||||
|
||||
// 5. 智能连线生成
|
||||
for (let d = 1; d < levels.length; d++) {
|
||||
const curLvl = levels[d];
|
||||
const prevLvl = levels[d - 1];
|
||||
curLvl.forEach(curr => {
|
||||
const currNode = nodes.find(n => n.id === curr.id);
|
||||
let parents = [];
|
||||
if (curr.parent_task_id) {
|
||||
parents = nodes.filter(n => n.id === curr.parent_task_id);
|
||||
}
|
||||
if (parents.length === 0) {
|
||||
parents = prevLvl.map(p => nodes.find(n => n.id === p.id));
|
||||
}
|
||||
parents.forEach(p => {
|
||||
nodes._lines.push({
|
||||
key: p.id + '-' + curr.id,
|
||||
x1: p.x + CARD_W / 2, y1: p.y + CARD_H,
|
||||
x2: currNode.x + CARD_W / 2, y2: currNode.y
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
this.product.task_tree.forEach(root => layoutNode(root));
|
||||
return nodes;
|
||||
},
|
||||
treeLines() { return this.treeNodes._lines || []; },
|
||||
branchLabelMap() {
|
||||
const map = {};
|
||||
if (!this.product || !this.product.task_tree) return map;
|
||||
const traverse = (tasks, prefix) => {
|
||||
if (!tasks) return;
|
||||
let spawnIndex = 0;
|
||||
tasks.forEach((t) => {
|
||||
if (t.task_type !== 'SPAWN') {
|
||||
map[t.id] = '主分支';
|
||||
traverse(t.child_tasks, prefix);
|
||||
} else {
|
||||
spawnIndex++;
|
||||
const num = prefix ? `${prefix}.${spawnIndex}` : `${spawnIndex}`;
|
||||
map[t.id] = `分支 ${num}`;
|
||||
traverse(t.child_tasks, num);
|
||||
}
|
||||
});
|
||||
};
|
||||
this.product.task_tree.forEach((t) => {
|
||||
map[t.id] = '主分支';
|
||||
traverse(t.child_tasks, '');
|
||||
});
|
||||
return map;
|
||||
},
|
||||
canvasWidth() { if (!this.treeNodes.length) return 400; return Math.max(800, Math.max(...this.treeNodes.map(n => n.x)) + 300); },
|
||||
canvasHeight() { if (!this.treeNodes.length) return 400; return Math.max(800, Math.max(...this.treeNodes.map(n => n.y)) + 300); }
|
||||
},
|
||||
@ -153,8 +156,8 @@ export default {
|
||||
const angle = Math.atan2(dy, dx) * 180 / Math.PI;
|
||||
return { left: line.x1 + 'px', top: line.y1 + 'px', width: len + 'px', transform: `rotate(${angle}deg)`, transformOrigin: '0 0' };
|
||||
},
|
||||
statusLabel(s) { const map = { PENDING: "待接收", WIP: "进行中", COMPLETED: "已完成", REJECTED: "已驳回", ARCHIVED: "已入库" }; return map[s] || s; },
|
||||
statusColor(s) { switch (s) { case "PENDING": return "s-yellow"; case "WIP": return "s-blue"; case "COMPLETED": return "s-green"; case "REJECTED": return "s-red"; default: return "s-gray"; } }
|
||||
statusLabel(s) { const map = { PENDING: "待接收", WIP: "进行中", COMPLETED: "已完成", REJECTED: "已驳回", ARCHIVED: "已入库", CANCELED: "已撤回" }; return map[s] || s; },
|
||||
statusColor(s) { switch (s) { case "PENDING": return "s-yellow"; case "WIP": return "s-blue"; case "COMPLETED": return "s-green"; case "REJECTED": return "s-red"; case "CANCELED": return "s-canceled"; default: return "s-gray"; } }
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@ -165,26 +168,29 @@ export default {
|
||||
.zero-icon { font-size: 40px; margin-bottom: 10px; }
|
||||
.zero-text { font-size: 14px; color: #9ca3af; }
|
||||
.canvas-hint { font-size: 11px; color: #9ca3af; text-align: center; padding: 8px 0; background: #fff; border-bottom: 1px solid #e5e7eb; flex-shrink: 0; }
|
||||
.tree-movable-area { flex: 1; width: 100%; }
|
||||
.tree-movable-area { flex: 1; width: 100%; background-color: #f8fafc; background-image: linear-gradient(#e5e7eb 1px, transparent 1px), linear-gradient(90deg, #e5e7eb 1px, transparent 1px); background-size: 20px 20px; }
|
||||
.canvas-inner { position: absolute; left: 0; top: 0; }
|
||||
.canvas-node { position: absolute; width: 240px; min-height: 120px; background: #ffffff; border-radius: 12px; padding: 16px; box-shadow: 0 6px 16px rgba(0,0,0,0.06); border-left: 8px solid #3b82f6; border-top: none; z-index: 10; display: flex; flex-direction: column; gap: 8px; }
|
||||
.canvas-node { position: absolute; width: 320px; min-height: 460px; background: #ffffff; border-radius: 20px; padding: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.10), 0 4px 8px rgba(0,0,0,0.06); border-left: 12px solid #3b82f6; z-index: 10; display: flex; flex-direction: column; gap: 10px; }
|
||||
.canvas-node.s-yellow { border-left-color: #f59e0b; }
|
||||
.canvas-node.s-blue { border-left-color: #3b82f6; }
|
||||
.canvas-node.s-green { border-left-color: #22c55e; }
|
||||
.canvas-node.s-red { border-left-color: #ef4444; }
|
||||
.canvas-node.s-canceled { border-left-color: #9ca3af; opacity: 0.5; filter: grayscale(0.6); }
|
||||
.cn-header { display: flex; align-items: center; justify-content: space-between; }
|
||||
.cn-name { font-size: 16px; font-weight: 800; color: #1f2937; }
|
||||
.cn-badge { font-size: 11px; padding: 2px 8px; border-radius: 8px; font-weight: 700; }
|
||||
.badge-main { font-size: 10px; padding: 2px 8px; border-radius: 6px; background: #2563eb; color: #fff; font-weight: 700; }
|
||||
.badge-sub { font-size: 10px; padding: 2px 8px; border-radius: 6px; background: #ede9fe; color: #7c3aed; font-weight: 700; }
|
||||
.cn-name { font-size: 24px; font-weight: 800; color: #1f2937; }
|
||||
.cn-badge { font-size: 14px; padding: 4px 12px; border-radius: 8px; font-weight: 700; }
|
||||
.cn-badge.s-yellow { background: #fef3c7; color: #b45309; }
|
||||
.cn-badge.s-blue { background: #dbeafe; color: #1d4ed8; }
|
||||
.cn-badge.s-green { background: #dcfce7; color: #15803d; }
|
||||
.cn-badge.s-red { background: #fce4ec; color: #be123c; }
|
||||
.cn-assignee { font-size: 13px; color: #6b7280; font-weight: 500; }
|
||||
.tag-rework { font-size: 11px; color: #fff; background: #ef4444; padding: 2px 6px; border-radius: 6px; display: inline-block; width: max-content; }
|
||||
.cn-remark { font-size: 12px; color: #a16207; background: #fefce8; padding: 6px 10px; border-radius: 6px; border: 1px solid #fef08a; line-height: 1.4; word-break: break-all; }
|
||||
.cn-footer { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 10px; border-top: 1px dashed #e5e7eb; }
|
||||
.cn-end { font-size: 11px; font-weight: 700; color: #16a34a; }
|
||||
.cn-assignee { font-size: 16px; color: #6b7280; font-weight: 500; margin-top: 10px; }
|
||||
.tag-rework { font-size: 13px; color: #fff; background: #ef4444; padding: 4px 10px; border-radius: 6px; display: inline-block; width: max-content; }
|
||||
.cn-remark { font-size: 16px; color: #a16207; background: #fefce8; padding: 16px; border-radius: 8px; border: 1px solid #fef08a; line-height: 1.5; word-break: break-all; min-height: 100px; white-space: normal; margin-top: 16px; }
|
||||
.cn-footer { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 14px; border-top: 1px dashed #e5e7eb; }
|
||||
.cn-end { font-size: 13px; font-weight: 700; color: #16a34a; }
|
||||
.cn-end-wh { color: #7c3aed; }
|
||||
.cn-records { font-size: 12px; color: #2563eb; font-weight: 700; background: #eff6ff; padding: 2px 8px; border-radius: 12px; }
|
||||
.canvas-line { position: absolute; height: 3px; background: #cbd5e1; z-index: 1; transform-origin: 0 0; }
|
||||
.cn-records { font-size: 14px; color: #2563eb; font-weight: 700; background: #eff6ff; padding: 4px 12px; border-radius: 12px; }
|
||||
.canvas-line { position: absolute; height: 3px; background: #94a3b8; z-index: 1; transform-origin: 0 0; }
|
||||
</style>
|
||||
|
||||
@ -23,7 +23,9 @@
|
||||
<view v-for="t in focusTasks" :key="t.id" class="task-list-item"
|
||||
:class="statusColor(t.status)" @tap="lockTask(t.id)">
|
||||
<view class="tli-left">
|
||||
<text class="tag-branch">{{ branchLabelsMap[t.id] || '' }}</text>
|
||||
<text class="tli-name">{{ t.task_name }}</text>
|
||||
<text class="tli-assignee">→ {{ t.assignee_id || '未分配' }}</text>
|
||||
<text v-if="getTaskRemark(t)" class="tli-remark">{{ getTaskRemark(t) }}</text>
|
||||
</view>
|
||||
<view class="tli-right">
|
||||
@ -44,8 +46,11 @@
|
||||
|
||||
<view class="focus-card" :class="statusColor(lockedTask.status)">
|
||||
<view class="fc-header">
|
||||
<text class="tag-branch">{{ branchLabelsMap[lockedTask.id] || '' }}</text>
|
||||
<text class="fc-status">{{ statusLabel(lockedTask.status) }}</text>
|
||||
<text v-if="lockedTask.is_rework" class="tag tag-rework-sm">⚠返工</text>
|
||||
<text v-if="lockedTask.parent_task_id && lockedTask.status === 'WIP'" class="sub-branch-end"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'end' })">🛑 结束协助</text>
|
||||
</view>
|
||||
<text class="fc-name">{{ lockedTask.task_name }}</text>
|
||||
|
||||
@ -73,26 +78,31 @@
|
||||
<view class="fc-time">{{ formatTaskTime(lockedTask) }}</view>
|
||||
</view>
|
||||
|
||||
<view class="footer-actions">
|
||||
<view v-if="isAssignee" class="footer-actions">
|
||||
<button v-if="lockedTask.status === 'WIP'" class="footer-btn footer-transfer"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'transfer' })">🔄 完工转交</button>
|
||||
@tap="$emit('action', { task: lockedTask, type: 'transfer' })"><text class="btn-icon">🔄</text><text class="btn-txt">完工转交</text></button>
|
||||
<button v-if="lockedTask.status === 'WIP'" class="footer-btn footer-record"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'record' })">📝 记录/拍照</button>
|
||||
@tap="$emit('action', { task: lockedTask, type: 'record' })"><text class="btn-icon">📝</text><text class="btn-txt">记录拍照</text></button>
|
||||
<button v-if="lockedTask.status === 'WIP'" class="footer-btn footer-spawn"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'spawn' })">➕ 派发协助分支</button>
|
||||
<button v-if="lockedTask.status === 'WIP'" class="footer-btn footer-end"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'end' })">🏁 结束分支</button>
|
||||
@tap="$emit('action', { task: lockedTask, type: 'spawn' })"><text class="btn-icon">➕</text><text class="btn-txt">派发协助</text></button>
|
||||
<button v-if="lockedTask.status === 'PENDING'" class="footer-btn footer-receive"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'receive' })">✅ 接收任务</button>
|
||||
@tap="$emit('action', { task: lockedTask, type: 'receive' })"><text class="btn-icon">✅</text><text class="btn-txt">接收任务</text></button>
|
||||
<button v-if="lockedTask.status === 'PENDING'" class="footer-btn footer-reject"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'reject' })">❌ 驳回任务</button>
|
||||
@tap="$emit('action', { task: lockedTask, type: 'reject' })"><text class="btn-icon">❌</text><text class="btn-txt">驳回任务</text></button>
|
||||
</view>
|
||||
<view v-else-if="lockedTask.status === 'PENDING' && canRecall" class="footer-actions">
|
||||
<button class="footer-btn footer-recall"
|
||||
@tap="$emit('action', { task: lockedTask, type: 'recall' })"><text class="btn-icon">🔄</text><text class="btn-txt">撤回转交</text></button>
|
||||
</view>
|
||||
<view v-else class="footer-actions footer-readonly">
|
||||
<text class="readonly-hint">🔒 非当前任务指派人,仅可查看</text>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const STATUS_MAP = { PENDING: "待接收", WIP: "进行中", COMPLETED: "已完成", REJECTED: "已驳回", ARCHIVED: "已入库" };
|
||||
const STATUS_MAP = { PENDING: "待接收", WIP: "进行中", COMPLETED: "已完成", REJECTED: "已驳回", ARCHIVED: "已入库", CANCELED: "已撤回" };
|
||||
|
||||
export default {
|
||||
name: "WorkspaceArea",
|
||||
@ -117,15 +127,54 @@ export default {
|
||||
const walk = (tasks) => {
|
||||
if (!tasks) return;
|
||||
for (const t of tasks) {
|
||||
const isMine = t.status === 'WIP' || t.status === 'PENDING';
|
||||
if (isMine && (t.assignee_id == this.currentUserId || t.assignee_id == this.currentUsername)) result.push(t);
|
||||
if (t.status === 'WIP' || t.status === 'PENDING') result.push(t);
|
||||
walk(t.child_tasks);
|
||||
}
|
||||
};
|
||||
if (this.product) walk(this.product.task_tree);
|
||||
result.sort((a, b) => {
|
||||
const aIsMain = !a.parent_task_id || a.task_type !== 'SPAWN';
|
||||
const bIsMain = !b.parent_task_id || b.task_type !== 'SPAWN';
|
||||
if (aIsMain && !bIsMain) return -1;
|
||||
if (!aIsMain && bIsMain) return 1;
|
||||
return new Date(a.created_at) - new Date(b.created_at);
|
||||
});
|
||||
return result;
|
||||
},
|
||||
lockedTask() { return this.focusTasks.find(t => t.id === this.lockedTaskId) || null; },
|
||||
isAssignee() { if (!this.lockedTask) return false; return this.lockedTask.assignee_id == this.currentUserId || this.lockedTask.assignee_id == this.currentUsername; },
|
||||
canRecall() {
|
||||
if (!this.lockedTask || this.lockedTask.status !== 'PENDING') return false;
|
||||
if (this.isAssignee) return false;
|
||||
if (!this.lockedTask.parent_task_id) return false;
|
||||
const parent = this.taskMap[this.lockedTask.parent_task_id];
|
||||
if (!parent) return false;
|
||||
return parent.assignee_id == this.currentUserId || parent.assignee_id == this.currentUsername;
|
||||
},
|
||||
branchLabelsMap() {
|
||||
const map = {};
|
||||
if (!this.product || !this.product.task_tree) return map;
|
||||
const traverse = (tasks, prefix) => {
|
||||
if (!tasks) return;
|
||||
let spawnIndex = 0;
|
||||
tasks.forEach((t) => {
|
||||
if (t.task_type !== 'SPAWN') {
|
||||
map[t.id] = '主分支';
|
||||
traverse(t.child_tasks, prefix);
|
||||
} else {
|
||||
spawnIndex++;
|
||||
const num = prefix ? `${prefix}.${spawnIndex}` : `${spawnIndex}`;
|
||||
map[t.id] = `分支 ${num}`;
|
||||
traverse(t.child_tasks, num);
|
||||
}
|
||||
});
|
||||
};
|
||||
this.product.task_tree.forEach((t) => {
|
||||
map[t.id] = '主分支';
|
||||
traverse(t.child_tasks, '');
|
||||
});
|
||||
return map;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
statusLabel(s) { return STATUS_MAP[s] || s; },
|
||||
@ -150,7 +199,9 @@ export default {
|
||||
.task-list-item.s-yellow { border-left-color: #f59e0b; }
|
||||
.task-list-item.s-blue { border-left-color: #3b82f6; }
|
||||
.tli-left { flex: 1; min-width: 0; }
|
||||
.tag-branch { font-size: 10px; padding: 2px 8px; border-radius: 6px; background: #ede9fe; color: #7c3aed; font-weight: 700; display: inline-block; width: max-content; margin-bottom: 4px; }
|
||||
.tli-name { font-size: 15px; font-weight: 700; color: #1f2937; display: block; }
|
||||
.tli-assignee { font-size: 11px; color: #9ca3af; display: block; margin-top: 2px; }
|
||||
.tli-remark { font-size: 12px; color: #a16207; font-weight: bold; margin-top: 4px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tli-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; margin-left: 8px; }
|
||||
.tli-badge { font-size: 11px; padding: 2px 10px; border-radius: 12px; font-weight: 600; }
|
||||
@ -172,6 +223,7 @@ export default {
|
||||
.s-yellow .fc-status { background: #fef3c7; color: #b45309; }
|
||||
.s-blue .fc-status { background: #dbeafe; color: #1d4ed8; }
|
||||
.tag-rework-sm { font-size: 10px; padding: 2px 6px; border-radius: 8px; background: #ef4444; color: #fff; }
|
||||
.sub-branch-end { font-size: 11px; color: #ef4444; font-weight: 600; margin-left: auto; padding: 2px 6px; }
|
||||
.fc-name { font-size: 22px; font-weight: 800; color: #1f2937; display: block; margin-bottom: 10px; }
|
||||
.fc-link { padding: 6px 10px; border-radius: 8px; margin-bottom: 4px; font-size: 12px; margin-top: 10px; }
|
||||
.fc-up { background: #f0fdf4; color: #16a34a; }
|
||||
@ -183,13 +235,18 @@ export default {
|
||||
.zero-task { display: flex; flex-direction: column; align-items: center; padding: 24px 0; }
|
||||
.zero-icon { font-size: 40px; margin-bottom: 8px; }
|
||||
.zero-text { font-size: 14px; color: #9ca3af; }
|
||||
.footer-actions { display: flex; gap: 20rpx; padding: 20rpx 30rpx; padding-bottom: calc(20rpx + env(safe-area-inset-bottom)); background: #ffffff; box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05); flex-shrink: 0; }
|
||||
.footer-btn { flex: 1; height: 88rpx; border: none; border-radius: 12rpx; font-size: 30rpx; font-weight: 700; line-height: 88rpx; }
|
||||
.footer-actions { display: flex; gap: 12rpx; padding: 16rpx 20rpx; padding-bottom: calc(16rpx + env(safe-area-inset-bottom)); background: #ffffff; box-shadow: 0 -2rpx 10rpx rgba(0,0,0,0.05); flex-shrink: 0; }
|
||||
.footer-btn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100rpx; border: none; border-radius: 16rpx; line-height: 1.2; padding: 0; }
|
||||
.footer-btn::after { border: none; }
|
||||
.btn-icon { font-size: 36rpx; margin-bottom: 6rpx; }
|
||||
.btn-txt { font-size: 24rpx; font-weight: 700; }
|
||||
.footer-readonly { justify-content: center; background: #fef2f2; }
|
||||
.readonly-hint { font-size: 24rpx; color: #dc2626; font-weight: 600; }
|
||||
.footer-transfer { background: #dcfce7; color: #16a34a; }
|
||||
.footer-record { background: #eff6ff; color: #2563eb; }
|
||||
.footer-receive { background: #dbeafe; color: #1d4ed8; }
|
||||
.footer-reject { background: #fce4ec; color: #dc2626; }
|
||||
.footer-end { background: #fef3c7; color: #b45309; }
|
||||
.footer-spawn { background: #ede9fe; color: #7c3aed; }
|
||||
.footer-recall { background: #fef2f2; color: #dc2626; }
|
||||
</style>
|
||||
|
||||
@ -4,10 +4,10 @@
|
||||
<view v-if="error" class="error-box">{{ error }}</view>
|
||||
|
||||
<template v-if="product && !loading">
|
||||
<view class="overall-bar" @tap="showStatusPicker = true">
|
||||
<view class="overall-bar" @tap="handleOverallBarClick">
|
||||
<text class="overall-label">宏观状态</text>
|
||||
<text :class="['overall-val', product.overall_status ? '' : 'overall-empty']">{{ product.overall_status || '点击设定' }}</text>
|
||||
<text class="overall-arrow">▾</text>
|
||||
<text :class="['overall-val', product.overall_status ? '' : 'overall-empty']">{{ product.overall_status || '未激活 — 点击发起首道工序' }}</text>
|
||||
<text v-if="product.task_tree && product.task_tree.length" class="overall-arrow">▾</text>
|
||||
</view>
|
||||
|
||||
<view class="card">
|
||||
@ -20,7 +20,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="info-grid">
|
||||
<view class="info-item"><text class="label">序列号</text><text class="value sn">{{ product.serial_number }}</text></view>
|
||||
<view class="info-item"><text class="label">身份证</text><text class="value sn">{{ product.serial_number }}</text></view>
|
||||
<view class="info-item"><text class="label">物料名称</text><text class="value">{{ product.material_name || product.material_id || '—' }}</text></view>
|
||||
<view class="info-item"><text class="label">规格型号</text><text class="value">{{ product.spec_model || '—' }}</text></view>
|
||||
<view class="info-item"><text class="label">订单编号</text><text class="value">{{ product.order_no || '—' }}</text></view>
|
||||
@ -31,6 +31,13 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 📤 仓库转出横幅(当前用户有活跃任务时隐藏) -->
|
||||
<view v-if="product && product.current_location_id === 'virtual_warehouse' && !hasMyActiveTask"
|
||||
class="warehouse-transfer-banner" @tap="openWarehouseTransfer">
|
||||
<text class="wt-icon">📤</text>
|
||||
<text class="wt-text">该产品在仓库中 — 点击此处转出并派发给指定人员</text>
|
||||
</view>
|
||||
|
||||
<WorkspaceArea v-if="currentMode === 'workspace'" :product="product"
|
||||
:currentUserId="currentUserId" :currentUsername="currentUsername"
|
||||
@action="handleTaskAction" @viewRecords="handleViewRecords" />
|
||||
@ -53,23 +60,26 @@
|
||||
<view v-if="editProductVisible" class="overlay" @tap="editProductVisible = false">
|
||||
<view class="popup" @tap.stop>
|
||||
<text class="popup-title">编辑产品</text>
|
||||
<input v-model="editForm.order_no" class="popup-input" placeholder="订单编号" />
|
||||
<input v-model="editForm.external_serial" class="popup-input" placeholder="外部序列号" />
|
||||
<view class="field-label">订单编号</view>
|
||||
<input v-model="editForm.order_no" class="popup-input" placeholder="请输入订单编号" />
|
||||
<view class="field-label" style="margin-top:10px;">产品序列号</view>
|
||||
<input v-model="editForm.external_serial" class="popup-input" placeholder="请输入产品序列号" />
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="editProductVisible = false">取消</button><button class="btn-primary" :disabled="editSaving" @tap="doEditProduct">{{ editSaving ? '保存中...' : '保存' }}</button></view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 发起首道工序 -->
|
||||
<!-- 发起首道工序 (只选人+填备注) -->
|
||||
<view v-if="createFirstVisible" class="overlay" @tap="createFirstVisible = false">
|
||||
<view class="popup" @tap.stop>
|
||||
<text class="popup-title">🚀 发起首道工序</text>
|
||||
<view class="field-label">工序名称 <text class="required">*</text></view>
|
||||
<picker :range="TASK_NAME_OPTIONS" :value="firstForm.taskNameIdx" @change="onTaskNameChange"><view class="picker-box">{{ firstForm.task_name || '请选择工序名称' }}</view></picker>
|
||||
<text class="popup-title">{{ isWarehouseTransfer ? '📤 仓库转出派发' : '🚀 发起首道工序' }}</text>
|
||||
<view class="field-label">接收人 <text class="required">*</text></view>
|
||||
<picker :range="userLabels" :value="firstForm.assigneeIdx" @change="onAssigneeChange"><view class="picker-box">{{ firstForm.assigneeLabel || '请选择接收人' }}</view></picker>
|
||||
<view class="field-label">备注 <text class="required">*</text></view>
|
||||
<view class="user-grid">
|
||||
<view v-for="u in userGridOptions" :key="u.id"
|
||||
:class="['user-grid-item', firstForm.assignee_id === u.id ? 'user-grid-active' : '']"
|
||||
@tap="firstForm.assignee_id = u.id; firstForm.assigneeLabel = u.name">{{ formatName(u.name) }}</view>
|
||||
</view>
|
||||
<view class="field-label" style="margin-top:12px;">备注 <text class="required">*</text></view>
|
||||
<textarea v-model="firstForm.note" class="popup-textarea" placeholder="请填写备注说明(必填)" :maxlength="500" />
|
||||
<label class="switch-row" @tap="firstForm.autoReceive = !firstForm.autoReceive"><text class="switch-label">⚡ 立即接收并开始计时</text><switch :checked="firstForm.autoReceive" color="#2563EB" style="transform:scale(0.8)" /></label>
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="createFirstVisible = false">取消</button><button class="btn-primary" :disabled="firstSaving || !firstForm.task_name || !firstForm.assignee_id || !firstForm.note.trim()" @tap="doCreateFirstTask">{{ firstSaving ? '创建中...' : (firstForm.autoReceive ? '创建并接收' : '确认创建') }}</button></view>
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="createFirstVisible = false">取消</button><button class="btn-primary" :disabled="firstSaving || !firstForm.assignee_id || !firstForm.note.trim()" @tap="doCreateFirstTask">{{ firstSaving ? '创建中...' : '确认创建' }}</button></view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 记录/拍照 -->
|
||||
@ -93,8 +103,14 @@
|
||||
<text class="popup-title">确认接收任务</text>
|
||||
<view class="popup-task">{{ actionPopup.task && actionPopup.task.task_name }}</view>
|
||||
<text class="popup-hint">状态: {{ statusLabel(actionPopup.task && actionPopup.task.status) }} → 进行中</text>
|
||||
<textarea v-model="receiveRemark" class="popup-textarea" placeholder="接收备注(选填)" :maxlength="500" />
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary" :disabled="actionLoading" @tap="doReceive">确认接收</button></view>
|
||||
<view class="field-label">选择工序 <text class="required">*</text></view>
|
||||
<view class="user-grid">
|
||||
<view v-for="opt in TASK_NAME_OPTIONS" :key="opt"
|
||||
:class="['user-grid-item', receiveTaskName === opt ? 'user-grid-active' : '']"
|
||||
@tap="receiveTaskName = opt">{{ opt }}</view>
|
||||
</view>
|
||||
<textarea v-model="receiveRemark" class="popup-textarea" placeholder="接收备注(选填)" :maxlength="500" style="margin-top:12px;" />
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary" :disabled="actionLoading || !receiveTaskName" @tap="doReceive">确认接收</button></view>
|
||||
</template>
|
||||
<template v-if="actionPopup.type === 'reject'">
|
||||
<text class="popup-title">品质驳回</text>
|
||||
@ -104,20 +120,31 @@
|
||||
</template>
|
||||
<template v-if="actionPopup.type === 'transfer'">
|
||||
<text class="popup-title">完工转交</text>
|
||||
<view class="form-item"><text class="form-label">下一道工序 <text class="required">*</text></text><picker mode="selector" :range="processOptions" @change="onTransferProcessChange"><view class="picker-value"><text :class="transferForm.next_task_name ? '' : 'picker-placeholder'">{{ transferForm.next_task_name || '请选择工序' }}</text><text class="picker-arrow">▾</text></view></picker></view>
|
||||
<view v-if="!transferForm.isWarehouse" class="form-item"><text class="form-label">接收人 <text class="required">*</text></text><picker mode="selector" :range="userOptions" range-key="name" @change="onTransferUserChange"><view class="picker-value"><text :class="transferUserName ? '' : 'picker-placeholder'">{{ transferUserName || '请选择接收人' }}</text><text class="picker-arrow">▾</text></view></picker></view>
|
||||
<view v-if="transferForm.isWarehouse" class="warehouse-hint">📦 入库 — 直接归档,无需指定接收人</view>
|
||||
<input v-model="transferForm.note" class="popup-input" placeholder="交接备注(选填)" style="margin-top:12px;" />
|
||||
<view v-if="transferForm.next_task_name" class="preview-hint">{{ transferForm.isWarehouse ? '产品将入库并从个人待办中移除' : '将创建 1 个「' + transferForm.next_task_name + '」任务指派给 ' + (transferUserName || '—') }}</view>
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary" :disabled="actionLoading || !transferForm.next_task_name || (!transferForm.isWarehouse && !transferForm.selectedUserId)" @tap="doTransfer">{{ actionLoading ? '提交中...' : (transferForm.isWarehouse ? '📦 确认入库' : '确认转交') }}</button></view>
|
||||
<view class="field-label">接收人 <text class="required">*</text></view>
|
||||
<view class="user-grid">
|
||||
<view v-for="u in userGridOptions" :key="u.id"
|
||||
:class="['user-grid-item', transferForm.selectedUserId === u.id ? 'user-grid-active' : '']"
|
||||
@tap="selectTransferUser(u.id)">{{ formatName(u.name) }}</view>
|
||||
</view>
|
||||
<view class="field-label" style="margin-top:12px;">或</view>
|
||||
<view :class="['user-grid-item', transferForm.isWarehouse ? 'user-grid-active' : '']" style="width:100%;" @tap="toggleWarehouse">📦 入库 (virtual_warehouse)</view>
|
||||
<view class="field-label" style="margin-top:12px;">交接备注 <text class="required">*</text></view>
|
||||
<textarea v-model="transferForm.note" class="popup-textarea" placeholder="请填写交接备注(必填)" :maxlength="500" />
|
||||
<view v-if="transferForm.isWarehouse || transferForm.selectedUserId" class="preview-hint">{{ transferForm.isWarehouse ? '产品将入库并从个人待办中移除' : '将创建新任务指派给 ' + (transferUserName || '—') }}</view>
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary" :disabled="actionLoading || (!transferForm.isWarehouse && !transferForm.selectedUserId) || !transferForm.note.trim()" @tap="doTransfer">{{ actionLoading ? '提交中...' : (transferForm.isWarehouse ? '📦 确认入库' : '确认转交') }}</button></view>
|
||||
</template>
|
||||
<template v-if="actionPopup.type === 'spawn'">
|
||||
<text class="popup-title">➕ 派发协助分支</text>
|
||||
<text class="popup-hint">为当前任务创建一个并行协助任务,当前任务保持进行中</text>
|
||||
<view class="form-item"><text class="form-label">工序名称 <text class="required">*</text></text><picker mode="selector" :range="spawnProcessOptions" @change="onSpawnProcessChange"><view class="picker-value"><text :class="spawnForm.task_name ? '' : 'picker-placeholder'">{{ spawnForm.task_name || '请选择工序' }}</text><text class="picker-arrow">▾</text></view></picker></view>
|
||||
<view class="form-item"><text class="form-label">接收人 <text class="required">*</text></text><picker mode="selector" :range="userOptions" range-key="name" @change="onSpawnUserChange"><view class="picker-value"><text :class="spawnUserName ? '' : 'picker-placeholder'">{{ spawnUserName || '请选择接收人' }}</text><text class="picker-arrow">▾</text></view></picker></view>
|
||||
<input v-model="spawnForm.remark" class="popup-input" placeholder="派发备注(选填)" />
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary btn-spawn" :disabled="actionLoading || !spawnForm.task_name || !spawnForm.assignee_id" @tap="doSpawn">{{ actionLoading ? '提交中...' : '确认派发' }}</button></view>
|
||||
<text class="popup-hint">为当前任务创建并行协助,当前任务保持进行中</text>
|
||||
<view class="field-label">接收人 <text class="required">*</text></view>
|
||||
<view class="user-grid">
|
||||
<view v-for="u in userGridOptions" :key="u.id"
|
||||
:class="['user-grid-item', spawnForm.assignee_id === u.id ? 'user-grid-active' : '']"
|
||||
@tap="spawnForm.assignee_id = u.id">{{ formatName(u.name) }}</view>
|
||||
</view>
|
||||
<view class="field-label" style="margin-top:12px;">派发备注 <text class="required">*</text></view>
|
||||
<textarea v-model="spawnForm.remark" class="popup-textarea" placeholder="请填写派发备注说明(必填)" :maxlength="500" />
|
||||
<view class="popup-btns"><button class="btn-cancel" @tap="closeActionPopup">取消</button><button class="btn-primary btn-spawn" :disabled="actionLoading || !spawnForm.assignee_id || !spawnForm.remark.trim()" @tap="doSpawn">{{ actionLoading ? '提交中...' : '确认派发' }}</button></view>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
@ -131,7 +158,7 @@ import TreeCanvas from "./components/TreeCanvas.vue";
|
||||
|
||||
const OVERALL_OPTIONS = ["备货", "生产", "测试", "维修", "在库"];
|
||||
const TASK_NAME_OPTIONS = ["备货", "生产", "测试", "维修", "在库"];
|
||||
const STATUS_MAP = { PENDING: "待接收", WIP: "进行中", COMPLETED: "已完成", REJECTED: "已驳回", ARCHIVED: "已入库" };
|
||||
const STATUS_MAP = { PENDING: "待接收", WIP: "进行中", COMPLETED: "已完成", REJECTED: "已驳回", ARCHIVED: "已入库", CANCELED: "已撤回" };
|
||||
|
||||
export default {
|
||||
components: { WorkspaceArea, TreeCanvas },
|
||||
@ -140,13 +167,13 @@ export default {
|
||||
OVERALL_OPTIONS, loading: true, error: "", product: null,
|
||||
showStatusPicker: false, editProductVisible: false, editForm: { order_no: "", external_serial: "" }, editSaving: false,
|
||||
users: [], TASK_NAME_OPTIONS,
|
||||
createFirstVisible: false, firstForm: { task_name: "", taskNameIdx: 0, assignee_id: "", assigneeLabel: "", assigneeIdx: 0, note: "", autoReceive: true }, firstSaving: false,
|
||||
createFirstVisible: false, isWarehouseTransfer: false, firstForm: { task_name: "", taskNameIdx: 0, assignee_id: "", assigneeLabel: "", assigneeIdx: 0, note: "" }, firstSaving: false,
|
||||
recordPopup: { visible: false, task: null }, recordForm: { recordId: null, remark: "", images: [], pendingCount: 0 }, recordSaving: false, isUploading: false,
|
||||
currentUser: null, currentUserId: "", currentUsername: "", currentMode: "tree",
|
||||
processOptions: [], userOptions: [],
|
||||
actionPopup: { visible: false, type: "", task: null }, actionLoading: false, rejectReason: "", receiveRemark: "",
|
||||
transferForm: { next_task_name: "", selectedUserId: "", isWarehouse: false, note: "" },
|
||||
spawnForm: { task_name: "", assignee_id: "", remark: "" },
|
||||
actionPopup: { visible: false, type: "", task: null }, actionLoading: false, rejectReason: "", receiveRemark: "", receiveTaskName: "",
|
||||
transferForm: { selectedUserId: "", isWarehouse: false, note: "" },
|
||||
spawnForm: { assignee_id: "", remark: "" },
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -154,7 +181,7 @@ export default {
|
||||
canDeleteImage() { if (!this.recordPopup.task) return true; if (!this.currentUser) return true; return this.currentUser.username === this.recordPopup.task.assignee_id; },
|
||||
transferUserName() { const u = this.userOptions.find(u => u.id === this.transferForm.selectedUserId); return u ? u.name : ""; },
|
||||
spawnUserName() { const u = this.userOptions.find(u => u.id === this.spawnForm.assignee_id); return u ? u.name : ""; },
|
||||
spawnProcessOptions() { return (this.processOptions || []).filter(o => o !== "🏭 入库 (virtual_warehouse)"); },
|
||||
userGridOptions() { return (this.userOptions || []).map(u => ({ id: u.id, name: u.name })); },
|
||||
hasMyActiveTask() {
|
||||
const find = (tasks) => { if (!tasks) return false; for (const t of tasks) { if ((t.status === 'WIP' || t.status === 'PENDING') && (t.assignee_id == this.currentUserId || t.assignee_id == this.currentUsername)) return true; if (find(t.child_tasks)) return true; } return false; };
|
||||
return this.product ? find(this.product.task_tree) : false;
|
||||
@ -162,23 +189,26 @@ export default {
|
||||
},
|
||||
onLoad(options) { this.loadUsers(); this.loadCurrentUser(); const sn = options.serial || ""; if (sn) this.doQuery(sn); },
|
||||
methods: {
|
||||
formatName(name) { if (!name) return ""; return name.length === 2 ? name[0] + " " + name[1] : name; },
|
||||
statusLabel(s) { return STATUS_MAP[s] || s; },
|
||||
statusColor(s) { switch (s) { case "PENDING": return "s-yellow"; case "WIP": return "s-blue"; case "COMPLETED": return "s-green"; case "REJECTED": return "s-red"; default: return "s-gray"; } },
|
||||
|
||||
async doQuery(sn) { this.loading = true; this.error = ""; try { this.product = await get(`/products/scan/${sn}`); if (!this.product.overall_status) this.showStatusPicker = true; this.$nextTick(() => { this.currentMode = this.hasMyActiveTask ? 'workspace' : 'tree'; }); } catch (e) { this.error = e?.data?.detail || "查询失败"; } finally { this.loading = false; } },
|
||||
async doQuery(sn) { this.loading = true; this.error = ""; try { this.product = await get(`/products/scan/${sn}`); this.$nextTick(() => { this.currentMode = this.hasMyActiveTask ? 'workspace' : 'tree'; if (!this.product.task_tree || !this.product.task_tree.length) { this.openCreateFirstTask(); } }); } catch (e) { this.error = e?.data?.detail || "查询失败"; } finally { this.loading = false; } },
|
||||
toggleMode() { this.currentMode = this.currentMode === 'workspace' ? 'tree' : 'workspace'; },
|
||||
|
||||
async handleSetOverallStatus(status) { try { this.product = await patch(`/products/scan/${this.product.serial_number}/status`, { status }); uni.showToast({ title: `状态已更新: ${status}`, icon: "success" }); this.showStatusPicker = false; } catch {} },
|
||||
openEditProduct() { this.editForm = { order_no: this.product.order_no || "", external_serial: this.product.external_serial || "" }; this.editProductVisible = true; },
|
||||
async doEditProduct() { this.editSaving = true; try { this.product = await patch(`/products/${this.product.id}`, { order_no: this.editForm.order_no.trim(), external_serial: this.editForm.external_serial.trim() }); uni.showToast({ title: "已保存", icon: "success" }); this.editProductVisible = false; } catch {} finally { this.editSaving = false; } },
|
||||
|
||||
async loadUsers() { try { this.users = await get("/users/", { limit: 200 }); this.userOptions = (this.users || []).map(u => ({ id: u.username || u.id, name: u.full_name || u.username })); } catch {} },
|
||||
async loadUsers() { try { const res = await get("/users/", { limit: 200, dept: "IRIS" }); this.users = (res || []).filter(u => u.department === "IRIS"); this.userOptions = this.users.map(u => ({ id: u.username || u.id, name: u.full_name || u.username })); } catch {} },
|
||||
loadCurrentUser() { try { let user = uni.getStorageSync("user"); if (typeof user === "string" && user) { try { user = JSON.parse(user); } catch (e) { user = null; } } if (user && typeof user === "object") { this.currentUser = user; this.currentUserId = String(user.id || ""); this.currentUsername = user.username || ""; } } catch {} },
|
||||
|
||||
onTaskNameChange(e) { const idx = e.detail.value; this.firstForm.taskNameIdx = idx; this.firstForm.task_name = TASK_NAME_OPTIONS[idx]; },
|
||||
onAssigneeChange(e) { const idx = e.detail.value; const u = this.users[idx]; if (u) { this.firstForm.assigneeIdx = idx; this.firstForm.assignee_id = u.username; this.firstForm.assigneeLabel = `${u.full_name} (${u.username})`; } },
|
||||
openCreateFirstTask() { this.firstForm = { task_name: TASK_NAME_OPTIONS[0], taskNameIdx: 0, assignee_id: this.users.length > 0 ? this.users[0].username : "", assigneeLabel: this.users.length > 0 ? `${this.users[0].full_name} (${this.users[0].username})` : "", assigneeIdx: 0, note: "", autoReceive: true }; this.createFirstVisible = true; },
|
||||
async doCreateFirstTask() { this.firstSaving = true; try { const task = await post("/tasks/", { product_id: this.product.id, task_name: this.firstForm.task_name, assignee_id: this.firstForm.assignee_id, notify_parent_on_complete: false, remark: this.firstForm.note.trim() || undefined }); if (this.firstForm.autoReceive) { try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${task.id}/receive?operator_id=${encodeURIComponent(opId)}`, { remark: this.firstForm.note.trim() || undefined }); } catch {} } uni.showToast({ title: this.firstForm.autoReceive ? "已创建并接收" : "已创建", icon: "success" }); this.createFirstVisible = false; this.doQuery(this.product.serial_number); } catch {} finally { this.firstSaving = false; } },
|
||||
openCreateFirstTask() { this.isWarehouseTransfer = false; if (this.currentMode === 'tree') this.currentMode = 'workspace'; this.firstForm = { assignee_id: "", assigneeLabel: "", note: "" }; this.createFirstVisible = true; },
|
||||
handleOverallBarClick() { if (!this.product.task_tree || !this.product.task_tree.length) { this.openCreateFirstTask(); } else { this.showStatusPicker = true; } },
|
||||
openWarehouseTransfer() { this.isWarehouseTransfer = true; this.openCreateFirstTask(); },
|
||||
async doCreateFirstTask() { this.firstSaving = true; try { await post("/tasks/", { product_id: this.product.id, task_name: "待确认", assignee_id: this.firstForm.assignee_id, notify_parent_on_complete: false, remark: this.firstForm.note.trim() || undefined }); if (this.product.current_location_id === 'virtual_warehouse') { try { await patch(`/products/${this.product.id}`, { current_location_id: this.firstForm.assignee_id }); } catch {} } uni.showToast({ title: "任务已派发,待接收", icon: "success" }); this.createFirstVisible = false; this.doQuery(this.product.serial_number); } catch {} finally { this.firstSaving = false; } },
|
||||
|
||||
openRecordPopup(task) { this.recordPopup = { visible: true, task }; this.recordForm = { recordId: null, remark: "", images: [], pendingCount: 0 }; this.isUploading = false; },
|
||||
openEditRecord({ task, record }) { this.recordPopup = { visible: true, task }; this.recordForm = { recordId: record.id, remark: record.remark || "", images: record.images || [], pendingCount: 0 }; this.isUploading = false; },
|
||||
@ -193,26 +223,27 @@ export default {
|
||||
if (type === "record") { this.openRecordPopup(task); return; }
|
||||
if (type === "deleteRecord") { this.doDeleteRecord(record); return; }
|
||||
if (type === "end") { this.confirmEndBranch(task); return; }
|
||||
if (type === "recall") { this.confirmRecall(task); return; }
|
||||
if (type === "transfer" || type === "spawn") { uni.showLoading({ title: "加载数据..." }); try { if (!this.userOptions.length) await this.loadUsers(); if (!this.processOptions.length) this.processOptions = ["🏭 入库 (virtual_warehouse)", ...TASK_NAME_OPTIONS]; } finally { uni.hideLoading(); } }
|
||||
this.actionPopup = { visible: true, type, task }; this.rejectReason = ""; this.receiveRemark = "";
|
||||
this.transferForm = { next_task_name: "", selectedUserId: "", isWarehouse: false, note: "" };
|
||||
this.spawnForm = { task_name: "", assignee_id: "", remark: "" };
|
||||
this.actionPopup = { visible: true, type, task }; this.rejectReason = ""; this.receiveRemark = ""; this.receiveTaskName = "";
|
||||
this.transferForm = { selectedUserId: "", isWarehouse: false, note: "" };
|
||||
this.spawnForm = { assignee_id: "", remark: "" };
|
||||
},
|
||||
handleViewRecords(task) { uni.navigateTo({ url: `/pages/scan/records?taskId=${task.id}` }); },
|
||||
async doDeleteRecord(record) { try { await request({ url: `/records/${record.id}`, method: "DELETE" }); uni.showToast({ title: "记录已删除", icon: "success" }); this.doQuery(this.product.serial_number); } catch {} },
|
||||
confirmEndBranch(task) { uni.showModal({ title: "结束分支", content: `确定结束「${task.task_name}」吗?`, success: (res) => { if (res.confirm) this.doEndBranch(task); } }); },
|
||||
confirmRecall(task) { uni.showModal({ title: "撤回转交", content: `确定撤回「${task.task_name}」吗?撤回后任务将回到您的手中。`, success: (res) => { if (res.confirm) this.doRecall(task); } }); },
|
||||
async doRecall(task) { try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${task.id}/recall?operator_id=${encodeURIComponent(opId)}`); uni.showToast({ title: "已撤回", icon: "success" }); this.doQuery(this.product.serial_number); } catch {} },
|
||||
async doEndBranch(task) { try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${task.id}/end?operator_id=${encodeURIComponent(opId)}`); uni.showToast({ title: "分支已结束", icon: "success" }); this.doQuery(this.product.serial_number); } catch {} },
|
||||
closeActionPopup() { this.actionPopup = { visible: false, type: "", task: null }; },
|
||||
async doReceive() { this.actionLoading = true; try { const remark = this.receiveRemark.trim() || undefined; const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${this.actionPopup.task.id}/receive?operator_id=${encodeURIComponent(opId)}`, { remark }); uni.showToast({ title: "已接收", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch {} finally { this.actionLoading = false; } },
|
||||
async doReceive() { this.actionLoading = true; try { const remark = this.receiveRemark.trim() || undefined; const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${this.actionPopup.task.id}/receive?operator_id=${encodeURIComponent(opId)}`, { remark, task_name: this.receiveTaskName }); uni.showToast({ title: "已接收", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch {} finally { this.actionLoading = false; } },
|
||||
async doReject() { this.actionLoading = true; try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${this.actionPopup.task.id}/reject?operator_id=${encodeURIComponent(opId)}`, { reason: this.rejectReason.trim() }); uni.showToast({ title: "已驳回", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch {} finally { this.actionLoading = false; } },
|
||||
// 转交(单线)
|
||||
onTransferProcessChange(e) { this.transferForm.next_task_name = this.processOptions[e.detail.value]; this.transferForm.isWarehouse = this.transferForm.next_task_name === "🏭 入库 (virtual_warehouse)"; this.transferForm.selectedUserId = ""; },
|
||||
onTransferUserChange(e) { const user = this.userOptions[e.detail.value]; if (user) this.transferForm.selectedUserId = user.id; },
|
||||
async doTransfer() { this.actionLoading = true; try { const assignees = this.transferForm.isWarehouse ? ["virtual_warehouse"] : [this.transferForm.selectedUserId]; await post(`/tasks/${this.actionPopup.task.id}/transfer`, { next_tasks: [{ task_name: this.transferForm.next_task_name, assignees }], note: this.transferForm.note.trim() || undefined }); uni.showToast({ title: this.transferForm.isWarehouse ? "已入库" : "转交成功", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch {} finally { this.actionLoading = false; } },
|
||||
// 转交 — 互斥选择
|
||||
selectTransferUser(userId) { this.transferForm.selectedUserId = userId; this.transferForm.isWarehouse = false; },
|
||||
toggleWarehouse() { this.transferForm.isWarehouse = !this.transferForm.isWarehouse; if (this.transferForm.isWarehouse) this.transferForm.selectedUserId = ""; },
|
||||
async doTransfer() { this.actionLoading = true; try { const assignees = this.transferForm.isWarehouse ? ["virtual_warehouse"] : [this.transferForm.selectedUserId]; const taskName = this.transferForm.isWarehouse ? "🏭 入库 (virtual_warehouse)" : "待确认"; await post(`/tasks/${this.actionPopup.task.id}/transfer`, { next_tasks: [{ task_name: taskName, assignees }], note: this.transferForm.note.trim() || undefined }); uni.showToast({ title: this.transferForm.isWarehouse ? "已入库" : "转交成功", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch {} finally { this.actionLoading = false; } },
|
||||
// 派发协助分支
|
||||
onSpawnProcessChange(e) { this.spawnForm.task_name = this.spawnProcessOptions[e.detail.value]; },
|
||||
onSpawnUserChange(e) { const user = this.userOptions[e.detail.value]; if (user) this.spawnForm.assignee_id = user.id; },
|
||||
async doSpawn() { this.actionLoading = true; try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${this.actionPopup.task.id}/spawn?operator_id=${encodeURIComponent(opId)}`, { task_name: this.spawnForm.task_name, assignee_id: this.spawnForm.assignee_id, remark: this.spawnForm.remark.trim() || undefined }); uni.showToast({ title: "协助分支已派发", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch {} finally { this.actionLoading = false; } },
|
||||
async doSpawn() { this.actionLoading = true; try { const opId = this.currentUsername || this.currentUserId; await post(`/tasks/${this.actionPopup.task.id}/spawn?operator_id=${encodeURIComponent(opId)}`, { task_name: "待确认", assignee_id: this.spawnForm.assignee_id, remark: this.spawnForm.remark.trim() || undefined }); uni.showToast({ title: "协助分支已派发", icon: "success" }); this.closeActionPopup(); this.doQuery(this.product.serial_number); } catch {} finally { this.actionLoading = false; } },
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@ -272,9 +303,6 @@ export default {
|
||||
.field-label { font-size: 14px; font-weight: 600; color: #374151; margin-top: 10px; margin-bottom: 4px; }
|
||||
.required { color: #ef4444; }
|
||||
.picker-box { width: 100%; height: 42px; border: 1px solid #e5e7eb; border-radius: 10px; padding: 0 12px; font-size: 14px; color: #1f2937; line-height: 42px; box-sizing: border-box; background: #fff; }
|
||||
.switch-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding: 8px 0; }
|
||||
.switch-label { font-size: 15px; font-weight: 600; color: #2563eb; }
|
||||
.switch-hint { font-size: 11px; color: #9ca3af; display: block; margin-top: 2px; }
|
||||
.img-grid { display: flex; flex-wrap: wrap; margin: 8px -5px; }
|
||||
.img-cell { position: relative; width: 160rpx; height: 160rpx; margin: 10rpx; }
|
||||
.img-thumb { width: 160rpx; height: 160rpx; border-radius: 12rpx; border: 1px solid #e5e7eb; }
|
||||
@ -285,8 +313,12 @@ export default {
|
||||
.form-item { margin: 10px 0; }
|
||||
.form-label { font-size: 14px; font-weight: 600; color: #374151; display: block; margin-bottom: 4px; }
|
||||
.picker-value { display: flex; align-items: center; justify-content: space-between; width: 100%; height: 42px; padding: 0 12px; border: 1px solid #e5e7eb; border-radius: 10px; background: #f9fafb; font-size: 14px; box-sizing: border-box; }
|
||||
.picker-placeholder { color: #9ca3af; }
|
||||
.picker-arrow { font-size: 12px; color: #9ca3af; margin-left: 8px; }
|
||||
.user-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
|
||||
.user-grid-item { padding: 12px 8px; border-radius: 10px; background: #f3f4f6; text-align: center; font-size: 14px; font-weight: 600; color: #374151; border: 2px solid transparent; }
|
||||
.user-grid-active { background: #dbeafe; color: #2563eb; border-color: #2563eb; }
|
||||
.warehouse-hint { font-size: 13px; background: #ede9fe; color: #7c3aed; padding: 10px 14px; border-radius: 10px; margin: 8px 0; text-align: center; }
|
||||
.warehouse-transfer-banner { display: flex; align-items: center; gap: 12px; font-weight: 700; background: linear-gradient(135deg, #ede9fe, #dbeafe); color: #5b21b6; padding: 14px 16px; border-radius: 12px; margin-bottom: 12px; border: 2px dashed #a78bfa; }
|
||||
.wt-icon { font-size: 24px; }
|
||||
.wt-text { font-size: 14px; flex: 1; }
|
||||
.preview-hint { font-size: 12px; background: #f0fdf4; color: #16a34a; padding: 8px 10px; border-radius: 8px; margin: 6px 0; }
|
||||
</style>
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
<!-- 手动输入 -->
|
||||
<view class="manual-input">
|
||||
<input v-model="serialNumber" class="input" type="text" maxlength="16"
|
||||
placeholder="手动输入16位序列号" @confirm="handleSearch" />
|
||||
placeholder="手动输入16位身份证" @confirm="handleSearch" />
|
||||
<button class="search-btn" @tap="handleSearch" :disabled="loading">
|
||||
{{ loading ? '查询中' : '查询' }}
|
||||
</button>
|
||||
@ -24,7 +24,7 @@
|
||||
<!-- 空状态 -->
|
||||
<view v-if="!loading && !error" class="empty">
|
||||
<text class="empty-icon">📱</text>
|
||||
<text class="empty-text">扫码或手动输入序列号查询产品进度</text>
|
||||
<text class="empty-text">扫码或手动输入身份证查询产品进度</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@ -43,7 +43,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async doQuery(sn) {
|
||||
if (!sn || sn.length < 8) { this.error = "序列号至少需要 8 位"; return; }
|
||||
if (!sn || sn.length < 8) { this.error = "身份证至少需要 8 位"; return; }
|
||||
this.serialNumber = sn;
|
||||
this.lastScanned = sn;
|
||||
this.loading = true;
|
||||
|
||||
@ -2,24 +2,157 @@
|
||||
<view class="page">
|
||||
<view class="header">
|
||||
<text class="title">我的任务</text>
|
||||
<text class="subtitle">待处理和进行中的任务</text>
|
||||
</view>
|
||||
<view class="empty">
|
||||
<text class="empty-icon">📋</text>
|
||||
<text class="empty-text">暂无待办任务</text>
|
||||
|
||||
<!-- Tab 栏 — 固定顶部 -->
|
||||
<view class="tabs">
|
||||
<view v-for="t in TABS" :key="t.key"
|
||||
:class="['tab', tab === t.key ? 'tab-active' : '']"
|
||||
@tap="tab = t.key">{{ t.label }} ({{ countBy(t.key) }})</view>
|
||||
</view>
|
||||
|
||||
<!-- 内容区 -->
|
||||
<view v-if="loading" class="center">加载中...</view>
|
||||
<template v-else>
|
||||
<view v-if="filtered.length === 0" class="empty">
|
||||
<text class="empty-icon">📋</text>
|
||||
<text class="empty-text">{{ tab === 'all' ? '暂无待办任务' : '无此状态任务' }}</text>
|
||||
</view>
|
||||
<view v-for="task in filtered" :key="task.id" class="card" @tap="goDetail(task)">
|
||||
<view class="card-row">
|
||||
<view style="display:flex;align-items:center;gap:6px;min-width:0;">
|
||||
<text :class="['tag-badge', task.task_type === 'SPAWN' ? 'tag-sub' : 'tag-main']">{{ task.task_type === 'SPAWN' ? '协助' : '主干' }}</text>
|
||||
<text class="card-name">{{ task.task_name }}</text>
|
||||
</view>
|
||||
<text :class="['card-status', statusColor(task.status)]">{{ statusLabel(task.status) }}</text>
|
||||
</view>
|
||||
<view class="card-meta">
|
||||
<text>身份证: {{ task.product_sn || '—' }}</text>
|
||||
<text>物料: {{ task.product_material || '—' }}</text>
|
||||
</view>
|
||||
<view class="card-time">创建: {{ formatTime(task.created_at) }}</view>
|
||||
</view>
|
||||
</template>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<script>
|
||||
import { get } from "../../utils/request";
|
||||
|
||||
const TABS = [
|
||||
{ key: "all", label: "全部" },
|
||||
{ key: "PENDING", label: "待接收" },
|
||||
{ key: "WIP", label: "进行中" },
|
||||
{ key: "COMPLETED", label: "已完成" },
|
||||
];
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
TABS,
|
||||
tab: "PENDING",
|
||||
tasks: [],
|
||||
loading: true,
|
||||
currentUser: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
filtered() {
|
||||
if (this.tab === "all") return this.tasks;
|
||||
return this.tasks.filter(t => t.status === this.tab);
|
||||
},
|
||||
},
|
||||
onShow() {
|
||||
this.loadCurrentUser();
|
||||
this.fetchTasks();
|
||||
},
|
||||
methods: {
|
||||
statusLabel(s) {
|
||||
const map = { PENDING: "待接收", WIP: "进行中", COMPLETED: "已完成", REJECTED: "已驳回", ARCHIVED: "已入库", CANCELED: "已撤回" };
|
||||
return map[s] || s;
|
||||
},
|
||||
statusColor(s) {
|
||||
switch (s) {
|
||||
case "PENDING": return "s-yellow";
|
||||
case "WIP": return "s-blue";
|
||||
case "COMPLETED": return "s-green";
|
||||
default: return "s-gray";
|
||||
}
|
||||
},
|
||||
countBy(key) {
|
||||
if (key === "all") return this.tasks.length;
|
||||
return this.tasks.filter(t => t.status === key).length;
|
||||
},
|
||||
formatTime(t) {
|
||||
if (!t) return "";
|
||||
const d = new Date(t);
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
},
|
||||
loadCurrentUser() {
|
||||
try {
|
||||
const u = uni.getStorageSync("user");
|
||||
if (u) this.currentUser = typeof u === "string" ? JSON.parse(u) : u;
|
||||
} catch {}
|
||||
},
|
||||
async fetchTasks() {
|
||||
this.loading = true;
|
||||
try {
|
||||
const username = this.currentUser?.username || "";
|
||||
const res = await get("/tasks/", { assignee_id: username, limit: 100 });
|
||||
this.tasks = (res.tasks || []).sort((a, b) => {
|
||||
const aIsMain = !a.parent_task_id || a.task_type !== 'SPAWN';
|
||||
const bIsMain = !b.parent_task_id || b.task_type !== 'SPAWN';
|
||||
if (aIsMain && !bIsMain) return -1;
|
||||
if (!aIsMain && bIsMain) return 1;
|
||||
return new Date(a.created_at) - new Date(b.created_at);
|
||||
});
|
||||
} catch { this.tasks = []; }
|
||||
finally { this.loading = false; }
|
||||
},
|
||||
goDetail(task) {
|
||||
const sn = task.product_sn || task.product_id;
|
||||
if (sn) uni.navigateTo({ url: `/pages/scan/detail?serial=${sn}` });
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { min-height: 100vh; padding: 16px; padding-bottom: 80px; }
|
||||
.header { margin-bottom: 24px; }
|
||||
.title { font-size: 20px; font-weight: 700; color: #1f2937; display: block; }
|
||||
.subtitle { font-size: 13px; color: #9ca3af; margin-top: 4px; display: block; }
|
||||
.page { min-height: 100vh; padding: 16px; padding-bottom: 100px; }
|
||||
.header { margin-bottom: 12px; }
|
||||
.title { font-size: 20px; font-weight: 700; color: #1f2937; }
|
||||
.center { text-align: center; padding: 48px 0; color: #9ca3af; }
|
||||
.empty { display: flex; flex-direction: column; align-items: center; padding-top: 80px; }
|
||||
.empty-icon { font-size: 64px; margin-bottom: 12px; }
|
||||
.empty-text { font-size: 14px; color: #9ca3af; }
|
||||
|
||||
/* tabs — sticky 不换行,溢出滚动 */
|
||||
.tabs {
|
||||
display: flex; gap: 8px; margin-bottom: 14px;
|
||||
white-space: nowrap; overflow-x: auto;
|
||||
position: sticky; top: 0; z-index: 999;
|
||||
background: #f3f4f6; padding: 12px 0 8px;
|
||||
}
|
||||
.tab {
|
||||
padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 600;
|
||||
background: #fff; color: #6b7280; flex-shrink: 0;
|
||||
}
|
||||
.tab-active { background: #2563eb; color: #fff; }
|
||||
|
||||
/* card */
|
||||
.card { background: #fff; border-radius: 12px; padding: 14px; margin-bottom: 10px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
|
||||
.card-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
|
||||
.card-name { font-size: 15px; font-weight: 700; color: #1f2937; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tag-badge { display: inline-block; padding: 2rpx 12rpx; font-size: 20rpx; border-radius: 6rpx; font-weight: bold; flex-shrink: 0; }
|
||||
.tag-main { background-color: #dbeafe; color: #1e40af; }
|
||||
.tag-sub { background-color: #f3e8ff; color: #6b21a8; }
|
||||
.card-status { font-size: 11px; padding: 2px 10px; border-radius: 20px; font-weight: 600; }
|
||||
.s-yellow { background: #fef3c7; color: #b45309; }
|
||||
.s-blue { background: #dbeafe; color: #1d4ed8; }
|
||||
.s-green { background: #dcfce7; color: #15803d; }
|
||||
.s-gray { background: #f3f4f6; color: #6b7280; }
|
||||
.card-meta { font-size: 12px; color: #6b7280; display: flex; gap: 12px; }
|
||||
.card-time { font-size: 11px; color: #9ca3af; margin-top: 4px; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user