Files

320 lines
6.8 KiB
Vue
Raw Normal View History

2023-10-11 11:27:47 +08:00
<template>
<layout>
2023-11-15 19:59:37 +08:00
2023-11-17 20:55:32 +08:00
<Header :scroll-top="scrollTop">
2023-11-15 19:59:37 +08:00
{{ title }}
</Header>
2023-10-11 11:27:47 +08:00
<view class="addressList">
2023-11-14 17:21:03 +08:00
<template v-if=" main.address.length>0">
<uv-swipe-action>
<uv-swipe-action-item
v-for="(item, index) in main.address"
:key="index"
:options="options"
2023-11-17 20:55:32 +08:00
@click="showModal( item)"
2023-10-11 11:27:47 +08:00
>
2023-11-14 17:21:03 +08:00
<view
:class="{ address: true, noBorder: index == 0 }"
@tap="handleClick(item)"
>
<view class="address-main">
<view class="address-header">
<view class="address-name">{{ item.realName }}</view>
<view class="address-phone">{{ item.phone }}</view>
</view>
<view class="address-content">
<view
class="address-default"
v-if="item.isDefault"
>
<uv-tags
text="默认"
plain
size="mini"
></uv-tags>
</view>
<view class="address-desc">{{ item.province }}-{{ item.city }}-{{ item.district }} {{
item.detail
}}
2023-11-14 17:21:03 +08:00
</view>
</view>
2023-10-11 11:27:47 +08:00
</view>
2023-11-14 17:21:03 +08:00
<view class="address-actions">
2023-10-11 11:27:47 +08:00
<view
2023-11-14 17:21:03 +08:00
class="address-actions-edit"
@tap.stop="goEditorAddress(item)"
2023-10-11 11:27:47 +08:00
>
2023-11-14 17:21:03 +08:00
<image
class="image"
2023-11-22 18:55:55 +08:00
:src="addressEditIcon"
2023-11-14 17:21:03 +08:00
alt=""
></image>
2023-10-11 11:27:47 +08:00
</view>
</view>
</view>
2023-11-14 17:21:03 +08:00
</uv-swipe-action-item>
</uv-swipe-action>
</template>
<Empty
2023-11-17 20:55:32 +08:00
:iconSrc="emptyAddressIcon"
2023-11-14 17:21:03 +08:00
v-else
>
您还没有新增地址~
</Empty>
2023-10-11 11:27:47 +08:00
</view>
2023-11-15 19:59:37 +08:00
<view class="form-buttons">
<view class="btn">
<uv-button
round
block
type="primary"
@tap="goCreateAddress"
>
新增地址
</uv-button>
</view>
</view>
2023-11-17 20:55:32 +08:00
<ReturnTop :scroll-top="scrollTop" />
<Modal
ref="modalRef"
content="确认要删除地址吗?"
@confirm="doDeleteRequest" />
2023-10-11 11:27:47 +08:00
</layout>
</template>
<script setup>
2023-11-14 17:21:03 +08:00
import { ref, unref } from 'vue'
import { onLoad, onReachBottom } from '@dcloudio/uni-app'
2024-02-22 18:37:23 +08:00
import { useMainStore } from '@/store/modules/useMainStore'
2023-11-14 17:21:03 +08:00
import Empty from '@/components/Empty/index.vue'
import { addressEditIcon, emptyAddressIcon } from "@/utils/images";
2023-11-14 17:21:03 +08:00
import { getAddressDel, } from '@/api/address'
import { useRouter } from "@/hooks/useRouter";
2023-11-15 19:59:37 +08:00
import Header from "@/components/Header/index.vue"
2023-11-17 20:55:32 +08:00
import ReturnTop from "@/components/ReturnTop/index.vue";
import { useScroll } from "@/hooks/useScroll";
import Modal from "@/components/Modal/index.vue";
2023-10-11 11:27:47 +08:00
2023-11-14 17:21:03 +08:00
const {push, goBack} = useRouter()
2023-11-17 20:55:32 +08:00
const {scrollTop} = useScroll()
2023-10-11 11:27:47 +08:00
const title = ref('')
const main = useMainStore()
2023-11-14 17:21:03 +08:00
const moreLoding = ref(true)
2023-10-11 11:27:47 +08:00
const actionType = ref('')
2023-11-14 17:21:03 +08:00
const page = ref(1)
const selectCartId = ref(undefined)
2023-10-11 11:27:47 +08:00
const options = ref([{
text: '删除',
style: {
2023-11-17 20:55:32 +08:00
backgroundColor: '#EE6D46'
2023-10-11 11:27:47 +08:00
}
}])
2023-11-14 17:21:03 +08:00
onReachBottom((e) => {
if (main.moreLoading) {
page.value = page.value + 1
main.getAddressList(page.value)
}
})
2023-10-11 11:27:47 +08:00
const goCreateAddress = () => {
2023-11-14 17:21:03 +08:00
let addressData = {};
if (actionType.value === 'select') {
2023-11-14 17:21:03 +08:00
addressData.type = 'select';
}
push({url: '/pages/createAddress/createAddress'}, {data: addressData})
2023-10-11 11:27:47 +08:00
}
const goEditorAddress = (address) => {
2023-11-14 17:21:03 +08:00
let addressData = {
id: address.id
};
if (actionType.value === 'select') {
2023-11-14 17:21:03 +08:00
addressData.type = 'select';
}
push({url: '/pages/createAddress/createAddress'}, {data: addressData})
2023-10-11 11:27:47 +08:00
}
const handleClick = (item) => {
if (actionType.value === 'select') {
2023-10-11 11:27:47 +08:00
main.setSelectAddress(item.id)
goBack()
// push({url: '/pages/submitOrder/submitOrder'}, {
// data: {cartId: unref(selectCartId) || main.cartId},
// type: 'redirectTo'
// })
2023-10-11 11:27:47 +08:00
}
}
2023-11-14 17:21:03 +08:00
const {getParams} = useRouter()
2023-10-11 11:27:47 +08:00
onLoad((option) => {
2023-11-14 17:21:03 +08:00
main.restAddress()
const params = getParams(option)
params.cartId ? main.cartId = params.cartId : void (0)
if (params.type) {
actionType.value = params.type
2023-10-11 11:27:47 +08:00
title.value = '选择地址'
2023-11-14 17:21:03 +08:00
selectCartId.value = params.cartId
2023-10-11 11:27:47 +08:00
} else {
title.value = '地址管理'
}
2023-11-14 17:21:03 +08:00
main.getAddressList(page.value)
2023-10-11 11:27:47 +08:00
})
2023-11-17 20:55:32 +08:00
const modalRef = ref()
const prepareData = ref({})
2023-10-11 11:27:47 +08:00
2023-11-17 20:55:32 +08:00
/**
* 打开弹窗
*/
function showModal(data) {
2023-11-17 20:55:32 +08:00
prepareData.value = data
unref(modalRef).show()
}
2023-11-15 19:59:37 +08:00
2023-11-17 20:55:32 +08:00
/**
* 删除地址
*/
async function doDeleteRequest() {
2023-11-17 20:55:32 +08:00
await getAddressDel(prepareData.value)
await main.restAddress()
await main.getAddressList(1)
if (main.selectAddress && prepareData.value.id === main.selectAddress.id) {
2023-11-17 20:55:32 +08:00
main.clearSelectAddress()
2023-10-11 11:27:47 +08:00
}
}
</script>
2023-11-14 17:21:03 +08:00
<style lang="scss">
2023-11-22 18:55:55 +08:00
@import "../../style/images";
2023-10-11 11:27:47 +08:00
.address {
padding: 25rpx 35rpx;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
&-actions {
&-edit {
width: 33rpx;
height: 33rpx;
.image {
width: 100%;
height: 100%;
display: block;
}
}
}
&.noBorder {
&::after {
display: none;
}
}
&::after {
content: '';
position: absolute;
left: 35rpx;
top: 0;
right: 0;
height: 1rpx;
background: #E6E6E6;
}
background: #fff;
&-header {
display: flex;
align-items: center;
margin-bottom: 8rpx;
}
&-name {
line-height: 40rpx;
font-size: 28rpx;
color: #333333;
margin-right: 30rpx;
}
&-phone {
line-height: 40rpx;
font-size: 28rpx;
color: #333333;
}
&-content {
display: flex;
align-items: center;
2023-11-14 17:21:03 +08:00
padding-right: 10rpx;
2023-10-11 11:27:47 +08:00
}
&-default {
2023-11-14 17:21:03 +08:00
width: 80rpx;
margin-right: 20rpx;
2023-10-11 11:27:47 +08:00
}
&-desc {
2023-11-14 17:21:03 +08:00
flex: 1;
2023-10-11 11:27:47 +08:00
line-height: 33rpx;
font-size: 24rpx;
color: #999999;
2023-11-14 17:21:03 +08:00
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
2023-10-11 11:27:47 +08:00
}
}
2023-11-14 17:21:03 +08:00
.addressList {
padding-bottom: 100rpx;
}
.form-buttons {
position: fixed;
bottom: env(safe-area-inset-bottom);
2023-11-14 17:21:03 +08:00
left: 0;
z-index: 999;
width: 100%;
padding: 0;
}
2023-11-15 19:59:37 +08:00
.form-buttons .btn {
2023-11-14 17:21:03 +08:00
width: 90%;
margin: 0 auto;
}
.address-default :deep(.uv-tags) {
justify-content: center;
2023-11-15 19:59:37 +08:00
white-space: nowrap;
2023-11-14 17:21:03 +08:00
}
2023-11-17 20:55:32 +08:00
.addressList :deep(.uv-swipe-action-item__right__button__wrapper) {
position: relative;
2023-11-17 20:55:32 +08:00
&:before {
position: absolute;
content: '';
2023-11-22 18:55:55 +08:00
background: $addDelIcon no-repeat center center;
2023-11-17 20:55:32 +08:00
width: 50rpx;
height: 50rpx;
background-size: contain;
}
}
2023-11-17 20:55:32 +08:00
.addressList :deep(.uv-swipe-action-item__right__button__wrapper__text) {
visibility: hidden;
}
2023-10-11 11:27:47 +08:00
</style>