Files
2026-05-26 15:52:30 +08:00

219 lines
5.6 KiB
Vue

<!-- 收件地址列表 -->
<template>
<s-layout
:bgStyle="{ color: theme == '1' ? '#F2F4F7' : '#F2F4F7' }"
title="收货地址"
class="theme-ai"
:opacityBgUi="theme == '2' ? 'bg24' : ''"
:color="theme == 2 ? '#ffffff' : ''"
:navbarStyle="{
color: theme == '2' ? '#ffffff' : '',
}"
>
<view v-if="state?.list?.length" style="padding-top: 14rpx">
<s-address-item
hasBorderBottom
v-for="item in state.list"
:key="item.id"
:item="item"
@tap="onSelect(item)"
@edit="onEdit(item)"
@del="delAddress(item)"
@getData="getData"
:theme="theme"
/>
</view>
<!-- <su-fixed bottom placeholder> -->
<view class="footer-box">
<view class="ss-flex ss-row-between ss-p-20">
<button
class="add-btn ss-reset-button ui-Shadow-Main"
:class="theme == '1' ? '' : 'ai-button2'"
@tap="openPopup"
>
新增收货地址
</button>
</view></view
>
<!-- </su-fixed> -->
<s-empty
v-if="state.list.length === 0 && !state.loading"
text="暂无收货地址"
icon="/static/data-empty.png"
/>
<uni-popup ref="popupRef" background-color="#ffffff">
<card_edit ref="cardEditRef" @close="close" :theme="theme"></card_edit>
</uni-popup>
<!-- <su-popup type="center" :show="show" round="10" @close="close" :backgroundColor="theme == '1' ? '#fff' : '#161C35'">
<card_edit ref="cardEditRef" @close="close" :theme="theme"></card_edit>
</su-popup> -->
</s-layout>
</template>
<script setup>
import { ref, onBeforeMount, reactive } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import sheep from '@/sheep';
import { isEmpty } from 'lodash-es';
import AreaApi from '@/sheep/api/system/area';
import AddressApi from '@/sheep/api/member/address';
const state = reactive({
list: [], // 地址列表
loading: true,
openType: '', // 页面打开类型
});
let theme = ref('2');
// 选择收货地址
const onSelect = (addressInfo) => {
if (state.openType !== 'select') {
// 不作为选择组件时阻断操作
return;
}
uni.$emit('SELECT_ADDRESS', {
addressInfo,
});
sheep.$router.back();
};
// 导入微信地址
function importWechatAddress() {
let wechatAddress = {};
// #ifdef MP
uni.chooseAddress({
success: (res) => {
wechatAddress = {
consignee: res.userName,
mobile: res.telNumber,
province_name: res.provinceName,
city_name: res.cityName,
district_name: res.countyName,
address: res.detailInfo,
region: '',
is_default: false,
};
if (!isEmpty(wechatAddress)) {
sheep.$router.go('/pages/user/address/edit', {
data: JSON.stringify(wechatAddress),
});
}
},
fail: (err) => {
console.log('%cuni.chooseAddress,调用失败', 'color:green;background:yellow');
},
});
// #endif
// #ifdef H5
sheep.$platform.useProvider('wechat').jssdk.openAddress({
success: (res) => {
wechatAddress = {
consignee: res.userName,
mobile: res.telNumber,
province_name: res.provinceName,
city_name: res.cityName,
district_name: res.countryName,
address: res.detailInfo,
region: '',
is_default: false,
};
if (!isEmpty(wechatAddress)) {
sheep.$router.go('/pages/user/address/edit', {
data: JSON.stringify(wechatAddress),
});
}
},
});
// #endif
}
const getData = async () => {
state.list = (await AddressApi.getAddressList()).data;
state.loading = false;
};
onLoad((option) => {
if (option.type) {
state.openType = option.type;
}
getData();
theme.value = option.theme || 2;
});
onBeforeMount(() => {
if (!!uni.getStorageSync('areaData')) {
return;
}
// 提前加载省市区数据
AreaApi.getAreaTree().then((res) => {
if (res.code === 0) {
uni.setStorageSync('areaData', res.data);
}
});
});
let show = ref(false);
let popupRef = ref(null);
const openPopup = () => {
// show.value = true;
popupRef.value.open('center');
};
const close = () => {
// show.value = false;
popupRef.value.close();
getData();
};
let cardEditRef = ref(null);
const onEdit = (item) => {
openPopup();
setTimeout(() => {
if (cardEditRef.value) {
cardEditRef.value.onEdit(item.id);
}
}, 1000);
};
const delAddress = (item) => {
AddressApi.deleteAddress(item.id).then((res) => {
if (res.code === 0) {
uni.showToast({
title: '删除成功',
icon: 'none',
});
setTimeout(() => {
getData();
}, 500);
}
});
};
</script>
<style lang="scss" scoped>
.footer-box {
width: 100%;
position: fixed;
bottom: 0;
.add-btn {
flex: 1;
background: linear-gradient(131deg, #f7772e 0%, #ee0a24 100%);
border-radius: 8rpx;
font-size: 32rpx;
// font-weight: 500;
line-height: 82rpx;
color: $white;
position: relative;
z-index: 1;
}
.sync-wxaddress {
flex: 1;
line-height: 80rpx;
background: $white;
border-radius: 80rpx;
font-size: 30rpx;
font-weight: 500;
color: $dark-6;
margin-right: 18rpx;
}
}
:deep(.uni-radio-input) {
background-color: rgba(255, 255, 255, 0);
}
</style>