You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

398 lines
8.6 KiB

<template>
<view class="bg">
<!-- <view class="cancat-nav flex-around">
<view :class="['concat-nav-item',showType===0?'active':'']" @click="showType=0">
<view>出行人信息</view>
<view v-if="showType===0" class="active-bar"></view>
</view>
<view :class="['concat-nav-item',showType===1?'active':'']" @click="showType=1">
<view>收货地址</view>
<view v-if="showType===1" class="active-bar"></view>
</view>
</view> -->
<!-- 出行人信息 -->
<view v-if="showType === 0">
<view class="item" v-for="(item, index) in travelList" :key="index">
<view class="name">
<view class="">
{{ item.name }}
</view>
<view class="">
{{ item.tel }}
<span v-if="item.is_default == 1">默认</span>
</view>
</view>
<view class="idcard">
<view class=""> {{ item.document_type_text }}: </view>
<view class="">
{{ item.id_number }}
</view>
</view>
<view class="item-btn">
<view class="choice">
<!-- <image src="https://static.ticket.sz-trip.com/yandu/images/user/dui.png" mode="aspectFill"
v-if="item.is_default==1">
</image>
<view class="yuan" v-else @click.stop="defaultC(item)">
</view>
<view class="">
默认出行人
</view> -->
</view>
<view class="btn-list">
<view class="btn-item" @click.stop="edit(item.id)"> 修改 </view>
<view class="btn-item" @click.stop="delet(item)"> 删除 </view>
</view>
</view>
</view>
</view>
<!-- 收货地址 -->
<view v-else>
<view
class="item"
v-for="(item, index) in addressList"
:key="index"
@click="selectAddressForOrder(item)"
>
<view class="name">
<view>
{{ item.name }}
</view>
<view class="">
{{ item.tel }}
<span v-if="item.is_default == 1">默认</span>
</view>
</view>
<view class="idcard">
<view class=""> 收货地址: </view>
<view class="text-overflow">
{{ item.address }}
</view>
</view>
<view class="item-btn" style="justify-content: flex-end">
<view class="btn-list">
<view class="btn-item" @click.stop="edit(item.id)"> 修改 </view>
<view class="btn-item" @click.stop="delet(item)"> 删除 </view>
</view>
</view>
<!-- 选择指示器 -->
<view class="select-indicator" v-if="isSelectMode">
<uni-icons type="right" size="16" color="#6CA5AA" />
</view>
</view>
</view>
<view class="btn-box">
<navigator
:url="
showType
? '/subPackages/user/myAddressAdd'
: '/subPackages/user/myContactsAdd'
"
class="btn"
>
{{ showType ? "新增收货地址" : "添加联系人" }}
</navigator>
</view>
</view>
</template>
<script>
export default {
name: "travelerList",
data() {
return {
showType: 1,
travelList: [],
addressList: [],
isSelectMode: false, // 是否为选择模式
fromPage: "", // 来源页面
};
},
onLoad(options) {
// 检查是否为选择模式
if (options.from) {
this.isSelectMode = true;
this.fromPage = options.from;
}
},
onShow() {
this.init();
},
methods: {
init() {
// 出行人信息
// this.Post({}, "/api/user/contactList").then(res => {
// if (res) this.travelList = res.data
// })
// 收货地址
this.Post({}, "/api/user/consigneeList").then((res) => {
if (res) this.addressList = res.data;
});
},
delet(item) {
let that = this;
uni.showModal({
title: "提示",
content: "确定要删除该出行人吗?",
success: function (res) {
if (res.confirm) {
that
.Post(
{
id: item.id,
},
"/api/user/delDetail"
)
.then((res) => {
if (res) {
uni.showToast({
icon: "none",
title: res.msg,
});
}
that.init();
});
} else if (res.cancel) {
console.log("用户点击取消");
}
},
});
},
defaultC(item) {
this.Post(
{
id: item.id,
is_default: 1,
},
"/api/user/editContact"
).then((res) => {
if (res.code == 1) {
this.travelList.forEach((i) => (i.is_default = 0));
item.is_default = !item.is_default;
}
});
},
// 修改出行人信息
edit(id) {
let url = "";
if (this.showType) {
url = "/subPackages/user/myAddressAdd?id=" + id;
} else {
url = "/subPackages/user/myContactsAdd?type=edit&id=" + id;
}
uni.navigateTo({
url: url,
});
},
// 选择地址用于订单
selectAddressForOrder(address) {
if (!this.isSelectMode) {
return; // 如果不是选择模式,不处理点击
}
// 通过事件总线传递选中的地址
uni.$emit("addressSelected", {
address: address,
fromPage: this.fromPage,
});
// 也可以通过storage传递数据
uni.setStorageSync("selectedAddress", address);
uni.showToast({
title: "地址选择成功",
icon: "success",
});
setTimeout(() => {
uni.navigateBack();
}, 800);
},
},
};
</script>
<style lang="scss" scoped>
.bg {
position: relative;
background: #f7f7f7;
height: 100vh;
overflow-x: hidden;
padding-bottom: 200rpx;
}
.cancat-nav {
width: 100%;
display: flex;
height: 112rpx;
flex-shrink: 0;
background-color: #fff;
.concat-nav-item {
font-weight: 500;
font-size: 35rpx;
color: #000000;
height: 100%;
text-align: center;
position: relative;
padding-top: 35rpx;
}
.concat-nav-item.active {
color: #000000;
}
.active-bar {
width: 73rpx;
height: 7rpx;
background: #515150;
border-radius: 3rpx;
margin: auto;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
}
.item {
width: 697rpx;
background: #ffffff;
border-radius: 13rpx;
margin: 28rpx auto 0;
padding: 26rpx;
position: relative;
.name,
.idcard {
display: flex;
font-size: 31rpx;
font-weight: bold;
color: #333333;
}
.name {
view:last-child {
margin-left: 40rpx;
}
span {
padding: 3rpx 9rpx;
background: #515150;
border-radius: 7rpx;
font-weight: bold;
font-size: 24rpx;
color: #ffffff;
margin-left: 15rpx;
}
}
.idcard {
margin-top: 26rpx;
view:last-child {
margin-left: 14rpx;
font-weight: 400;
max-width: 492rpx;
}
}
.item-btn {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 40rpx;
.choice {
display: flex;
align-items: center;
view:last-child {
margin-left: 20rpx;
font-size: 27rpx;
font-weight: 500;
color: #333333;
}
image {
width: 40rpx;
height: 40rpx;
}
.yuan {
width: 40rpx;
height: 40rpx;
background: rgba(255, 200, 37, 0);
border: 1rpx solid #999999;
border-radius: 20rpx;
}
}
.btn-list {
display: flex;
align-items: center;
view {
width: 134rpx;
height: 54rpx;
background: #ffffff;
border: 1px solid #999999;
border-radius: 27rpx;
font-size: 27rpx;
font-weight: 500;
color: #333333;
line-height: 52rpx;
text-align: center;
}
view:last-child {
margin-left: 14rpx;
}
}
}
}
.btn-box {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: 200rpx;
background-color: #fff;
.btn {
width: 697rpx;
line-height: 80rpx;
background: #6ca5aa;
border-radius: 37rpx;
font-weight: 500;
font-size: 36rpx;
color: #fff;
text-align: center;
position: fixed;
bottom: 53rpx;
left: 26.67rpx;
}
}
// 选择指示器
.select-indicator {
position: absolute;
right: 26rpx;
top: 50%;
transform: translateY(-50%);
background-color: rgba(108, 165, 170, 0.1);
border-radius: 50%;
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
}
</style>