deming/pageE/more/Address.vue

89 lines
1.9 KiB
Vue
Raw Normal View History

2020-06-02 11:42:13 +08:00
<template>
<view class="address">
2020-06-22 17:45:17 +08:00
<u-radio-group v-model="current" @change="changeDefault" size="29" active-color="#FF780F">
<view v-for="(item, index) in addressList" :key="index" class="address-item">
2020-06-23 17:21:01 +08:00
<AddressItem :item="item" :current='current' @getAddressList="getAddressList"></AddressItem>
2020-06-22 17:45:17 +08:00
</view>
</u-radio-group>
<view class="address-btn" @click="addAddress">添加地址</view>
2020-06-23 17:21:01 +08:00
<u-toast ref="uToast" />
2020-06-02 11:42:13 +08:00
</view>
</template>
<script>
import AddressItem from '@/components/mine/address-block/address-item'
export default {
data() {
return {
2020-06-23 17:21:01 +08:00
current: -1,
2020-06-22 17:45:17 +08:00
addressList: []
2020-06-02 11:42:13 +08:00
}
},
2020-06-02 15:35:19 +08:00
components: {
2020-06-02 11:42:13 +08:00
AddressItem
},
2020-06-22 17:45:17 +08:00
onLoad() {
this.getAddressList();
},
methods: {
getAddressList() {
this.$u.api.getAddressList().then((res)=>{
if (res.errCode == 0) {
this.addressList = res.data.addressList;
let defaultAddress = this.addressList.filter(item => {
return item.address_is_default == '1';
})
2020-06-23 17:21:01 +08:00
if(defaultAddress[0]) this.current = defaultAddress[0].address_id;
2020-06-22 17:45:17 +08:00
}
})
},
addAddress() {
uni.navigateTo({
url: '/pageE/more/AddAddress'
});
},
2020-06-23 17:21:01 +08:00
// 设置默认地址
changeDefault(id) {
// console.log(id)
this.$u.api.setDefaultAddress({
address_id: id
}).then((res)=>{
if(res.errCode == 0) {
this.getAddressList();
} else {
this.$refs.uToast.show({
title: res.message,
type: 'warning',
})
}
})
2020-06-22 17:45:17 +08:00
},
},
2020-06-02 11:42:13 +08:00
}
</script>
<style lang="scss" scoped>
.address {
2020-06-04 08:21:34 +08:00
min-height: calc(100vh - var(--window-top));
2020-06-02 11:42:13 +08:00
background-color: #ECECEC;
2020-06-22 17:45:17 +08:00
padding: 1rpx 0 40rpx;
box-sizing: border-box;
.u-radio-group {
display: block;
.address-item {
background-color: #ffffff;
margin-bottom: 20rpx;
padding: 30rpx;
}
}
.address-btn {
2020-06-23 17:21:01 +08:00
margin: 260rpx auto 0;
2020-06-22 17:45:17 +08:00
width: 690rpx;
height: 98rpx;
background: rgba(255,119,15,1);
border-radius: 49rpx;
font-size: 36rpx;
color: rgba(255,255,255,1);
line-height: 98rpx;
text-align: center;
}
2020-06-02 11:42:13 +08:00
}
</style>