From dd6be0d41aaaf9adba3281948030a26f36a4bca4 Mon Sep 17 00:00:00 2001 From: wsb1224 Date: Tue, 23 Jun 2026 00:32:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E8=A1=A5=E9=BD=90=E5=85=A8=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=93=8D=E4=BD=9C=EF=BC=9A=E5=88=86=E9=85=8D=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E3=80=81=E5=8F=B8=E6=9C=BA=E3=80=81=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=B5=81=E8=BD=AC=E3=80=81=E7=94=B3=E8=AF=B7=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E3=80=81=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- .../manager/approve-detail/approve-detail.js | 320 ++++++++++++++++++ .../approve-detail/approve-detail.wxml | 130 ++++++- .../approve-detail/approve-detail.wxss | 17 + 3 files changed, 457 insertions(+), 10 deletions(-) diff --git a/frontend/mini-app/pages/manager/approve-detail/approve-detail.js b/frontend/mini-app/pages/manager/approve-detail/approve-detail.js index 2d1193d..b25ac58 100644 --- a/frontend/mini-app/pages/manager/approve-detail/approve-detail.js +++ b/frontend/mini-app/pages/manager/approve-detail/approve-detail.js @@ -45,6 +45,12 @@ Page({ driverList: [], selectedDriverIndex: -1, selectedDriverId: null, + taskForm: { + pickup_address: "", + delivery_address: "", + pickup_content: "", + quantity: "1", + }, }, async onLoad(options) { @@ -128,6 +134,18 @@ Page({ if (logistics && logistics.tracking_number) { this.loadTrace(); } + + // 待工厂状态:自动填充任务表单 + if (data.order_status === "pending_factory") { + this.setData({ + taskForm: { + pickup_address: data.factory_name || "", + delivery_address: data.customer_address || "", + pickup_content: data.customer_name ? data.customer_name + " 订单货物" : "", + quantity: "1", + }, + }); + } } catch (error) { this.setData({ message: error.message || "加载失败" }); } finally { @@ -265,6 +283,308 @@ Page({ }); }, + // 任务表单输入 + onTaskFormInput: function (e) { + var field = e.currentTarget.dataset.field; + var obj = {}; + obj["taskForm." + field] = e.detail.value; + this.setData(obj); + }, + + // 提交审核(草稿/已驳回 → 待审批) + handleSubmitReview: function () { + var that = this; + var app = getApp(); + wx.showModal({ + title: "确认提交", + content: "确认提交此订单进入审核?", + confirmColor: "#2563eb", + success: function (res) { + if (!res.confirm) return; + that.setData({ actionLoading: true, message: "" }); + app.request({ + url: "/api/orders/" + that.data.orderInfo.order_id + "/submit", + method: "POST", + }).then(function () { + wx.showToast({ title: "已提交审核", icon: "success" }); + return that.loadDetail(); + }).catch(function (error) { + that.setData({ message: error.message || "提交失败" }); + }).finally(function () { + that.setData({ actionLoading: false }); + }); + }, + }); + }, + + // 推进待工厂(已审批 → 待工厂处理) + handlePushToFactory: function () { + var that = this; + var app = getApp(); + var orderInfo = this.data.orderInfo; + if (!orderInfo) return; + + // 自发订单:直接完成 + if (orderInfo.tracking_number) { + wx.showModal({ + title: "确认", + content: "马甸工厂自发,审批通过后将直接完成订单", + confirmColor: "#2563eb", + success: function (res) { + if (!res.confirm) return; + that._changeStatus("completed", "订单已直接完成"); + }, + }); + return; + } + + if (!that.data.selectedFactoryId) { + wx.showToast({ title: "请选择工厂", icon: "none" }); + return; + } + if (!that.data.selectedDriverId) { + wx.showToast({ title: "请选择司机", icon: "none" }); + return; + } + + that.setData({ actionLoading: true, message: "" }); + app.request({ + url: "/api/orders/" + orderInfo.order_id + "/status", + method: "POST", + data: { target_status: "pending_factory", factory_id: that.data.selectedFactoryId }, + }).then(function () { + return app.request({ + url: "/api/logistics/tasks", + method: "POST", + data: { + order_id: orderInfo.order_id, + driver_id: Number(that.data.selectedDriverId), + pickup_address: orderInfo.factory_name || "", + delivery_address: orderInfo.customer_address || "", + pickup_content: orderInfo.customer_name ? orderInfo.customer_name + " 订单货物" : "", + quantity: 1, + factory_id: that.data.selectedFactoryId, + }, + }); + }).then(function () { + wx.showToast({ title: "已推进待工厂并分配司机", icon: "success" }); + return that.loadDetail(); + }).catch(function (error) { + that.setData({ message: error.message || "操作失败" }); + }).finally(function () { + that.setData({ actionLoading: false }); + }); + }, + + // 分配任务(待工厂处理 → 待司机接单) + handleAssignTask: function () { + var that = this; + var app = getApp(); + var orderInfo = this.data.orderInfo; + if (!orderInfo) return; + + if (!that.data.selectedDriverId) { + wx.showToast({ title: "请选择司机", icon: "none" }); + return; + } + var form = that.data.taskForm; + if (!form.pickup_address.trim()) { + wx.showToast({ title: "请填写取货地址", icon: "none" }); + return; + } + if (!form.delivery_address.trim()) { + wx.showToast({ title: "请填写送货地址", icon: "none" }); + return; + } + if (!form.pickup_content.trim()) { + wx.showToast({ title: "请填写取货内容", icon: "none" }); + return; + } + + that.setData({ actionLoading: true, message: "" }); + app.request({ + url: "/api/logistics/tasks", + method: "POST", + data: { + order_id: orderInfo.order_id, + driver_id: Number(that.data.selectedDriverId), + pickup_address: form.pickup_address.trim(), + delivery_address: form.delivery_address.trim(), + pickup_content: form.pickup_content.trim(), + quantity: Number(form.quantity) || 1, + factory_id: orderInfo.factory_id || undefined, + }, + }).then(function () { + wx.showToast({ title: "任务分配成功", icon: "success" }); + return that.loadDetail(); + }).catch(function (error) { + that.setData({ message: error.message || "分配失败" }); + }).finally(function () { + that.setData({ actionLoading: false }); + }); + }, + + // 分配/重新分配司机(待司机接单) + handleAssignDriver: function () { + var that = this; + var app = getApp(); + var orderInfo = this.data.orderInfo; + if (!orderInfo) return; + + if (!that.data.selectedDriverId) { + wx.showToast({ title: "请选择司机", icon: "none" }); + return; + } + + var doAssign = function () { + that.setData({ actionLoading: true, message: "" }); + app.request({ + url: "/api/logistics/tasks", + method: "POST", + data: { + order_id: orderInfo.order_id, + driver_id: Number(that.data.selectedDriverId), + pickup_address: orderInfo.factory_name || "", + delivery_address: orderInfo.customer_address || "", + pickup_content: orderInfo.customer_name ? orderInfo.customer_name + " 订单货物" : "", + quantity: 1, + factory_id: orderInfo.factory_id || undefined, + }, + }).then(function () { + wx.showToast({ title: "司机分配成功", icon: "success" }); + return that.loadDetail(); + }).catch(function (error) { + that.setData({ message: error.message || "分配失败" }); + }).finally(function () { + that.setData({ actionLoading: false }); + }); + }; + + // 如果已有物流任务,先取消 + if (that.data.logistics && that.data.logistics.task_id) { + wx.showModal({ + title: "重新分配", + content: "确定要重新分配司机吗?当前物流任务将被取消。", + confirmColor: "#2563eb", + success: function (res) { + if (!res.confirm) return; + that.setData({ actionLoading: true }); + app.request({ + url: "/api/logistics/tasks/" + that.data.logistics.task_id + "/cancel", + method: "POST", + data: { cancel_reason: "管理员重新分配司机" }, + }).then(function () { + return doAssign(); + }).catch(function (error) { + that.setData({ message: error.message || "取消物流任务失败", actionLoading: false }); + }); + }, + }); + } else { + doAssign(); + } + }, + + // 简单状态变更 + handleSimpleTransition: function (e) { + var that = this; + var target = e.currentTarget.dataset.target; + var labelMap = { + picked_up: "确认揽货", + delivered: "确认送达", + production: "标记生产", + shipped: "标记发货", + completed: "标记完成", + pending_settle: "待结算", + }; + wx.showModal({ + title: "确认操作", + content: "确认" + (labelMap[target] || "变更状态") + "?", + confirmColor: "#2563eb", + success: function (res) { + if (!res.confirm) return; + that._changeStatus(target, labelMap[target] || "操作成功"); + }, + }); + }, + + _changeStatus: function (targetStatus, successMsg) { + var that = this; + var app = getApp(); + that.setData({ actionLoading: true, message: "" }); + app.request({ + url: "/api/orders/" + that.data.orderInfo.order_id + "/status", + method: "POST", + data: { target_status: targetStatus }, + }).then(function () { + wx.showToast({ title: successMsg || "操作成功", icon: "success" }); + return that.loadDetail(); + }).catch(function (error) { + that.setData({ message: error.message || "操作失败" }); + }).finally(function () { + that.setData({ actionLoading: false }); + }); + }, + + // 申请取消 + handleApplyCancel: function () { + var that = this; + wx.showModal({ + title: "申请取消", + editable: true, + placeholderText: "请输入取消原因(必填)", + confirmColor: "#be123c", + success: function (res) { + if (!res.confirm) return; + var reason = (res.content || "").trim(); + if (!reason) { + wx.showToast({ title: "请输入取消原因", icon: "none" }); + return; + } + var app = getApp(); + that.setData({ actionLoading: true, message: "" }); + app.request({ + url: "/api/orders/" + that.data.orderInfo.order_id + "/cancel", + method: "POST", + data: { cancel_reason: reason }, + }).then(function () { + wx.showToast({ title: "已发起取消", icon: "success" }); + return that.loadDetail(); + }).catch(function (error) { + that.setData({ message: error.message || "取消失败" }); + }).finally(function () { + that.setData({ actionLoading: false }); + }); + }, + }); + }, + + // 结算提成 + handleSettle: function () { + var that = this; + var app = getApp(); + wx.showModal({ + title: "确认结算", + content: "确认结算此订单提成?", + confirmColor: "#2563eb", + success: function (res) { + if (!res.confirm) return; + that.setData({ actionLoading: true, message: "" }); + app.request({ + url: "/api/orders/" + that.data.orderInfo.order_id + "/settle", + method: "POST", + }).then(function () { + wx.showToast({ title: "提成已结算", icon: "success" }); + return that.loadDetail(); + }).catch(function (error) { + that.setData({ message: error.message || "结算失败" }); + }).finally(function () { + that.setData({ actionLoading: false }); + }); + }, + }); + }, + handleBack: function () { wx.navigateBack({ delta: 1 }); }, // 分享给好友 diff --git a/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxml b/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxml index e23fbb1..e19863a 100644 --- a/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxml +++ b/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxml @@ -168,11 +168,14 @@ 暂无物流轨迹 - + + 马甸工厂自发 — 已填写快递单号({{orderInfo.tracking_number}}),审批通过后跳过工厂下发 - + + + 下发工厂 @@ -181,9 +184,48 @@ + + 分配司机 + + + {{selectedDriverIndex >= 0 ? driverList[selectedDriverIndex].real_name : '请选择司机'}} + + + + - - + + + 分配任务 + + 选择司机 + + + {{selectedDriverIndex >= 0 ? driverList[selectedDriverIndex].real_name : '请选择司机'}} + + + + + + 取货地址 + + + + 送货地址 + + + + 取货内容 + + + + 数量 + + + + + + 分配司机 @@ -196,11 +238,79 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxss b/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxss index 2845d6b..24441c3 100644 --- a/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxss +++ b/frontend/mini-app/pages/manager/approve-detail/approve-detail.wxss @@ -170,6 +170,23 @@ font-weight: 600; } +/* 表单字段 */ +.field-group { margin-bottom: 20rpx; } +.field-group:last-child { margin-bottom: 0; } +.field-label { font-size: 24rpx; color: #64748b; font-weight: 600; margin-bottom: 8rpx; } +.field-input { + width: 100%; padding: 16rpx 20rpx; background: #f8fafc; + border: 1rpx solid #d1d5db; border-radius: 12rpx; + font-size: 28rpx; color: #0f172a; box-sizing: border-box; +} + +/* 取消按钮 */ +.cancel-btn { + background: #fff1f2; + color: #be123c; + border: 2rpx solid #fecdd3; +} + /* 物流轨迹 */ .trace-timeline { position: relative; padding-left: 28rpx; margin-top: 16rpx; } .trace-item { position: relative; padding-bottom: 20rpx; }