xiaohaizhao 2 месяцев назад
Родитель
Сommit
05706389b0

+ 376 - 141
CRM/customer/modules/orderCreate/create.js

@@ -6,116 +6,106 @@ Page({
     disabled: false,
     showAll: false,
     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,
-      "sa_customersid": "",
-      "name": "",
-      "storename": "",
-      "billdate": "",
-      "orderCount": 0,
-      "amount": 0,
-      "remarks": "",
-      "siteid": "MD"
+      "sa_customersid": 0,
     }
   },
   onLoad(options) {
-    // 获取客户ID和客户信息
-    if (options.sa_customersid) {
+    // 如果传递了客户信息,填充到表单
+    try {
+      const customerInfo = getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').data.detail;
+      let form = this.data.form;
+      console.log("customerInfo", customerInfo)
+      // 填充客户信息到表单
+      form.forEach(item => {
+        if (item.valueName === 'name' && customerInfo.name) {
+          item.value = customerInfo.name;
+        }
+        if (item.valueName === 'storename' && customerInfo.storename) {
+          item.value = customerInfo.storename;
+        }
+      });
       this.setData({
-        "content.sa_customersid": options.sa_customersid
+        form,
+        "content.sa_storeid": customerInfo.sa_storeid,
+        "content.storeno": customerInfo.storeno,
+        "content.sa_customersid": customerInfo.sa_customersid,
       });
-
-      // 如果传递了客户信息,填充到表单
-      try {
-        const customerInfo = getCurrentPages().find(v => v.__route__ == 'CRM/customer/detail').data.detail;
-        let form = this.data.form;
-        console.log("customerInfo", customerInfo)
-        // 填充客户信息到表单
-        form.forEach(item => {
-          if (item.valueName === 'name' && customerInfo.name) {
-            item.value = customerInfo.name;
-          }
-          if (item.valueName === 'storename' && customerInfo.storename) {
-            item.value = customerInfo.storename;
-          }
-        });
-        this.setData({
-          form
-        });
-      } catch (error) {
-        console.error("解析客户信息失败", error);
-      }
+    } catch (error) {
+      console.error("解析客户信息失败", error);
     }
 
     // 设置默认开单日期为当天
@@ -134,15 +124,23 @@ Page({
     });
   },
   submit() {
+    // 检查是否有商品
+    if (this.data.productList.length === 0) {
+      this.addProduct();
+      wx.showToast({
+        title: '请先添加商品',
+        icon: 'none'
+      });
+      return;
+    }
+    
     this.setData({
       loading: true
     });
     let formData = this.selectComponent("#Form").submit();
-
+    
     if (!formData) {
-      this.setData({
-        loading: false
-      });
+      this.setData({ loading: false });
       return;
     }
 
@@ -151,30 +149,32 @@ Page({
       ...formData
     };
 
+    // 先创建订单
     _Http.basic({
       "id": "2026031309441701", // 创建订单的接口ID
       content
     }).then(res => {
-      this.setData({
-        loading: false
-      });
       console.log("保存订单", res);
       if (res.code == 1) {
-        // 刷新客户详情页面
-        const pages = getCurrentPages();
-        const detailPage = pages.find(v => v.__route__ == 'CRM/customer/detail');
-        if (detailPage) {
-          detailPage.partialRenewal(true);
-        }
-        wx.navigateBack({
-          success() {
-            wx.showToast({
-              title: "开单成功",
-              icon: "success"
-            });
-          }
+        const orderId = res.data;
+        console.log("订单ID", orderId);
+        
+        // 显示加载提示
+        wx.showLoading({
+          title: '正在绑定商品...',
+          mask: true
+        });
+        
+        // 使用Promise.all处理商品绑定
+        this.bindProductsWithPromise(orderId).then(() => {
+          // 绑定完成,跳转到订单详情
+          this.navigateToOrderDetail(orderId);
+        }).catch(() => {
+          // 绑定失败,跳转到订单详情
+          this.navigateToOrderDetail(orderId);
         });
       } else {
+        this.setData({ loading: false });
         wx.showToast({
           title: res.msg || '保存失败',
           icon: 'none'
@@ -191,33 +191,268 @@ Page({
       });
     });
   },
-  interrupt({
-    detail
-  }) {
-    // 处理中断逻辑,如果需要的话
-  },
-  /* 表单必填项是否完成 */
-  onConfirm({
-    detail
-  }) {
-    this.setData({
-      disabled: detail
+  // 使用Promise.all绑定商品
+  bindProductsWithPromise(orderId) {
+    const productList = this.data.productList;
+
+    // 创建商品绑定的Promise数组
+    const bindPromises = productList.map(product => {
+      return new Promise((resolve, reject) => {
+        _Http.basic({
+          "id": "2026031415462301", // 绑定商品接口ID
+          content: {
+            sa_custorderid: orderId,
+            sa_custorderitemsid: 0,
+            sys_enterprise_itemid:product.sys_enterprise_itemid|| product.itemid,
+            qty: product.qty,
+            oldprice: product.originalPrice || product.price,
+            discountrate: product.discount,
+            price: product.price,
+            amount: product.amount,
+            remarks: product.remarks || ""
+          }
+        }).then(res => {
+            if (res.code != 1) {
+              console.error("绑定商品失败", res);
+            }
+            resolve(res);
+          }).catch(err => {
+            console.error("绑定商品失败", err);
+            resolve(null); // 即使失败也继续处理
+          });
     });
+  });
+
+// 处理附件绑定(预留接口)
+const attachmentPromise = this.bindAttachmentsWithPromise(orderId);
+
+// 合并所有Promise
+const allPromises = [...bindPromises, attachmentPromise];
+
+// 使用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,
+      });
+    }
+  });
+  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({
+    url: `/select/product1/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 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,
+          itemname: item.itemname,
+          itemno: item.itemno,
+          model: item.model,
+          originalPrice: price,
+          price: price,
+          discount: 1,
+          qty: qty,
+          amount: parseFloat((price * qty * 1).toFixed(2)),
+          remarks: item.remarks || ''
+        };
+      });
+      
+      if (newProducts.length > 0) {
+        this.setData({
+          productList: [...this.data.productList, ...newProducts]
+        });
+        
+        // 更新订单金额
+        this.updateOrderAmount();
+      } else {
+        wx.showToast({
+          title: '所选商品已在列表中',
+          icon: 'none'
+        });
+      }
+      
+      // 返回页面
+      wx.navigateBack();
+    }
   },
-  onChange(e) {
+  // 处理字段编辑
+  onFieldBlur(e) {
+    const index = e.currentTarget.dataset.index;
+    const field = e.currentTarget.dataset.field;
+    const value = e.detail.value;
+
+    const productList = [...this.data.productList];
+    const product = productList[index];
+
+    // 处理不同字段的编辑
+    switch (field) {
+      case 'price':
+        product.price = parseFloat(value) || 0;
+        // 重新计算金额,保留两位小数,折扣1=100%
+        product.amount = parseFloat((product.price * product.qty * product.discount).toFixed(2));
+        break;
+      case 'discount':
+        product.discount = parseFloat(value) || 1;
+        // 重新计算金额,保留两位小数,折扣1=100%
+        product.amount = parseFloat((product.price * product.qty * product.discount).toFixed(2));
+        break;
+      case 'qty':
+        let qty = parseInt(value) || 1;
+        // 数量不能为0
+        qty = Math.max(1, qty);
+        product.qty = qty;
+        // 重新计算金额,保留两位小数,折扣1=100%
+        product.amount = parseFloat((product.price * product.qty * product.discount).toFixed(2));
+        break;
+      case 'amount':
+        product.amount = parseFloat(value) || 0;
+        // 重新计算单价(假设数量和折扣不变),保留两位小数,折扣1=100%
+        if (product.qty > 0 && product.discount > 0) {
+          product.price = parseFloat((product.amount / (product.qty * product.discount)).toFixed(2));
+        }
+        break;
+      case 'remarks':
+        product.remarks = value;
+        break;
+    }
+
     this.setData({
-      showAll: e.detail
+      productList
     });
+
+    // 更新订单金额
+    this.updateOrderAmount();
   },
-  closePage() {
-    wx.navigateBack({
-      delta: 1
+  // 删除商品
+  deleteProduct(e) {
+    wx.showModal({
+      title: '提示',
+      content: '确定要删除这个商品吗?',
+      confirmText: '确定',
+      cancelText: '取消',
+      success: (res) => {
+        if (res.confirm) {
+          const index = e.currentTarget.dataset.index;
+          const productList = [...this.data.productList];
+          productList.splice(index, 1);
+
+          this.setData({
+            productList
+          });
+
+          // 更新订单金额
+          this.updateOrderAmount();
+        }
+      }
     });
   },
-  // tab切换
-  onTabChange(e) {
-    this.setData({
-      activeTab: e.detail
+  // 更新订单金额
+  updateOrderAmount() {
+    // 计算总金额,确保不是NaN,默认0
+    const totalAmount = parseFloat(this.data.productList.reduce((sum, item) => {
+      const amount = parseFloat(item.amount) || 0;
+      return sum + amount;
+    }, 0)) || 0;
+
+    // 计算总数量,所有商品数量的总计
+    const totalQty = this.data.productList.reduce((sum, item) => {
+      const qty = parseInt(item.qty) || 0;
+      return sum + qty;
+    }, 0);
+
+    const form = [...this.data.form];
+    form.forEach(item => {
+      if (item.valueName === 'amount') {
+        item.value = totalAmount.toString();
+        this.setData({ "content.amount": totalAmount });
+      }
+      if (item.valueName === 'orderCount') {
+        item.value = totalQty.toString();
+        this.setData({ "content.orderCount": totalQty });
+      }
     });
+    this.setData({ form });
   }
 });

+ 157 - 0
CRM/customer/modules/orderCreate/create.scss

@@ -20,4 +20,161 @@
   font-size: 32rpx;
   background-color: #3874F6;
   color: #fff;
+}
+
+.empty {
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  height: 200rpx;
+  color: #999;
+  background-color: #f5f5f5;
+  border-radius: 8rpx;
+}
+
+.head {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding: 20rpx;
+  border-bottom: 1rpx solid #f0f0f0;
+}
+
+.count {
+  font-size: 32rpx;
+  font-weight: bold;
+  color: #333;
+}
+
+.but {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  width: 60rpx;
+  height: 60rpx;
+  background-color: #3874F6;
+  color: #fff;
+  border-radius: 50%;
+}
+
+.product-list {
+  padding: 20rpx;
+  background-color: #F4F5F7;
+}
+
+/* 页面背景颜色 */
+page {
+  background-color: #F4F5F7;
+}
+
+.product-item {
+  margin-bottom: 20rpx;
+  background-color: #fff;
+  border-radius: 8rpx;
+  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
+  overflow: hidden;
+}
+
+.product-header {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  padding: 20rpx;
+  background-color: #e8e8e8;
+  border-bottom: 1rpx solid #d9d9d9;
+}
+
+.product-name {
+  font-size: 30rpx;
+  font-weight: bold;
+  color: #333;
+  flex: 1;
+}
+
+.product-actions {
+  display: flex;
+  gap: 20rpx;
+}
+
+.product-actions van-icon {
+  font-size: 32rpx;
+  color: #999;
+}
+
+.product-body {
+  padding: 20rpx;
+}
+
+.product-desc {
+  display: flex;
+  flex-wrap: wrap;
+  gap: 20rpx;
+  font-size: 24rpx;
+  color: #666;
+  margin-bottom: 20rpx;
+}
+
+.product-edit {
+  display: flex;
+  flex-wrap: wrap;
+  gap: 20rpx;
+  margin-bottom: 20rpx;
+}
+
+.edit-item {
+  display: flex;
+  align-items: center;
+  flex: 1;
+  min-width: 45%;
+}
+
+.label {
+  font-size: 24rpx;
+  color: #666;
+  margin-right: 10rpx;
+  white-space: nowrap;
+}
+
+.input {
+  flex: 1;
+  height: 60rpx;
+  padding: 0 10rpx;
+  border: 1rpx solid #e8e8e8;
+  border-radius: 4rpx;
+  font-size: 24rpx;
+  color: #333;
+  background-color: #f9f9f9;
+  max-width: 100%;
+  box-sizing: border-box;
+}
+
+.textarea {
+  flex: 1;
+  padding: 20rpx;
+  border: 1rpx solid #e8e8e8;
+  border-radius: 4rpx;
+  font-size: 24rpx;
+  color: #333;
+  background-color: #f9f9f9;
+  max-width: 100%;
+  box-sizing: border-box;
+  resize: none;
+}
+
+.product-remarks {
+  display: flex;
+  align-items: flex-start;
+  gap: 10rpx;
+  width: 100%;
+  box-sizing: border-box;
+  margin-top: 10rpx;
+}
+
+.product-remarks .textarea {
+  flex: 1;
+  min-width: 0;
+}
+
+.product-remarks .label {
+  margin-top: 10rpx;
 }

+ 53 - 4
CRM/customer/modules/orderCreate/create.wxml

@@ -4,11 +4,59 @@
 <!-- Tab切换 -->
 <van-tabs active="{{activeTab}}" color='#3874F6' title-active-color='#3874F6' bind:change="onTabChange">
   <van-tab title="商品">
-    <view style="padding: 20rpx;">
-      <view class="empty">
-        <text>请添加商品</text>
+    <view class="head">
+      <view class="count">商品明细</view>
+      <view class="expand">
+        <navigator url="#" class="but" bindtap="addProduct">
+          <van-icon name="plus" />
+        </navigator>
       </view>
     </view>
+    <view wx:if="{{productList.length == 0}}" class="empty">
+      <text>请添加商品</text>
+    </view>
+    <view wx:else class="product-list">
+      <view wx:for="{{productList}}" wx:key="index" class="product-item">
+        <view class="product-header">
+          <view class="product-name">{{item.itemname}}</view>
+          <view class="product-actions">
+            <van-icon name="delete" bindtap="deleteProduct" data-index="{{index}}" />
+          </view>
+        </view>
+        <view class="product-body">
+          <view class="product-desc">
+            <text>品号:{{item.itemno || '--'}}</text>
+            <text>型号:{{item.model || '--'}}</text>
+          </view>
+          <view class="product-desc">
+            <text>原价:{{item.originalPrice || item.price}}元</text>
+          </view>
+          <view class="product-edit">
+            <view class="edit-item">
+              <view class="label">单价:</view>
+              <input class="input" type="digit" value="{{item.price}}" data-index="{{index}}" data-field="price" bindblur="onFieldBlur" />
+            </view>
+            <view class="edit-item">
+              <view class="label">折扣:</view>
+              <input class="input" type="digit" value="{{item.discount || 1}}" data-index="{{index}}" data-field="discount" bindblur="onFieldBlur" />
+            </view>
+            <view class="edit-item">
+              <view class="label">数量:</view>
+              <input class="input" type="digit" value="{{item.qty}}" data-index="{{index}}" data-field="qty" bindblur="onFieldBlur" />
+            </view>
+            <view class="edit-item">
+              <view class="label">金额:</view>
+              <input class="input" type="digit" value="{{item.amount}}" data-index="{{index}}" data-field="amount" bindblur="onFieldBlur" />
+            </view>
+          </view>
+          <view class="product-remarks">
+            <view class="label">备注:</view>
+            <textarea class="textarea remarks-input" placeholder="请输入备注" value="{{item.remarks || ''}}" data-index="{{index}}" data-field="remarks" bindblur="onFieldBlur" auto-height />
+          </view>
+        </view>
+      </view>
+    </view>
+
   </van-tab>
   <van-tab title="附件">
     <view style="padding: 20rpx;">
@@ -22,4 +70,5 @@
 <view style="height: 150rpx;" />
 <view class="new-footer">
   <van-button custom-class='new-submit' color='#3874F6' disabled='{{disabled || loading}}' loading='{{loading}}' bind:tap='submit'>确定</van-button>
-</view>
+</view>
+

+ 2 - 3
CRM/order/detail.js

@@ -51,14 +51,13 @@ Page({
   },
   getOrderDetail(id) {
     _Http.basic({
-      "id": "2026031410293201",
+      "id": "2026031414243401",
       content: {
         nocache: true,
         pageNumber: 1,
         pageSize: 1,
+        sa_custorderid: id,
         where: {
-          condition: `sa_custorderid = ${id}`,
-          tableid: 2484
         }
       }
     }).then(res => {