proMixins.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. this.$api.navigateTo('/pages/goods/cart')
  23. } else {
  24. this.$api.navigateTo('/pages/login/login?type=1')
  25. }
  26. },
  27. btnGetConfirm(type) {
  28. //加入购物车&&立即购买点击
  29. if (this.hasLogin) {
  30. this.btnType = type
  31. this.popupShow3 = true
  32. this.unitPopupType = 1
  33. } else {
  34. this.$api.navigateTo('/pages/login/login?type=1')
  35. }
  36. },
  37. handleSkuClick(sku) { //sku修改选择
  38. console.log(sku)
  39. this.addParams.skuId = sku.skuId
  40. this.skuProduct.originalPrice = sku.originalPrice
  41. this.skuProduct.price = sku.price
  42. this.skuProduct.svipPriceTag = sku.svipPriceTag
  43. },
  44. handleBuyConfirm(data) {
  45. // 监听确定选择规格
  46. console.log('data', data)
  47. if (data.type == 'buy') {
  48. this.handleToConfirm({ productIds: this.product.productId, skuId: this.addParams.skuId, productCount: data.productCount })
  49. } else {
  50. this.addParams.productCount = data.productCount
  51. this.handleAddClubCart(this.addParams)
  52. }
  53. },
  54. handleToConfirm(data) {
  55. //跳转确认订单页面
  56. this.$api.navigateTo(`/pages/user/order/create-order?type=1&data=${JSON.stringify({ data: data })}`)
  57. },
  58. handleAddClubCart(params) {
  59. //增加购物车成功和toast弹窗提示成功
  60. this.ProductService.shoppingAddCart(params)
  61. .then(response => {
  62. this.specClass = 'hide'
  63. this.$util.msg('加入购物车成功', 1500, true, 'success')
  64. this.isAnimation = true
  65. setTimeout(() => {
  66. this.specClass = 'none'
  67. }, 200)
  68. setTimeout(() => {
  69. this.isAnimation = false
  70. }, 2000)
  71. this.bottomCartNumber = response.data
  72. })
  73. .catch(error => {
  74. console.log('error', error.msg)
  75. })
  76. }
  77. }
  78. }
  79. export default proMixins