(function(global,factory){
typeof define == 'function' && define(['store'],factory);
})(this,function(storeApi){
var template = '
暂无可用优惠劵
满{{coupon.use_min_price}}元可用现金券
{{coupon._add_time}}至{{coupon._end_time}}使用
';
return {
factory:function(Vue){
return Vue.extend({
name:'use-coupon',
template:template,
props:{
onClose:Function,
onSelect:Function,
onShow:Function,
},
data:function(){
return {
couponList:[],
isShow:false,
minPrice:0
};
},
methods:{
getCouponList:function(){
var that = this;
storeApi.getUseCoupon(function(res){
that.couponList = res.data.data;
});
},
select:function(coupon){
if(this.minPrice < coupon.use_min_price) return ;
this.onSelect && this.onSelect(coupon);
this.close();
},
active:function(){
this.isShow = true;
this.onShow && this.onShow();
},
close:function(){
this.isShow = false;
this.onClose && this.onClose();
},
init:function(minPrice,opt){
if(!opt) opt = {};
if(!minPrice) minPrice = 0;
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;
this.minPrice = minPrice;
}
},
mounted:function(){
this.getCouponList();
}
});
},
install:function(Vue){
var that = this;
Vue.prototype.$useCoupon = function(minPrice,opt){
var useCoupon = that.factory(Vue);
var $vm = new useCoupon().$mount(),$el = $vm.$el;
document.body.appendChild($el);
$vm.init(minPrice,opt);
$vm.remove = function(){
setTimeout(function(){
document.body.removeChild($el);
},600);
};
return {
remove:$vm.remove,
active:$vm.active,
close:$vm.close
};
};
}
}
});