Commit 77781584 authored by 刘玉宏's avatar 刘玉宏

添加地址

parent fd021984
...@@ -20,7 +20,7 @@ export async function updateAddress(data) { ...@@ -20,7 +20,7 @@ export async function updateAddress(data) {
export async function deleteAddress(addrId) { export async function deleteAddress(addrId) {
return request({ return request({
url: `/sgyrdd/useraddr/delete/${addrId}`, url: `/sgyrdd/useraddr/delete/${addrId}`,
method: 'GET', method: 'POST',
}); });
} }
// 查询收货地址列表 // 查询收货地址列表
......
...@@ -79,9 +79,11 @@ const forMData = ref({ ...@@ -79,9 +79,11 @@ const forMData = ref({
lat: '', lat: '',
commonAddr: false, commonAddr: false,
}); });
const content = ref([]);
onLoad((options) => { onLoad((options) => {
newAddressFlag.value = options.new; newAddressFlag.value = options.new;
content.value = JSON.parse(options.content);
forMData.value = content.value;
}); });
function fieldNotEmpty(val) { function fieldNotEmpty(val) {
...@@ -93,12 +95,22 @@ function fieldNotEmpty(val) { ...@@ -93,12 +95,22 @@ function fieldNotEmpty(val) {
} }
const hdSubmit = async () => { const hdSubmit = async () => {
await addAddress({ if (!content.value.addrId) {
...forMData.value, await addAddress({
commonAddr: forMData.value.commonAddr ? 1 : 0, ...forMData.value,
province: forMData.value.province, commonAddr: forMData.value.commonAddr ? 1 : 0,
city: forMData.value.city, province: forMData.value.province,
area: forMData.value.area, city: forMData.value.city,
area: forMData.value.area,
});
} else {
await updateAddress({
...forMData.value,
commonAddr: forMData.value.commonAddr ? 1 : 0,
});
}
uni.navigateTo({
url: '/pages/address/addressList',
}); });
}; };
function handleSubmit() { function handleSubmit() {
...@@ -126,7 +138,6 @@ async function changeLocation() { ...@@ -126,7 +138,6 @@ async function changeLocation() {
forMData.value.addr = res.address; forMData.value.addr = res.address;
forMData.value.lng = res.longitude; forMData.value.lng = res.longitude;
forMData.value.lat = res.latitude; forMData.value.lat = res.latitude;
console.log('位置信息:' + JSON.stringify(res));
uni.request({ uni.request({
url: '/ws/geocoder/v1/', url: '/ws/geocoder/v1/',
data: { data: {
......
...@@ -9,29 +9,31 @@ ...@@ -9,29 +9,31 @@
</view> </view>
<view class="full_list" v-else> <view class="full_list" v-else>
<view class="additem" v-for="(item, index) in addressList" :key="index"> <wd-swipe-action>
<view class="additem_l"> <view class="additem" v-for="(item, index) in addressList" :key="index">
<view class="address">{{ item.addr }}</view> <view class="additem_l">
<view class="info"> <view class="address">{{ item.addr }}</view>
<view class="name">{{ item.receiver }}</view> <view class="info">
<view class="phone">{{ item.mobile }}</view> <view class="name">{{ item.receiver }}</view>
</view> <view class="phone">{{ item.mobile }}</view>
<view class="address_status">
<view v-if="item.commonAddr === 1" class="box active">
<wd-icon name="check-circle-filled" size="12px"></wd-icon>
<view class="txt">默认</view>
</view> </view>
<view class="address_status">
<view v-else class="box"> <view v-if="item.commonAddr === 1" class="box active">
<wd-icon name="circle1" size="12px"></wd-icon> <wd-icon name="check-circle-filled" size="12px"></wd-icon>
<view class="txt">默认</view> <view class="txt">默认</view>
</view>
<view v-else class="box" @click="deleteAdd(item.addrId)">
<wd-icon name="circle1" size="12px"></wd-icon>
<view class="txt">删除</view>
</view>
</view> </view>
</view> </view>
<view class="additem_r">
<wd-icon name="edit-outline" size="14px" @tap="editAddress(item)"></wd-icon>
</view>
</view> </view>
<view class="additem_r"> </wd-swipe-action>
<wd-icon name="edit-outline" size="14px" @tap="editAddress"></wd-icon>
</view>
</view>
<wd-button type="error" block class="addBtn" @tap="addNewAddress">新增地址</wd-button> <wd-button type="error" block class="addBtn" @tap="addNewAddress">新增地址</wd-button>
</view> </view>
...@@ -45,7 +47,6 @@ import Header from '@/pages/order/components/Header/index.vue'; ...@@ -45,7 +47,6 @@ import Header from '@/pages/order/components/Header/index.vue';
import { getAddressList, deleteAddress } from '@/api/address'; import { getAddressList, deleteAddress } from '@/api/address';
const isAdressEmpty = ref(false); const isAdressEmpty = ref(false);
const mainAddFlag = ref(false);
const addressList = ref([]); const addressList = ref([]);
const getAddressListData = async () => { const getAddressListData = async () => {
...@@ -56,26 +57,32 @@ const getAddressListData = async () => { ...@@ -56,26 +57,32 @@ const getAddressListData = async () => {
res.length === 0 ? (isAdressEmpty.value = true) : (isAdressEmpty.value = false); res.length === 0 ? (isAdressEmpty.value = true) : (isAdressEmpty.value = false);
} }
}; };
onLoad(() => {});
getAddressListData(); getAddressListData();
const addNewAddress = () => { const addNewAddress = () => {
xma.navigateTo({ url: '/pages/address/addressEdit?new=true' }); xma.navigateTo({ url: '/pages/address/addressEdit?new=true' });
}; };
const editAddress = () => { const editAddress = (col) => {
xma.navigateTo({ url: '/pages/address/addressEdit' }); xma.navigateTo({
url: `/pages/address/addressEdit?content=${JSON.stringify(col)}`,
});
}; };
const deleteAdd = async (id) => {
onLoad(() => { console.log(id);
xma.getLocation({ xma.showModal({
success: (res) => { title: '提示',
console.log(res); content: '确定删除该地址吗?',
}, showCancel: true,
fail: (err) => { confirmText: '确定',
console.log(err); cancelText: '取消',
success: async (res) => {
if (res.confirm) {
await deleteAddress(id);
getAddressListData();
}
}, },
}); });
}); };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
...@@ -92,6 +99,7 @@ page { ...@@ -92,6 +99,7 @@ page {
.full_list { .full_list {
margin-top: 20rpx; margin-top: 20rpx;
padding-bottom: 180rpx;
.additem { .additem {
width: 710rpx; width: 710rpx;
...@@ -146,6 +154,7 @@ page { ...@@ -146,6 +154,7 @@ page {
display: flex; display: flex;
font-size: 18rpx; font-size: 18rpx;
align-items: center; align-items: center;
// justify-content: space-between;
.txt { .txt {
margin-left: 5rpx; margin-left: 5rpx;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment