selectAddress.vue 4.95 KB
<template>
    <div class="zj-main">
        <mt-header title="选择地址">
            <span @click="gotoback" slot="left">
                <mt-button icon="back"></mt-button>
            </span>
        </mt-header>
        <div class="zj-main-mid">
            <mt-loadmore :bottom-method="loadBottom" @bottom-status-change="handleBottomChange"
                         :bottom-all-loaded="allLoaded" ref="loadmore">
                <ul class="page-loadmore-list">
                    <li class="addressitem-div selected" v-for="item in myAddressList"
                        @click="selectedaddress(item.buyerAddressId)">
                        <div class="address-top">
                            <span class="name">{{item.buyerNickName}}</span>
                            <span class="phone">{{item.buyerMobile}}</span>
                        </div>
                        <div class="address-mid">
                            <p><b v-show="item.isDefault==1">【默认地址】</b>{{item.buyerAddress}}</p>
                        </div>
                    </li>
                    <li class="loadmore-end" v-show="allLoaded&&myAddressList.length>0">--end--</li>
                </ul>
                <div slot="bottom" class="mint-loadmore-bottom">
                    <span v-show="bottomStatus !== 'loading'" :class="{ 'is-rotate': bottomStatus === 'drop' }">↑</span>
                    <span v-show="bottomStatus === 'loading'">
                        <mt-spinner type="snake"></mt-spinner>
                      </span>
                </div>
            </mt-loadmore>

            <no-data v-if="myAddressList.length==0">
                <img src="../../static/images/noaddress.svg"/>
                <p>您还没有收货地址哦~</p>
            </no-data>
        </div>
        <div class="zj-bottom">
            <router-link to="/myAddress" tag="button" class="zj-bottom-btn">
                编辑地址
            </router-link>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import noData from '../common/noData.vue';
    import {getmyAddressList, ClearAddresslist} from '../../vuex/actions';

    export default {
        data() {
            return {
                page: 0,
                pageNum: 20,
                allLoaded: false,
                bottomStatus: '',
                addressId: '',
                cplID: '',
                from: '',
                Goods: ''
            }
        },
        components: {
            noData
        },
        methods: {
            gotoback(){
                this.$router.go(-1)
            },
            handleBottomChange(status) {
                this.bottomStatus = status;
            },
            loadBottom(id) {
                var self = this;
                setTimeout(function () {
                    if (self.myAddressList.length >= self.myAddressCount) {
                        console.log("allLoaded:" + self.allLoaded);
                        self.allLoaded = true;
                    }
                }, 0);
                if (this.myAddressList.length > 0 && !this.allLoaded) {
                    var self = this;
                    self.page++;
                    self.getmyAddressList(self.page, self.pageNum).then(function (result) {
                        if (result == "stop") {
                            self.allLoaded = true;
                        }
                    });
                }
                this.$refs.loadmore.onBottomLoaded(id);

            },
            selectedaddress(id){
                this.addressId = id;
                this.$route.params.id = id;
                this.$router.go(-1);
//                this.$router.replace({
//                    name:'count',
//                    params:{
//                        addressId:id,
//                        cplID:this.cplID,
//                        from:this.from,
//                        Goods:this.Goods
//                    }
//                })

            }
        },
        vuex: {
            getters: {
                myAddressList: ({addressData}) => {
                    return addressData.myAddressList;
                },
                myAddressCount: ({addressData}) => {
                    return addressData.myAddressCount;
                }
            },
            actions: {
                getmyAddressList,
                ClearAddresslist
            }
        },
        beforeRouteEnter (to, from, next){
            next(vm => {
                vm.ClearAddresslist().then(function () {
                    vm.getmyAddressList(vm.page, vm.pageNum).then(function (result) {
                        if (result == "stop") {
                            vm.allLoaded = true;
                        }
                    });
                });
                setTimeout(function () {
                    $(".zj-main-mid").scrollTop(0);
                }, 0)
            });
        },
        beforeRouteLeave (to, from, next){
            next();
        }
    }
</script>