addAddress.vue
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<template>
<view class="container">
<Navbar :title="title" canBack></Navbar>
<view class="">
<addAddress ref="addAds" mode="add" v-if="dataReady" :formData="formData" @setInput="getAds"></addAddress>
</view>
<view class="bomBarCss">
<view class="btnCss">
<u-button color="#ED2920" shape="circle" @click="savaAds">
<text class="text-lg">确定</text>
</u-button>
</view>
</view>
<!-- <u-toast ref="uToast"></u-toast> -->
</view>
</template>
<script>
import addAddress from '@/components/addAddress/addAddress.vue'
export default {
components: {
addAddress
},
data() {
return {
id: "",
formData: {},
dataReady: false,
type: null,
qpid: "",
title:"新增地址"
};
},
mounted() {
},
onLoad(data) {
console.log(data);
if (data.id) {
this.ifEdit = true;
this.id = data.id;
this.title = "编辑地址";
console.log("编辑", this.id);
this.getAdsxx()
} else {
this.dataReady = true;
}
if (data.qpid) {
this.qpid = data.qpid
}
},
methods: {
// 获取编辑信息
async getAdsxx() {
let query = {
id: this.id
}
const result = await this.$api.memberApi.getwHydzDetail(query);
let {
code,
value
} = result;
if (code === 200) {
this.formData = value;
this.dataReady = true;
}
console.log('查询地址信息', result);
},
// 组件传参
getAds(ads) {
console.log("组件传递地址",ads);
const {
area,
...formData
} = ads;
this.formData = formData;
console.log('获取地址', JSON.parse(JSON.stringify(this.formData)));
},
async savaAds() {
let that = this;
// this.$modal.showLoading('获取当前定位中');
// await this.getJwd();
console.log('新建地址详情', JSON.parse(JSON.stringify(this.formData)));
this.$refs.addAds.$refs.uForm.validate().then(async res => {
// uni.$u.toast('校验通过')
console.log('打印this.formData', this.formData);
const result = await that.$api.memberApi.savewHydz(this.formData);
console.log("添加返回", result);
let {
code,
value,
message
} = result;
if (code === 200) {
console.log("添加成功", result);
let adsId = result.value;
uni.$u.toast(message);
setTimeout(() => {
if (that.qpid) {
// console.log("首次添加地址");
uni.redirectTo({
url: `/pages/home/placeOrder?qpid=${that.qpid}&adsId=${adsId}`
})
} else {
that.$goBack();
}
}, 500)
}
}).catch(errors => {
console.log("添加地址eroros",errors);
// uni.$u.toast('校验失败')
})
},
getJwd() {
let that = this;
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'wgs84',
success: (res) => {
that.formData.fJd = res.longitude;
that.formData.fWd = res.latitude;
resolve(); // 成功获取经纬度后 resolve
},
fail: (error) => {
reject(error); // 获取经纬度失败时 reject
},
complete() {
that.$modal.closeLoading();
}
});
});
},
}
}
</script>
<style lang="scss" scoped>
.bomBarCss {
width: 100%;
height: 50px;
background: #fff;
position: absolute;
bottom: 0px;
left: 0;
right: 0;
.btnCss {
width: 60%;
margin: 5px auto;
}
}
</style>