diff --git a/track-uniapp/src/pages/scan/detail.vue b/track-uniapp/src/pages/scan/detail.vue index 53580ee..606edd9 100644 --- a/track-uniapp/src/pages/scan/detail.vue +++ b/track-uniapp/src/pages/scan/detail.vue @@ -10,7 +10,7 @@ 宏观状态 {{ product.overall_status || '未激活 — 点击发起首道工序' }} - + @@ -245,6 +245,27 @@ export default { return this.product ? find(this.product.task_tree) : false; }, msgUnreadCount() { if (!this.lastMsgSeenAt) return this.messages.length; return this.messages.filter(m => m.created_at > this.lastMsgSeenAt).length; }, + // 🔒 宏观状态修改权限:对齐后端 update_overall_status 的 main_task 判断标准 + canEditOverallStatus() { + if (!this.currentUser) return false; + if (this.currentUser.role === 'SUPER_ADMIN') return true; + if (!this.product || !this.product.task_tree) return false; + let hasPermission = false; + const checkTask = (tasks) => { + if (!tasks || hasPermission) return; + for (const t of tasks) { + const isMain = !t.parent_task_id || t.task_type === 'TRANSFER' || t.task_type === 'RECOVERY'; + if (isMain && (t.status === 'WIP' || t.status === 'PENDING')) { + if (t.assignee_id == this.currentUserId || t.assignee_id == this.currentUsername) { + hasPermission = true; + } + } + checkTask(t.child_tasks); + } + }; + checkTask(this.product.task_tree); + return hasPermission; + }, }, onLoad(options) { this.loadUsers(); this.loadCurrentUser(); const sn = options.serial || ""; if (sn) { this.doQuery(sn); return; } /* 🚀 兜底: 从 taskId 反查 product */ const tid = options.taskId || ""; if (tid) this.doQueryByTask(tid); }, // 🚀 onShow 生命周期:每次页面显示时刷新留言板(解决从聊天室退回不更新问题) @@ -286,7 +307,7 @@ export default { 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.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; } }, + handleOverallBarClick() { if (!this.product.task_tree || !this.product.task_tree.length) { this.openCreateFirstTask(); } else if (this.canEditOverallStatus) { this.showStatusPicker = true; } else { uni.showToast({ title: '仅超级管理员或当前主线负责人可修改状态', icon: 'none', duration: 2500 }); } }, 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; } },