소스 검색

用户订单地址修改

jiayubo 3 달 전
부모
커밋
01e90ccd99

+ 0 - 1
pages/mine/index.vue

@@ -1,7 +1,6 @@
 <template>
   <view>
     <view class="mine-container">
-
       <view class="mine-header" :style="{ paddingTop: globalData.navBarHeight + 'px' }">
         <view class="flex_c_s mine-header-info">
           <img :show-loading="true" :src="userInfo.avatar" class="header-avatar" />

+ 35 - 6
pages_classify/pages/orderItem/orderdetails.vue

@@ -1,12 +1,12 @@
 <template>
   <view>
-    <view class="address-container">
+    <view class="address-container" @click="handleAddressClick">
       <view class="address-header">
         <!-- 左侧默认标签-->
 
         <!-- 中间收货人信息 -->
         <view class="contact-info">
-          {{ listData.cityName }}
+          {{ listData.name || listData.cityName }}
           {{ listData.telephone }}
         </view>
 
@@ -117,10 +117,11 @@
 </template>
 
 <script setup>
-import { onLoad } from '@dcloudio/uni-app'
+import { onLoad, onShow } from '@dcloudio/uni-app'
 import { ref, computed, onMounted } from 'vue'
 import { orderInfomainOrderId } from '@/api/userList.js'
 import { systemDictdaTalist } from '@/api/userList.js'
+import store from '@/store'
 
 const listData = ref({}) //志愿者详情数据
 const dataList = ref([])
@@ -184,9 +185,30 @@ const handlButClick = (item) => {
 onLoad(async (options) => {
   mainOrderId.value = options.mainOrderId
   const res = await orderInfomainOrderId(mainOrderId.value)
-  // console.log('API Response:', res)
-  listData.value = res.data
-  // console.log('listData:', listData.value)
+  // 检查是否有临时地址
+  const tempAddress = store.state.user.tempSelectedAddress
+  if (tempAddress) {
+    // 合并临时地址和订单数据
+    listData.value = {
+      ...res.data,
+      ...tempAddress
+    }
+  } else {
+    listData.value = res.data
+  }
+})
+
+// 添加 onShow 生命周期钩子
+onShow(async () => {
+  // 从 store 获取临时地址
+  const tempAddress = store.state.user.tempSelectedAddress
+  if (tempAddress) {
+    // 合并临时地址和订单数据
+    listData.value = {
+      ...listData.value,
+      ...tempAddress
+    }
+  }
 })
 
 const hadlClickError = {
@@ -203,6 +225,13 @@ const previewImage = (current, urls) => {
   })
 }
 
+// 添加地址点击事件处理
+const handleAddressClick = () => {
+  uni.navigateTo({
+    url: '/pages_mine/pages/selectAddress/index'
+  })
+}
+
 onMounted(() => {
   getData()
 })

+ 36 - 11
pages_home/pages/Volunteerside/goodsDetails.vue

@@ -208,14 +208,11 @@
             <view v-if="selectedAddress" style="margin-left: 8px; flex: 1">
               <view class="address-display">
                 <text class="address-line">
-                  {{ selectedAddress.provinceName }}{{ selectedAddress.cityName
-                  }}{{ selectedAddress.districtName }}
+                  {{ selectedAddress.provinceName }}{{ selectedAddress.cityName }}{{ selectedAddress.districtName }}
                 </text>
                 <view class="contact-info">
                   <text class="contact-name">{{ selectedAddress.name }}</text>
-                  <text class="contact-phone">{{
-                    selectedAddress.telephone
-                    }}</text>
+                  <text class="contact-phone">{{ selectedAddress.telephone }}</text>
                 </view>
               </view>
             </view>
@@ -298,8 +295,8 @@
 </template>
 
 <script setup>
