Skip to content

Commit

Permalink
Add deleteProduct and updateProductStatus api and index.vue use api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jzow committed Oct 23, 2023
1 parent f49f8f0 commit b68793c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
26 changes: 24 additions & 2 deletions src/api/product/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {ErrorMessageMode} from "#/axios";

enum Api {
getBarCode = '/product/getBarCode',
addProduct = '/product/addProduct',
addProduct = '/product/addOrUpdateProduct',
getProductInfo = '/product/getProductInfo',
getProductInfoDetail = '/product/getProductInfoDetail',
deleteProduct = '/product/deleteProduct',
updateProductStatus = '/product/updateProductStatus',
}

export function getBarCode() {
Expand All @@ -18,7 +20,7 @@ export function getBarCode() {
);
}

export function addProduct(params: AddProductReq, mode: ErrorMessageMode = 'notice') {
export function addOrUpdateProduct(params: AddProductReq, mode: ErrorMessageMode = 'notice') {
return defHttp.post<BaseResp>(
{
url: Api.addProduct,
Expand Down Expand Up @@ -48,4 +50,24 @@ export function getProductInfoDetail(productId: number) {
url: `${Api.getProductInfoDetail}/${productId}`,
}
);
}

export function deleteProduct(productIds: number[], mode: ErrorMessageMode = 'notice') {
return defHttp.delete<BaseResp>(
{
url: `${Api.deleteProduct}/${productIds}`,
},{
errorMessageMode: mode,
}
);
}

export function updateProductStatus(productIds: number[], status: number, mode: ErrorMessageMode = 'notice') {
return defHttp.put<BaseResp>(
{
url: `${Api.updateProductStatus}/${productIds}/${status}`,
},{
errorMessageMode: mode,
}
);
}
19 changes: 17 additions & 2 deletions src/views/product/info/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {BasicTable, TableAction, useTable} from "@/components/Table";
import {useMessage} from "@/hooks/web/useMessage";
import {columns, searchFormSchema} from "@/views/product/info/info.data";
import ProductInfoModal from "@/views/product/info/components/ProductInfoModal.vue";
import {getProductInfo} from "@/api/product/product";
import {getProductInfo, deleteProduct, updateProductStatus} from "@/api/product/product";
export default defineComponent({
name: 'ProductInfo',
Expand Down Expand Up @@ -82,19 +82,29 @@ export default defineComponent({
productModalRef.value.openModal()
}
async function handleBatchDelete(record: Recordable) {
async function handleBatchDelete() {
const data = getSelectRows();
if (data.length === 0) {
createMessage.warn('请选择一条数据');
return;
}
const ids = data.map((item) => item.id);
const { code } = await deleteProduct(ids);
if (code === "P0012") {
await reload();
}
}
function handleEdit(record: Recordable) {
productModalRef.value.openModal(record.id)
}
async function handleDelete(record: Recordable) {
// 调用deleteProduct接口 注意是批量删除 这里传递的是数组
const { code } = await deleteProduct([record.id]);
if (code === "P0012") {
await reload();
}
}
async function handleSuccess() {
Expand All @@ -107,6 +117,11 @@ export default defineComponent({
createMessage.warn('请选择一条数据');
return;
}
const ids = data.map((item) => item.id);
const result = await updateProductStatus(ids, newStatus);
if (result.code === "P0013") {
await reload();
}
}
async function handleCancel() {
Expand Down
39 changes: 32 additions & 7 deletions src/views/product/info/info.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { h } from 'vue';
import {Switch} from "ant-design-vue";
import {useMessage} from "@/hooks/web/useMessage";
import {useI18n} from "@/hooks/web/useI18n";
import {updateOperatorStatus} from "@/api/basic/operator";
import {updateProductStatus} from "@/api/product/product";
import {getCategoryList} from "@/api/product/productCategory";

const { t } = useI18n();

Expand Down Expand Up @@ -90,7 +91,7 @@ export const columns: BasicColumn[] = [
}
record.pendingStatus = true;
const newStatus = checked ? 0 : 1;
updateOperatorStatus([record.id], newStatus )
updateProductStatus([record.id], newStatus )
.then(() => {
record.status = newStatus;
})
Expand All @@ -110,13 +111,19 @@ export const columns: BasicColumn[] = [

export const searchFormSchema: FormSchema[] = [
{
label: '类别',
label: '商品类别',
field: 'productCategoryId',
component: 'Select',
component: 'ApiTreeSelect',
colProps: {
xl: 8,
xxl: 8,
},
componentProps: {
api: getCategoryList,
resultField: 'data',
labelField: 'categoryName',
valueField: 'id',
},
},
{
label: '关键词',
Expand All @@ -139,29 +146,47 @@ export const searchFormSchema: FormSchema[] = [
{
label: '状态',
field: 'status',
component: 'Input',
component: 'Select',
colProps: {
xl: 12,
xxl: 8,
},
componentProps: {
options: [
{ label: '启用', value: 0, key: 0 },
{ label: '停用', value: 1, key: 1 },
],
},
},
{
label: '序列号',
field: 'enableSerialNumber',
component: 'Input',
component: 'Select',
colProps: {
xl: 12,
xxl: 8,
},
componentProps: {
options: [
{ label: '无', value: 0, key: 0 },
{ label: '有', value: 1, key: 1 },
],
},
},
{
label: '批次号',
field: 'enableBatchNumber',
component: 'Input',
component: 'Select',
colProps: {
xl: 12,
xxl: 8,
},
componentProps: {
options: [
{ label: '无', value: 0, key: 0 },
{ label: '有', value: 1, key: 1 },
],
},
},
{
label: '仓位货架',
Expand Down

0 comments on commit b68793c

Please sign in to comment.