|
@@ -38,13 +38,17 @@ Component({
|
|
|
content.sa_custorderid = id || this.data.orderId || this.data.sa_custorderid;
|
|
content.sa_custorderid = id || this.data.orderId || this.data.sa_custorderid;
|
|
|
if (init) {
|
|
if (init) {
|
|
|
content.pageNumber = 1;
|
|
content.pageNumber = 1;
|
|
|
- this.setData({ loading: true });
|
|
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ loading: true
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
_Http.basic({
|
|
_Http.basic({
|
|
|
"id": "2026031414243401",
|
|
"id": "2026031414243401",
|
|
|
content
|
|
content
|
|
|
}).then(res => {
|
|
}).then(res => {
|
|
|
- this.setData({ loading: false });
|
|
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ loading: false
|
|
|
|
|
+ });
|
|
|
console.log("订单明细列表", res)
|
|
console.log("订单明细列表", res)
|
|
|
if (res.code != 1) return wx.showToast({
|
|
if (res.code != 1) return wx.showToast({
|
|
|
title: res.msg,
|
|
title: res.msg,
|
|
@@ -68,6 +72,297 @@ Component({
|
|
|
"sa_custorderid": content.sa_custorderid
|
|
"sa_custorderid": content.sa_custorderid
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
+ },
|
|
|
|
|
+ // 打开添加商品面板
|
|
|
|
|
+ addProduct() {
|
|
|
|
|
+ // 直接跳转到产品选择页面
|
|
|
|
|
+ wx.navigateTo({
|
|
|
|
|
+ url: `/CRM/customer/modules/orderCreate/productSelect/index?params=${JSON.stringify({
|
|
|
|
|
+ "id": "2026031312441901",
|
|
|
|
|
+ "content": {
|
|
|
|
|
+ "pageNumber": 1,
|
|
|
|
|
+ "pageSize": 20,
|
|
|
|
|
+ "where": {
|
|
|
|
|
+ "tablefilter": {
|
|
|
|
|
+ "itemname": null,
|
|
|
|
|
+ "itemno": null,
|
|
|
|
|
+ "model": null,
|
|
|
|
|
+ "guid_price": null,
|
|
|
|
|
+ "guid_price_cus": null,
|
|
|
|
|
+ "packageqty": null
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ })}&butText=添加商品`
|
|
|
|
|
+ });
|
|
|
|
|
+ // 设置全局回调函数
|
|
|
|
|
+ getApp().globalData.handleSelect = this.handleSelect.bind(this);
|
|
|
|
|
+ },
|
|
|
|
|
+ // 处理选择商品回调
|
|
|
|
|
+ handleSelect(detail) {
|
|
|
|
|
+ if (detail && detail.list) {
|
|
|
|
|
+ const orderId = this.data.sa_custorderid;
|
|
|
|
|
+ if (!orderId) {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '订单ID不存在',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 显示加载提示
|
|
|
|
|
+ wx.showLoading({
|
|
|
|
|
+ title: '正在添加商品...',
|
|
|
|
|
+ mask: true
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 准备绑定操作
|
|
|
|
|
+ const promises = detail.list.map(item => {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ // 处理价格字段,去除格式化符号
|
|
|
|
|
+ const priceStr = item.guid_price_cus || item.price || "0";
|
|
|
|
|
+ const price = parseFloat(priceStr.toString().replace(/[¥,]/g, '')) || 0;
|
|
|
|
|
+ const qty = parseInt(item.qty) || 1;
|
|
|
|
|
+ const amount = parseFloat((price * qty * 1).toFixed(2));
|
|
|
|
|
+
|
|
|
|
|
+ // 直接调用绑定商品接口
|
|
|
|
|
+ _Http.basic({
|
|
|
|
|
+ "id": "2026031415462301", // 绑定商品接口ID
|
|
|
|
|
+ content: {
|
|
|
|
|
+ sa_custorderid: orderId,
|
|
|
|
|
+ sa_custorderitemsid: 0,
|
|
|
|
|
+ sys_enterprise_itemid: item.sys_enterprise_itemid || item.itemid,
|
|
|
|
|
+ qty: qty,
|
|
|
|
|
+ oldprice: price,
|
|
|
|
|
+ discountrate: 1,
|
|
|
|
|
+ price: price,
|
|
|
|
|
+ amount: amount,
|
|
|
|
|
+ remarks: item.remarks || ""
|
|
|
|
|
+ }
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ if (res.code != 1) {
|
|
|
|
|
+ console.error("绑定商品失败", res);
|
|
|
|
|
+ }
|
|
|
|
|
+ resolve(res);
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ console.error("绑定商品失败", err);
|
|
|
|
|
+ resolve(null); // 即使失败也继续处理
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 使用Promise.all处理所有绑定操作
|
|
|
|
|
+ Promise.all(promises).then(() => {
|
|
|
|
|
+ // 隐藏加载提示
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+
|
|
|
|
|
+ // 刷新商品列表
|
|
|
|
|
+ this.getList(orderId, true);
|
|
|
|
|
+
|
|
|
|
|
+ // 显示成功提示
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '商品添加成功',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 返回页面
|
|
|
|
|
+ wx.navigateBack();
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ // 隐藏加载提示
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+
|
|
|
|
|
+ // 刷新商品列表
|
|
|
|
|
+ this.getList(orderId, true);
|
|
|
|
|
+
|
|
|
|
|
+ // 显示成功提示
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '商品添加成功',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 返回页面
|
|
|
|
|
+ wx.navigateBack();
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ // 处理字段编辑
|
|
|
|
|
+ onFieldBlur(e) {
|
|
|
|
|
+ const index = e.currentTarget.dataset.index;
|
|
|
|
|
+ const field = e.currentTarget.dataset.field;
|
|
|
|
|
+ const value = e.detail.value;
|
|
|
|
|
+
|
|
|
|
|
+ const list = [...this.data.list];
|
|
|
|
|
+ const item = list[index];
|
|
|
|
|
+
|
|
|
|
|
+ // 获取原价,默认为当前价格
|
|
|
|
|
+ const originalPrice = item.oldprice || item.price || 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 处理不同字段的编辑
|
|
|
|
|
+ switch (field) {
|
|
|
|
|
+ case 'price':
|
|
|
|
|
+ item.price = parseFloat(value) || 0;
|
|
|
|
|
+ // 根据原价和新单价计算折扣
|
|
|
|
|
+ if (originalPrice > 0) {
|
|
|
|
|
+ item.discountrate = parseFloat((item.price / originalPrice).toFixed(4));
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'discountrate':
|
|
|
|
|
+ // 确保折扣值有效,默认为1(100%)
|
|
|
|
|
+ let discount = parseFloat(value) || 1;
|
|
|
|
|
+ // 折扣不能小于0
|
|
|
|
|
+ discount = Math.max(0, discount);
|
|
|
|
|
+ item.discountrate = discount;
|
|
|
|
|
+ // 根据原价和新折扣计算单价
|
|
|
|
|
+ item.price = parseFloat((originalPrice * discount).toFixed(2));
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'qty':
|
|
|
|
|
+ let qty = parseInt(value) || 1;
|
|
|
|
|
+ // 数量不能为0
|
|
|
|
|
+ qty = Math.max(1, qty);
|
|
|
|
|
+ item.qty = qty;
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'amount':
|
|
|
|
|
+ // 根据新金额计算单价
|
|
|
|
|
+ const newAmount = parseFloat(value) || 0;
|
|
|
|
|
+ item.amount = newAmount;
|
|
|
|
|
+ if (item.qty > 0) {
|
|
|
|
|
+ item.price = parseFloat((newAmount / item.qty).toFixed(2));
|
|
|
|
|
+ // 根据原价和新单价计算折扣
|
|
|
|
|
+ if (originalPrice > 0) {
|
|
|
|
|
+ item.discountrate = parseFloat((item.price / originalPrice).toFixed(4));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'remarks':
|
|
|
|
|
+ item.remarks = value;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 重新计算金额,保留两位小数
|
|
|
|
|
+ item.amount = parseFloat((item.price * item.qty).toFixed(2));
|
|
|
|
|
+
|
|
|
|
|
+ // 立即更新页面显示
|
|
|
|
|
+ this.setData({
|
|
|
|
|
+ list
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 调用接口更新商品信息
|
|
|
|
|
+ this.updateProduct(item);
|
|
|
|
|
+ },
|
|
|
|
|
+ // 更新商品信息
|
|
|
|
|
+ updateProduct(item) {
|
|
|
|
|
+ const orderId = this.data.sa_custorderid;
|
|
|
|
|
+ if (!orderId || !item.sa_custorderitemsid) return;
|
|
|
|
|
+
|
|
|
|
|
+ // 显示加载提示
|
|
|
|
|
+ wx.showLoading({
|
|
|
|
|
+ title: '正在更新商品...',
|
|
|
|
|
+ mask: true
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 调用绑定商品接口(用于更新)
|
|
|
|
|
+ _Http.basic({
|
|
|
|
|
+ "id": "2026031415462301", // 绑定商品接口ID
|
|
|
|
|
+ content: {
|
|
|
|
|
+ sa_custorderid: orderId,
|
|
|
|
|
+ sa_custorderitemsid: item.sa_custorderitemsid,
|
|
|
|
|
+ sys_enterprise_itemid: item.sys_enterprise_itemid || item.itemid,
|
|
|
|
|
+ qty: item.qty,
|
|
|
|
|
+ oldprice: item.oldprice || item.price,
|
|
|
|
|
+ discountrate: item.discountrate,
|
|
|
|
|
+ price: item.price,
|
|
|
|
|
+ amount: item.amount,
|
|
|
|
|
+ remarks: item.remarks || ""
|
|
|
|
|
+ }
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ // 隐藏加载提示
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+
|
|
|
|
|
+ if (res.code === 1) {
|
|
|
|
|
+ // 显示成功提示
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '更新商品成功',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ // 刷新商品列表
|
|
|
|
|
+ this.getList(orderId, true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.error("更新商品失败", res);
|
|
|
|
|
+ // 显示失败提示
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '更新商品失败',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ // 隐藏加载提示
|
|
|
|
|
+ wx.hideLoading();
|
|
|
|
|
+
|
|
|
|
|
+ console.error("更新商品失败", err);
|
|
|
|
|
+ // 显示失败提示
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '网络错误',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ // 删除商品
|
|
|
|
|
+ deleteProduct(e) {
|
|
|
|
|
+ const index = e.currentTarget.dataset.index;
|
|
|
|
|
+ const item = this.data.list[index];
|
|
|
|
|
+
|
|
|
|
|
+ if (!item.sa_custorderitemsid) {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '商品ID不存在',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ wx.showModal({
|
|
|
|
|
+ title: '提示',
|
|
|
|
|
+ content: '确定要删除这个商品吗?',
|
|
|
|
|
+ confirmText: '确定',
|
|
|
|
|
+ cancelText: '取消',
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ if (res.confirm) {
|
|
|
|
|
+ // 调用删除接口
|
|
|
|
|
+ _Http.basic({
|
|
|
|
|
+ "id": "2026031416083401", // 删除产品明细接口ID
|
|
|
|
|
+ content: {
|
|
|
|
|
+ sa_custorderid: item.sa_custorderid,
|
|
|
|
|
+ sa_custorderitemsid: item.sa_custorderitemsid
|
|
|
|
|
+ }
|
|
|
|
|
+ }).then(res => {
|
|
|
|
|
+ console.log('删除商品结果:', res);
|
|
|
|
|
+ if (res.code === 1) {
|
|
|
|
|
+ // 显示成功提示
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '删除成功',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ // 刷新商品列表
|
|
|
|
|
+ this.getList(this.data.sa_custorderid, true);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: res.msg || '删除失败',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(err => {
|
|
|
|
|
+ console.error('删除商品失败:', err);
|
|
|
|
|
+ wx.showToast({
|
|
|
|
|
+ title: '网络错误',
|
|
|
|
|
+ icon: 'none'
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|