From 92230c9a97dc9ce9df3313d11d26999c04bb6b26 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期二, 15 七月 2025 13:12:48 +0800 Subject: [PATCH] 项目初始化 --- src/pages_template/pages/address/index.vue | 262 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 262 insertions(+), 0 deletions(-) diff --git a/src/pages_template/pages/address/index.vue b/src/pages_template/pages/address/index.vue new file mode 100644 index 0000000..b7c6a11 --- /dev/null +++ b/src/pages_template/pages/address/index.vue @@ -0,0 +1,262 @@ +<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> -- Gitblit v1.9.3