Browse Source

fix(订单): 修复客户数据加载和表单回显问题

yz 1 month ago
parent
commit
4b9ebaad00
2 changed files with 23 additions and 19 deletions
  1. 0 1
      src/views/order/order/constants.js
  2. 23 18
      src/views/order/order/index.js

+ 0 - 1
src/views/order/order/constants.js

@@ -96,7 +96,6 @@ export const ORDER_STATUS_OPTIONS = [
  * @returns {string} 订单类型标签
  */
 export const getOrderTypeLabel = (orderType) => {
-    console.log(orderType)
     return ORDER_TYPE_LABELS[orderType] || '未知类型';
 };
 

+ 23 - 18
src/views/order/order/index.js

@@ -247,7 +247,7 @@ export default {
                   this.form.customerCode = selectedCustomer.customerCode
                   this.form.customerName = selectedCustomer.customerName
                   // Load customer addresses
-                  this.loadCustomerAddresses(value)
+                  this.loadCustomerAddresses(selectedCustomer.customerCode)
                 } else {
                   this.clearCustomerData()
                 }
@@ -503,19 +503,6 @@ export default {
             ]
           },
           {
-            label: '客户ID',
-            prop: 'customerId',
-            type: 'number',
-            hide: true,
-            rules: [
-              {
-                required: true,
-                message: '请输入客户ID',
-                trigger: 'blur'
-              }
-            ]
-          },
-          {
             label: '创建时间',
             prop: 'createTime',
             type: 'datetime',
@@ -742,19 +729,37 @@ export default {
      * @returns {Promise<void>}
      */
     async beforeOpen(done, type) {
-
       // 确保客户选项已加载
       if (this.customerOptions.length === 0) {
-        this.loadCustomerOptions()
+        await this.loadCustomerOptions()
       }
 
+      // 更新客户选项到表格配置中
+      this.updateCustomerOptionsInColumn()
+
       if (['edit', 'view'].includes(type)) {
         try {
           const res = await getDetail(this.form.id)
-          this.form = res.data.data
-          // 如果是编辑模式,加载对应客户的地址列表
+          const orderData = res.data.data
+
+          // 先设置基本数据
+          this.form = { ...orderData }
+
+          // 如果有客户编码,加载对应的地址列表
           if (this.form.customerCode) {
             await this.loadCustomerAddresses(this.form.customerCode)
+
+            // 确保客户字段正确回显
+            // 查找匹配的客户选项
+            const matchedCustomer = this.customerOptions.find(option =>
+              option.customerCode === this.form.customerCode ||
+              option.value === this.form.customerId
+            )
+
+            if (matchedCustomer) {
+              // 确保客户ID字段正确设置
+              this.form.customerId = matchedCustomer.value
+            }
           }
         } catch (error) {
           window.console.log(error)