1
This commit is contained in:
@ -56,14 +56,24 @@
|
||||
@scrolltolower="onLoadMore"
|
||||
>
|
||||
<view class="goods-list">
|
||||
<good-item
|
||||
v-for="good in goodsList"
|
||||
:key="good.product_id"
|
||||
:ref="`goodItem_${good.product_id}`"
|
||||
:data="good"
|
||||
@addToCar="addToCar"
|
||||
@buyNow="handleBuyNow"
|
||||
/>
|
||||
<view class="goods-list-item left">
|
||||
<good-item
|
||||
v-for="(good, i) in leftColumnGoods"
|
||||
:index="2 * i"
|
||||
:key="2 * i"
|
||||
:data="good"
|
||||
@addToCar="addToCar"
|
||||
/>
|
||||
</view>
|
||||
<view class="goods-list-item right">
|
||||
<good-item
|
||||
v-for="(good, i) in rightColumnGoods"
|
||||
:index="2 * i + 1"
|
||||
:key="2 * i + 1"
|
||||
:data="good"
|
||||
@addToCar="addToCar"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="isLoading" class="loading-wrapper flex-center">
|
||||
<uni-load-more status="loading" :show-text="false" />
|
||||
@ -98,7 +108,7 @@
|
||||
<script>
|
||||
import { imgPrefix } from "@/utils/common";
|
||||
|
||||
import GoodItem from "../category/components/GoodItem.vue";
|
||||
import GoodItem from "../shop/components/GoodItem.vue";
|
||||
import AddGoodsModal from "@/components/goods/AddGoodsModal.vue";
|
||||
import ContactModal from "@/components/ContactModal.vue";
|
||||
import WeChatCopyModal from "@/components/WeChatCopyModal.vue";
|
||||
@ -179,6 +189,12 @@ export default {
|
||||
cartShowCount() {
|
||||
return this.cartCount > 9 ? "9+" : this.cartCount;
|
||||
},
|
||||
leftColumnGoods() {
|
||||
return this.goodsList.filter((v, i) => i % 2 === 0);
|
||||
},
|
||||
rightColumnGoods() {
|
||||
return this.goodsList.filter((v, i) => i % 2 === 1);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.initData();
|
||||
@ -267,14 +283,11 @@ export default {
|
||||
if (this.isLoading) return;
|
||||
this.isLoading = true;
|
||||
getGoodsListData({
|
||||
type: this.selectCategoryId ? this.selectCategoryId : 1,
|
||||
p: this.page,
|
||||
num: this.size,
|
||||
keyword: this.searchKeyword,
|
||||
type: this.selectCategoryId ? this.selectCategoryId : 0,
|
||||
})
|
||||
.then((res) => {
|
||||
const list = res?.data || [];
|
||||
this.goodsList = list;
|
||||
const list = res?.data.data.products || [];
|
||||
this.goodsList = list;
|
||||
this.total = res?.count || 0;
|
||||
})
|
||||
.finally(() => {
|
||||
@ -348,11 +361,38 @@ export default {
|
||||
this.cartCountBounce = false;
|
||||
}, 600);
|
||||
},
|
||||
addToCar(good) {
|
||||
this.showModal = true;
|
||||
this.addGoodInfo = {
|
||||
...good,
|
||||
};
|
||||
addToCar(goodsData) {
|
||||
// Parse image_list and get the first image URL
|
||||
let firstImageUrl = '';
|
||||
const imageList = goodsData.product.attr_key_value_map.image_list;
|
||||
if (imageList) {
|
||||
try {
|
||||
// Try to parse as JSON if it's a string
|
||||
const parsedList = typeof imageList === 'string' ? JSON.parse(imageList) : imageList;
|
||||
if (Array.isArray(parsedList) && parsedList.length > 0) {
|
||||
firstImageUrl = parsedList[0].url || parsedList[0] || '';
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error parsing image_list:', e);
|
||||
}
|
||||
}
|
||||
|
||||
uni.navigateTo({
|
||||
url: `/pages/client/order/create`,
|
||||
success: (res) => {
|
||||
// 通过eventChannel向被打开页面传送数据
|
||||
res.eventChannel.emit("createOrder", {
|
||||
goodList: [{
|
||||
goods_id:goodsData.product.out_id,
|
||||
product_pic: firstImageUrl,
|
||||
number:1,
|
||||
goods_name: goodsData.product.product_name,
|
||||
price_name: goodsData?.product.product_name,
|
||||
goods_price: goodsData.sku.actual_amount / 100
|
||||
}, ],
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
// 购物车列表
|
||||
getCartListData() {
|
||||
@ -597,4 +637,22 @@ export default {
|
||||
.loading-wrapper {
|
||||
padding: 10rpx 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
.goods-list {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
margin-top: 40rpx;
|
||||
padding: 0 20rpx;
|
||||
|
||||
.goods-list-item {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
&.left {
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user