<template>
    <van-address-list
            v-model="chosenAddressId"
            :list="list"
            :disabled-list="disabledList"
            @add="onAdd"
            @select="onSelect"
            @edit="onEdit"
    />
</template>

<script>
    import request from '@/utils/request'
    export default {
        name: "address_list",
        data(){
            return {
                disabledList:[],
                list:[],
                chosenAddressId:0
            }
        },
        created(){
            this.get_list()
        },
        methods:{
            get_list(){
                let self = this
                self.$toast.loading({
                    mask: true,
                    message: '处理中...'
                })
                request('get','/shop/ajax/getAddressList.html').then((res) => {
                    self.$toast.clear()
                    let list = []
                    for(let i in res.data.data.list){
                        list.push({
                            id:res.data.data.list[i].id,
                            name:res.data.data.list[i].name,
                            tel:res.data.data.list[i].tel,
                            address:res.data.data.list[i].fulladdresss
                        })
                        if(res.data.data.list[i].isdefault == 1){
                            self.chosenAddressId = res.data.data.list[i].id
                        }
                    }
                    this.list = list
                })
            },
            onAdd(){
                this.$router.push({name:'address_add'})
            },
            onSelect(e){
                this.$store.commit('SET_ADDRESSINFO', e)
                window.history.go(-1)
            },
            onEdit(e){

                this.$router.push({name:'address_edit', query:{id:e.id}})
            }
        }
    }
</script>

<style scoped>

</style>