From 910c6c02af382fd173da53bc2cb27c1917a3c7c6 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Wed, 14 Aug 2024 13:42:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E4=BB=B7=E6=A0=BC?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E4=BA=A7=E5=93=81=E5=8F=AA=E5=89=A9=E4=B8=80?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Products/Index.js | 38 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index add4d20..6e489f5 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, isEmpty } from '@/utils/commons'; +import { groupBy, generateId, isNotEmpty } from '@/utils/commons'; export const searchAgencyAction = async (param) => { const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, param); @@ -291,31 +291,39 @@ export const useProductsStore = create( const { editingProduct, quotationList, agencyProducts } = get() const productTypeId = editingProduct.info.product_type_id; const quotationId = quotation.id - const newList = quotationList.filter(q => { + const newQuotationList = quotationList.filter(q => { return q.key != quotation.key }) + const newProductList = agencyProducts[productTypeId].map(p => { + if (p.info.id == editingProduct.info.id) { + return { + ...editingProduct, + quotation: newQuotationList + } + } else { + return p + } + }) + set({ agencyProducts: { ...agencyProducts, - [productTypeId]: [{ - ...editingProduct, - quotation: newList - }] + [productTypeId]: newProductList }, - quotationList: newList + quotationList: newQuotationList }) - if (isEmpty(quotationId)) { - return Promise.resolve(newList) - } else { - const { result, success } = await deleteQuotationAction(quotationId) - if (success) { - return Promise.resolve(result) - } else { - return Promise.reject(result) + let promiseDelete = Promise.resolve(newQuotationList) + + if (isNotEmpty(quotationId)) { + const { result, success } = await deleteQuotationAction('quotationId') + if (!success) { + promiseDelete = Promise.reject(result) } } + + return promiseDelete }, // side effects