调试接口

This commit is contained in:
wangxiaowei
2025-12-30 19:08:44 +08:00
parent f69536a7e4
commit 031649e9c4
11 changed files with 455 additions and 327 deletions

View File

@ -15,12 +15,12 @@
<navbar title="新增地址" :leftArrow="false" custom-class='!bg-[#F6F7F8]'></navbar>
<view class="bg-white mx-32rpx rounded-16rpx px-42rpx py-34rpx mt-32rpx">
<view class="bg-white mx-32rpx rounded-16rpx px-42rpx mt-32rpx">
<view class="flex items-center">
<view class="text-30rpx leading-42rpx text-[#303133] w-200rpx">选择地区</view>
<wd-picker :columns="cityColumns" v-model="form.city" use-default-slot>
<wd-picker :columns="cityColumns" v-model="form.city_id" use-default-slot @confirm="Add.handleConfirmAddress">
<view class="flex items-center">
<wd-input readonly v-model="form.city" size="large" placeholder="请选择地区" no-border placeholderStyle="font-size: 30rpx; line-height: 42rpx; color: #c9c9c9;"></wd-input>
<wd-input readonly v-model="city" size="large" placeholder="请选择地区" no-border placeholderStyle="font-size: 30rpx; line-height: 42rpx; color: #c9c9c9;"></wd-input>
<wd-icon name="chevron-right" size="32rpx" color="#909399"></wd-icon>
</view>
</wd-picker>
@ -48,8 +48,7 @@
</view>
<view class="flex items-center justify-between mx-30rpx" v-if="addressId > 0">
<view class="w-330rpx h-90rpx leading-90rpx text-center bg-[#F6F7F8] text-#303133 rounded-8rpx mr-30rpx" @click="Add.handleDeleteAddress">删除地址</view>
<view class="w-330rpx h-90rpx leading-90rpx text-center bg-[#4C9F44] text-#FFFFFF rounded-8rpx" @click="Add.handleAddAddress">确定</view>
<view class="w-630rpx h-90rpx leading-90rpx text-center bg-[#4C9F44] text-#FFFFFF rounded-8rpx" @click="Add.handleAddAddress">确定</view>
</view>
</view>
@ -59,7 +58,7 @@
<script lang="ts" setup>
import { useMessage } from 'wot-design-uni'
import { useColPickerData } from '@/hooks/useColPickerData'
// import { addUserAddress, IAddUserAddressParams, deleteUserAddress, userAddressDetails, editUserAddress } from '@/api/user'
import { addUserAddress, deleteUserAddress, editUserAddress, getOpenCityList } from '@/api/user'
import { toast } from '@/utils/toast'
import { mobile } from '@/utils/test'
import { router } from '@/utils/tools'
@ -70,12 +69,7 @@
const message = useMessage('wd-message-box-slot')
// 获取已开通城市
const cityColumns = ref<Array<{ label: string; value: string }>>([
{ label: '北京市', value: '110000' },
{ label: '上海市', value: '310000' },
{ label: '广州市', value: '440100' },
{ label: '深圳市', value: '440300' },
])
const cityColumns = ref<Array<{ label: string, value: number }>>([])
// 页面标题
const title = ref<string>('新增地址')
@ -85,10 +79,12 @@
// 表单信息
const form = ref({
city: '',
city_id: 0,
latitude: 0,
longitude: 0,
address: '',
id: 0
})
const city = ref<string>('')
onLoad((args) => {
@ -97,19 +93,30 @@
title.value = '修改地址'
addressId.value = Number(args.id)
// Add.handleGetAddressDetails()
}
}
Add.handleGetCity()
})
const Add = {
// // 确认省市区
// handleConfirmAddress: (e) => {
// form.province = e.selectedItems[0]?.label || ''
// form.province_id = Number(e.selectedItems[0]?.value) || 0
// form.city = e.selectedItems[1]?.label || ''
// form.city_id = Number(e.selectedItems[1]?.value) || 0
// form.district = e.selectedItems[2]?.label || ''
// form.district_id = Number(e.selectedItems[2]?.value) || 0
// },
/**
* 获取已开通城市
*/
handleGetCity: async () => {
const res = await getOpenCityList()
cityColumns.value = res.list.map((item: any) => ({
label: item.name,
value: item.id
}))
},
/**
* 确认选择的地址
*/
handleConfirmAddress: (e: any) => {
form.value.city_id = Number(e.value)
city.value = e.selectedItems.label || ''
},
// // 获取地址详情
// handleGetAddressDetails: async () => {
@ -136,36 +143,6 @@
// console.log("🚀 ~ address.value:", address.value)
// },
// // 删除地址
// handleDeleteAddress: async () => {
// console.log("🚀 ~ 删除地址:", message)
// message.confirm({
// title: '删除地址',
// msg: '确定要删除该地址吗?',
// confirmButtonText: '确定',
// cancelButtonText: '取消',
// cancelButtonProps: {
// customClass: '!bg-[#F6F7F8] !text-[#303133] !text-32rpx !leading-44rpx !rounded-8rpx',
// },
// confirmButtonProps: {
// customClass: '!bg-[#4C9F44] !text-[#fff] !text-32rpx !leading-44rpx !rounded-8rpx',
// }
// }).then(async (res) => {
// // 点击确认按钮回调事件
// await deleteUserAddress({
// id: addressId.value
// })
// toast.info('删除成功')
// uni.$emit('refreshAddressList')
// router.navigateBack(500)
// }).catch((res) => {
// console.log("🚀 ~ res2:", res)
// // 点击取消按钮回调事件
// })
// },
/**
* 选择地址
*/
@ -177,7 +154,9 @@
// res.name: "嘉兴市南湖区人民政府(景宜路西)"
// res.latitude: 30.74744
// res.longitude: 120.78483
form.value.address = res.address + res.name
form.value.address = res.address
form.value.latitude = res.latitude
form.value.longitude = res.longitude
},
fail: (err) => {
console.log("🚀 ~ err:", err)
@ -189,24 +168,29 @@
* 添加地址
*/
handleAddAddress: async () => {
// if (!form.address) {
// toast.info('请填写地址信息')
// return
// }
if (!form.value.city_id) {
toast.info('请选择地区')
return false
}
if (!form.value.address) {
toast.info('请填写地址信息')
return false
}
// // form.is_default = isDefaultAddress.value ? 1 : 0
// if (addressId.value > 0 ) {
// // 编辑地址
// form.id = addressId.value
// // await editUserAddress(form)
// } else {
// // await addUserAddress(form)
// }
if (addressId.value > 0 ) {
// 编辑地址
// form.id = addressId.value
// await editUserAddress(form)
} else {
await addUserAddress(form.value)
}
uni.$emit('refreshAddressList')
router.navigateBack(500)
},
// uni.$emit('refreshAddressList')
// router.navigateBack(500)
}
// // 添加地址
// handleAddAddress: async () => {
// if (!form.contact) {