-import { onLoad } from '@dcloudio/uni-app'
-import { onMounted, ref, reactive, computed, nextTick } from 'vue'
+import { onLoad, onShow } from '@dcloudio/uni-app'
+import { onMounted, ref, reactive, computed, nextTick, onUnmounted } from 'vue'
 import {
   getDetailsvolunteerId,
   volunteerwork,
@@ -312,6 +309,7 @@ import itsCalendar from '@/components/its-calendar/its-calendar.vue'
 import uniDatetimePickerMy from '@/uni_modules/lic-uni-datetime-picker/components/lic-uni-datetime-picker/lic-uni-datetime-picker.vue'
 import addressComponent from '@/pages_home/components/volunteerData/adresss.vue'
 import Detiles from './detiles.vue'
+import store from '@/store'
 
 // const src = ref(
 //   'http://pic2.sc.chinaz.com/Files/pic/pic9/202002/hpic2119_s.jpg'
@@ -427,13 +425,11 @@ const handlCancel = () => {
   totalTimes.value = 0 // 重置点击次数
 }
 
-const jumpToAddressSelect = () => {
-  addressFlag.value = true
-}
-
 // 新增:处理子组件传回的地址数据
 const handleAddressUpdate = (newAddress) => {
   selectedAddress.value = newAddress
+  // 保存到store中
+  store.dispatch('SetTempAddress', newAddress)
   addressFlag.value = false // 关闭选择器
 }
 // 详情底部底部数据
@@ -845,11 +841,40 @@ const firstVolunteerPicture = computed(() => {
   return pictures[0];
 });
 
+// 添加 onShow 生命周期钩子
+onShow(() => {
+  // 从 store 获取临时地址
+  const tempAddress = store.state.user.tempSelectedAddress
+  if (tempAddress) {
+    selectedAddress.value = tempAddress
+    console.log('地址已更新:', selectedAddress.value)
+  }
+})
+
+// 修改地址显示部分
+const jumpToAddressSelect = () => {
+  uni.navigateTo({
+    url: '/pages_mine/pages/selectAddress/index'
+  })
+}
+
 onMounted(async () => {
   await getListTime()
+  // 检查store中是否有临时地址
+  const tempAddress = store.state.user.tempSelectedAddress
+  if (tempAddress) {
+    selectedAddress.value = tempAddress
+  }
+})
+
+// 在页面卸载时清除临时地址
+onUnmounted(() => {
+  store.dispatch('ClearTempAddress')
 })
 </script>
 
 <style scoped lang="scss">
 @import '../../styles/goodsDetails.scss';
+
+
 </style>

+ 1 - 0
pages_mine/pages/index.vue

@@ -0,0 +1 @@
+ 

+ 7 - 0
pages_mine/pages/selectAddress/index.vue

@@ -55,6 +55,7 @@
 <script setup>
 import { onMounted, ref } from 'vue'
 import { addressList, addressAddressIds } from '@/api/userSettings.js'
+import store from '@/store'
 
 const radioValue = ref(null)
 const dataList = ref([])
@@ -140,6 +141,12 @@ const handleRadioChange = (addressId, item) => {
     (item) => item.addressId === addressId
   )
   console.log('选中项完整数据:', selectedItem)
+  
+  // 将选中的地址保存到store
+  store.dispatch('SetTempAddress', selectedItem)
+  
+  // 返回上一页
+  uni.navigateBack()
 }
 
 // onLoad((options) => {

+ 16 - 1
store/modules/user.ts

@@ -26,7 +26,8 @@ const user: Module<UserState, UserState> = {
         data: ['重庆市', '重庆市', '永川区'],
         index: [21, 0, 17],
       },
-    }
+    },
+    tempSelectedAddress: null
   },
   mutations: {
     SET_TOKEN: (state, token: string) => {
@@ -69,6 +70,12 @@ const user: Module<UserState, UserState> = {
     SET_ADDRESSINFO: (state, data: any) => {
       state.addressInfo = data
     },
+    SET_TEMP_ADDRESS: (state, address) => {
+      state.tempSelectedAddress = address
+    },
+    CLEAR_TEMP_ADDRESS: (state) => {
+      state.tempSelectedAddress = null
+    }
   },
 
   actions: {
@@ -183,6 +190,14 @@ const user: Module<UserState, UserState> = {
         storage.clean()
       })
     },
+    // 设置临时地址
+    SetTempAddress({ commit }, address) {
+      commit('SET_TEMP_ADDRESS', address)
+    },
+    // 清空临时地址
+    ClearTempAddress({ commit }) {
+      commit('CLEAR_TEMP_ADDRESS')
+    }
   }
 }