修复小程序审批通过后剪切板仍无内容:内联构建采购文本避免时序问题
将采购信息构建逻辑从独立方法移入 _submitApproval 回调内, 直接从 orderInfo.items 原始数据构建,绕过 this.data.products 可能未就绪的时序问题;移除未使用的 _buildProcurementText 方法。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7d2941eca1
commit
a0e5120c7d
@ -261,23 +261,6 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
_buildProcurementText: function () {
|
||||
var info = this.data.orderInfo;
|
||||
var products = this.data.products;
|
||||
if (!info || !products || !products.length) return "";
|
||||
var lines = [];
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
var p = products[i];
|
||||
lines.push((i + 1) + ". " + (p.name || ""));
|
||||
if (p.spec) lines.push(" 规格: " + p.spec);
|
||||
if (p.demandSpec) lines.push(" 需求规格: " + p.demandSpec);
|
||||
if (p.qty) lines.push(" 数量: " + p.qty + (p.unit || ""));
|
||||
}
|
||||
if (info.remark) lines.push("备注: " + info.remark);
|
||||
if (info.customer_demand) lines.push("客户需求: " + info.customer_demand);
|
||||
return lines.join("\n");
|
||||
},
|
||||
|
||||
_submitApproval: async function (targetUrl, payload) {
|
||||
var that = this;
|
||||
var app = getApp();
|
||||
@ -289,16 +272,28 @@ Page({
|
||||
app.request({
|
||||
url: targetUrl, method: "POST",
|
||||
data: payload,
|
||||
}).then(function () {
|
||||
}).then(function (res) {
|
||||
if (payload.approve_result === "pass") {
|
||||
var text = that._buildProcurementText();
|
||||
// 从原始数据直接构建采购信息,避免 this.data 时序问题
|
||||
var orderData = that.data.orderInfo;
|
||||
var text = "";
|
||||
if (orderData) {
|
||||
var items = orderData.items || [];
|
||||
var lines = [];
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var ci = items[i];
|
||||
if (!ci.product_name) continue;
|
||||
lines.push((lines.length + 1) + ". " + ci.product_name);
|
||||
if (ci.specification) lines.push(" 规格: " + ci.specification);
|
||||
if (ci.demand_specification) lines.push(" 需求规格: " + ci.demand_specification);
|
||||
if (ci.quantity) lines.push(" 数量: " + ci.quantity + (ci.unit || ""));
|
||||
}
|
||||
if (orderData.remark) lines.push("备注: " + orderData.remark);
|
||||
if (orderData.customer_demand) lines.push("客户需求: " + orderData.customer_demand);
|
||||
text = lines.join("\n");
|
||||
}
|
||||
if (text) {
|
||||
wx.setClipboardData({
|
||||
data: text,
|
||||
success: function () {
|
||||
wx.showToast({ title: "审批通过,采购信息已复制", icon: "success" });
|
||||
},
|
||||
});
|
||||
wx.setClipboardData({ data: text });
|
||||
} else {
|
||||
wx.showToast({ title: "审批通过", icon: "success" });
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user