2025-10-29 09:05:59 +08:00
|
|
|
|
<script lang="ts" setup>
|
2025-10-31 15:36:35 +08:00
|
|
|
|
import { ref, onMounted } from 'vue'
|
|
|
|
|
|
import { useWxStore } from '@/pinia/stores/wx'
|
|
|
|
|
|
import { useProductStore } from '@/pinia/stores/product'
|
|
|
|
|
|
import { useCartStore } from '@/pinia/stores/cart'
|
|
|
|
|
|
import { getShopListApi } from '@/api/shop'
|
|
|
|
|
|
import type { ShopEntity } from '@/api/shop/types'
|
2025-10-31 17:44:08 +08:00
|
|
|
|
import ProductContainer from './components/product-container.vue';
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
|
|
|
|
|
definePage({
|
|
|
|
|
|
style: {
|
|
|
|
|
|
navigationBarTitleText: '首页',
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
// 状态管理
|
|
|
|
|
|
const wxStore = useWxStore()
|
|
|
|
|
|
const productStore = useProductStore()
|
|
|
|
|
|
const cartStore = useCartStore()
|
|
|
|
|
|
|
|
|
|
|
|
// 显示选择商店列表
|
|
|
|
|
|
const showShopList = ref<boolean>(true)
|
|
|
|
|
|
const shopList = ref<ShopEntity[]>([])
|
|
|
|
|
|
const shopId = ref<number>(0)
|
|
|
|
|
|
|
|
|
|
|
|
// 页面加载
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
if (showShopList.value) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 等待 handleWxCallback 完成
|
|
|
|
|
|
await wxStore.waitForHandleWxCallbackComplete();
|
2025-10-31 17:44:08 +08:00
|
|
|
|
const res = await getShopListApi(wxStore.corpid || '');
|
|
|
|
|
|
console.log('获取店铺列表:', res)
|
|
|
|
|
|
if (res?.code === 0 && res?.data?.length > 0) {
|
|
|
|
|
|
shopList.value = res.data;
|
|
|
|
|
|
|
|
|
|
|
|
shopList.value = [...shopList.value, ...res.data, ...res.data, ...res.data];
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
2025-10-31 15:36:35 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('获取店铺列表失败:', error)
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
// 点击分类导航
|
|
|
|
|
|
function handleShopSelect(selectedShopId: number) {
|
|
|
|
|
|
shopId.value = selectedShopId
|
|
|
|
|
|
showShopList.value = false
|
|
|
|
|
|
const selectedShop = shopList.value.find(shop => shop.shopId === selectedShopId)
|
|
|
|
|
|
if (selectedShop) {
|
|
|
|
|
|
productStore.setSelectedShop(selectedShop)
|
|
|
|
|
|
if (selectedShop.mode == 3) {
|
|
|
|
|
|
// 租用模式
|
|
|
|
|
|
// rentingCabinetStore.fetchRentingCabinetDetail(selectedShopId)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
productStore.getGoods(selectedShopId)
|
|
|
|
|
|
}
|
|
|
|
|
|
cartStore.clearCart()
|
|
|
|
|
|
}
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
// 返回店铺列表
|
|
|
|
|
|
function backToShopList() {
|
|
|
|
|
|
showShopList.value = true
|
|
|
|
|
|
shopId.value = 0
|
|
|
|
|
|
productStore.categories = []
|
|
|
|
|
|
cartStore.clearCart()
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
// 结算方法
|
|
|
|
|
|
function handleCheckout() {
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages/index/shopping-cart/index'
|
|
|
|
|
|
})
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-10-31 17:44:08 +08:00
|
|
|
|
<!-- 直接使用 shop-list 类,合并 shop-container 的样式 -->
|
|
|
|
|
|
<view class="shop-list">
|
|
|
|
|
|
<view class="shop-header">
|
|
|
|
|
|
<wd-img
|
|
|
|
|
|
:src="`/static/cover.png`"
|
|
|
|
|
|
width="100%"
|
|
|
|
|
|
height="150"
|
|
|
|
|
|
mode="aspectFill"
|
|
|
|
|
|
></wd-img>
|
|
|
|
|
|
</view>
|
2025-10-31 15:36:35 +08:00
|
|
|
|
|
2025-10-31 17:44:08 +08:00
|
|
|
|
<!-- 店铺选择列表内容 -->
|
|
|
|
|
|
<view v-if="showShopList" class="shop-list-content">
|
2025-10-31 15:36:35 +08:00
|
|
|
|
<view class="shop-prompt">
|
|
|
|
|
|
<view class="prompt-text">请选择机柜地址:</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
<view class="shop-row">
|
|
|
|
|
|
<view v-for="shop in shopList" :key="shop.shopId" class="shop-col" @click="handleShopSelect(shop.shopId)">
|
|
|
|
|
|
<view class="shop-item">
|
|
|
|
|
|
<wd-img
|
|
|
|
|
|
:src="shop.coverImg || '/static/product-image.png'"
|
|
|
|
|
|
width="100%"
|
|
|
|
|
|
height="80"
|
|
|
|
|
|
mode="aspectFill"
|
|
|
|
|
|
></wd-img>
|
|
|
|
|
|
<view class="shop-info">
|
|
|
|
|
|
<view class="shop-name">
|
|
|
|
|
|
<wd-icon name="shop" size="16px" color="#666"></wd-icon>
|
|
|
|
|
|
<text>{{ shop.shopName }}</text>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
2025-10-29 09:05:59 +08:00
|
|
|
|
</view>
|
2025-10-31 15:36:35 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</view>
|
2025-10-29 09:05:59 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
<!-- 商品列表 -->
|
2025-10-31 17:44:08 +08:00
|
|
|
|
<ProductContainer
|
|
|
|
|
|
v-if="!showShopList"
|
|
|
|
|
|
@backToShopList="backToShopList"
|
|
|
|
|
|
@checkout="handleCheckout"
|
|
|
|
|
|
/>
|
2025-10-29 09:05:59 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
<style scoped lang="scss">
|
2025-10-31 17:44:08 +08:00
|
|
|
|
.shop-list {
|
2025-10-29 09:05:59 +08:00
|
|
|
|
display: flex;
|
2025-10-31 15:36:35 +08:00
|
|
|
|
flex-direction: column;
|
2025-10-31 17:44:08 +08:00
|
|
|
|
height: calc(100vh - 94px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
|
2025-10-31 15:36:35 +08:00
|
|
|
|
background: #f7f8fa;
|
2025-10-31 17:44:08 +08:00
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
.shop-header {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 150px;
|
|
|
|
|
|
overflow: hidden;
|
2025-10-31 17:44:08 +08:00
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.shop-list-content {
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
overflow-y: auto;
|
|
|
|
|
|
overflow-x: hidden;
|
2025-10-31 15:36:35 +08:00
|
|
|
|
}
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
.shop-prompt {
|
|
|
|
|
|
margin: 8px;
|
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
|
background: white;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
|
|
|
|
|
|
|
|
|
|
|
.prompt-text {
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
font-weight: 500;
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
2025-10-31 15:36:35 +08:00
|
|
|
|
}
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
.shop-row {
|
|
|
|
|
|
padding: 0 8px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
}
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
.shop-col {
|
|
|
|
|
|
width: calc(50% - 4px);
|
|
|
|
|
|
margin-bottom: 8px;
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
.shop-item {
|
|
|
|
|
|
background: white;
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
|
|
|
|
|
transition: transform 0.2s;
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
&:active {
|
|
|
|
|
|
transform: scale(0.98);
|
|
|
|
|
|
}
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
.shop-info {
|
|
|
|
|
|
padding: 12px;
|
|
|
|
|
|
}
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
.shop-name {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: #333;
|
|
|
|
|
|
font-weight: 500;
|
2025-10-29 09:05:59 +08:00
|
|
|
|
|
2025-10-31 15:36:35 +08:00
|
|
|
|
text {
|
|
|
|
|
|
margin-left: 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-10-29 09:05:59 +08:00
|
|
|
|
}
|
2025-10-31 15:36:35 +08:00
|
|
|
|
</style>
|