proMixins.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.handleNavLogin()
  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.handleNavLogin()
  35. }
  36. },
  37. handleNavLogin(){
  38. //未登录跳转
  39. const pages = getCurrentPages()
  40. const page = pages[pages.length - 1]
  41. uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
  42. this.$api.redirectTo('/pages/login/login')
  43. },
  44. handleSkuClick(sku) { //sku修改选择
  45. console.log(sku)
  46. this.addParams.skuId = sku.skuId
  47. this.skuProduct = {...this.skuProduct ,...sku}
  48. },
  49. handleBuyConfirm(data) {
  50. // 监听确定选择规格
  51. console.log('data', data)
  52. if (data.type == 'buy') {
  53. this.handleToConfirm({ productIds: this.product.productId, skuId: this.addParams.skuId, productCount: data.productCount })
  54. } else {
  55. this.addParams.productCount = data.productCount
  56. this.handleAddClubCart(this.addParams)
  57. }
  58. },
  59. handleToConfirm(data) {
  60. //跳转确认订单页面
  61. this.$api.navigateTo(`/pages/user/order/create-order?type=1&data=${JSON.stringify({ data: data })}`)
  62. },
  63. handleAddClubCart(params) {
  64. //增加购物车成功和toast弹窗提示成功
  65. this.ProductService.shoppingAddCart(params)
  66. .then(response => {
  67. this.specClass = 'hide'
  68. this.$util.msg('加入购物车成功', 1500, true, 'success')
  69. this.isAnimation = true
  70. setTimeout(() => {
  71. this.specClass = 'none'
  72. }, 200)
  73. setTimeout(() => {
  74. this.isAnimation = false
  75. }, 2000)
  76. this.bottomCartNumber = response.data
  77. })
  78. .catch(error => {
  79. console.log('error', error.msg)
  80. })
  81. }
  82. }
  83. }
  84. export default proMixins