productMixins.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // 商品详情
  2. var productMixins = function () {
  3. return {
  4. data() {
  5. return {
  6. addParams:{
  7. skuId:0,
  8. productCount:0,
  9. productId:0,
  10. userId:0,
  11. source:1
  12. },
  13. handleSkuId:0,
  14. currentIndex:0,
  15. skuIndex:0,
  16. skuSupportingIndex:0,
  17. ladderList: [],//阶梯价
  18. isDetailsBtnDisable:false
  19. }
  20. },
  21. filters: {
  22. NumFormat(value) {
  23. console.log('value',value)
  24. //处理金额
  25. return Number(value).toFixed(2)
  26. }
  27. },
  28. methods: {
  29. handleAddShopCart(){ //加入购物车
  30. if(this.isDetailsBtnDisable){ return }
  31. if(this.addStatus){
  32. this.addStatus = false;
  33. this.addParams.productCount = this.number;
  34. this.handleClubAddCart(this.addParams)
  35. }
  36. },
  37. handleClubAddCart(params){// 调用加入购物车
  38. var _self = this;
  39. ShoppingApi.ClubAddCart(params,function (response){
  40. if(response.code == 0){
  41. _self.addStatus = true;
  42. $.confirm({
  43. useBootstrap: false,
  44. boxWidth: (isPC?'338px':'74.6vw'),
  45. title: false,
  46. content:'<div class="cartAlert"><h6>商品已成功加入购物车!</h6><p>当前购物车共<em>'+response.data+'</em>种商品</p></div>',
  47. closeIcon: true,
  48. animation: 'opacity',
  49. closeAnimation: 'opacity',
  50. animateFromElement: false,
  51. scrollToPreviousElement: false,
  52. buttons: {
  53. login: {
  54. text: '去结算',
  55. btnClass: 'btn-to-cart',
  56. action: function(){
  57. window.location.href = '/shopping/cart.html';
  58. }
  59. },
  60. close: {
  61. text: '继续购物',
  62. btnClass: 'btn-to-goon',
  63. action:function(){
  64. }
  65. }
  66. }
  67. });
  68. globalHead.getHeadCart(_self.userId);
  69. }else{
  70. CAIMEI.dialog('加入购物车失败!',true,function () {
  71. _self.addStatus = true;
  72. });
  73. }
  74. })
  75. },
  76. handleBuyNowSubmit(){ // type:(1购物车提交[对应表cm_cart],2直接购买提交, 3协销下单)
  77. if(this.isDetailsBtnDisable){ return }
  78. if(this.productId && this.number){
  79. window.location.href = '/shopping/confirm.html?type=2&productId='+this.productId+'&count='+this.number+'&skuId='+this.addParams.skuId;
  80. }
  81. },
  82. handleChoisSku(sku,index){
  83. this.skuIndex = index;
  84. this.priceObj.originalPrice = sku.originalPrice;
  85. this.priceObj.normalPrice = sku.normalPrice;
  86. this.priceObj.price = sku.price;
  87. this.addParams.skuId = sku.skuId;
  88. this.number = this.priceObj.minBuyNumber = sku.minBuyNumber;
  89. this.productStock = sku.stock;
  90. this.ladderList = sku.ladderPriceList ? sku.ladderPriceList : [];
  91. this.isDetailsBtnDisable = sku.stock === 0;
  92. $('#prosductStock').text(sku.stock);
  93. $('#proMinBuyNumber').text(sku.minBuyNumber);
  94. },
  95. hanSkuClickSEo(){// 静态化下控制点击
  96. var grade = $(".unitTags").eq(0).attr('data-grade');
  97. $('#priceGrade').addClass(`i${grade}`);
  98. $(".unitTags").each(function() {
  99. var _this = $(this);
  100. _this.click(function () {
  101. _this.addClass("active");
  102. _this.siblings().removeClass('active');
  103. var priceGrade = 'i'+_this.attr('data-grade');
  104. const el = $('#priceGrade');
  105. el.parent().append('<i id="priceGrade" class="icon mIcon ' + priceGrade +'"></i>');
  106. el.remove();
  107. })
  108. });
  109. }
  110. },
  111. mounted: function() {
  112. this.hanSkuClickSEo();
  113. }
  114. }
  115. }();