coupon-collection.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ;
  2. var orderPage = new Vue({
  3. el: "#beansPage",
  4. data: {
  5. isRequset:false,
  6. noMore: false,
  7. tabsListIndex:0,
  8. listQuery:{
  9. userId:0,
  10. pageNum:1,
  11. pageSize:9
  12. },
  13. beansList:[],
  14. listRecord: 0,
  15. pageInput: '1',
  16. modelType:0,
  17. coupinList:[],
  18. },
  19. filters: {
  20. TypeFormat:function(value) {
  21. switch (value) {
  22. case 0:
  23. return '活动券';
  24. break;
  25. case 1:
  26. return '品类券';
  27. break;
  28. case 2:
  29. return '用户专享券';
  30. break;
  31. case 3:
  32. return '店铺券';
  33. break;
  34. case 4:
  35. return '新用户券';
  36. break;
  37. }
  38. }
  39. },
  40. computed: {
  41. pageTotal: function () {
  42. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  43. return total > 0 ? total : 1;
  44. },
  45. showPageBtn: function () {
  46. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  47. total = total > 0 ? total : 1;
  48. var index = this.listQuery.pageNum, arr = [];
  49. if (total <= 6) {
  50. for (var i = 1; i <= total; i++) {
  51. arr.push(i);
  52. }
  53. return arr;
  54. }
  55. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  56. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  57. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  58. }
  59. },
  60. methods: {
  61. toPagination: function (pageNum) {//点击切换分页
  62. if (pageNum <= this.pageTotal) {
  63. this.listQuery.pageNum = pageNum;
  64. this.QueryCouponCollarList();
  65. }
  66. },
  67. checkNum: function () {//输入跳转分页
  68. if (this.pageInput > this.pageTotal) {
  69. this.pageInput = this.pageTotal;
  70. } else if (this.pageInput < 1) {
  71. this.pageInput = 1;
  72. }
  73. },
  74. changeOrderFn:function(index,status){
  75. var _self = this;
  76. _self.orderTabBarIndex = index;
  77. _self.listQuery.orderState = status;
  78. _self.listQuery.searchNo = '';
  79. _self.listQuery.beginTime = '';
  80. _self.listQuery.endTime = '';
  81. _self.listQuery.pageNum = 1;
  82. _self.isRequset = true;
  83. _self.QueryCouponCollarList()
  84. },
  85. QueryCouponCollarList:function(){//查询优惠券列表
  86. var _self = this;
  87. ProductApi.QueryCouponCollarList(_self.listQuery,function (response) {
  88. if(response.code == 0){
  89. var data = response.data;
  90. if( data.list && data.list.length>0) {
  91. _self.coupinList = [];
  92. _self.coupinList = data.list;
  93. _self.listRecord = data.total;
  94. }else{
  95. _self.coupinList = [];
  96. _self.coupinList = data.list;
  97. _self.listRecord = data.total;
  98. }
  99. _self.isRequset = false;
  100. }else{
  101. CAIMEI.Alert(response.msg, '确定', false);
  102. }
  103. })
  104. },
  105. toBuyCoupon:function (coupon) {// 点击购买按钮事件处理
  106. var _self = this;
  107. if(this.listQuery.userId == 0){
  108. window.location.href='/login.html';
  109. }else{
  110. ProductApi.createCouponRecord({userId:_self.listQuery.userId, couponId:coupon.couponId}, function (response) {
  111. if(response.code == 0){
  112. let couponRecordId = response.data.couponRecordId
  113. window.location.href = '/pay/caimei-paycash.html?pageType=3&couponId='+coupon.couponId+'&couponRecordId='+couponRecordId;
  114. }else{
  115. if(response.code == -1){//个人机构不能购买
  116. CAIMEI.Alert('该优惠券仅限医美机构购买,请升级为医美机构后再次购买。', '去升级', true, function(){
  117. window.location.href = "/user/setting/upgrade.html";
  118. });
  119. }else if(response.code == -2){//会员机构不是医美机构不能购买
  120. CAIMEI.dialog('该优惠券仅限医美机构购买',false,function () {});
  121. }else{
  122. CAIMEI.Alert(response.msg, '确定', false);
  123. }
  124. }
  125. })
  126. }
  127. },
  128. receiveCoupon:function(coupon){// 点击领取按钮事件处理
  129. var _self = this;
  130. console.log(coupon)
  131. if(_self.listQuery.userId == 0){
  132. window.location.href='/login.html';
  133. }else{
  134. ProductApi.ReceiveCoupon({userId:_self.listQuery.userId, couponId:coupon.couponId, source:1}, function (response) {
  135. if(response.code == 0){
  136. CAIMEI.dialog('领取成功',true,function () {
  137. setTimeout(function(){
  138. coupon.couponBtnType = 1;
  139. },200)
  140. });
  141. }else{
  142. CAIMEI.Alert(response.msg, '确定', false);
  143. }
  144. })
  145. }
  146. },
  147. myClickCoupon:function (){// 我的优惠券跳转
  148. var _self = this;
  149. if(_self.listQuery.userId>0){
  150. window.location.href='/user/coupon.html';
  151. }else{
  152. window.location.href='/login.html';
  153. }
  154. },
  155. toUseCoupon:function (coupon){// 去使用跳转路径
  156. var _self = this;
  157. switch (coupon.couponType) {
  158. case 0:// 活动券跳转到商城首页 / 或者活动页(看是否指定了商品)
  159. if(coupon.productType == 1){
  160. _self.QueryCouponCollarList()
  161. window.open('/index.html');
  162. }else{
  163. _self.QueryCouponCollarList()
  164. window.open('/product/product-coupon.html?couponId='+coupon.couponId);
  165. }
  166. break;
  167. case 1:// 品类券:跳转到产品 / 仪器页
  168. if(coupon.categoryType == 1){
  169. _self.QueryCouponCollarList()
  170. window.open('/product/type-287.html');
  171. }else{
  172. _self.QueryCouponCollarList()
  173. window.open('/product/type-286.html');
  174. }
  175. break;
  176. case 2:// 专享券:跳转到商城首页
  177. _self.QueryCouponCollarList()
  178. window.open('/index.html');
  179. break;
  180. case 3:// 店铺券:跳转到店铺首页
  181. _self.QueryCouponCollarList()
  182. window.open('/supplier-'+coupon.shopId+'.html');
  183. break;
  184. case 4:// 新用户券:跳转到商城首页
  185. _self.QueryCouponCollarList()
  186. window.open('/index.html');
  187. break;
  188. }
  189. }
  190. },
  191. mounted: function () {
  192. var _self = this;
  193. if(globalUserData){
  194. _self.userId = globalUserData.userId;
  195. _self.listQuery.userId = _self.userId;
  196. }
  197. _self.QueryCouponCollarList();
  198. }
  199. });