|
@@ -14,17 +14,18 @@
|
|
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
|
|
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
|
|
import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
|
|
import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
|
|
import { addressDel, addressList } from '@/api/mine'
|
|
import { addressDel, addressList } from '@/api/mine'
|
|
|
|
+import { bindingAddress } from '@/api/order'
|
|
import { t } from '@/locale'
|
|
import { t } from '@/locale'
|
|
-import { toPage } from '@/utils/page'
|
|
|
|
|
|
+import { getPageParams, goBack, toPage } from '@/utils/page'
|
|
import { toast } from '@/utils/toast'
|
|
import { toast } from '@/utils/toast'
|
|
|
|
|
|
defineOptions({
|
|
defineOptions({
|
|
name: 'AddressBook', // 地址簿
|
|
name: 'AddressBook', // 地址簿
|
|
})
|
|
})
|
|
|
|
|
|
-const userInfo = computed(() => {
|
|
|
|
- return getUserInfoHook()
|
|
|
|
-})
|
|
|
|
|
|
+// 页面参数
|
|
|
|
+const pageParams = ref<any>({})
|
|
|
|
+const isSelectMode = computed(() => pageParams.value.selectMode === true)
|
|
|
|
|
|
// z-paging
|
|
// z-paging
|
|
const paging = ref(null)
|
|
const paging = ref(null)
|
|
@@ -45,11 +46,53 @@ async function queryList(pageNo: number, pageSize: number) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 处理地址项点击
|
|
|
|
+function handleAddressClick(item: any) {
|
|
|
|
+ if (isSelectMode.value) {
|
|
|
|
+ // 选择模式:选择地址并绑定到订单
|
|
|
|
+ selectAddressForOrder(item)
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // 普通模式:编辑地址
|
|
|
|
+ editAddress(item.id)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// 编辑地址
|
|
// 编辑地址
|
|
function editAddress(id: any) {
|
|
function editAddress(id: any) {
|
|
toPage('/pages/mine/addressBookOperate', { id })
|
|
toPage('/pages/mine/addressBookOperate', { id })
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 选择地址并绑定到订单
|
|
|
|
+async function selectAddressForOrder(address: any) {
|
|
|
|
+ try {
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ title: t('addressBook.select.binding'),
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ const res = await bindingAddress({
|
|
|
|
+ orderId: pageParams.value.orderId,
|
|
|
|
+ addressId: address.id,
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ if (res.code === '200') {
|
|
|
|
+ toast.success(t('addressBook.select.success'))
|
|
|
|
+ // 返回上一页
|
|
|
|
+ goBack()
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ toast.error(res.message || t('addressBook.select.failed'))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (error: any) {
|
|
|
|
+ console.error('Bind address error:', error)
|
|
|
|
+ toast.error(t('addressBook.select.networkError'))
|
|
|
|
+ }
|
|
|
|
+ finally {
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// 删除地址
|
|
// 删除地址
|
|
async function deleteAddress(id: any) {
|
|
async function deleteAddress(id: any) {
|
|
try {
|
|
try {
|
|
@@ -87,13 +130,20 @@ function handleAction(action: string, item: any) {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+onShow(() => {
|
|
|
|
+ paging.value.reload(true)
|
|
|
|
+})
|
|
|
|
+// 页面加载时获取参数
|
|
|
|
+onLoad((options) => {
|
|
|
|
+ pageParams.value = getPageParams(options)
|
|
|
|
+})
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
|
|
<z-paging ref="paging" v-model="dataList" use-page-scroll @query="queryList">
|
|
<view class="py-20rpx">
|
|
<view class="py-20rpx">
|
|
<wd-swipe-action v-for="item in dataList" :key="item.id">
|
|
<wd-swipe-action v-for="item in dataList" :key="item.id">
|
|
- <view class="flex items-center justify-between bg-white px-22rpx py-18rpx" @click="editAddress(item.id)">
|
|
|
|
|
|
+ <view class="flex items-center justify-between bg-white px-22rpx py-18rpx" @click="handleAddressClick(item)">
|
|
<view class="flex-1">
|
|
<view class="flex-1">
|
|
<view class="mb-20rpx flex items-center justify-between text-24rpx">
|
|
<view class="mb-20rpx flex items-center justify-between text-24rpx">
|
|
<view>
|
|
<view>
|