From 6ecdb549384a58cf4b04b0506295783db23875d3 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Wed, 14 Aug 2024 09:16:48 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=B0=E5=A2=9E=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E5=90=8E=E7=AB=AF=E5=88=A0=E9=99=A4=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Products/Index.js | 41 +++++++++++-------- .../products/Detail/ProductInfoQuotation.jsx | 10 ++--- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index 618fb05..94c3cc2 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -3,7 +3,7 @@ import { devtools } from 'zustand/middleware'; import dayjs from 'dayjs' import { fetchJSON, postForm, postJSON } from '@/utils/request'; import { HT_HOST } from '@/config'; -import { groupBy, generateId } from '@/utils/commons'; +import { groupBy, generateId, isEmpty } from '@/utils/commons'; export const searchAgencyAction = async (param) => { const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, param); @@ -287,29 +287,34 @@ export const useProductsStore = create( return mergedList }, - deleteQuotationById: async(quotaionId) => { + deleteQuotation: async(quotation) => { const { editingProduct, quotationList, agencyProducts } = get() const productTypeId = editingProduct.info.product_type_id; + const quotationId = quotation.id const newList = quotationList.filter(q => { - return q.id != quotaionId + return q.key != quotation.key }) - const { result, success } = await deleteQuotationAction(quotaionId) - - if (success) { - set({ - agencyProducts: { - ...agencyProducts, - [productTypeId]: [{ - ...editingProduct, - quotation: newList - }] - }, - quotationList: newList - }) - return Promise.resolve(result) + set({ + agencyProducts: { + ...agencyProducts, + [productTypeId]: [{ + ...editingProduct, + quotation: newList + }] + }, + quotationList: newList + }) + + if (isEmpty(quotationId)) { + return Promise.resolve(newList) } else { - return Promise.reject(result) + const { result, success } = await deleteQuotationAction(quotationId) + if (success) { + return Promise.resolve(result) + } else { + return Promise.reject(result) + } } }, diff --git a/src/views/products/Detail/ProductInfoQuotation.jsx b/src/views/products/Detail/ProductInfoQuotation.jsx index f4b45df..940bb6b 100644 --- a/src/views/products/Detail/ProductInfoQuotation.jsx +++ b/src/views/products/Detail/ProductInfoQuotation.jsx @@ -144,8 +144,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => { const datePresets = useDatePresets() - const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotationById] = - useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotationById]) + const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotation] = + useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotation]) const triggerChange = (changedValue) => { onChange?.( @@ -180,13 +180,13 @@ const ProductInfoQuotation = ({ editable, ...props }) => { setBatchSetupModalOpen(false) } - const onDeleteQuotation = (quotationId) => { + const onDeleteQuotation = (quotation) => { modal.confirm({ title: '请确认', icon: , content: '你要删除这条价格吗?', onOk() { - deleteQuotationById(quotationId) + deleteQuotation(quotation) .catch(ex => { notification.error({ message: 'Notification', @@ -236,7 +236,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => { return ( - + ) },