接入商品评论数据

This commit is contained in:
2026-03-20 17:30:30 +08:00
parent 620ae742df
commit 13811ae87d
14 changed files with 535 additions and 1753 deletions

View File

@@ -57,11 +57,6 @@
<text class="label">当前库存</text>
<text class="value">{{ currentProduct?.total_stock }}</text>
</view>
<<<<<<< HEAD
<view class="form-item">
<text class="label">新库存</text>
<input class="input" type="number" v-model="newStock" placeholder="请输入新库存"/>
=======
<view class="adjust-type">
<view class="type-btn" :class="{ active: adjustType === 'set' }" @click="adjustType = 'set'">直接设为</view>
@@ -77,16 +72,11 @@
<view class="form-item">
<text class="label">备注 (可选)</text>
<input class="input" v-model="stockRemark" placeholder="如:入库、损耗等"/>
>>>>>>> local-backup-root-cyj
</view>
</view>
<view class="modal-footer">
<view class="modal-btn cancel" @click="closeStockModal">取消</view>
<<<<<<< HEAD
<view class="modal-btn confirm" @click="saveStock">保存</view>
=======
<view class="modal-btn confirm" @click="saveStock">确认提交</view>
>>>>>>> local-backup-root-cyj
</view>
</view>
</view>
@@ -118,13 +108,9 @@
stats: { totalProducts: 0, lowStock: 0, outOfStock: 0 },
showStockModal: false,
currentProduct: null as ProductType | null,
<<<<<<< HEAD
newStock: ''
=======
newStock: '',
adjustType: 'set', // 'set', 'add', 'sub'
stockRemark: ''
>>>>>>> local-backup-root-cyj
}
},
@@ -133,10 +119,7 @@
},
onShow() {
<<<<<<< HEAD
=======
this.page = 1
>>>>>>> local-backup-root-cyj
this.loadProducts()
this.loadStats()
},
@@ -145,31 +128,16 @@
async initMerchantId() {
try {
const session = supa.getSession()
<<<<<<< HEAD
this.merchantId = session?.user?.getString('id') || uni.getStorageSync('user_id') || ''
=======
if (session != null && session.user != null) {
this.merchantId = session.user.getString('id') || ''
}
if (!this.merchantId) {
this.merchantId = uni.getStorageSync('user_id') || ''
}
>>>>>>> local-backup-root-cyj
} catch (e) {}
},
async loadProducts() {
<<<<<<< HEAD
this.loading = true
try {
let query = supa.from('ml_products').select('id, name, main_image_url, total_stock, warning_stock').eq('merchant_id', this.merchantId).order('total_stock', { ascending: true }).page(this.page).limit(this.limit)
const response = await query.execute()
if (response.error != null || !response.data) {
this.products = []
=======
if (this.loading && this.page === 1) return
this.loading = true
@@ -191,41 +159,19 @@
if (response.error != null) {
console.error('加载商品失败:', response.error)
>>>>>>> local-backup-root-cyj
return
}
const rawData = response.data as any[]
<<<<<<< HEAD
let productsData: ProductType[] = []
for (let i = 0; i < rawData.length; i++) {
const item = rawData[i] as UTSJSONObject
const stock = item.getNumber('total_stock') || 0
const warning = item.getNumber('warning_stock') || 10
if (this.currentFilter === 'low' && stock > warning) continue
if (this.currentFilter === 'out' && stock > 0) continue
=======
if (!rawData) return
const productsData: ProductType[] = []
for (let i = 0; i < rawData.length; i++) {
const item = rawData[i] as UTSJSONObject
>>>>>>> local-backup-root-cyj
productsData.push({
id: item.getString('id') || '',
name: item.getString('name') || '',
main_image_url: item.getString('main_image_url') || '',
<<<<<<< HEAD
total_stock: stock,
warning_stock: warning
})
}
this.products = productsData
=======
total_stock: item.getNumber('total_stock') || 0,
warning_stock: item.getNumber('warning_stock') || 10
} as ProductType)
@@ -238,7 +184,6 @@
}
this.hasMore = rawData.length === this.limit
>>>>>>> local-backup-root-cyj
} catch (e) {
console.error('加载失败:', e)
} finally {
@@ -288,13 +233,9 @@
editStock(product: ProductType) {
this.currentProduct = product
<<<<<<< HEAD
this.newStock = String(product.total_stock)
=======
this.newStock = ''
this.adjustType = 'set'
this.stockRemark = ''
>>>>>>> local-backup-root-cyj
this.showStockModal = true
},
@@ -305,15 +246,6 @@
},
async saveStock() {
<<<<<<< HEAD
if (!this.newStock || isNaN(parseInt(this.newStock))) {
uni.showToast({ title: '请输入有效库存', icon: 'none' })
return
}
try {
const response = await supa.from('ml_products').update({ total_stock: parseInt(this.newStock), updated_at: new Date().toISOString() }).eq('id', this.currentProduct!.id).execute()
=======
const val = parseInt(this.newStock)
if (isNaN(val)) {
uni.showToast({ title: '请输入有效数值', icon: 'none' })
@@ -345,21 +277,12 @@
})
.eq('id', this.currentProduct!.id)
.execute()
>>>>>>> local-backup-root-cyj
if (response.error != null) {
uni.showToast({ title: '保存失败', icon: 'none' })
return
}
<<<<<<< HEAD
uni.showToast({ title: '保存成功', icon: 'success' })
this.closeStockModal()
this.loadProducts()
this.loadStats()
} catch (e) {
uni.showToast({ title: '保存失败', icon: 'none' })
=======
uni.showToast({ title: '更新成功', icon: 'success' })
this.closeStockModal()
this.page = 1
@@ -369,7 +292,6 @@
uni.showToast({ title: '操作异常', icon: 'none' })
} finally {
uni.hideLoading()
>>>>>>> local-backup-root-cyj
}
},
@@ -413,17 +335,10 @@
.action-btn { padding: 12rpx 24rpx; font-size: 24rpx; background-color: #E3F2FD; color: #1976D2; border-radius: 24rpx; }
.modal-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { width: 80%; background-color: #fff; border-radius: 16rpx; }
<<<<<<< HEAD
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 30rpx; border-bottom: 1rpx solid #f5f5f5; }
.modal-title { font-size: 32rpx; font-weight: bold; color: #333; }
.modal-close { font-size: 44rpx; color: #999; }
.modal-body { padding: 30rpx; }
=======
.modal-body { padding: 30rpx; }
.adjust-type { display: flex; justify-content: space-between; margin-bottom: 30rpx; }
.type-btn { flex: 1; height: 64rpx; line-height: 64rpx; text-align: center; font-size: 24rpx; background-color: #f5f5f5; color: #666; margin: 0 10rpx; border-radius: 32rpx; border: 1rpx solid #eee; }
.type-btn.active { background-color: #E3F2FD; color: #007AFF; border-color: #007AFF; }
>>>>>>> local-backup-root-cyj
.form-item { margin-bottom: 20rpx; }
.form-item .label { font-size: 26rpx; color: #999; display: block; margin-bottom: 10rpx; }
.form-item .value { font-size: 28rpx; color: #333; }