From ee6361ab56a440ca28cf4d4bbd864aad09f6818f Mon Sep 17 00:00:00 2001 From: jinna Date: Wed, 23 Aug 2023 15:41:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=9C=B0=E5=9D=80=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/pages_zhentou/myPage/address.vue | 284 +++++++++++++++++++++++-- 1 file changed, 261 insertions(+), 23 deletions(-) diff --git a/pages/pages_zhentou/myPage/address.vue b/pages/pages_zhentou/myPage/address.vue index 2281ec3..4163cdf 100644 --- a/pages/pages_zhentou/myPage/address.vue +++ b/pages/pages_zhentou/myPage/address.vue @@ -1,33 +1,36 @@ @@ -108,6 +111,10 @@ export default { data() { return { + isEdit:false, + buyUser:'', + buyPhone:'', + address:'', imgPrefix: getApp().globalData.imgPrefix, locationArr: [ [], @@ -119,8 +126,8 @@ city:'', district:'', addressData: [ - {name:'张三',phone:'15612345678',address:'山东省青岛市市北区大港街道大港三路8号铁路住宅小区6号楼6单元666室',status:1}, - {name:'张三',phone:'15612345678',address:'山东省青岛市市北区大港街道大港三路8号铁路住宅小区6号楼6单元666室',status:0}, + // {name:'张三',phone:'15612345678',address:'山东省青岛市市北区大港街道大港三路8号铁路住宅小区6号楼6单元666室',status:1}, + // {name:'张三',phone:'15612345678',address:'山东省青岛市市北区大港街道大港三路8号铁路住宅小区6号楼6单元666室',status:0}, ], allCityData, current: 0, @@ -131,10 +138,15 @@ contentdown: "点击查看更多", contentrefresh: "正在加载...", contentnomore: "没有更多数据了", - } + }, + title:'', + addressId:'', + userInfo:{}, + pageFrom:'' } }, - onLoad() { + onLoad(options) { + this.pageFrom = options.from; this.getData() let userInfo = uni.getStorageSync('userInfo'); if (userInfo) { @@ -143,8 +155,222 @@ this.loadMore(); } } + this.userInfo = JSON.parse(uni.getStorageSync('userInfo')); + // console.log(userInfo) }, methods: { + // 保存地址 + handleSave(){ + if(this.userInfo){ + if(!this.isEdit){ + if(this.address == '' || this.province == '' || this.buyUser == '' || this.buyPhone == ''){ + uni.showToast({ + title: '请完整填写信息', + icon: 'none' + }) + }else{ + let params = { + userId:this.userInfo.id, + consignee:this.buyUser, + phone:this.buyPhone, + province:this.province, + city:this.city, + district:this.district ? this.district : '', + address:this.address, + isDefault:0 + } + uni.request({ + url:getApp().globalData.baseUrl + '/address/save', + method:'POST', + header:{ + 'Blade-Auth': 'bearer ' + uni.getStorageSync('token') + }, + data:params, + success:(res) =>{ + console.log(res) + if(res.data.code == 200){ + uni.showToast({ + title: '新增成功', + icon: 'none' + }) + this.$refs.popup.close(); + this.hasMore = true; + this.current = 0; + this.loadMore() + } + } + }) + } + }else{ + if(this.address == '' || this.province == '' || this.buyUser == '' || this.buyPhone == ''){ + uni.showToast({ + title: '请完整填写信息', + icon: 'none' + }) + }else{ + let params = { + id:this.addressId, + userId:this.userInfo.id, + consignee:this.buyUser, + phone:this.buyPhone, + province:this.province, + city:this.city, + district:this.district ? this.district : '', + address:this.address, + } + uni.request({ + url:getApp().globalData.baseUrl + '/address/update', + method:"POST", + header:{ + 'Blade-Auth': 'bearer ' + uni.getStorageSync('token') + }, + data:JSON.stringify(params), + success:res =>{ + console.log(res) + if(res.data.code == 200){ + uni.showToast({ + title: '地址修改成功', + icon: 'none' + }); + this.addressData = [] + this.$refs.popup.close(); + this.hasMore = true; + this.current = 0; + this.loadMore() + }else{ + uni.showToast({ + title: res.data.msg, + icon: 'none' + }) + } + } + }) + } + } + } + console.log(this.address) + }, + // 编辑地址 + handleEdit(item){ + console.log(item) + this.title = '编辑地址' + this.addressId = item.id + this.isEdit = true; + this.buyUser = item.consignee; + this.buyPhone = item.phone; + this.address = item.address; + this.province = item.province; + this.city = item.city; + this.district = item.area; + this.$refs.popup.open('bottom') + }, + // 删除地址 + handleDelete(){ + uni.showModal({ + title: '提示', + content: '确认删除该地址?', + success: (res) => { + if (res.confirm) { + uni.request({ + url:getApp().globalData.baseUrl + '/address/delete?ids=' + this.addressId, + method:"POST", + header:{ + 'Blade-Auth': 'bearer ' + uni.getStorageSync('token') + }, + success:(res) =>{ + console.log(res) + if(res.data.code == 200){ + uni.showToast({ + title: '删除成功', + icon: 'none' + }) + this.addressData = [] + this.$refs.popup.close(); + this.hasMore = true; + this.current = 0; + this.loadMore() + }else{ + uni.showToast({ + title: res.data.msg, + icon: 'none' + }) + } + }, + }) + } else if (res.cancel) { + + } + }, + }) + }, + // 添加默认 + handleDefault(item){ + uni.showModal({ + title: '提示', + content: '确认将该地址设置为默认地址?', + success: (res) => { + if (res.confirm) { + let params = { + id:item.id, + userId:this.userInfo.id, + isDefault:1 + } + uni.request({ + url:getApp().globalData.baseUrl + '/address/update', + method:"POST", + header:{ + 'Blade-Auth': 'bearer ' + uni.getStorageSync('token') + }, + data:JSON.stringify(params), + success:res =>{ + console.log(res) + if(res.data.code == 200){ + uni.showToast({ + title: '默认地址设置成功', + icon: 'none' + }); + this.addressData = [] + this.$refs.popup.close(); + this.hasMore = true; + this.current = 0; + this.loadMore() + }else{ + uni.showToast({ + title: res.data.msg, + icon: 'none' + }) + } + } + }) + }else if(res.cancel){ + + } + } + }) + }, + + turnToOrder(item){ + if(this.pageFrom == 1){ + var pages = getCurrentPages(); // 获取页面栈 + var currPage = pages[pages.length - 1]; // 当前页面 + var prevPage = pages[pages.length - 2]; // 上一个页面 + console.log(pages) + console.log(prevPage) + if(prevPage.__route__ == 'pages/pages_zhentou/order/confirmOrder'){ + prevPage.__data__.changeAddress( + { + name:item.consignee, + phone:item.phone, + address:item.province + item.city + (item.area ? item.area : '') + item.address, + } + ) + } + } + }, + // 取消新增 + closePop(){ + this.$refs.popup.close(); + }, // 获取地区数据 getData() { console.log(this.allCityData) @@ -158,12 +384,13 @@ console.log(this.locationArr) }, cityChange(e) { - console.log(e) + console.log('111') this.multiIndex = e.detail.value; console.log(this.locationArr) this.province = this.locationArr[0][this.multiIndex[0]] this.city = this.locationArr[1][this.multiIndex[1]] - this.district = this.locationArr[2][this.multiIndex[2]] + this.district = this.locationArr[2][this.multiIndex[2]]; + this.address = '' }, columnchange(e) { let value = e.detail.value; @@ -207,6 +434,14 @@ }, // 添加地址 handleAdd(){ + this.isEdit = false; + this.title = '新增地址' + this.buyUser = ''; + this.buyPhone = ''; + this.address = ''; + this.province = ''; + this.city = ''; + this.district = ''; this.$refs.popup.open('bottom') }, // 定位 @@ -269,6 +504,9 @@ url: getApp().globalData.baseUrl + '/address/list?userId=' + this.userInfo.id + '¤t=' + this .current + '&size=' + this.size, method: 'GET', + header:{ + 'Blade-Auth': 'bearer ' + uni.getStorageSync('token') + }, success: (res) => { if (res.data.code == 200) { this.addressData = this.addressData.concat(res.data.data.records);