删除商品

This commit is contained in:
xiaowang
2026-02-25 20:31:00 +08:00
parent 06bb2bcea2
commit 0d5619441c
4 changed files with 58 additions and 15 deletions
+53 -9
View File
@@ -105,8 +105,28 @@
<a-form-item label="标签ID" name="tags"> <a-form-item label="标签ID" name="tags">
<a-input v-model:value="formState.tags" placeholder="请输入标签ID,多个用分号分隔" /> <a-input v-model:value="formState.tags" placeholder="请输入标签ID,多个用分号分隔" />
</a-form-item> </a-form-item>
<a-form-item label="店铺ID" name="shopId"> <a-form-item label="店铺" name="shopId">
<a-input-number v-model:value="formState.shopId" :min="1" style="width: 100%" placeholder="请输入店铺ID" /> <a-select
v-model:value="formState.shopId"
placeholder="请选择店铺"
style="width: 100%"
:loading="loadingShops"
>
<a-select-option
v-if="shops.length === 0"
disabled
value=""
>
暂无店铺数据
</a-select-option>
<a-select-option
v-for="shop in shops"
:key="shop.id"
:value="shop.id"
>
{{ shop.shopName }}
</a-select-option>
</a-select>
</a-form-item> </a-form-item>
</a-form> </a-form>
</a-modal> </a-modal>
@@ -119,7 +139,7 @@ import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue' import type { FormInstance } from 'ant-design-vue'
import { PlusOutlined } from '@ant-design/icons-vue' import { PlusOutlined } from '@ant-design/icons-vue'
import { DEFAULT_PRODUCT_IMAGE } from '@/constants' import { DEFAULT_PRODUCT_IMAGE } from '@/constants'
import { adminProductApi, type Product } from '@/api/admin' import { adminProductApi, type Product, adminShopApi, type Shop } from '@/api/admin'
const loading = ref(false) const loading = ref(false)
const searchText = ref('') const searchText = ref('')
@@ -129,6 +149,8 @@ const modalLoading = ref(false)
const isEdit = ref(false) const isEdit = ref(false)
const formRef = ref<FormInstance>() const formRef = ref<FormInstance>()
const currentProduct = ref<Product | null>(null) const currentProduct = ref<Product | null>(null)
const shops = ref<Shop[]>([])
const loadingShops = ref(false)
const pagination = reactive({ const pagination = reactive({
current: 1, current: 1,
@@ -140,7 +162,7 @@ const pagination = reactive({
}) })
const formState = reactive({ const formState = reactive({
shopId: 1, shopId: undefined as number | undefined,
title: '', title: '',
description: '', description: '',
imageFileIds: '', imageFileIds: '',
@@ -155,7 +177,7 @@ const formRules = {
title: [{ required: true, message: '请输入商品名称', trigger: 'blur' }], title: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
description: [{ required: true, message: '请输入商品描述', trigger: 'blur' }], description: [{ required: true, message: '请输入商品描述', trigger: 'blur' }],
price: [{ required: true, message: '请输入价格', trigger: 'blur' }], price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
shopId: [{ required: true, message: '请输入店铺ID', trigger: 'blur' }] shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }]
} }
const columns = [ const columns = [
@@ -182,6 +204,24 @@ const getCurrentUserInfo = () => {
return null return null
} }
const fetchShops = async () => {
loadingShops.value = true
try {
const res = await adminShopApi.listAllShops()
shops.value = res || []
const currentUser = getCurrentUserInfo()
if (currentUser && currentUser.type !== 4 && currentUser.shopId) {
formState.shopId = currentUser.shopId
}
} catch (error) {
console.error('获取店铺列表失败', error)
message.error('获取店铺列表失败')
} finally {
loadingShops.value = false
}
}
const fetchProductList = async () => { const fetchProductList = async () => {
loading.value = true loading.value = true
try { try {
@@ -219,8 +259,9 @@ const handleTableChange = (pag: any) => {
const showAddModal = () => { const showAddModal = () => {
isEdit.value = false isEdit.value = false
const currentUser = getCurrentUserInfo()
Object.assign(formState, { Object.assign(formState, {
shopId: 1, shopId: (currentUser && currentUser.type !== 4 && currentUser.shopId) ? currentUser.shopId : undefined,
title: '', title: '',
description: '', description: '',
imageFileIds: '', imageFileIds: '',
@@ -265,8 +306,9 @@ const handleModalOk = async () => {
modalVisible.value = false modalVisible.value = false
fetchProductList() fetchProductList()
} catch (error) { } catch (error: any) {
console.error(error) console.error(error)
message.error(error.message || (isEdit.value ? '更新失败' : '创建失败'))
} finally { } finally {
modalLoading.value = false modalLoading.value = false
} }
@@ -282,12 +324,14 @@ const handleDelete = async (record: Product) => {
await adminProductApi.deleteProduct(record.id) await adminProductApi.deleteProduct(record.id)
message.success('删除成功') message.success('删除成功')
fetchProductList() fetchProductList()
} catch (error) { } catch (error: any) {
message.error('删除失败') console.error('删除失败:', error)
message.error(error.message || '删除失败')
} }
} }
onMounted(() => { onMounted(() => {
fetchShops()
fetchProductList() fetchProductList()
}) })
</script> </script>
@@ -1,6 +1,7 @@
package com.xiaowang.yuminailcore.entity; package com.xiaowang.yuminailcore.entity;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@@ -89,5 +90,6 @@ public class ProductDO extends BaseEntity {
* 逻辑删除标识:0-未删除,1-已删除 * 逻辑删除标识:0-未删除,1-已删除
*/ */
@TableField("is_delete") @TableField("is_delete")
@TableLogic
private Integer isDelete; private Integer isDelete;
} }
@@ -1,6 +1,7 @@
package com.xiaowang.yuminailcore.entity; package com.xiaowang.yuminailcore.entity;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@@ -51,5 +52,6 @@ public class ShopDO extends BaseEntity {
* 逻辑删除:0-未删,1-已删 * 逻辑删除:0-未删,1-已删
*/ */
@TableField("is_delete") @TableField("is_delete")
@TableLogic
private Integer isDelete; private Integer isDelete;
} }
@@ -71,12 +71,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
@Override @Override
public boolean deleteProduct(Long id) { public boolean deleteProduct(Long id) {
ProductDO productDO = productMapper.selectById(id); return removeById(id);
if (productDO == null) {
return false;
}
productDO.setIsDelete(1);
return productMapper.updateById(productDO) > 0;
} }
@Override @Override