View File

@ -26,45 +26,19 @@
<view class="text-28rpx leading-40rpx text-[#8A94A3] mt-18rpx">还没有地址请尽快新建地址</view>
</view>
<!-- <wd-radio-group v-model="addressId" shape="button" >
<wd-radio :value="1">沃特</wd-radio>
<wd-radio :value="2">商家后台</wd-radio>
</wd-radio-group> -->
<!-- 地址列表 -->
<!-- <view class="mx-30rpx mt-20rpx" v-if="addressList.length > 0">
<view class="bg-#fff rounded-16rpx px-30rpx py-36rpx flex items-center mb-20rpx" v-for="(item, index) in addressList" :key="index">
<view @click="List.handleChooseAddress(item)">
<view class="flex items-center">
<view class="mr-10rpx">
<wd-tag color="#4C9F44" bg-color="#F3F3F3" custom-class="!rounded-4rpx !px-10rpx" v-if="item.is_default">默认</wd-tag>
</view>
<view class="text-30rpx leading-42rpx text-#303133">
<text class="mr-16rpx">{{ item.contact}}</text>
<text>{{ item.telephone }}</text>
</view>
</view>
<view class="w-562rpx line-1 text-26rpx leading-34rpx text-#909399 mt-10rpx">{{ item.address }}</view>
</view>
<view class="flex-1 ml-30rpx" @click="List.handleEditAddress(item.id)">
<wd-icon name="edit-outline" size="32rpx" color="#666666"></wd-icon>
</view>
</view>
</view> -->
<view class="mx-30rpx mt-38rpx address-radio">
<wd-radio-group v-model="addressId" shape="dot" >
<view class="bg-white rounded-16rpx px-40rpx py-30rpx mb-20rpx" v-for="item in addressList" :key="item.id">
<view class="bg-white rounded-16rpx px-40rpx py-30rpx mb-20rpx" v-for="(item, index) in addressList" :key="item.id">
<view class="">
<wd-radio :value="item.id" checked-color="#4C9F44">
<view class="flex items-center">
<wd-img :src="`${OSS}icon/icon_location5.png`" width="40rpx" height="40rpx"></wd-img>
<view class="ml-16rpx text-30rpx leading-42rpx text-[#303133]">位置1</view>
<view class="ml-16rpx text-30rpx leading-42rpx text-[#303133]">位置{{ index + 1 }}</view>
</view>
</wd-radio>
</view>
<view class="line-2 text-26rpx leading-34rpx text-[#606266] mt-16rpx">
北京市海淀区恒大新宏福苑西区20号楼2单元301
{{ item.address }}
</view>
<view class="flex items-center justify-end mt-24rpx text-26rpx leading-34rpx text-[##303133]">
@ -99,9 +73,12 @@
import type { IUserAddressListResult } from '@/api/types/user'
import { router } from '@/utils/tools'
import { useMessage } from 'wot-design-uni'
import { getUserAddressList, deleteUserAddress } from '@/api/user'
import { useToast } from 'wot-design-uni'
const OSS = inject('OSS')
const from = ref<string>('')
const toast = useToast()
// 弹出框
const message = useMessage('wd-message-box-slot')
@ -111,24 +88,14 @@
// 选中的地址ID
const addressId = ref<number>(0)
const addressList = ref<Array<{id:number, address: string}>>([
{
id: 1,
address: '浙江省杭州市西湖区文三路138号',
},
{
id: 2,
address: '浙江省杭州市西湖区文三路138号',
}
])
const addressList = ref<Array<{id:number, address: string}>>([])
onLoad((args) => {
if (args.from) {
from.value = args.from as string
}
// 监听地址列表刷新
// 监听地址列表刷新
uni.$on('refreshAddressList', () => {
List.handleInit()
})
@ -146,8 +113,8 @@
* 初始化地址列表
*/
handleInit: async () => {
const res = await getUserAddress()
addressList.value = Array.isArray(res) ? res : []
const res = await getUserAddressList()
addressList.value = res
},
/**
@ -185,17 +152,11 @@
customClass: '!bg-[#4C9F44] !text-[#fff] !text-32rpx !leading-44rpx !rounded-8rpx',
}
}).then(async (res) => {
// // 点击确认按钮回调事件
// await deleteUserAddress({
// id: addressId.value
// })
// toast.info('删除成功')
// uni.$emit('refreshAddressList')
// router.navigateBack(500)
}).catch((res) => {
console.log("🚀 ~ res2:", res)
// 点击取消按钮回调事件
})
// 点击确认按钮回调事件
await deleteUserAddress(id)
toast.show('删除成功')
List.handleInit()
}).catch((res) => { })
},
/**
@ -208,7 +169,7 @@
</script>
<style lang="scss" scoped>
<style lang="scss">
page {
background-color: $cz-page-background;
}

View File

@ -207,9 +207,10 @@
const response = JSON.parse(e.file.response)
if (response.code) {
const avatarUrl = response.data.url
await updateUserInfo({ avatar: avatarUrl })
user.value.avatar = avatarUrl
toast.info('头像上传成功')
console.log("🚀 ~ avatarUrl:", response)
// await updateUserInfo({ avatar: avatarUrl })
// user.value.avatar = avatarUrl
// toast.info('头像上传成功')
} else {
throw new Error('上传失败')
}