use-coupon.js 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. (function(global,factory){
  2. typeof define == 'function' && define(['store'],factory);
  3. })(this,function(storeApi){
  4. var template = '<div><div class="model-bg" @touchmove.prevent :class="{on:isShow == true}" @click="close"></div><div class="card-model" :class="{up:isShow == true}" style="height: 72%;"><div style="position: absolute;left: 0px;top: -2px;width: 100%;height: 0.7rem;background-color: rgb(255, 255, 255);z-index: 99;padding-left: .3rem;line-height: .7rem;">请选择优惠劵<div style="top: 50%;margin-top: -.2rem;" class="model-close" @click="close"></div></div><div class="empty" v-show="couponList.length == 0" @touchmove.prevent> <img src="/public/wap/first/crmeb/images/empty_coupon.png"><p>暂无可用优惠劵</p></div><div v-show="couponList.length > 0" id="selects-wrapper" class="discount-list" style="height: 100%; overflow-y: scroll;padding-top: .7rem;padding-bottom: .2rem;-webkit-overflow-scrolling : touch; " @touchmove.stop><div style="margin-top: 0" class="list-box"><ul><li class="new" :class="{use:coupon._type == 0 || minPrice < coupon.use_min_price}" v-for="coupon in couponList" @click="select(coupon)"><div class="txt-info"><div class="con-cell"><p>满{{coupon.use_min_price}}元可用现金券</p><span>{{coupon._add_time}}至{{coupon._end_time}}使用</span></div></div><div class="price"><span>¥</span>{{coupon.coupon_price}}<p><a href="javascript:void(0);" v-if="coupon._type == 0">{{coupon._msg}}</a><a href="javascript:void(0);" v-if="coupon._type != 0">{{minPrice< coupon.use_min_price ? "无法使用" : "立即使用"}}</a></p></div><span class="text-icon" v-show="coupon._type == 2"></span></li></ul></div></div></div></div>';
  5. return {
  6. factory:function(Vue){
  7. return Vue.extend({
  8. name:'use-coupon',
  9. template:template,
  10. props:{
  11. onClose:Function,
  12. onSelect:Function,
  13. onShow:Function,
  14. },
  15. data:function(){
  16. return {
  17. couponList:[],
  18. isShow:false,
  19. minPrice:0
  20. };
  21. },
  22. methods:{
  23. getCouponList:function(){
  24. var that = this;
  25. storeApi.getUseCoupon(function(res){
  26. that.couponList = res.data.data;
  27. });
  28. },
  29. select:function(coupon){
  30. if(this.minPrice < coupon.use_min_price) return ;
  31. this.onSelect && this.onSelect(coupon);
  32. this.close();
  33. },
  34. active:function(){
  35. this.isShow = true;
  36. this.onShow && this.onShow();
  37. },
  38. close:function(){
  39. this.isShow = false;
  40. this.onClose && this.onClose();
  41. },
  42. init:function(minPrice,opt){
  43. if(!opt) opt = {};
  44. if(!minPrice) minPrice = 0;
  45. if(typeof opt.onClose == 'function') this.onClose = opt.onClose;
  46. if(typeof opt.onSelect == 'function') this.onSelect = opt.onSelect;
  47. if(typeof opt.onShow == 'function') this.onShow = opt.onShow;
  48. this.minPrice = minPrice;
  49. }
  50. },
  51. mounted:function(){
  52. this.getCouponList();
  53. }
  54. });
  55. },
  56. install:function(Vue){
  57. var that = this;
  58. Vue.prototype.$useCoupon = function(minPrice,opt){
  59. var useCoupon = that.factory(Vue);
  60. var $vm = new useCoupon().$mount(),$el = $vm.$el;
  61. document.body.appendChild($el);
  62. $vm.init(minPrice,opt);
  63. $vm.remove = function(){
  64. setTimeout(function(){
  65. document.body.removeChild($el);
  66. },600);
  67. };
  68. return {
  69. remove:$vm.remove,
  70. active:$vm.active,
  71. close:$vm.close
  72. };
  73. };
  74. }
  75. }
  76. });