109 lines
4.4 KiB
Vue
109 lines
4.4 KiB
Vue
<template>
|
|
<view class="">
|
|
<!-- 使用标题栏 -->
|
|
<status-nav :statusBackw="true" :statusTitle="true" :whereCome="wherenum*1" :title-val="'地址管理'" :tabcolor="'#ffffff'"></status-nav>
|
|
<!-- 地址信息 -->
|
|
<view class="bacb padding-zy30 posir" :style="{paddingTop:statusHNH+'px'}">
|
|
<view v-if="dataArr.length!=0" class="disba borbot" v-for="(item,index) in dataArr" :key="index">
|
|
<view @tap="chooseAddress(index)" class="margin-sx40" style="margin-top: 20px;">
|
|
<view class="fon28 color33 disac">
|
|
<view v-if="item.is_default==1" class="fon24 colorb margin-y20 btnaddress" style="background-color: #e91111;">默认</view>
|
|
<!-- <view v-if="item.tag==1" class="fon24 colorb margin-y20 btnaddress" style="background-color: #ffc600;">{{item.tag}}</view> -->
|
|
<view class="fon28 color33">{{item.name}} {{item.phone}}</view>
|
|
</view>
|
|
<view class="fon30 bold margin-sx10">{{item.address}}</view>
|
|
<view class="fon28 color33">{{item.province_str}} {{item.city_str}} {{item.county_str}}</view>
|
|
</view>
|
|
<view>
|
|
<image @tap="updateAddress(index,item.id)" style="width: 27rpx;height: 26rpx;margin-right: 20rpx;" src="/static/img/order/addEdit.png" mode=""></image>
|
|
<image @tap="delAddress(index,item.id)" style="width: 33rpx;height: 33rpx;" src="/static/img/gouwc/del.png" mode=""></image>
|
|
</view>
|
|
</view>
|
|
<view v-if="dataArr.length==0" class="zanwu">暂无收货地址</view>
|
|
</view>
|
|
<view class="disbc" style="position: fixed;bottom: 40px;left: 60px;right: 60px;">
|
|
<view @tap="updateAddress('-1',0)" class="colorb fon30 addbtn">+新建收货地址</view>
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
dataArr:[],
|
|
wherenum:0,
|
|
isOrder:'',
|
|
statusHNH:uni.getStorageSync('statusHNH')
|
|
}
|
|
},
|
|
onShow() {
|
|
this.$toolAll.tools.guoq()
|
|
this.checkAddress()
|
|
},
|
|
onLoad(options) {
|
|
this.wherenum = options.wherenum;
|
|
if(options.isOrder!=undefined) this.isOrder = options.isOrder
|
|
},
|
|
methods: {
|
|
checkAddress(){//查询地址列表事件
|
|
this.$requst.post('user/address').then(res=>{
|
|
this.dataArr = res.data
|
|
// console.log(this.dataArr);
|
|
if(this.dataArr.length!=0){
|
|
// let obj = this.dataArr.filter(item=>item.isMo==true)//返回找到的对象
|
|
let index = this.dataArr.findIndex((v) => {//找到是否有默认地址
|
|
return v.is_default == 1;
|
|
});
|
|
let newArr = this.dataArr.splice(index,1)//有删除改地址
|
|
this.dataArr.unshift(newArr[0])//插入改地址到第一位
|
|
}
|
|
},error=>{})
|
|
},
|
|
chooseAddress(index){//选中当前地址作为收货地址
|
|
// console.log('选择当前地址:'+index);
|
|
if(this.isOrder!=''){
|
|
uni.setStorageSync('isAddr',this.dataArr[index])
|
|
uni.navigateTo({
|
|
url:'/pagesA/confirmOrder/confirmOrder?index=3'
|
|
})
|
|
}
|
|
},
|
|
updateAddress(index,id){//编辑地址事件
|
|
// console.log('新增/编辑地址:'+index);
|
|
if(index!='-1'){
|
|
uni.setStorageSync('updataAddress',this.dataArr[index])
|
|
}
|
|
uni.navigateTo({
|
|
url:'/pagesB/newAddress/newAddress'
|
|
})
|
|
},
|
|
delAddress(index,id){//删除地址事件
|
|
// console.log('删除地址:'+id);
|
|
uni.showModal({
|
|
title:'提示:',
|
|
content:`确定要删除 " ${this.dataArr[index].name} " 的地址吗?`,
|
|
cancelText:'取消',
|
|
cancelColor:'#999999',
|
|
confirmText:'确定',
|
|
confirmColor:'#164396',
|
|
success: (res) => {
|
|
if(res.confirm){
|
|
this.$requst.post('user/address-del',{id:id}).then(res=>{
|
|
uni.showToast({
|
|
title:'删除地址成功',
|
|
icon:'none'
|
|
})
|
|
this.checkAddress()//重新执行查询地址
|
|
},error=>{})
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
</style>
|