(function(global,factory){ typeof define == 'function' && define(['store','helper'],factory); })(this,function(storeApi,$h){ var template = '
收货地址

 

'; return { factory:function(Vue){ return Vue.extend({ template:template, props:{ checkedAddressId:{ type:Number, default:function(){return 0;} }, onSelect:{ type:Function }, onClose:{ type:Function }, onShow:{ type:Function }, show:Boolean }, data:function(){ return { addressList:[] } }, methods:{ goEdit:function(addressId){ location.href = $h.U({ c:'my', a:'edit_address', p:{addressId:addressId} }); }, goAdd:function(){ location.href = $h.U({ c:'my', a:'edit_address' }); }, getUserAddress:function(){ var that = this; storeApi.getUserAddress(function(res){ that.addressList = res.data.data; }); }, addressText:function(address){ return address.province+address.city+address.district+address.detail }, close:function(){ this.show = false; this.onClose && this.onClose(); }, remove:function(){ var that = this; setTimeout(function(){ that.$el.remove(); },600); }, active:function(){ this.show = true; this.onShow && this.onShow(); }, selectAddress:function(address){ this.close(); this.onSelect && this.onSelect(address.id,address); }, init:function(opt){ if(!opt) opt = {}; if(typeof opt.onClose == 'function') this.onClose = opt.onClose; if(typeof opt.onSelect == 'function') this.onSelect = opt.onSelect; if(typeof opt.onShow == 'function') this.onShow = opt.onShow; if(opt.checked != undefined) this.checkedAddressId = opt.checked; } }, mounted:function(){ vm = this; this.getUserAddress(); } }); }, install:function(Vue){ var useAddress = this.factory(Vue); var $vm = new useAddress().$mount(),$el = $vm.$el; document.body.appendChild($el); Vue.prototype.$useAddress = function(opt){ $vm.init(opt); $vm.active(); }; } } });