代码提交
This commit is contained in:
@ -1,65 +1,76 @@
|
||||
<template>
|
||||
<layout>
|
||||
<uv-navbar
|
||||
:fixed="false"
|
||||
:title="title"
|
||||
left-arrow
|
||||
@leftClick="$onClickLeft"
|
||||
:fixed="false"
|
||||
:title="title"
|
||||
left-arrow
|
||||
@leftClick="goBack"
|
||||
/>
|
||||
|
||||
<view class="addressList">
|
||||
<uv-swipe-action>
|
||||
<uv-swipe-action-item
|
||||
v-for="(item, index) in main.address"
|
||||
:key="index"
|
||||
:options="options"
|
||||
@click="handleAddressClick($event, item)"
|
||||
>
|
||||
<view
|
||||
:class="{ address: true, noBorder: index == 0 }"
|
||||
@tap="handleClick(item)"
|
||||
<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"
|
||||
@click="handleAddressClick($event, 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
|
||||
: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
|
||||
}}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="address-actions">
|
||||
<view
|
||||
class="address-actions-edit"
|
||||
@tap.stop="goEditorAddress(item)"
|
||||
>
|
||||
<image
|
||||
class="image"
|
||||
src="@/static/images/icon-edit.png"
|
||||
alt=""
|
||||
></image>
|
||||
</view>
|
||||
<view class="address-desc">{{ item.detail }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="address-actions">
|
||||
<view
|
||||
class="address-actions-edit"
|
||||
@tap="goEditorAddress(item)"
|
||||
>
|
||||
<image
|
||||
class="image"
|
||||
src="@/static/images/icon-edit.png"
|
||||
alt=""
|
||||
></image>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</uv-swipe-action-item>
|
||||
</uv-swipe-action>
|
||||
</uv-swipe-action-item>
|
||||
</uv-swipe-action>
|
||||
</template>
|
||||
<Empty
|
||||
:iconSrc="emptyIcon"
|
||||
v-else
|
||||
>
|
||||
您还没有新增地址~
|
||||
</Empty>
|
||||
</view>
|
||||
<div class="form-buttons">
|
||||
<uv-button
|
||||
round
|
||||
block
|
||||
type="primary"
|
||||
@tap="goCreateAddress"
|
||||
round
|
||||
block
|
||||
type="primary"
|
||||
@tap="goCreateAddress"
|
||||
>
|
||||
新增地址
|
||||
</uv-button>
|
||||
@ -69,25 +80,23 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { navigateTo, back } from '@/utils/router'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { ref, unref } from 'vue'
|
||||
import { onLoad, onReachBottom } from '@dcloudio/uni-app'
|
||||
import { useMainStore } from '@/store/store'
|
||||
import Empty from '@/components/Empty/index.vue'
|
||||
import emptyIcon from '@/static/icon/empty/地址.png'
|
||||
import { getAddressDel, } from '@/api/address'
|
||||
import { useRouter } from "@/hooks/useRouter";
|
||||
|
||||
import {
|
||||
getAddressDel,
|
||||
getAddressDefault,
|
||||
getAddressAddAndEdit,
|
||||
getAddressList,
|
||||
getAddressCityList,
|
||||
} from '@/api/address'
|
||||
const {push, goBack} = useRouter()
|
||||
|
||||
const title = ref('')
|
||||
|
||||
const main = useMainStore()
|
||||
|
||||
const moreLoding = ref(true)
|
||||
const actionType = ref('')
|
||||
|
||||
const page = ref(1)
|
||||
const selectCartId = ref(undefined)
|
||||
const options = ref([{
|
||||
text: '删除',
|
||||
style: {
|
||||
@ -95,65 +104,91 @@ const options = ref([{
|
||||
}
|
||||
}])
|
||||
|
||||
onReachBottom((e) => {
|
||||
if (main.moreLoading) {
|
||||
page.value = page.value + 1
|
||||
main.getAddressList(page.value)
|
||||
}
|
||||
})
|
||||
|
||||
const goCreateAddress = () => {
|
||||
navigateTo({
|
||||
url: "/pages/createAddress/createAddress"
|
||||
});
|
||||
let addressData = {};
|
||||
if (actionType.value == 'select') {
|
||||
addressData.type = 'select';
|
||||
}
|
||||
push({url: '/pages/createAddress/createAddress'}, {data: addressData})
|
||||
}
|
||||
|
||||
const goEditorAddress = (address) => {
|
||||
navigateTo({
|
||||
url: "/pages/createAddress/createAddress",
|
||||
query: {
|
||||
id: address.id
|
||||
}
|
||||
});
|
||||
let addressData = {
|
||||
id: address.id
|
||||
};
|
||||
if (actionType.value == 'select') {
|
||||
addressData.type = 'select';
|
||||
}
|
||||
push({url: '/pages/createAddress/createAddress'}, {data: addressData})
|
||||
}
|
||||
|
||||
const handleClick = (item) => {
|
||||
if (actionType.value == 'select') {
|
||||
main.setSelectAddress(item.id)
|
||||
back()
|
||||
console.log(main.cartId, 'main.cartId')
|
||||
push({url: '/pages/submitOrder/submitOrder'}, {
|
||||
data: {cartId: unref(selectCartId) || main.cartId},
|
||||
type: 'redirectTo'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const {getParams} = useRouter()
|
||||
onLoad((option) => {
|
||||
if (option.type) {
|
||||
actionType.value = option.type
|
||||
main.restAddress()
|
||||
const params = getParams(option)
|
||||
params.cartId ? main.cartId = params.cartId : void (0)
|
||||
if (params.type) {
|
||||
actionType.value = params.type
|
||||
title.value = '选择地址'
|
||||
selectCartId.value = params.cartId
|
||||
} else {
|
||||
title.value = '地址管理'
|
||||
}
|
||||
main.getAddressList()
|
||||
main.getAddressList(page.value)
|
||||
})
|
||||
|
||||
|
||||
const handleAddressClick = async ({ index }, data) => {
|
||||
const handleAddressClick = async ({index}, data) => {
|
||||
if (index == 0) {
|
||||
uni.showLoading({
|
||||
title: '删除中',
|
||||
mask: true,
|
||||
})
|
||||
uni.showModal({
|
||||
title: '温馨提示',
|
||||
content: '是否确认删除此地址?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
uni.showLoading({
|
||||
title: '删除中',
|
||||
mask: true,
|
||||
})
|
||||
|
||||
await getAddressDel(data)
|
||||
uni.showToast({
|
||||
title: "删除成功",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
await getAddressDel(data)
|
||||
uni.showToast({
|
||||
title: "删除成功",
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
uni.hideLoading()
|
||||
main.restAddress()
|
||||
main.getAddressList(1)
|
||||
} else if (res.cancel) {
|
||||
}
|
||||
}
|
||||
});
|
||||
uni.hideLoading()
|
||||
main.getAddressList()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
<style lang="scss">
|
||||
.addressList {
|
||||
.address {
|
||||
&:last-child {
|
||||
@ -172,7 +207,8 @@ const handleAddressClick = async ({ index }, data) => {
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
&-main {}
|
||||
&-main {
|
||||
}
|
||||
|
||||
&-actions {
|
||||
&-edit {
|
||||
@ -207,7 +243,6 @@ const handleAddressClick = async ({ index }, data) => {
|
||||
}
|
||||
|
||||
|
||||
|
||||
background: #fff;
|
||||
|
||||
&-header {
|
||||
@ -231,19 +266,48 @@ const handleAddressClick = async ({ index }, data) => {
|
||||
}
|
||||
|
||||
&-content {
|
||||
height: 52rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding-right: 10rpx;
|
||||
}
|
||||
|
||||
&-default {
|
||||
margin-right: 82rpx;
|
||||
width: 80rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
&-desc {
|
||||
flex: 1;
|
||||
line-height: 33rpx;
|
||||
font-size: 24rpx;
|
||||
color: #999999;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
}
|
||||
|
||||
.addressList {
|
||||
padding-bottom: 100rpx;
|
||||
}
|
||||
|
||||
.form-buttons {
|
||||
position: fixed;
|
||||
bottom: 40rpx;
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.form-buttons :deep(.uv-button) {
|
||||
width: 90%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.address-default :deep(.uv-tags) {
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user