|
|
@@ -8,75 +8,75 @@ Page({
|
|
|
activeTab: 0,
|
|
|
productList: [],
|
|
|
form: [{
|
|
|
- label: "客户",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "text",
|
|
|
- value: "",
|
|
|
- placeholder: "客户名称",
|
|
|
- valueName: "name",
|
|
|
- required: false,
|
|
|
- checking: "base",
|
|
|
- disabled: true
|
|
|
- },
|
|
|
- {
|
|
|
- label: "门店",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "text",
|
|
|
- value: "",
|
|
|
- placeholder: "门店名称",
|
|
|
- valueName: "storename",
|
|
|
- required: false,
|
|
|
- checking: "base",
|
|
|
- disabled: true
|
|
|
- },
|
|
|
- {
|
|
|
- label: "开单日期",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "date",
|
|
|
- value: "",
|
|
|
- placeholder: "请选择开单日期",
|
|
|
- valueName: "billdate",
|
|
|
- required: false,
|
|
|
- checking: "base"
|
|
|
- },
|
|
|
- {
|
|
|
- label: "订单数量",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "number",
|
|
|
- value: "0",
|
|
|
- placeholder: "订单数量",
|
|
|
- valueName: "orderCount",
|
|
|
- required: false,
|
|
|
- checking: "base",
|
|
|
- disabled: true
|
|
|
- },
|
|
|
- {
|
|
|
- label: "订单金额",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "number",
|
|
|
- value: "0",
|
|
|
- placeholder: "订单金额",
|
|
|
- valueName: "amount",
|
|
|
- required: false,
|
|
|
- checking: "base",
|
|
|
- disabled: true
|
|
|
- },
|
|
|
- {
|
|
|
- label: "备注",
|
|
|
- error: false,
|
|
|
- errMsg: "",
|
|
|
- type: "textarea",
|
|
|
- value: "",
|
|
|
- placeholder: "请输入备注",
|
|
|
- valueName: "remarks",
|
|
|
- required: false,
|
|
|
- checking: "base"
|
|
|
- }
|
|
|
+ label: "客户",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "客户名称",
|
|
|
+ valueName: "name",
|
|
|
+ required: false,
|
|
|
+ checking: "base",
|
|
|
+ disabled: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "门店",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "text",
|
|
|
+ value: "",
|
|
|
+ placeholder: "门店名称",
|
|
|
+ valueName: "storename",
|
|
|
+ required: false,
|
|
|
+ checking: "base",
|
|
|
+ disabled: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "开单日期",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "date",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请选择开单日期",
|
|
|
+ valueName: "billdate",
|
|
|
+ required: false,
|
|
|
+ checking: "base"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "订单数量",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "number",
|
|
|
+ value: "0",
|
|
|
+ placeholder: "订单数量",
|
|
|
+ valueName: "orderCount",
|
|
|
+ required: false,
|
|
|
+ checking: "base",
|
|
|
+ disabled: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "订单金额",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "number",
|
|
|
+ value: "0",
|
|
|
+ placeholder: "订单金额",
|
|
|
+ valueName: "amount",
|
|
|
+ required: false,
|
|
|
+ checking: "base",
|
|
|
+ disabled: true
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: "备注",
|
|
|
+ error: false,
|
|
|
+ errMsg: "",
|
|
|
+ type: "textarea",
|
|
|
+ value: "",
|
|
|
+ placeholder: "请输入备注",
|
|
|
+ valueName: "remarks",
|
|
|
+ required: false,
|
|
|
+ checking: "base"
|
|
|
+ }
|
|
|
],
|
|
|
"content": {
|
|
|
"sa_custorderid": 0,
|
|
|
@@ -133,14 +133,16 @@ Page({
|
|
|
});
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
this.setData({
|
|
|
loading: true
|
|
|
});
|
|
|
let formData = this.selectComponent("#Form").submit();
|
|
|
-
|
|
|
+
|
|
|
if (!formData) {
|
|
|
- this.setData({ loading: false });
|
|
|
+ this.setData({
|
|
|
+ loading: false
|
|
|
+ });
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -158,23 +160,39 @@ Page({
|
|
|
if (res.code == 1) {
|
|
|
const orderId = res.data;
|
|
|
console.log("订单ID", orderId);
|
|
|
-
|
|
|
+
|
|
|
// 显示加载提示
|
|
|
wx.showLoading({
|
|
|
- title: '正在绑定商品...',
|
|
|
+ title: '正在处理...',
|
|
|
mask: true
|
|
|
});
|
|
|
-
|
|
|
- // 使用Promise.all处理商品绑定
|
|
|
- this.bindProductsWithPromise(orderId).then(() => {
|
|
|
- // 绑定完成,跳转到订单详情
|
|
|
+
|
|
|
+ // 准备绑定操作
|
|
|
+ const promises = [];
|
|
|
+
|
|
|
+ // 绑定商品
|
|
|
+ if (this.data.productList.length > 0) {
|
|
|
+ promises.push(this.bindProductsWithPromise(orderId));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 绑定附件
|
|
|
+ const attachmentids = this.selectComponent("#Yl_files").getFiles().attachmentids;
|
|
|
+ if (attachmentids && attachmentids.length > 0) {
|
|
|
+ promises.push(this.bindAttachmentsWithPromise(orderId, attachmentids));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 使用Promise.all处理所有绑定操作
|
|
|
+ Promise.all(promises).then(() => {
|
|
|
+ // 所有绑定完成,跳转到订单详情
|
|
|
this.navigateToOrderDetail(orderId);
|
|
|
}).catch(() => {
|
|
|
// 绑定失败,跳转到订单详情
|
|
|
this.navigateToOrderDetail(orderId);
|
|
|
});
|
|
|
} else {
|
|
|
- this.setData({ loading: false });
|
|
|
+ this.setData({
|
|
|
+ loading: false
|
|
|
+ });
|
|
|
wx.showToast({
|
|
|
title: res.msg || '保存失败',
|
|
|
icon: 'none'
|
|
|
@@ -203,7 +221,7 @@ Page({
|
|
|
content: {
|
|
|
sa_custorderid: orderId,
|
|
|
sa_custorderitemsid: 0,
|
|
|
- sys_enterprise_itemid:product.sys_enterprise_itemid|| product.itemid,
|
|
|
+ sys_enterprise_itemid: product.sys_enterprise_itemid || product.itemid,
|
|
|
qty: product.qty,
|
|
|
oldprice: product.originalPrice || product.price,
|
|
|
discountrate: product.discount,
|
|
|
@@ -212,82 +230,107 @@ Page({
|
|
|
remarks: product.remarks || ""
|
|
|
}
|
|
|
}).then(res => {
|
|
|
- if (res.code != 1) {
|
|
|
- console.error("绑定商品失败", res);
|
|
|
- }
|
|
|
- resolve(res);
|
|
|
- }).catch(err => {
|
|
|
- console.error("绑定商品失败", err);
|
|
|
- resolve(null); // 即使失败也继续处理
|
|
|
- });
|
|
|
+ if (res.code != 1) {
|
|
|
+ console.error("绑定商品失败", res);
|
|
|
+ }
|
|
|
+ resolve(res);
|
|
|
+ }).catch(err => {
|
|
|
+ console.error("绑定商品失败", err);
|
|
|
+ resolve(null); // 即使失败也继续处理
|
|
|
+ });
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
-// 处理附件绑定(预留接口)
|
|
|
-const attachmentPromise = this.bindAttachmentsWithPromise(orderId);
|
|
|
+ // 处理附件绑定(预留接口)
|
|
|
+ const attachmentPromise = this.bindAttachmentsWithPromise(orderId);
|
|
|
|
|
|
-// 合并所有Promise
|
|
|
-const allPromises = [...bindPromises, attachmentPromise];
|
|
|
+ // 合并所有Promise
|
|
|
+ const allPromises = [...bindPromises, attachmentPromise];
|
|
|
|
|
|
-// 使用Promise.all处理所有请求
|
|
|
-return Promise.all(allPromises);
|
|
|
+ // 使用Promise.all处理所有请求
|
|
|
+ return Promise.all(allPromises);
|
|
|
},
|
|
|
-// 绑定附件(预留接口)
|
|
|
-bindAttachmentsWithPromise(orderId) {
|
|
|
- return new Promise((resolve) => {
|
|
|
- // 这里预留附件绑定的逻辑
|
|
|
- // 目前暂时直接resolve
|
|
|
- resolve(null);
|
|
|
- });
|
|
|
-},
|
|
|
-// 跳转到订单详情
|
|
|
-navigateToOrderDetail(orderId) {
|
|
|
- // 隐藏加载提示
|
|
|
- wx.hideLoading();
|
|
|
- this.setData({ loading: false });
|
|
|
- wx.redirectTo({
|
|
|
- url: `/CRM/order/detail?id=${orderId}`,
|
|
|
- success: () => {
|
|
|
- // 跳转到订单详情页面
|
|
|
- wx.showToast({
|
|
|
- title: "开单成功",
|
|
|
- icon: "none",
|
|
|
- duration: 1500,
|
|
|
+ // 绑定附件
|
|
|
+ bindAttachmentsWithPromise(orderId, attachmentids) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ if (!attachmentids || attachmentids.length === 0) {
|
|
|
+ resolve(null);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ _Http.basic({
|
|
|
+ "classname": "system.attachment.Attachment",
|
|
|
+ "method": "createFileLink",
|
|
|
+ id: 10020501,
|
|
|
+ "content": {
|
|
|
+ ownertable: "sa_custorder",
|
|
|
+ ownerid: orderId,
|
|
|
+ usetype: 'default',
|
|
|
+ attachmentids
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log('绑定附件', res);
|
|
|
+ if (res.code == 1) {
|
|
|
+ resolve(res.data);
|
|
|
+ } else {
|
|
|
+ console.error('绑定附件失败', res);
|
|
|
+ resolve(); // 绑定失败也继续执行
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.error('绑定附件错误', err);
|
|
|
+ resolve(); // 错误也继续执行
|
|
|
});
|
|
|
- }
|
|
|
- });
|
|
|
- getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').partialRenewal(true);
|
|
|
-},
|
|
|
-interrupt({
|
|
|
- detail
|
|
|
-}) {
|
|
|
- // 处理中断逻辑,如果需要的话
|
|
|
-},
|
|
|
-/* 表单必填项是否完成 */
|
|
|
-onConfirm({
|
|
|
- detail
|
|
|
-}) {
|
|
|
- this.setData({
|
|
|
- disabled: detail
|
|
|
- });
|
|
|
-},
|
|
|
-onChange(e) {
|
|
|
- this.setData({
|
|
|
- showAll: e.detail
|
|
|
- });
|
|
|
-},
|
|
|
-closePage() {
|
|
|
- wx.navigateBack({
|
|
|
- delta: 1
|
|
|
- });
|
|
|
-},
|
|
|
-// tab切换
|
|
|
-onTabChange(e) {
|
|
|
- this.setData({
|
|
|
- activeTab: e.detail
|
|
|
- });
|
|
|
-},
|
|
|
-// 打开添加商品面板
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 跳转到订单详情
|
|
|
+ navigateToOrderDetail(orderId) {
|
|
|
+ // 隐藏加载提示
|
|
|
+ wx.hideLoading();
|
|
|
+ this.setData({
|
|
|
+ loading: false
|
|
|
+ });
|
|
|
+ wx.redirectTo({
|
|
|
+ url: `/CRM/order/detail?id=${orderId}`,
|
|
|
+ success: () => {
|
|
|
+ // 跳转到订单详情页面
|
|
|
+ wx.showToast({
|
|
|
+ title: "开单成功",
|
|
|
+ icon: "none",
|
|
|
+ duration: 1500,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').partialRenewal(true);
|
|
|
+ },
|
|
|
+ interrupt({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ // 处理中断逻辑,如果需要的话
|
|
|
+ },
|
|
|
+ /* 表单必填项是否完成 */
|
|
|
+ onConfirm({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ this.setData({
|
|
|
+ disabled: detail
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onChange(e) {
|
|
|
+ this.setData({
|
|
|
+ showAll: e.detail
|
|
|
+ });
|
|
|
+ },
|
|
|
+ closePage() {
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // tab切换
|
|
|
+ onTabChange(e) {
|
|
|
+ this.setData({
|
|
|
+ activeTab: e.detail
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 打开添加商品面板
|
|
|
addProduct() {
|
|
|
// 直接跳转到产品选择页面
|
|
|
wx.navigateTo({
|
|
|
@@ -316,14 +359,14 @@ onTabChange(e) {
|
|
|
handleSelect(detail) {
|
|
|
if (detail && detail.list) {
|
|
|
const existingItemIds = this.data.productList.map(item => item.sys_enterprise_itemid);
|
|
|
-
|
|
|
+
|
|
|
// 过滤掉已经存在的商品
|
|
|
const newProducts = detail.list.filter(item => !existingItemIds.includes(item.sys_enterprise_itemid)).map(item => {
|
|
|
// 处理价格字段,去除格式化符号
|
|
|
const priceStr = item.guid_price_cus || item.price || "0";
|
|
|
const price = parseFloat(priceStr.toString().replace(/[¥,]/g, '')) || 0;
|
|
|
const qty = parseInt(item.qty) || 1;
|
|
|
-
|
|
|
+
|
|
|
return {
|
|
|
itemid: item.itemid,
|
|
|
sys_enterprise_itemid: item.sys_enterprise_itemid,
|
|
|
@@ -338,12 +381,12 @@ onTabChange(e) {
|
|
|
remarks: item.remarks || ''
|
|
|
};
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
if (newProducts.length > 0) {
|
|
|
this.setData({
|
|
|
productList: [...this.data.productList, ...newProducts]
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
// 更新订单金额
|
|
|
this.updateOrderAmount();
|
|
|
} else {
|
|
|
@@ -352,7 +395,7 @@ onTabChange(e) {
|
|
|
icon: 'none'
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 返回页面
|
|
|
wx.navigateBack();
|
|
|
}
|
|
|
@@ -446,13 +489,46 @@ onTabChange(e) {
|
|
|
form.forEach(item => {
|
|
|
if (item.valueName === 'amount') {
|
|
|
item.value = totalAmount.toString();
|
|
|
- this.setData({ "content.amount": totalAmount });
|
|
|
+ this.setData({
|
|
|
+ "content.amount": totalAmount
|
|
|
+ });
|
|
|
}
|
|
|
if (item.valueName === 'orderCount') {
|
|
|
item.value = totalQty.toString();
|
|
|
- this.setData({ "content.orderCount": totalQty });
|
|
|
+ this.setData({
|
|
|
+ "content.orderCount": totalQty
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
- this.setData({ form });
|
|
|
- }
|
|
|
+ this.setData({
|
|
|
+ form
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 处理上传状态
|
|
|
+ changeState({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ this.setData({
|
|
|
+ loading: detail
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 处理文件上传回调
|
|
|
+ handleFileUpload({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ console.log("detail",detail)
|
|
|
+ Promise.all(detail.map(attachmentid => {
|
|
|
+ return _Http.basic({
|
|
|
+ "id": 2024061710590401,
|
|
|
+ "content": {
|
|
|
+ "pageSize": 1,
|
|
|
+ "pageNumber": 1,
|
|
|
+ "attachmentid": attachmentid
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })).then(res => {
|
|
|
+ console.log('获取文件详情', res);
|
|
|
+ this.selectComponent("#Yl_files").handleFiles(res.map(v=>v.data[0]))
|
|
|
+ })
|
|
|
+ },
|
|
|
});
|