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