fix: 删除价格导致产品只剩一项

perf/export-docx
Jimmy Liow 11 months ago
parent 20bd547fd6
commit 910c6c02af

@ -3,7 +3,7 @@ import { devtools } from 'zustand/middleware';
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { fetchJSON, postForm, postJSON } from '@/utils/request'; import { fetchJSON, postForm, postJSON } from '@/utils/request';
import { HT_HOST } from '@/config'; import { HT_HOST } from '@/config';
import { groupBy, generateId, isEmpty } from '@/utils/commons'; import { groupBy, generateId, isNotEmpty } from '@/utils/commons';
export const searchAgencyAction = async (param) => { export const searchAgencyAction = async (param) => {
const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, 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 { editingProduct, quotationList, agencyProducts } = get()
const productTypeId = editingProduct.info.product_type_id; const productTypeId = editingProduct.info.product_type_id;
const quotationId = quotation.id const quotationId = quotation.id
const newList = quotationList.filter(q => { const newQuotationList = quotationList.filter(q => {
return q.key != quotation.key 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({ set({
agencyProducts: { agencyProducts: {
...agencyProducts, ...agencyProducts,
[productTypeId]: [{ [productTypeId]: newProductList
...editingProduct,
quotation: newList
}]
}, },
quotationList: newList quotationList: newQuotationList
}) })
if (isEmpty(quotationId)) { let promiseDelete = Promise.resolve(newQuotationList)
return Promise.resolve(newList)
} else { if (isNotEmpty(quotationId)) {
const { result, success } = await deleteQuotationAction(quotationId) const { result, success } = await deleteQuotationAction('quotationId')
if (success) { if (!success) {
return Promise.resolve(result) promiseDelete = Promise.reject(result)
} else {
return Promise.reject(result)
} }
} }
return promiseDelete
}, },
// side effects // side effects

Loading…
Cancel
Save