接入商品评论数据

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

@@ -1,8 +1,4 @@
<<<<<<< HEAD
<!-- 商家端 - 商品编辑页面 -->
=======
 <!-- 商家端 - 商品编辑页面 (已修复缓存) -->
>>>>>>> local-backup-root-cyj
<template>
<view class="product-edit-page">
<!-- 商品基本信息 -->
@@ -135,10 +131,6 @@
</view>
</view>
<<<<<<< HEAD
<view class="form-item">
<text class="label">总库存 *</text>
=======
<view class="form-item">
<text class="label">VIP独立折扣</text>
<switch :checked="product.is_vip_discount" @change="e => { product.is_vip_discount = e.detail.value as boolean }" />
@@ -156,7 +148,6 @@
<view class="form-item">
<text class="label">总库存 *</text>
>>>>>>> local-backup-root-cyj
<input
class="input"
type="number"
@@ -176,8 +167,6 @@
</view>
</view>
<<<<<<< HEAD
=======
<!-- 会员阶梯价 -->
<view class="section">
<view class="section-title">会员等级价格 (选填)</view>
@@ -197,7 +186,6 @@
</view>
</view>
>>>>>>> local-backup-root-cyj
<!-- 商品属性 -->
<view class="section">
<view class="section-title">商品属性</view>
@@ -277,8 +265,6 @@
logo_url: string
}
<<<<<<< HEAD
=======
type MemberLevelType = {
id: string
name: string
@@ -287,7 +273,6 @@
price: string // 绑定输入框用
}
>>>>>>> local-backup-root-cyj
export default {
data() {
return {
@@ -299,10 +284,7 @@
brands: [] as BrandType[],
brandIndex: -1,
selectedBrand: null as BrandType | null,
<<<<<<< HEAD
=======
memberLevels: [] as MemberLevelType[],
>>>>>>> local-backup-root-cyj
product: {
name: '',
subtitle: '',
@@ -316,17 +298,11 @@
total_stock: '',
warning_stock: '10',
unit: '件',
<<<<<<< HEAD
is_hot: false,
is_new: false,
is_featured: false,
=======
is_hot: false,
is_new: false,
is_featured: false,
is_vip_discount: true,
vip_discount_rate: '',
>>>>>>> local-backup-root-cyj
description: ''
},
merchantId: ''
@@ -334,13 +310,6 @@
},
onLoad(options: any) {
<<<<<<< HEAD
const productId = options.productId as string
if (productId) {
this.productId = productId
this.isEdit = true
this.loadProductDetail(productId)
=======
let productId = ''
if (options) {
const keys = Object.keys(options as object)
@@ -371,15 +340,11 @@
this.loadProductDetail(productId)
} else {
uni.setNavigationBarTitle({ title: '添加商品' })
>>>>>>> local-backup-root-cyj
}
this.initMerchantId()
this.loadCategories()
this.loadBrands()
<<<<<<< HEAD
=======
this.loadMemberLevels()
>>>>>>> local-backup-root-cyj
},
methods: {
@@ -387,11 +352,7 @@
try {
const session = supa.getSession()
if (session != null && session.user != null) {
<<<<<<< HEAD
this.merchantId = session.user.getString('id') || ''
=======
this.merchantId = (session.user as any)['id'] != null ? String((session.user as any)['id']) : ''
>>>>>>> local-backup-root-cyj
}
if (!this.merchantId) {
this.merchantId = uni.getStorageSync('user_id') || ''
@@ -401,8 +362,6 @@
}
},
<<<<<<< HEAD
=======
async loadMemberLevels() {
try {
const response = await supa
@@ -472,7 +431,6 @@
}
},
>>>>>>> local-backup-root-cyj
async loadCategories() {
try {
const response = await supa
@@ -491,17 +449,10 @@
if (rawData == null) return
for (let i = 0; i < rawData.length; i++) {
<<<<<<< HEAD
const item = rawData[i] as UTSJSONObject
this.categories.push({
id: item.getString('id') || '',
name: item.getString('name') || ''
=======
const item = rawData[i] as any
this.categories.push({
id: item['id'] != null ? String(item['id']) : '',
name: item['name'] != null ? String(item['name']) : ''
>>>>>>> local-backup-root-cyj
} as CategoryType)
}
} catch (e) {
@@ -527,19 +478,11 @@
if (rawData == null) return
for (let i = 0; i < rawData.length; i++) {
<<<<<<< HEAD
const item = rawData[i] as UTSJSONObject
this.brands.push({
id: item.getString('id') || '',
name: item.getString('name') || '',
logo_url: item.getString('logo_url') || ''
=======
const item = rawData[i] as any
this.brands.push({
id: item['id'] != null ? String(item['id']) : '',
name: item['name'] != null ? String(item['name']) : '',
logo_url: item['logo_url'] != null ? String(item['logo_url']) : ''
>>>>>>> local-backup-root-cyj
} as BrandType)
}
} catch (e) {
@@ -549,10 +492,7 @@
async loadProductDetail(productId: string) {
try {
<<<<<<< HEAD
=======
uni.showLoading({ title: '加载商品中...' })
>>>>>>> local-backup-root-cyj
const response = await supa
.from('ml_products')
.select('*')
@@ -560,35 +500,6 @@
.single()
.execute()
<<<<<<< HEAD
if (response.error != null) {
console.error('获取商品详情失败:', response.error)
return
}
const rawData = response.data as UTSJSONObject
if (rawData == null) return
this.product = {
name: rawData.getString('name') || '',
subtitle: rawData.getString('subtitle') || '',
category_id: rawData.getString('category_id') || '',
brand_id: rawData.getString('brand_id') || '',
main_image_url: rawData.getString('main_image_url') || '',
imageList: this.parseImageUrls(rawData.getString('image_urls')),
base_price: rawData.getString('base_price') || '',
market_price: rawData.getString('market_price') || '',
cost_price: rawData.getString('cost_price') || '',
total_stock: rawData.getString('total_stock') || '',
warning_stock: rawData.getString('warning_stock') || '10',
unit: rawData.getString('unit') || '件',
is_hot: rawData.getBoolean('is_hot') || false,
is_new: rawData.getBoolean('is_new') || false,
is_featured: rawData.getBoolean('is_featured') || false,
description: rawData.getString('description') || ''
}
=======
uni.hideLoading()
if (response.error != null) {
console.error('获取详情失败:', response.error)
@@ -628,7 +539,6 @@
this.product.vip_discount_rate = getStr('vip_discount_rate')
this.product.description = getStr('description')
>>>>>>> local-backup-root-cyj
if (this.product.category_id) {
this.categoryIndex = this.categories.findIndex(c => c.id === this.product.category_id)
if (this.categoryIndex >= 0) {
@@ -643,13 +553,9 @@
}
}
} catch (e) {
<<<<<<< HEAD
console.error('获取商品详情异常:', e)
=======
uni.hideLoading()
console.error('获取商品详情异常:', e)
uni.showToast({ title: '加载异常: ' + String(e), icon: 'none', duration: 3000 })
>>>>>>> local-backup-root-cyj
}
},
@@ -702,88 +608,6 @@
this.product.imageList.splice(index, 1)
},
<<<<<<< HEAD
async saveProduct() {
if (!this.product.name) {
uni.showToast({ title: '请输入商品名称', icon: 'none' })
return
}
if (!this.product.category_id) {
uni.showToast({ title: '请选择商品分类', icon: 'none' })
return
}
if (!this.product.base_price) {
uni.showToast({ title: '请输入销售价', icon: 'none' })
return
}
if (!this.product.total_stock) {
uni.showToast({ title: '请输入总库存', icon: 'none' })
return
}
uni.showLoading({ title: '保存中...' })
try {
const imageUrlsStr = JSON.stringify(this.product.imageList)
const productData = {
merchant_id: this.merchantId,
name: this.product.name,
subtitle: this.product.subtitle,
category_id: this.product.category_id,
brand_id: this.product.brand_id || null,
main_image_url: this.product.main_image_url,
image_urls: imageUrlsStr,
base_price: parseFloat(this.product.base_price),
market_price: this.product.market_price ? parseFloat(this.product.market_price) : null,
cost_price: this.product.cost_price ? parseFloat(this.product.cost_price) : null,
total_stock: parseInt(this.product.total_stock),
warning_stock: parseInt(this.product.warning_stock) || 10,
unit: this.product.unit,
is_hot: this.product.is_hot,
is_new: this.product.is_new,
is_featured: this.product.is_featured,
description: this.product.description,
status: 1,
updated_at: new Date().toISOString()
}
let response
if (this.isEdit) {
response = await supa
.from('ml_products')
.update(productData)
.eq('id', this.productId)
.execute()
} else {
productData['created_at'] = new Date().toISOString()
response = await supa
.from('ml_products')
.insert(productData)
.execute()
}
uni.hideLoading()
if (response.error != null) {
console.error('保存商品失败:', response.error)
uni.showToast({ title: '保存失败', icon: 'none' })
return
}
uni.showToast({ title: '保存成功', icon: 'success' })
setTimeout(() => {
uni.navigateBack()
}, 1500)
} catch (e) {
uni.hideLoading()
console.error('保存商品异常:', e)
uni.showToast({ title: '保存失败', icon: 'none' })
}
}
}
}
=======
async uploadImageToSupa(localPath: string): Promise<string> {
if (localPath.startsWith('http://') || localPath.startsWith('https://')) {
return localPath
@@ -979,7 +803,6 @@
}
}
}
>>>>>>> local-backup-root-cyj
</script>
<style>
@@ -1004,8 +827,6 @@
border-bottom: 1rpx solid #f5f5f5;
}
<<<<<<< HEAD
=======
.section-desc {
font-size: 24rpx;
color: #999;
@@ -1013,7 +834,6 @@
margin-bottom: 30rpx;
}
>>>>>>> local-backup-root-cyj
.form-item {
margin-bottom: 30rpx;
}
@@ -1170,9 +990,3 @@
color: #fff;
}
</style>
<<<<<<< HEAD
=======
>>>>>>> local-backup-root-cyj