¶Ô±ÈÐÂÎļþ |
| | |
| | | <script setup lang="ts"> |
| | | import tab from '@/plugins/tab'; |
| | | import { AddressInfo, useAddressListPage } from './index'; |
| | | |
| | | // 使ç¨å表页é¢Hook |
| | | const { |
| | | addressList, |
| | | emptyStatus, |
| | | setDefaultAddress, |
| | | deleteAddress |
| | | } = useAddressListPage(); |
| | | |
| | | // è·³è½¬å°æ·»å å°åé¡µé¢ |
| | | function toAddSite() { |
| | | tab.navigateTo('/pages_template/pages/address/addSite'); |
| | | } |
| | | |
| | | // 跳转å°ç¼è¾å°åé¡µé¢ |
| | | function toEditSite(id: string) { |
| | | tab.navigateTo(`/pages_template/pages/address/addSite?id=${id}`); |
| | | } |
| | | |
| | | // 设置为é»è®¤å°å |
| | | function handleSetDefault(id: string) { |
| | | try { |
| | | const success = setDefaultAddress(id); |
| | | |
| | | if (success) { |
| | | uni.showToast({ |
| | | title: '设置æå', |
| | | icon: 'success' |
| | | }); |
| | | } else { |
| | | uni.showToast({ |
| | | title: '设置失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | } catch (e) { |
| | | console.error('设置é»è®¤å°å失败', e); |
| | | uni.showToast({ |
| | | title: '设置失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // å é¤å°å |
| | | function handleDeleteAddress(id: string) { |
| | | uni.showModal({ |
| | | title: 'æç¤º', |
| | | content: 'ç¡®å®è¦å 餿¤å°ååï¼', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | try { |
| | | const success = deleteAddress(id); |
| | | |
| | | if (success) { |
| | | uni.showToast({ |
| | | title: 'å 餿å', |
| | | icon: 'success' |
| | | }); |
| | | } else { |
| | | uni.showToast({ |
| | | title: 'å é¤å¤±è´¥', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | } catch (e) { |
| | | console.error('å é¤å°å失败', e); |
| | | uni.showToast({ |
| | | title: 'å é¤å¤±è´¥', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 鿩并è¿åå°åï¼ç¨äºä»è®¢å页é¢éæ©å°åçåºæ¯ï¼ |
| | | function selectAddress(address: AddressInfo) { |
| | | const pages = getCurrentPages(); |
| | | const prevPage: any = pages[pages.length - 2]; |
| | | |
| | | // æ£æ¥é¡µé¢æ¯å¦ä»è®¢å页é¢è·³è½¬èæ¥ |
| | | if (prevPage && prevPage.$page?.options?.from === 'order') { |
| | | // 设置éä¸çå°åå¹¶è¿å |
| | | uni.$emit('address-selected', address); |
| | | tab.navigateBack(); |
| | | } |
| | | } |
| | | </script> |
| | | |
| | | <template> |
| | | <view class="address-container"> |
| | | <!-- ç©ºç¶æ --> |
| | | <view class="empty-state" v-if="emptyStatus"> |
| | | <image src="/static/images/empty-address.png" mode="aspectFit" class="empty-image"></image> |
| | | <view class="empty-text">æ¨è¿æ²¡ææ·»å æ¶è´§å°å</view> |
| | | </view> |
| | | |
| | | <!-- å°åå表 --> |
| | | <view v-else> |
| | | <view class="item" v-for="(address, index) in addressList" :key="address.id"> |
| | | <view class="top" @tap="selectAddress(address)"> |
| | | <view class="name">{{ address.name }}</view> |
| | | <view class="phone">{{ address.phone }}</view> |
| | | <view class="tag"> |
| | | <text v-if="address.isDefault" class="red">é»è®¤</text> |
| | | <text v-if="address.tag">{{ address.tag }}</text> |
| | | </view> |
| | | </view> |
| | | <view class="bottom" @tap="selectAddress(address)"> |
| | | {{ address.region }} {{ address.address }} |
| | | </view> |
| | | <view class="actions"> |
| | | <view class="action-btn" @tap="handleSetDefault(address.id)" v-if="!address.isDefault"> |
| | | <u-icon name="checkmark-circle" color="#999" size="40rpx"></u-icon> |
| | | <text>设为é»è®¤</text> |
| | | </view> |
| | | <view class="action-btn" @tap="toEditSite(address.id)"> |
| | | <u-icon name="edit-pen" color="#999" size="40rpx"></u-icon> |
| | | <text>ç¼è¾</text> |
| | | </view> |
| | | <view class="action-btn" @tap="handleDeleteAddress(address.id)"> |
| | | <u-icon name="trash" color="#999" size="40rpx"></u-icon> |
| | | <text>å é¤</text> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </view> |
| | | |
| | | <!-- æ°å»ºå°åæé® --> |
| | | <view class="addSite" @tap="toAddSite"> |
| | | <view class="add"> |
| | | <u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>æ°å»ºæ¶è´§å°å |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </template> |
| | | |
| | | <style lang="scss" scoped> |
| | | .address-container { |
| | | padding-bottom: 180rpx; |
| | | min-height: 100vh; |
| | | background-color: #f5f5f5; |
| | | } |
| | | |
| | | .empty-state { |
| | | display: flex; |
| | | flex-direction: column; |
| | | align-items: center; |
| | | justify-content: center; |
| | | padding-top: 200rpx; |
| | | |
| | | .empty-image { |
| | | width: 200rpx; |
| | | height: 200rpx; |
| | | margin-bottom: 40rpx; |
| | | } |
| | | |
| | | .empty-text { |
| | | color: #999; |
| | | font-size: 30rpx; |
| | | } |
| | | } |
| | | |
| | | .item { |
| | | box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.1); |
| | | border-radius: 16rpx; |
| | | margin: 20rpx; |
| | | padding: 30rpx; |
| | | background-color: #ffffff; |
| | | |
| | | .top { |
| | | display: flex; |
| | | align-items: center; |
| | | font-size: 32rpx; |
| | | font-weight: bold; |
| | | |
| | | .phone { |
| | | margin-left: 40rpx; |
| | | color: #666666; |
| | | } |
| | | |
| | | .tag { |
| | | margin-left: auto; |
| | | |
| | | text { |
| | | background-color: #e0f7fa; |
| | | color: #00bcd4; |
| | | border-radius: 20rpx; |
| | | padding: 8rpx 16rpx; |
| | | font-size: 24rpx; |
| | | margin-left: 10rpx; |
| | | } |
| | | |
| | | .red { |
| | | background-color: #ffebee; |
| | | color: #d32f2f; |
| | | } |
| | | } |
| | | } |
| | | |
| | | .bottom { |
| | | margin-top: 20rpx; |
| | | font-size: 28rpx; |
| | | color: #666666; |
| | | line-height: 1.6; |
| | | padding-bottom: 20rpx; |
| | | border-bottom: 1px solid #f0f0f0; |
| | | } |
| | | |
| | | .actions { |
| | | display: flex; |
| | | justify-content: flex-end; |
| | | margin-top: 20rpx; |
| | | |
| | | .action-btn { |
| | | display: flex; |
| | | align-items: center; |
| | | margin-left: 30rpx; |
| | | font-size: 26rpx; |
| | | color: #666; |
| | | |
| | | text { |
| | | margin-left: 6rpx; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | .addSite { |
| | | position: fixed; |
| | | bottom: 40rpx; |
| | | left: 50%; |
| | | transform: translateX(-50%); |
| | | width: 80%; |
| | | height: 100rpx; |
| | | line-height: 100rpx; |
| | | background: linear-gradient(90deg, #ff4034, #fa3534); |
| | | border-radius: 50rpx; |
| | | text-align: center; |
| | | color: #ffffff; |
| | | font-size: 32rpx; |
| | | box-shadow: 0 8rpx 16rpx rgba(250, 53, 52, 0.2); |
| | | z-index: 100; |
| | | |
| | | .add { |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | height: 100%; |
| | | width: 100%; |
| | | |
| | | .icon { |
| | | margin-right: 10rpx; |
| | | } |
| | | } |
| | | } |
| | | </style> |