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
<template>
<div>
<headerNav title="我的地址"/>
<van-address-list
v-model="chosenAddressId"
:class="isSelect?'':'hideselect'"
:list="list"
@add="onAdd"
@edit="onEdit"
@select="onSelect"
/>
</div>
</template>
<script>
import {GetAddressList} from "../../../api/user.js";
import { AddressList } from 'vant';
import eventBus from '../../eventBus';
import orderStore from '../../../store/order'
export default {
components: {
[AddressList.name]: AddressList,
},
data() {
return {
chosenAddressId: -1,
isSelect: false,
list: [],
}
},
methods: {
onAdd() {
this.$router.push('/user/address/edit')
},
onEdit(item, index) {
this.$router.push('/user/address/edit?id=' + item.id);
},
onSelect(item, index) {
if (!this.isSelect) {
return;
}
this.$store.commit('changeAddressData', {
...item
});
this.$router.go(-1);
}
},
created: function () {
this.chosenAddressId = this.$route.query.id;
this.isSelect = this.$route.query.id > 0;
GetAddressList().then(response => {
this.list = response.map(item => {
if (item.hasDefault == 2) {
this.chosenAddressId = item.id;
}
// convert data
return {
...item,
tel: item.mobile,
}
});
})
},
store: orderStore,
}
</script>
<style lang="less">
.hideselect {
.van-radio__input {
display: none;
}
}
</style>