|
|
@@ -6,12 +6,14 @@ import router from '@/router'
|
|
|
const props = defineProps<{ categoryList: Api.xsbCategories[], hotText: Api.xsbSearchTerm[] }>()
|
|
|
const { statusBarHeight, MenuButtonHeight } = storeToRefs(useSysStore())
|
|
|
const { topNavActive, leftActive, SelectShopInfo } = storeToRefs(useSysXsbStore())
|
|
|
-const { cartList } = storeToRefs(useSmqjhCartStore())
|
|
|
-const { userInfo } = storeToRefs(useUserStore())
|
|
|
+const { userInfo, token } = storeToRefs(useUserStore())
|
|
|
const classfiylist = computed(() => props.categoryList)
|
|
|
const sortClassBtn = ref(1)
|
|
|
const show = ref(false)
|
|
|
+const cartList = ref<Api.xsbCategoriesCartList[]>([])
|
|
|
+const cartIds = computed(() => cartList.value.filter(it => it.isDelete !== '1' && it.shopSkuStocks !== '0').map(it => it.id))
|
|
|
const showball = ref(false)
|
|
|
+const _this = getCurrentInstance()
|
|
|
definePage({
|
|
|
name: 'xsb-classfiy',
|
|
|
islogin: false,
|
|
|
@@ -26,8 +28,8 @@ const cartPopup = ref(false)
|
|
|
const basllObj = ref({
|
|
|
left: 0,
|
|
|
top: 0,
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
+ x: -402,
|
|
|
+ y: 773,
|
|
|
})
|
|
|
const x = computed(() => `${basllObj.value.x}px`)
|
|
|
const y = computed(() => `${basllObj.value.y}px`)
|
|
|
@@ -68,7 +70,25 @@ const categories = computed(() => {
|
|
|
const categoriesId = computed(() => {
|
|
|
return categories.value.find(it => it.code === leftActive.value)?.id
|
|
|
})
|
|
|
-
|
|
|
+async function getCartCategorList() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ Apis.xsb.myShoppingCartCategory({
|
|
|
+ data: {
|
|
|
+ businessType: 'XSB',
|
|
|
+ channelId: unref(userInfo).channelTopId,
|
|
|
+ shopId: unref(SelectShopInfo).shopId,
|
|
|
+ },
|
|
|
+ }).then((res) => {
|
|
|
+ cartList.value = res.data
|
|
|
+ if (cartList.value.length) {
|
|
|
+ getGoodsPrice()
|
|
|
+ }
|
|
|
+ resolve(res)
|
|
|
+ }).catch((err) => {
|
|
|
+ reject(err)
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
function handleChange({ value }: { value: string }) {
|
|
|
leftActive.value = value
|
|
|
getProductList()
|
|
|
@@ -109,14 +129,19 @@ async function handleAddCart(event: WechatMiniprogram.TouchEvent, item: Api.xsbC
|
|
|
console.log(event.detail.x, item)
|
|
|
if (showball.value)
|
|
|
return
|
|
|
+ if (!token.value) {
|
|
|
+ useGlobalToast().show('请先登录!')
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- await useSmqjhCartStore().addCart(item.skuId, 1, Number(item.shopId), 'XSB')
|
|
|
basllObj.value.left = event.detail.x
|
|
|
basllObj.value.top = event.detail.y
|
|
|
showball.value = true
|
|
|
setTimeout(() => {
|
|
|
showball.value = false
|
|
|
}, 500)
|
|
|
+ await useSmqjhCartStore().addCart(item.skuList[0].skuId, 1, Number(item.shopId), 'XSB')
|
|
|
+ getCartCategorList()
|
|
|
}
|
|
|
onMounted(async () => {
|
|
|
topNavActive.value = props.categoryList[0].code || ''
|
|
|
@@ -130,26 +155,56 @@ onMounted(async () => {
|
|
|
topScrollView.value = topNavActive.value
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
- if (cartList.value.length) {
|
|
|
- const query = uni.createSelectorQuery().in(getCurrentInstance())
|
|
|
- query.select('.cart-box').boundingClientRect()
|
|
|
- query.exec((res) => {
|
|
|
- basllObj.value.y = res[0].top
|
|
|
- uni.getSystemInfo().then((info) => {
|
|
|
- basllObj.value.x = -(info.screenWidth - res[0].left - 15)
|
|
|
- })
|
|
|
- })
|
|
|
- const ids = cartList.value.map(it => it.skuList.map(its => its.id)).flat()
|
|
|
- totalProduct.value = await useSmqjhCartStore().getCartAddGoodsPrice(ids.join(','))
|
|
|
+ if (token.value) {
|
|
|
+ await getCartCategorList()
|
|
|
+ if (cartList.value.length) {
|
|
|
+ getCartBox()
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
+function getCartBox() {
|
|
|
+ const query = uni.createSelectorQuery().in(_this)
|
|
|
+ query.select('.cart-box').boundingClientRect()
|
|
|
+ query.exec((res) => {
|
|
|
+ basllObj.value.y = res[0].top
|
|
|
+ uni.getSystemInfo().then((info) => {
|
|
|
+ basllObj.value.x = -(info.screenWidth - res[0].left - 15)
|
|
|
+ console.log(basllObj.value.x, basllObj.value.y)
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|
|
|
function handleGo(item: Api.xsbCategoryProductList) {
|
|
|
- if (item.id) {
|
|
|
+ if (!item.prodId) {
|
|
|
useGlobalToast().show('后端数据异常!')
|
|
|
return
|
|
|
}
|
|
|
- router.push({ name: 'xsb-goods', params: { id: String(item.id) } })
|
|
|
+ router.push({ name: 'xsb-goods', params: { id: String(item.prodId) } })
|
|
|
+}
|
|
|
+
|
|
|
+async function getGoodsPrice() {
|
|
|
+ const res = await useSmqjhCartStore().getCartAddGoodsPrice(cartIds.value.join(','))
|
|
|
+ totalProduct.value = res
|
|
|
+}
|
|
|
+async function handleSub(item: Api.xsbCategoriesCartList) {
|
|
|
+ if (item.num === 1) {
|
|
|
+ useGlobalMessage().confirm({
|
|
|
+ msg: '是否删除该商品?',
|
|
|
+ success: async () => {
|
|
|
+ await useSmqjhCartStore().addCart(item.skuId, -1, item.shopId, 'XSB')
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ await useSmqjhCartStore().addCart(item.skuId, -1, item.shopId, 'XSB')
|
|
|
+ getGoodsPrice()
|
|
|
+ await getCartCategorList()
|
|
|
+ }
|
|
|
+}
|
|
|
+async function handleAdd(item: Api.xsbCategoriesCartList) {
|
|
|
+ await useSmqjhCartStore().addCart(item.skuId, 1, item.shopId, 'XSB')
|
|
|
+ getGoodsPrice()
|
|
|
+ await getCartCategorList()
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
@@ -363,10 +418,65 @@ function handleGo(item: Api.xsbCategoryProductList) {
|
|
|
</view>
|
|
|
</view>
|
|
|
<Zpopup v-model="cartPopup">
|
|
|
- <view class="ios h800rpx">
|
|
|
+ <view class="ios h800rpx overflow-y-scroll">
|
|
|
<view class="p24rpx">
|
|
|
- 1212
|
|
|
+ <view
|
|
|
+ v-for="item in cartList" :key="item.id" class="relative mt20rpx box-border flex items-center overflow-hidden rounded-16rpx bg-white p24rpx"
|
|
|
+ >
|
|
|
+ <view class="flex flex-1">
|
|
|
+ <image
|
|
|
+ :src="item.pic"
|
|
|
+ class="h206rpx w200rpx flex-shrink-0"
|
|
|
+ @click.stop="router.push({ name: 'xsb-goods', params: { id: String(item.skuId) } })"
|
|
|
+ />
|
|
|
+ <view class="ml20rpx flex-1">
|
|
|
+ <view class="text-left text-28rpx font-semibold">
|
|
|
+ <!-- <view v-for="i in 2" :key="i" class="mr5px inline-block">
|
|
|
+ <wd-tag type="danger">
|
|
|
+ 惊喜回馈
|
|
|
+ </wd-tag>
|
|
|
+ </view> -->
|
|
|
+ {{ item.skuName }}
|
|
|
+ </view>
|
|
|
+ <view class="mt14rpx text-24rpx text-#AAAAAA">
|
|
|
+ 规格:{{ item.spec }}
|
|
|
+ </view>
|
|
|
+ <view class="mt14rpx flex items-center justify-between">
|
|
|
+ <view class="text-36rpx text-#FF4A39 font-semibold">
|
|
|
+ ¥{{ item.price }}
|
|
|
+ </view>
|
|
|
+ <!-- <wd-input-number v-model="item.num" disable-input @change="handleChangeNum($event, item)" /> -->
|
|
|
+ <view class="flex items-center">
|
|
|
+ <image
|
|
|
+ :src="` ${StaticUrl}/sub-cart.png`"
|
|
|
+ class="h44rpx w44rpx"
|
|
|
+ @click.stop="handleSub(item)"
|
|
|
+ />
|
|
|
+ <view class="box-border h44rpx w84rpx flex items-center justify-center border border-#F0F0F0 border-solid text-24rpx text-#AAAAAA">
|
|
|
+ {{ item.num }}
|
|
|
+ </view>
|
|
|
+ <image
|
|
|
+ :src="` ${StaticUrl}/add-cart.png`"
|
|
|
+ class="h44rpx w44rpx"
|
|
|
+ @click.stop="handleAdd(item)"
|
|
|
+ />
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view v-if="item.shopSkuStocks == '0'" class="absolute left-0 top-0 z-1 h-full w-full flex items-center justify-center bg-[rgba(255,255,255,.6)]">
|
|
|
+ <view class="rounded-16rpx bg-[rgba(0,0,0,.5)] p20rpx text-white">
|
|
|
+ 商品已售罄
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ <view v-if="item.isDelete == '1'" class="absolute left-0 top-0 z-1 h-full w-full flex items-center justify-center bg-[rgba(255,255,255,.6)]">
|
|
|
+ <view class="rounded-16rpx bg-[rgba(0,0,0,.5)] p20rpx text-white">
|
|
|
+ 商品已删除
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
+ <view class="h320rpx" />
|
|
|
</view>
|
|
|
</Zpopup>
|
|
|
<view v-if="showball" class="ball">
|