收货地址的两种状态

This commit is contained in:
jqtmviyu@gmail.com 2021-03-05 19:16:28 +08:00
parent cc72e22c35
commit 6f621bc328

View File

@ -1,13 +1,96 @@
<template> <template>
<view>支付页面</view> <view clang="pay">
<!-- 1. 假设本地能拿到收货地址 -->
<view v-if="address.userName" class="address" @tap="getAddressHandle">
<view class="address_detail">{{addressDetail}}</view>
<view class="address_info">
<text class="address_text">{{address.userName}}</text>
<text class="address_text">{{address.telNumber}}</text>
</view>
</view>
<!-- 2. 本地拿不到收货地址 -->
<view v-else class="address_empty">
<view @tap="getAddressHandle" class="address_empty_button">选择收货地址</view>
</view>
</view>
</template> </template>
<script> <script>
export default { export default {
data() {
return {
address: {}
}
},
onLoad(){
this.address = uni.getStorageSync("address") || {}
},
methods: {
//
getAddressHandle(){
uni.chooseAddress({
success: (res) => {
uni.setStorageSync("address", res)
console.log(res)
this.address = res
}
})
}
},
computed: {
//
addressDetail (){
const {detailInfo, countyName, cityName, provinceName} = this.address
return provinceName + cityName + countyName + detailInfo
}
},
} }
</script> </script>
<style lang="scss"> <style lang="scss">
page {
background-color: #f9f9f9;
}
//
.address {
background-color: #fff;
border-radius: 5rpx;
margin: 20rpx;
height: 188rpx;
padding: 20rpx;
display: flex;
flex-direction: column;
justify-content: space-between;
.address_detail {
font-size: 30rpx;
}
.address_info {
font-size: 26rpx;
.address_text {
margin-right: 40rpx;
}
}
}
.address_empty {
background-color: #fff;
border-radius: 5rpx;
margin: 20rpx;
height: 188rpx;
padding: 20rpx;
display: flex;
justify-content: center;
align-items: center;
.address_empty_button {
width: 300rpx;
height: 90rpx;
border-radius: 45rpx;
color: #eb4450;
border: 2rpx solid #eb4450;
display: flex;
justify-content: center;
align-items: center;
font-size: 30rpx;
}
}
</style> </style>