proMixins.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import Vue, { callWithAsyncErrorHandling } from 'vue'
  2. import { productTagStyle } from '@/plugins/mp-html/config.js'
  3. const proMixins = {
  4. data() {
  5. return {
  6. btnType:'',
  7. skuProduct: {},
  8. addParams: {
  9. skuId: 0,
  10. productCount: 0,
  11. productId: 0,
  12. userId: 0,
  13. source: 1
  14. },
  15. tagStyle:productTagStyle
  16. }
  17. },
  18. methods: {
  19. buyProductCart() {
  20. //底部购物车按钮点击
  21. if (this.hasLogin) {
  22. // 友盟埋点商品详情购物车入口点击事件
  23. if (process.env.NODE_ENV != 'development') {
  24. this.$uma.trackEvent('Um_Event_ProductShoppingCart', {
  25. Um_Key_PageName: '去购物车',
  26. Um_Key_SourcePage: '商品详情购物车入口'
  27. })
  28. }
  29. this.$api.navigateTo('/pages/goods/cart')
  30. } else {
  31. this.$api.navigateTo('/pages/login/login?type=1')
  32. }
  33. },
  34. btnGetConfirm(type) {
  35. //加入购物车&&立即购买点击
  36. if (this.hasLogin) {
  37. this.btnType = type
  38. this.popupShow3 = true
  39. this.unitPopupType = 1
  40. } else {
  41. this.$api.navigateTo('/pages/login/login?type=1')
  42. }
  43. },
  44. handleSkuClick(sku) { //sku修改选择
  45. console.log(sku)
  46. this.addParams.skuId = sku.skuId
  47. this.skuProduct.originalPrice = sku.originalPrice
  48. this.skuProduct.price = sku.price
  49. this.skuProduct.svipPriceTag = sku.svipPriceTag
  50. },
  51. handleBuyConfirm(data) {
  52. // 监听确定选择规格
  53. console.log('data', data)
  54. if (data.type == 'buy') {
  55. this.handleToConfirm({ productIds: this.product.productId, skuId: this.addParams.skuId, productCount: data.productCount })
  56. } else {
  57. this.addParams.productCount = data.productCount
  58. this.handleAddClubCart(this.addParams)
  59. }
  60. },
  61. handleToConfirm(data) {
  62. //跳转确认订单页面
  63. this.$api.navigateTo(`/pages/user/order/create-order?type=1&data=${JSON.stringify({ data: data })}`)
  64. },
  65. handleAddClubCart(params) {
  66. //增加购物车成功和toast弹窗提示成功
  67. this.ProductService.shoppingAddCart(params)
  68. .then(response => {
  69. this.specClass = 'hide'
  70. this.$util.msg('加入购物车成功', 1500, true, 'success')
  71. this.isAnimation = true
  72. setTimeout(() => {
  73. this.specClass = 'none'
  74. }, 200)
  75. setTimeout(() => {
  76. this.isAnimation = false
  77. }, 2000)
  78. this.bottomCartNumber = response.data
  79. })
  80. .catch(error => {
  81. console.log('error', error.msg)
  82. })
  83. }
  84. }
  85. }
  86. export default proMixins