From b68793c44e0f7ad2257f0f01576575883f2aca22 Mon Sep 17 00:00:00 2001 From: jameszow Date: Mon, 23 Oct 2023 16:53:30 +0800 Subject: [PATCH] Add deleteProduct and updateProductStatus api and index.vue use api --- src/api/product/product.ts | 26 +++++++++++++++++-- src/views/product/info/index.vue | 19 ++++++++++++-- src/views/product/info/info.data.ts | 39 +++++++++++++++++++++++------ 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/api/product/product.ts b/src/api/product/product.ts index 2b0ec11..f5b2c27 100644 --- a/src/api/product/product.ts +++ b/src/api/product/product.ts @@ -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() { @@ -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( { url: Api.addProduct, @@ -48,4 +50,24 @@ export function getProductInfoDetail(productId: number) { url: `${Api.getProductInfoDetail}/${productId}`, } ); +} + +export function deleteProduct(productIds: number[], mode: ErrorMessageMode = 'notice') { + return defHttp.delete( + { + url: `${Api.deleteProduct}/${productIds}`, + },{ + errorMessageMode: mode, + } + ); +} + +export function updateProductStatus(productIds: number[], status: number, mode: ErrorMessageMode = 'notice') { + return defHttp.put( + { + url: `${Api.updateProductStatus}/${productIds}/${status}`, + },{ + errorMessageMode: mode, + } + ); } \ No newline at end of file diff --git a/src/views/product/info/index.vue b/src/views/product/info/index.vue index 3794d75..0e6af90 100644 --- a/src/views/product/info/index.vue +++ b/src/views/product/info/index.vue @@ -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', @@ -82,12 +82,17 @@ 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) { @@ -95,6 +100,11 @@ export default defineComponent({ } async function handleDelete(record: Recordable) { + // 调用deleteProduct接口 注意是批量删除 这里传递的是数组 + const { code } = await deleteProduct([record.id]); + if (code === "P0012") { + await reload(); + } } async function handleSuccess() { @@ -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() { diff --git a/src/views/product/info/info.data.ts b/src/views/product/info/info.data.ts index 320583f..f756915 100644 --- a/src/views/product/info/info.data.ts +++ b/src/views/product/info/info.data.ts @@ -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(); @@ -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; }) @@ -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: '关键词', @@ -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: '仓位货架',