Procházet zdrojové kódy

feat: 修改地址和手机号

xdd před 3 dny
rodič
revize
53712ad7c4
1 změnil soubory, kde provedl 105 přidání a 23 odebrání
  1. 105 23
      src/views/hisStore/components/productOrder.vue

+ 105 - 23
src/views/hisStore/components/productOrder.vue

@@ -757,35 +757,117 @@ export default {
           this.province=res.data.filter(item => item.level===0 )
         })
     },
-    handleEditAddress() {
-        this.getCityList();
-        this.editAddressForm.id=this.order.id;
-        this.editAddressForm.realName=this.order.realName;
-        this.editAddressForm.userPhone=this.order.userPhone;
-        var address=this.order.userAddress.split(' ')
-        var province=this.citys.find((item)=>{
-          return item.name==address[0]&&item.level==0;
-        })
-        if(province!=null){
-          this.editAddressForm.provinceId=province.cityId;
-          this.city=this.citys.filter(item => item.parentId===province.cityId&&item.level==1 )
-        }
-        var city=this.citys.find((item)=>{
-          return item.name==address[1]&&item.level==1;
-        })
+    flattenCityData(data, level = 0) {
+      let result = [];
+      data.forEach(item => {
+        // 转换字段名
+        const cityItem = {
+          cityId: item.value,
+          name: item.label,
+          parentId: item.pid,
+          level: level
+        };
+        result.push(cityItem);
 
-        if(city!=null){
-          this.editAddressForm.cityId=city.cityId;
-          this.district=this.citys.filter(item => item.parentId===city.cityId&&item.level==2 )
+        // 递归处理子节点
+        if (item.children && item.children.length > 0) {
+          result = result.concat(this.flattenCityData(item.children, level + 1));
         }
-        var district=this.citys.find((item)=>{
-          return item.name==address[2]&&item.level==2;
+      });
+      return result;
+    },
+    handleEditAddress() {
+      let loading = this.$loading({
+        lock: true,
+        text: "请求中...",
+        background: "rgba(0, 0, 0, 0.7)",
+      });
+      const orderId = this.order.id;
+
+      getStoreOrderAddress(orderId).then(addressResponse => {
+        // 更新解密后的地址
+        this.order.userAddress = addressResponse.address;
+
+      }).then(res=>{
+        const id = this.order.id;
+        return getUserPhone(id).then(response =>{
+          this.order.userPhone = response.userPhone;
         })
-        if(district!=null){
-          this.editAddressForm.districtId=district.cityId;
+      }).then(res=>{
+        return getCitys();
+      }).then(res => {
+        this.citys = this.flattenCityData(res.data);
+        this.province = this.citys.filter(item => item.level === 0);
+
+        this.editAddressForm = {
+          id: this.order.id,
+          realName: this.order.realName,
+          userPhone: this.order.userPhone,
+          provinceId: null,
+          cityId: null,
+          districtId: null,
+          province: '',
+          city: '',
+          district: '',
+          detail: ''
+        };
+
+        // 解析地址
+        if (this.order.userAddress) {
+          var addressParts = this.order.userAddress.split(' ');
+
+          // 查找省份
+          if (addressParts.length > 0) {
+            var province = this.citys.find((item) => {
+              return item.name === addressParts[0] && item.level === 0;
+            });
+
+            if (province != null) {
+              this.editAddressForm.provinceId = province.cityId;
+              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;
+            });
+
+            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(' ');
+          }
         }
 
         this.editAddress.open = true;
+      }).catch(error => {
+        this.msgError("加载数据失败");
+        console.error(error);
+      }).finally(()=>{
+        loading.close();
+      })
+
     },
     /** 提交按钮 */
     submitEditAddressForm() {