|
@@ -94,7 +94,7 @@
|
|
@open="$refs.receiveBuyPopup.close()"
|
|
@open="$refs.receiveBuyPopup.close()"
|
|
@close="$refs.receiveBuyPopup.open()"
|
|
@close="$refs.receiveBuyPopup.open()"
|
|
></goods-activity-popup>
|
|
></goods-activity-popup>
|
|
-
|
|
|
|
|
|
+
|
|
<!-- 分享弹窗 -->
|
|
<!-- 分享弹窗 -->
|
|
<cm-share-popup ref="sharePopup" :data="posterData" type="product"></cm-share-popup>
|
|
<cm-share-popup ref="sharePopup" :data="posterData" type="product"></cm-share-popup>
|
|
|
|
|
|
@@ -124,16 +124,18 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-// 配置
|
|
|
|
-import { generateNavbarButtonText } from './commons/helper.js'
|
|
|
|
-import { generateActivityType, generatePriceType } from '@/common/goods.helper.js'
|
|
|
|
import uParse from '@/components/uni/uParse/src/wxParse'
|
|
import uParse from '@/components/uni/uParse/src/wxParse'
|
|
import { debounce } from '@/common/utils.js'
|
|
import { debounce } from '@/common/utils.js'
|
|
import { shareDataResult } from '@/common/share.helper.js'
|
|
import { shareDataResult } from '@/common/share.helper.js'
|
|
-import { fetchProductDetail } from '@/services/api/goods.js'
|
|
|
|
-import { fetchCouponListByProductId } from '@/services/api/coupon.js'
|
|
|
|
import { queryStringify } from '@/common/utils.js'
|
|
import { queryStringify } from '@/common/utils.js'
|
|
import { mapGetters, mapActions } from 'vuex'
|
|
import { mapGetters, mapActions } from 'vuex'
|
|
|
|
+import {
|
|
|
|
+ generateNavbarButtonText,
|
|
|
|
+ fetchPorductInfo,
|
|
|
|
+ fetchCouponListByProduct,
|
|
|
|
+ generateNavbarType
|
|
|
|
+} from '@/common/goods.helper.js'
|
|
|
|
+
|
|
export default {
|
|
export default {
|
|
components: {
|
|
components: {
|
|
uParse
|
|
uParse
|
|
@@ -182,7 +184,7 @@ export default {
|
|
},
|
|
},
|
|
// 商品导航类型
|
|
// 商品导航类型
|
|
navbarType() {
|
|
navbarType() {
|
|
- return this.generateNavbarType()
|
|
|
|
|
|
+ return generateNavbarType(this.productInfo)
|
|
},
|
|
},
|
|
// 当前商品默认可以使的优惠券
|
|
// 当前商品默认可以使的优惠券
|
|
couponTip() {
|
|
couponTip() {
|
|
@@ -212,8 +214,7 @@ export default {
|
|
this.jumpState = parseInt(options.jumpState)
|
|
this.jumpState = parseInt(options.jumpState)
|
|
},
|
|
},
|
|
onShow() {
|
|
onShow() {
|
|
- this.autoplay = true
|
|
|
|
- this.fetchProductDetail()
|
|
|
|
|
|
+ this.initPage()
|
|
},
|
|
},
|
|
onHide() {
|
|
onHide() {
|
|
this.autoplay = false
|
|
this.autoplay = false
|
|
@@ -227,22 +228,47 @@ export default {
|
|
this.goodsBuyPopup = true
|
|
this.goodsBuyPopup = true
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ async initPage() {
|
|
|
|
+ this.autoplay = true
|
|
|
|
+ // 获取商品详情
|
|
|
|
+ this.fetchProductDetail()
|
|
|
|
+ // 获取商品可用优惠券
|
|
|
|
+ this.couponList = await fetchCouponListByProduct(this.productId)
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ // 获取商品详情
|
|
|
|
+ async fetchProductDetail() {
|
|
|
|
+ this.productInfo = await fetchPorductInfo(this.productId)
|
|
|
|
+ this.isRequest = false
|
|
|
|
+ this.productInfo.heUserId = this.jumpState === 1 ? 0 : this.userId
|
|
|
|
+ this.initNavbarButton()
|
|
|
|
+ },
|
|
|
|
+
|
|
// 商品提交
|
|
// 商品提交
|
|
onSubmit(detail) {
|
|
onSubmit(detail) {
|
|
|
|
+ // 用户未登录
|
|
|
|
+ if (!this.userId) {
|
|
|
|
+ const pages = getCurrentPages()
|
|
|
|
+ const page = pages[pages.length - 1]
|
|
|
|
+ uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
|
|
|
|
+ uni.redirectTo({ url: '/pages/authorize/login-custom' })
|
|
|
|
+ this.goodsBuyPopup = false
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 加入购物车
|
|
if (detail.type === 'cart') {
|
|
if (detail.type === 'cart') {
|
|
this.addToCart({
|
|
this.addToCart({
|
|
skuId: detail.sku.skuId,
|
|
skuId: detail.sku.skuId,
|
|
productCount: detail.count,
|
|
productCount: detail.count,
|
|
heUserId: this.productInfo.heUserId
|
|
heUserId: this.productInfo.heUserId
|
|
})
|
|
})
|
|
- } else if (detail.type === 'buy') {
|
|
|
|
- if (!this.userId) {
|
|
|
|
- const pages = getCurrentPages()
|
|
|
|
- const page = pages[pages.length - 1]
|
|
|
|
- uni.setStorageSync('LOGIN_REDIRECT_URL', page.$page.fullPath)
|
|
|
|
- uni.redirectTo({ url: '/pages/authorize/login-custom' })
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ this.goodsBuyPopup = false
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 立即购买
|
|
|
|
+ if (detail.type === 'buy') {
|
|
const submitData = {
|
|
const submitData = {
|
|
productId: detail.sku.productId, // 产品id
|
|
productId: detail.sku.productId, // 产品id
|
|
skuId: detail.sku.skuId, // sku id
|
|
skuId: detail.sku.skuId, // sku id
|
|
@@ -255,8 +281,9 @@ export default {
|
|
}
|
|
}
|
|
uni.setStorageSync('COMMIT_PRODUCT_INFO', submitData)
|
|
uni.setStorageSync('COMMIT_PRODUCT_INFO', submitData)
|
|
this.$router.navigateTo('order/order-create?type=product')
|
|
this.$router.navigateTo('order/order-create?type=product')
|
|
|
|
+ this.goodsBuyPopup = false
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- this.goodsBuyPopup = false
|
|
|
|
},
|
|
},
|
|
|
|
|
|
// 优惠券点击事件
|
|
// 优惠券点击事件
|
|
@@ -366,96 +393,6 @@ export default {
|
|
this.currentTab = index
|
|
this.currentTab = index
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- },
|
|
|
|
-
|
|
|
|
- // 获取商品详情
|
|
|
|
- async fetchProductDetail() {
|
|
|
|
- try {
|
|
|
|
- const res = await fetchProductDetail({ productId: this.productId, userId: this.userId })
|
|
|
|
- this.isRequest = false
|
|
|
|
- this.productInfo.heUserId = this.jumpState === 1 ? 0 : this.userId
|
|
|
|
- this.productInfo = this.generateProductInfo(res.data)
|
|
|
|
- this.initNavbarButton()
|
|
|
|
- this.fetchCouponList()
|
|
|
|
- } catch (e) {
|
|
|
|
- console.log(e)
|
|
|
|
- console.log('获取商品详情失败')
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 生成导航菜单类型
|
|
|
|
- generateNavbarType() {
|
|
|
|
- const { couponStatus = 0, collageStatus = 0, activeStatus = 0, discountStatus = 0 } = this.productInfo
|
|
|
|
-
|
|
|
|
- // 拼团价
|
|
|
|
- if (collageStatus > 0) {
|
|
|
|
- if (couponStatus === 1) {
|
|
|
|
- return 'groupWithCoupon' // 拼团券后价
|
|
|
|
- } else {
|
|
|
|
- return 'group' // 拼团价
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 限时活动
|
|
|
|
- else if (discountStatus > 0 || activeStatus > 0) {
|
|
|
|
- if (couponStatus === 1) {
|
|
|
|
- return 'activityWithCoupon' // 券后价
|
|
|
|
- } else {
|
|
|
|
- return 'normal' // 限时活动价格
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // 无活动价
|
|
|
|
- else {
|
|
|
|
- if (couponStatus === 1) {
|
|
|
|
- return 'normalWithCoupon' // 普通券后价
|
|
|
|
- } else {
|
|
|
|
- return 'normal' // 普通价
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 创建优惠券
|
|
|
|
- generateCoupon(coupon) {
|
|
|
|
- const obj = Object.assign({}, coupon)
|
|
|
|
- // 添加标题
|
|
|
|
- if (coupon.noThresholdFlag > 0) {
|
|
|
|
- obj.couponTitle = `减¥${coupon.couponAmount}元`
|
|
|
|
- } else {
|
|
|
|
- obj.couponTitle = `满¥${coupon.touchPrice}元减¥${coupon.couponAmount}元`
|
|
|
|
- }
|
|
|
|
- // 添加优惠券状态
|
|
|
|
- if (obj.useStatus === 0) {
|
|
|
|
- obj.controlType = 'receive'
|
|
|
|
- } else if (obj.useStatus === 1) {
|
|
|
|
- obj.couponStatus = 'received'
|
|
|
|
- obj.controlType = 'search'
|
|
|
|
- }
|
|
|
|
- return obj
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 获取商品可用优惠券
|
|
|
|
- async fetchCouponList() {
|
|
|
|
- try {
|
|
|
|
- const res = await fetchCouponListByProductId({ productId: this.productId, userId: this.userId })
|
|
|
|
- this.couponList = res.data.map(coupon => this.generateCoupon(coupon))
|
|
|
|
- } catch (e) {
|
|
|
|
- //TODO handle the exception
|
|
|
|
- console.log(e)
|
|
|
|
- console.log('获取优惠券列表失败')
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // 处理商品信息
|
|
|
|
- generateProductInfo(product) {
|
|
|
|
- if (!product) return product
|
|
|
|
- // 商品活动类型
|
|
|
|
- product.activityType = generateActivityType(product)
|
|
|
|
- product.priceType = generatePriceType(product)
|
|
|
|
- product.skus = product.skus.map(sku => {
|
|
|
|
- sku.activityType = generateActivityType(sku)
|
|
|
|
- sku.priceType = generatePriceType(sku)
|
|
|
|
- return sku
|
|
|
|
- })
|
|
|
|
- return product
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|