lilishop-uniapp/pages/mine/address/addressManage.vue

175 lines
4.8 KiB
Vue
Raw Normal View History

2021-05-13 11:03:32 +08:00
<template>
<view class="address">
2021-09-09 15:05:19 +08:00
<u-empty class="empty" v-if="this.addressList == 0" text="暂无收货地址" mode="address"></u-empty>
<view class="list" >
2021-05-13 11:03:32 +08:00
<view class="item c-content" v-for="(item, index) in addressList" :key="index">
<view class="basic">
<text>{{ item.name }}</text>
<text>{{ item.mobile }}</text>
<text class="default" v-show="item.isDefault"></text>
<view>
<div class="region">
2021-05-14 17:31:40 +08:00
<span v-if="item.consigneeAddressPath[0]">{{item.consigneeAddressPath[0]}}</span>
<span v-if="item.consigneeAddressPath[1]">{{item.consigneeAddressPath[1]}}</span>
<span v-if="item.consigneeAddressPath[2]">{{item.consigneeAddressPath[2]}}</span>
<span v-if="item.consigneeAddressPath[3]">{{item.consigneeAddressPath[3]}}</span>
<span>{{ item.detail }}</span>
2021-05-13 11:03:32 +08:00
</div>
</view>
</view>
<view class="edit">
<view class="relative" @click="setDefault(item)">
<view v-if="item.isDefault" class="alifont icon-xuanzhong"></view>
<text v-else class="unchecked"></text>
<text>{{ item.isDefault ? "默认地址" : "设为默认" }}</text>
</view>
<view class="relative">
<view class="alifont icon-bianji-copy"></view>
<text class="mr-40" @click="addAddress(item.id)"></text>
<view class="alifont icon-lajitong"></view>
2021-05-14 17:31:40 +08:00
<text @click="removeAddress(item.id)"></text>
2021-05-13 11:03:32 +08:00
</view>
</view>
</view>
<view style="height: 100px"></view>
</view>
<button type="default" class="btn" @click="addAddress('')">
<u-icon name="plus-circle"></u-icon>
添加新收货人
</button>
2021-05-14 17:31:40 +08:00
<u-action-sheet :list="removeList" :tips="tips" v-model="showAction" @click="deleteAddressMessage"></u-action-sheet>
2021-05-13 11:03:32 +08:00
</view>
</template>
<script>
import * as API_Address from "@/api/address.js";
export default {
data() {
return {
2021-05-14 17:31:40 +08:00
addressList: [], //地址列表
showAction: false, //是否显示下栏框
2021-09-09 15:05:19 +08:00
2021-05-14 17:31:40 +08:00
removeList: [
2021-05-13 11:03:32 +08:00
{
text: "确定",
},
],
tips: {
text: "确定要删除该收货人信息吗?",
},
2021-05-14 17:31:40 +08:00
removeId: "", //删除的地址id
2021-09-09 15:02:44 +08:00
routerVal: "",
2021-05-13 11:03:32 +08:00
params: {
pageNumber: 1,
pageSize: 1000,
},
};
},
// 返回上一级
onBackPress(e) {
uni.switchTab({
url: "/pages/tabbar/user/my",
});
return true;
},
onLoad: function (val) {
this.routerVal = val;
},
2021-09-09 15:02:44 +08:00
onPullDownRefresh() {
//下拉刷新
this.addressList = [];
this.getAddressList();
},
2021-05-14 17:31:40 +08:00
/**
* 进入页面检测当前账户是否登录
*/
2021-05-13 11:03:32 +08:00
onShow() {
2021-09-09 15:02:44 +08:00
let that = this;
2021-05-14 17:31:40 +08:00
if (this.$options.filters.isLogin("auth")) {
2021-05-13 11:03:32 +08:00
this.getAddressList();
2021-05-14 17:31:40 +08:00
} else {
uni.showModal({
title: "提示",
content: "检测到您的账号还未登录,是否去登录?",
confirmColor: this.$lightColor,
success: function (res) {
if (res.confirm) {
that.$options.filters.navigateToLogin();
2021-05-14 17:31:40 +08:00
} else if (res.cancel) {
uni.navigateBack();
}
},
});
2021-05-13 11:03:32 +08:00
}
},
methods: {
//获取地址列表
getAddressList() {
uni.showLoading();
API_Address.getAddressList(
this.params.pageNumber,
this.params.pageSize
).then((res) => {
2021-09-09 15:05:19 +08:00
res.data.result.records.forEach((item) => {
item.consigneeAddressPath = item.consigneeAddressPath.split(",");
});
this.addressList = res.data.result.records;
2021-05-13 11:03:32 +08:00
uni.hideLoading();
});
},
//删除地址
2021-05-14 17:31:40 +08:00
removeAddress(id) {
this.removeId = id;
2021-05-13 11:03:32 +08:00
this.showAction = true;
},
2021-05-14 17:31:40 +08:00
// 删除地址
2021-05-13 11:03:32 +08:00
deleteAddressMessage() {
2021-05-14 17:31:40 +08:00
API_Address.deleteAddress(this.removeId).then((res) => {
2021-05-13 11:03:32 +08:00
if (res.statusCode == 200) {
uni.showToast({
icon: "none",
title: "删除成功",
});
this.getAddressList();
} else {
uni.showToast({
icon: "none",
title: res.data.message,
duration: 2000,
});
}
});
},
//新建。编辑地址
addAddress(id) {
2021-05-14 17:31:40 +08:00
uni.navigateTo({
url: `/pages/mine/address/add${id ? "?id=" + id : ""}`,
});
2021-05-13 11:03:32 +08:00
},
//设为默认地址
setDefault(item) {
delete item.updateBy;
delete item.updateTime;
delete item.deleteFlag;
item.isDefault ? "" : (item.isDefault = !item.isDefault);
2021-05-14 17:31:40 +08:00
API_Address.editAddress(item).then(() => {
2021-05-13 11:03:32 +08:00
uni.showToast({
title: "设置默认地址成功",
icon: "none",
});
this.getAddressList();
});
},
},
};
</script>
<style lang="scss" scoped>
2021-09-09 15:02:44 +08:00
@import "./address.scss";
2021-05-13 11:03:32 +08:00
</style>