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.
high-mini/pages/address/address.vue

259 lines
5.4 KiB

2 years ago
<template>
<view class="user-address backcor9 ">
<scroll-view scroll-y="true" class="address-contain paading10" >
<radio-group @change="radioChange">
2 years ago
<view v-for="(item,index) in addressList" :key="item.id" class="border-8r paading10 backcolorfff marb10">
2 years ago
<view class="user-msg border-b paddbotm5">
<view class=" mart3 " >
2 years ago
<text class="address-name">{{item.consignee}}</text>
<text class=" margle10 ">{{item.phone}}</text>
2 years ago
</view>
<view class="color999 mart5" >
2 years ago
地址:{{item.regionName +" " +item.address}}
2 years ago
</view>
</view>
<view class="user-handle mart10">
<view class="handle-left">
2 years ago
<!-- <radio :checked="item.whetherDefault" style="transform:scale(0.7)" :value="item.id" color="#FF1A34" /> -->
<radio :checked="selectId == item.id" style="transform:scale(0.7)" :value="item.id" color="#FF1A34" />
2 years ago
<text class=" margle">默认地址</text>
</view>
<view class="handle-right">
2 years ago
<button type="primary" class="marRight10" plain="true" size="mini" @click="editAddress(item.id)">编辑</button>
<button type="warn" plain="true" size="mini" @click="deleteAddress(item.id)">删除</button>
2 years ago
</view>
</view>
</view>
</radio-group>
<noMore></noMore>
</scroll-view>
<view class="address-btn fcorfff font16">
<view class="add-btn" @click="addNewAddress">添加新地址</view>
<view class="add-btn" @click="daoRu">导入系统地址</view>
</view>
</view>
</template>
<script>
import noMore from '@/pages/classify/no-more/no-more.vue'
2 years ago
import { getDeliveryAddressList,deleteAddress,updateDeliveryAddress } from '@/Utils/physicalObject.js'
2 years ago
export default {
components:{
noMore,
},
data(){
return{
addressId:[
111,222,333,444
],
2 years ago
selectId:0,
addressList:[]
2 years ago
}
},
2 years ago
onLoad(){
this.initData()
},
2 years ago
methods:{
2 years ago
initData(){
this.selectId = 0;
getDeliveryAddressList().then(res=>{
if (res.return_code == '000000') {
if(res.return_data.length>0){
// console.log(res.return_data)
this.addressList = res.return_data;
this.addressList.map(item=>{
if(item.whetherDefault){
this.selectId = item.id;
}
})
}
}else{
uni.showToast({
title: res.return_msg,
icon: 'none',
duration: 2000
})
}
})
},
// 修改默认地址
2 years ago
radioChange(e){
2 years ago
let select = e.detail.value
let content =null;
this.addressList.map(item=>{
if(item.id == select){
content = item;
}
})
let params ={
"id": content.id,
"address": content.address,
"consignee": content.consignee,
"phone": content.phone,
"regionId": content.regionId,
"regionName":content.regionName,
"whetherDefault": true
}
updateDeliveryAddress(params).then(res=>{
let title ;
if (res.return_code == '000000') {
title = res.return_data;
this.selectId = e.detail.value;
}else{
title = res.return_msg;
}
uni.showToast({
title: title,
icon: 'none',
duration: 2000
})
})
2 years ago
},
2 years ago
editAddress(id){
2 years ago
uni.navigateTo({
2 years ago
url:"./addNewAddress/addNewAddress?id="+id
2 years ago
})
},
2 years ago
deleteAddress(id){
uni
let _this = this;
uni.showModal({
title: '提示',
content: '确定删除该地址吗?',
success: function(res) {
if (res.confirm) {
let params={
id:id
}
deleteAddress(params).then(res=>{
let title ;
if (res.return_code == '000000') {
title = res.return_data;
}else{
title = res.return_msg;
}
uni.showToast({
title: title,
icon: 'none',
duration: 2000
})
_this.initData();
})
} else if (res.cancel) {
// console.log('用户点击取消');
}
}
});
2 years ago
},
// 新增地址
addNewAddress(){
uni.navigateTo({
url:"./addNewAddress/addNewAddress"
})
},
// 导入系统地址
daoRu(){
uni.chooseAddress({
success: (res) => {
2 years ago
console.log(res)
2 years ago
var data = {
"name": res.userName || '',
"tel": res.telNumber || '',
"province": res.provinceName || '',
"city": res.cityName || '',
"county": res.countyName || '',
"address": res.detailInfo || ''
};
2 years ago
2 years ago
// 之后再发起一个添加地址的请求
},
fail: (err) => {
}
})
}
}
}
</script>
<style lang="scss" scoped>
.border-b{
border-bottom: 1px solid #f6f6f6;
}
.user-address{
height: 100vh;
overflow: hidden;
.address-contain{
height: calc(100vh - 70px);
width: calc(100% - 20px);
}
.user-handle{
display: flex;
align-items: center;
justify-content: space-between;
}
.handle-right{
vertical-align: middle;
}
}
// 底部按钮
.address-btn{
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 50px;
line-height: 50px;
box-sizing: border-box;
display: flex;
justify-content: space-around;
align-items: center;
.add-btn{
width:45%;
height: 40px;
line-height: 40px;
text-align: center;
border-radius: 20px;
&:first-of-type{
background-color:#F6C133;
}
&:last-of-type{
background-color: #3da7e7;
}
}
}
</style>