import Vue, { callWithAsyncErrorHandling } from 'vue' import { productTagStyle } from '@/plugins/mp-html/config.js' const proMixins = { data() { return { btnType:'', skuProduct: {}, addParams: { skuId: 0, productCount: 0, productId: 0, userId: 0, source: 1 }, tagStyle:productTagStyle } }, methods: { buyProductCart() { //底部购物车按钮点击 if (this.hasLogin) { this.$api.navigateTo('/pages/goods/cart') } else { this.handleNavLogin() } }, btnGetConfirm(type) { //加入购物车&&立即购买点击 if (this.hasLogin) { this.btnType = type this.popupShow3 = true this.unitPopupType = 1 } else { this.handleNavLogin() } }, handleNavLogin(){ //未登录跳转 const pages = getCurrentPages() const page = pages[pages.length - 1] uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath) this.$api.redirectTo('/pages/login/login') }, handleSkuClick(sku) { //sku修改选择 console.log(sku) this.addParams.skuId = sku.skuId this.skuProduct = {...this.skuProduct ,...sku} }, handleBuyConfirm(data) { // 监听确定选择规格 console.log('data', data) if (data.type == 'buy') { this.handleToConfirm({ productIds: this.product.productId, skuId: this.addParams.skuId, productCount: data.productCount }) } else { this.addParams.productCount = data.productCount this.handleAddClubCart(this.addParams) } }, handleToConfirm(data) { //跳转确认订单页面 this.$api.navigateTo(`/pages/user/order/create-order?type=1&data=${JSON.stringify({ data: data })}`) }, handleAddClubCart(params) { //增加购物车成功和toast弹窗提示成功 this.ProductService.shoppingAddCart(params) .then(response => { this.specClass = 'hide' this.$util.msg('加入购物车成功', 1500, true, 'success') this.isAnimation = true setTimeout(() => { this.specClass = 'none' }, 200) setTimeout(() => { this.isAnimation = false }, 2000) this.bottomCartNumber = response.data }) .catch(error => { console.log('error', error.msg) }) } } } export default proMixins