最低价格

This commit is contained in:
18631081161 2026-04-06 20:34:20 +08:00
parent 87148ac038
commit 2a736f0aae
3 changed files with 28 additions and 7 deletions

View File

@ -3,7 +3,8 @@
{ {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationStyle": "custom" "navigationStyle": "custom",
"enablePullDownRefresh": true
} }
}, },
{ {

View File

@ -65,6 +65,9 @@
<view v-if="loading" class="loading-tip"> <view v-if="loading" class="loading-tip">
<text>加载中...</text> <text>加载中...</text>
</view> </view>
<view v-else-if="products.length > 0 && !hasMore" class="loading-tip">
<text>没有更多了</text>
</view>
<!-- 客服二维码弹窗 --> <!-- 客服二维码弹窗 -->
<CustomerServiceBtn v-if="showQrcode" mode="qrcode" @close="showQrcode = false" /> <CustomerServiceBtn v-if="showQrcode" mode="qrcode" @close="showQrcode = false" />
@ -73,6 +76,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import { onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
import type { Product, Category } from '../../types' import type { Product, Category } from '../../types'
import { getProducts, getCategories } from '../../api/product' import { getProducts, getCategories } from '../../api/product'
import { BASE_URL } from '../../utils/request' import { BASE_URL } from '../../utils/request'
@ -114,8 +118,11 @@
} catch { /* handled */ } } catch { /* handled */ }
} }
const hasMore = ref(true)
async function loadProducts(reset = false) { async function loadProducts(reset = false) {
if (reset) { page.value = 1; products.value = [] } if (reset) { page.value = 1; products.value = []; hasMore.value = true }
if (!hasMore.value) return
loading.value = true loading.value = true
try { try {
const params : Record<string, unknown> = { page: page.value, pageSize } const params : Record<string, unknown> = { page: page.value, pageSize }
@ -123,6 +130,7 @@
if (keyword.value) params.keyword = keyword.value if (keyword.value) params.keyword = keyword.value
const data = await getProducts(params as any) const data = await getProducts(params as any)
if (reset) { products.value = data.list } else { products.value.push(...data.list) } if (reset) { products.value = data.list } else { products.value.push(...data.list) }
if (data.list.length < pageSize) hasMore.value = false
} catch { /* handled */ } } catch { /* handled */ }
finally { loading.value = false } finally { loading.value = false }
} }
@ -143,6 +151,18 @@
} }
onMounted(() => { loadCategories(); loadProducts(true) }) onMounted(() => { loadCategories(); loadProducts(true) })
onPullDownRefresh(async () => {
await Promise.all([loadCategories(), loadProducts(true)])
uni.stopPullDownRefresh()
})
onReachBottom(() => {
if (!loading.value && hasMore.value) {
page.value++
loadProducts()
}
})
</script> </script>
<style scoped> <style scoped>

View File

@ -97,9 +97,9 @@ export async function adminCreateProduct(req: Request, res: Response): Promise<v
const categoryIdStr = Array.isArray(categoryId) ? JSON.stringify(categoryId) : (categoryId ? JSON.stringify([categoryId]) : null) const categoryIdStr = Array.isArray(categoryId) ? JSON.stringify(categoryId) : (categoryId ? JSON.stringify([categoryId]) : null)
const [result] = await conn.execute<ResultSetHeader>( const [result] = await conn.execute<ResultSetHeader>(
`INSERT INTO products (name, base_price, style_no, stock, total_stock, loss, labor_cost, category_id, banner_images, banner_video, detail_images, thumb, side_stone, style, setting, status) `INSERT INTO products (name, style_no, total_stock, loss, labor_cost, category_id, banner_images, banner_video, detail_images, thumb, side_stone, style, setting, status)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[name, basePrice || 0, styleNo || '', stock || 0, totalStock || 0, loss || 0, laborCost || 0, categoryIdStr, JSON.stringify(bannerImages || []), JSON.stringify(bannerVideo || []), JSON.stringify(detailImages || []), thumb || null, sideStone || '', style || '', setting || '', status || 'on'] [name, styleNo || '', totalStock || 0, loss || 0, laborCost || 0, categoryIdStr, JSON.stringify(bannerImages || []), JSON.stringify(bannerVideo || []), JSON.stringify(detailImages || []), thumb || null, sideStone || '', style || '', setting || '', status || 'on']
) )
const productId = result.insertId const productId = result.insertId
@ -165,9 +165,9 @@ export async function adminUpdateProduct(req: Request, res: Response): Promise<v
const categoryIdStr = Array.isArray(categoryId) ? JSON.stringify(categoryId) : (categoryId ? JSON.stringify([categoryId]) : null) const categoryIdStr = Array.isArray(categoryId) ? JSON.stringify(categoryId) : (categoryId ? JSON.stringify([categoryId]) : null)
await conn.execute( await conn.execute(
`UPDATE products SET name=?, base_price=?, style_no=?, stock=?, total_stock=?, loss=?, labor_cost=?, category_id=?, banner_images=?, banner_video=?, detail_images=?, thumb=?, side_stone=?, style=?, setting=?, status=? `UPDATE products SET name=?, style_no=?, total_stock=?, loss=?, labor_cost=?, category_id=?, banner_images=?, banner_video=?, detail_images=?, thumb=?, side_stone=?, style=?, setting=?, status=?
WHERE id=?`, WHERE id=?`,
[name, basePrice || 0, styleNo || '', stock || 0, totalStock || 0, loss || 0, laborCost || 0, categoryIdStr, JSON.stringify(bannerImages || []), JSON.stringify(bannerVideo || []), JSON.stringify(detailImages || []), thumb || null, sideStone || '', style || '', setting || '', status || 'on', id] [name, styleNo || '', totalStock || 0, loss || 0, laborCost || 0, categoryIdStr, JSON.stringify(bannerImages || []), JSON.stringify(bannerVideo || []), JSON.stringify(detailImages || []), thumb || null, sideStone || '', style || '', setting || '', status || 'on', id]
) )
// Update detail parameter config // Update detail parameter config