完成用户地址

This commit is contained in:
TOP糯米 2023-03-08 15:51:13 +08:00
parent df5e9f2d15
commit 55c200b1e9
3 changed files with 133 additions and 42 deletions

View File

@ -23,6 +23,22 @@ export default {
info: { info: {
url: "/user/getuserinfo", url: "/user/getuserinfo",
auth: true, auth: true,
},
address: {
list: {
url: "/Useraddress/getalladdress",
showLoading: true,
},
edit: {
url: "/Useraddress/applyaddress"
},
detail: {
url: "/Useraddress/addressinfo",
showLoading: true,
},
delete: {
url: "/Useraddress/deleteaddress"
}
} }
}, },
project: { project: {

View File

@ -49,30 +49,30 @@ export default {
openType: "list", openType: "list",
chooseAddressId: 0, chooseAddressId: 0,
list: [ list: [
{ // {
id: 1, // id: 1,
isDefault: false, // isDefault: false,
address: "四川省绵阳市高新区", // address: "",
detail: "火炬东街110号", // detail: "110",
name: "李(先生)", // name: "",
mobile: "18200000001", // mobile: "18200000001",
}, // },
{ // {
id: 2, // id: 2,
isDefault: false, // isDefault: false,
address: "四川省绵阳市高新区", // address: "",
detail: "火炬东街110号", // detail: "110",
name: "李(先生)", // name: "",
mobile: "18200000001", // mobile: "18200000001",
}, // },
{ // {
id: 3, // id: 3,
isDefault: true, // isDefault: true,
address: "四川省绵阳市高新区", // address: "",
detail: "火炬东街110号", // detail: "110",
name: "李(先生)", // name: "",
mobile: "18200000001", // mobile: "18200000001",
}, // },
], ],
}; };
}, },
@ -99,11 +99,30 @@ export default {
this.chooseAddressId = e.id; this.chooseAddressId = e.id;
} }
}, },
onShow() {}, onShow() {
this.list = [];
this.loadAddress();
},
onReady() {}, onReady() {},
onReachBottom() {}, onReachBottom() {},
onPullDownRefresh() {}, onPullDownRefresh() {},
methods: { methods: {
loadAddress() {
this.$request({
api: "user.address.list",
}).then((response) => {
response.data.forEach((item) => {
this.list.push({
id: item.id,
address: item.address,
detail: item.doorplate,
name: item.name,
mobile: item.mobil,
isDefault: item.default == 1,
});
});
});
},
selectAddress(address) { selectAddress(address) {
if (this.openType == "choose") { if (this.openType == "choose") {
this.getOpenerEventChannel().emit("setAddress", address); this.getOpenerEventChannel().emit("setAddress", address);
@ -113,17 +132,18 @@ export default {
} }
}, },
getWechatAddress() { getWechatAddress() {
const that = this;
// #ifndef H5 // #ifndef H5
let wechatAddress = {}; let platformAddress = {};
uni.chooseAddress({ uni.chooseAddress({
success: (data) => { success: (data) => {
wechatAddress.address = data.provinceName + data.cityName + data.countyName; platformAddress.address = data.provinceName + data.cityName + data.countyName;
wechatAddress.detail = data.detailInfo; platformAddress.detail = data.detailInfo;
wechatAddress.mobile = data.telNumber; platformAddress.mobile = data.telNumber;
wechatAddress.name = data.userName; platformAddress.name = data.userName;
wechatAddress.gender = 1; setTimeout(() => {
wechatAddress.isDefault = false; that.$utils.toPage("/pages/address/edit?addr=" + JSON.stringify(platformAddress));
console.log(wechatAddress); }, 200);
}, },
}); });
// #endif // #endif
@ -132,12 +152,24 @@ export default {
this.$utils.toPage("/pages/address/edit?id=" + id); this.$utils.toPage("/pages/address/edit?id=" + id);
}, },
deleteAddress(id, index) { deleteAddress(id, index) {
const that = this;
uni.showModal({ uni.showModal({
title: "删除地址?", title: "删除地址?",
content: "数据删除后不可恢复,请谨慎操作!", content: "数据删除后不可恢复,请谨慎操作!",
complete: (res) => { complete(res) {
if (res.confirm) { if (res.confirm) {
this.list.splice(index, 1); that.$request({
api: "user.address.delete",
data: {
id: id,
},
}).then((response) => {
if (response.code == 1) {
that.list.splice(index, 1);
return;
}
that.$utils.toast(response.msg);
});
} }
}, },
}); });

View File

@ -56,12 +56,7 @@
<text>手机号码</text> <text>手机号码</text>
</view> </view>
<view class="input-box"> <view class="input-box">
<input <input class="input" v-model="mobile" placeholder="请输入手机号码" placeholder-class="placeholder-style-3" />
class="input"
v-model="mobile"
placeholder="请输入手机号码"
placeholder-class="placeholder-style-3"
/>
</view> </view>
</view> </view>
<view class="input-item default-address"> <view class="input-item default-address">
@ -95,6 +90,8 @@ export default {
isDefault: false, isDefault: false,
name: "", name: "",
mobile: "", mobile: "",
longitude: 0,
latitude: 0,
}; };
}, },
components: { components: {
@ -108,6 +105,15 @@ export default {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({
title: this.pageTitle, title: this.pageTitle,
}); });
this.id = e.id;
this.setAddressData();
}
if (e.addr) {
let platformAddress = JSON.parse(e.addr);
this.address = platformAddress.address;
this.detail = platformAddress.detail;
this.name = platformAddress.name;
this.mobile = platformAddress.mobile;
} }
}, },
onShow() {}, onShow() {},
@ -116,7 +122,42 @@ export default {
onPullDownRefresh() {}, onPullDownRefresh() {},
methods: { methods: {
save() { save() {
uni.navigateBack(); this.$request({
api: "user.address.edit",
data: {
id: this.id,
address: this.address,
doorplate: this.detail,
name: this.name,
mobil: this.mobile,
sex: this.gender == 1 ? "男" : "女",
default: this.isDefault ? 1 : 0,
lat: this.latitude,
lng: this.longitude,
},
}).then((response) => {
if (response.code == 1) {
return this.$utils.toPage("", {}, "back");
}
this.$utils.toast(response.msg);
});
},
setAddressData() {
this.$request({
api: "user.address.detail",
data: {
id: this.id,
},
}).then((response) => {
this.address = response.data.address;
this.detail = response.data.doorplate;
this.name = response.data.name;
this.mobile = response.data.mobil;
this.gender = response.data.sex == "男" ? 1 : 2;
this.isDefault = response.data.default == 1;
this.latitude = response.data.lat;
this.longitude = response.data.lng;
});
}, },
chooseLocation() { chooseLocation() {
const t = this; const t = this;
@ -124,6 +165,8 @@ export default {
success: ({ name, address, longitude, latitude }) => { success: ({ name, address, longitude, latitude }) => {
t.address = address; t.address = address;
t.detail = name; t.detail = name;
t.longitude = longitude;
t.latitude = latitude;
}, },
fail: (error) => {}, fail: (error) => {},
}); });