Browse Source

feat: 修改地址和手机号

xdd 3 days ago
parent
commit
9f99b5176e
1 changed files with 65 additions and 32 deletions
  1. 65 32
      src/views/hisStore/components/productOrder.vue

+ 65 - 32
src/views/hisStore/components/productOrder.vue

@@ -356,10 +356,10 @@
     </el-dialog>
     </el-dialog>
     <el-dialog :title="editAddress.title" :visible.sync="editAddress.open" width="600px" append-to-body>
     <el-dialog :title="editAddress.title" :visible.sync="editAddress.open" width="600px" append-to-body>
       <el-form ref="editAddressForm" :model="editAddressForm" :rules="editAddressRules" label-width="100px">
       <el-form ref="editAddressForm" :model="editAddressForm" :rules="editAddressRules" label-width="100px">
-        <el-form-item label="收件人" prop="realName">
+        <el-form-item label="收件人" prop="realName" required>
           <el-input v-model="editAddressForm.realName" placeholder="请输入收件人" />
           <el-input v-model="editAddressForm.realName" placeholder="请输入收件人" />
         </el-form-item>
         </el-form-item>
-          <el-form-item label="联系电话" prop="source">
+          <el-form-item label="联系电话" prop="userPhone" required>
           <el-input v-model="editAddressForm.userPhone" placeholder="请输入联系电话" />
           <el-input v-model="editAddressForm.userPhone" placeholder="请输入联系电话" />
         </el-form-item>
         </el-form-item>
         <el-form-item label="收货地址" prop="district">
         <el-form-item label="收货地址" prop="district">
@@ -396,7 +396,7 @@
           </el-col>
           </el-col>
         </el-row>
         </el-row>
         </el-form-item>
         </el-form-item>
-        <el-form-item label="详细地址" prop="detail">
+        <el-form-item label="详细地址" prop="detail" required>
           <el-input v-model="editAddressForm.detail" placeholder="请输入收货人详细地址" />
           <el-input v-model="editAddressForm.detail" placeholder="请输入收货人详细地址" />
         </el-form-item>
         </el-form-item>
       </el-form>
       </el-form>
@@ -821,42 +821,76 @@ export default {
             var province = this.citys.find((item) => {
             var province = this.citys.find((item) => {
               return item.name === addressParts[0] && item.level === 0;
               return item.name === addressParts[0] && item.level === 0;
             });
             });
-
             if (province != null) {
             if (province != null) {
               this.editAddressForm.provinceId = province.cityId;
               this.editAddressForm.provinceId = province.cityId;
               this.editAddressForm.province = province.name;
               this.editAddressForm.province = province.name;
-              this.city = this.citys.filter(item => item.parentId === province.cityId && item.level === 1);
-            }
-          }
 
 
-          // 查找城市
-          if (addressParts.length > 1) {
-            var city = this.citys.find((item) => {
-              return item.name === addressParts[1] && item.level === 1;
-            });
+              // 检查是否为直辖市(北京、上海、天津、重庆)
+              const isDirectMunicipality = ['北京市', '上海市', '天津市', '重庆市'].includes(province.name);
 
 
-            if (city != null) {
-              this.editAddressForm.cityId = city.cityId;
-              this.editAddressForm.city = city.name;
-              this.district = this.citys.filter(item => item.parentId === city.cityId && item.level === 2);
-            }
-          }
+              if (isDirectMunicipality) {
+                // 直辖市处理:先找到市级节点(市辖区)
+                if (addressParts.length > 1) {
+                  // 查找市级节点(第2部分,如"市辖区")
+                  var cityLevel = this.citys.find((item) => {
+                    return item.name === addressParts[1] && item.level === 1 && item.parentId === province.cityId;
+                  });
 
 
-          // 查找区县
-          if (addressParts.length > 2) {
-            var district = this.citys.find((item) => {
-              return item.name === addressParts[2] && item.level === 2;
-            });
+                  if (cityLevel != null) {
+                    this.editAddressForm.cityId = cityLevel.cityId;
+                    this.editAddressForm.city = cityLevel.name;
+                    this.city = this.citys.filter(item => item.parentId === province.cityId && item.level === 1);
 
 
-            if (district != null) {
-              this.editAddressForm.districtId = district.cityId;
-              this.editAddressForm.district = district.name;
-            }
-          }
+                    // 使用市级节点的cityId作为parentId查找区县
+                    if (addressParts.length > 2) {
+                      var district = this.citys.find((item) => {
+                        return item.name === addressParts[2] && item.level === 2 && item.parentId === cityLevel.cityId;
+                      });
+
+                      if (district != null) {
+                        this.editAddressForm.districtId = district.cityId;
+                        this.editAddressForm.district = district.name;
+                        this.district = this.citys.filter(item => item.parentId === cityLevel.cityId && item.level === 2);
+                      }
+                    }
+
+                    // 提取详细地址(第4部分及之后)
+                    if (addressParts.length > 3) {
+                      this.editAddressForm.detail = addressParts.slice(3).join(' ');
+                    }
+                  }
+                }
+              } else {
+                // 普通省份处理:正常匹配市、区
+                this.city = this.citys.filter(item => item.parentId === province.cityId && item.level === 1);
 
 
-          // 提取详细地址(第4部分及之后的所有内容)
-          if (addressParts.length > 3) {
-            this.editAddressForm.detail = addressParts.slice(3).join(' ');
+                // 查找城市
+                if (addressParts.length > 1) {
+                  var city = this.citys.find((item) => {
+                    return item.name === addressParts[1] && item.level === 1;
+                  });
+                  if (city != null) {
+                    this.editAddressForm.cityId = city.cityId;
+                    this.editAddressForm.city = city.name;
+                    this.district = this.citys.filter(item => item.parentId === city.cityId && item.level === 2);
+                  }
+                }
+                // 查找区县
+                if (addressParts.length > 2) {
+                  var district = this.citys.find((item) => {
+                    return item.name === addressParts[2] && item.level === 2;
+                  });
+                  if (district != null) {
+                    this.editAddressForm.districtId = district.cityId;
+                    this.editAddressForm.district = district.name;
+                  }
+                }
+                // 提取详细地址(第4部分及之后)
+                if (addressParts.length > 3) {
+                  this.editAddressForm.detail = addressParts.slice(3).join(' ');
+                }
+              }
+            }
           }
           }
         }
         }
 
 
@@ -867,7 +901,6 @@ export default {
       }).finally(()=>{
       }).finally(()=>{
         loading.close();
         loading.close();
       })
       })
-
     },
     },
     /** 提交按钮 */
     /** 提交按钮 */
     submitEditAddressForm() {
     submitEditAddressForm() {