删除商品
This commit is contained in:
@@ -105,8 +105,28 @@
|
||||
<a-form-item label="标签ID" name="tags">
|
||||
<a-input v-model:value="formState.tags" placeholder="请输入标签ID,多个用分号分隔" />
|
||||
</a-form-item>
|
||||
<a-form-item label="店铺ID" name="shopId">
|
||||
<a-input-number v-model:value="formState.shopId" :min="1" style="width: 100%" placeholder="请输入店铺ID" />
|
||||
<a-form-item label="店铺" name="shopId">
|
||||
<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>
|
||||
</a-modal>
|
||||
@@ -119,7 +139,7 @@ import { message } from 'ant-design-vue'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
import { PlusOutlined } from '@ant-design/icons-vue'
|
||||
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 searchText = ref('')
|
||||
@@ -129,6 +149,8 @@ const modalLoading = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const formRef = ref<FormInstance>()
|
||||
const currentProduct = ref<Product | null>(null)
|
||||
const shops = ref<Shop[]>([])
|
||||
const loadingShops = ref(false)
|
||||
|
||||
const pagination = reactive({
|
||||
current: 1,
|
||||
@@ -140,7 +162,7 @@ const pagination = reactive({
|
||||
})
|
||||
|
||||
const formState = reactive({
|
||||
shopId: 1,
|
||||
shopId: undefined as number | undefined,
|
||||
title: '',
|
||||
description: '',
|
||||
imageFileIds: '',
|
||||
@@ -155,7 +177,7 @@ const formRules = {
|
||||
title: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
|
||||
description: [{ 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 = [
|
||||
@@ -182,6 +204,24 @@ const getCurrentUserInfo = () => {
|
||||
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 () => {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -219,8 +259,9 @@ const handleTableChange = (pag: any) => {
|
||||
|
||||
const showAddModal = () => {
|
||||
isEdit.value = false
|
||||
const currentUser = getCurrentUserInfo()
|
||||
Object.assign(formState, {
|
||||
shopId: 1,
|
||||
shopId: (currentUser && currentUser.type !== 4 && currentUser.shopId) ? currentUser.shopId : undefined,
|
||||
title: '',
|
||||
description: '',
|
||||
imageFileIds: '',
|
||||
@@ -265,8 +306,9 @@ const handleModalOk = async () => {
|
||||
|
||||
modalVisible.value = false
|
||||
fetchProductList()
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(error)
|
||||
message.error(error.message || (isEdit.value ? '更新失败' : '创建失败'))
|
||||
} finally {
|
||||
modalLoading.value = false
|
||||
}
|
||||
@@ -282,12 +324,14 @@ const handleDelete = async (record: Product) => {
|
||||
await adminProductApi.deleteProduct(record.id)
|
||||
message.success('删除成功')
|
||||
fetchProductList()
|
||||
} catch (error) {
|
||||
message.error('删除失败')
|
||||
} catch (error: any) {
|
||||
console.error('删除失败:', error)
|
||||
message.error(error.message || '删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchShops()
|
||||
fetchProductList()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -89,5 +90,6 @@ public class ProductDO extends BaseEntity {
|
||||
* 逻辑删除标识:0-未删除,1-已删除
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.xiaowang.yuminailcore.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -51,5 +52,6 @@ public class ShopDO extends BaseEntity {
|
||||
* 逻辑删除:0-未删,1-已删
|
||||
*/
|
||||
@TableField("is_delete")
|
||||
@TableLogic
|
||||
private Integer isDelete;
|
||||
}
|
||||
|
||||
+1
-6
@@ -71,12 +71,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
|
||||
@Override
|
||||
public boolean deleteProduct(Long id) {
|
||||
ProductDO productDO = productMapper.selectById(id);
|
||||
if (productDO == null) {
|
||||
return false;
|
||||
}
|
||||
productDO.setIsDelete(1);
|
||||
return productMapper.updateById(productDO) > 0;
|
||||
return removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user