解决新增价格后端删除错误

perf/export-docx
Jimmy Liow 11 months ago
parent b861cc66ae
commit 6ecdb54938

@ -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 } from '@/utils/commons'; import { groupBy, generateId, isEmpty } 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);
@ -287,29 +287,34 @@ export const useProductsStore = create(
return mergedList return mergedList
}, },
deleteQuotationById: async(quotaionId) => { deleteQuotation: async(quotation) => {
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 newList = quotationList.filter(q => { const newList = quotationList.filter(q => {
return q.id != quotaionId return q.key != quotation.key
}) })
const { result, success } = await deleteQuotationAction(quotaionId) set({
agencyProducts: {
if (success) { ...agencyProducts,
set({ [productTypeId]: [{
agencyProducts: { ...editingProduct,
...agencyProducts, quotation: newList
[productTypeId]: [{ }]
...editingProduct, },
quotation: newList quotationList: newList
}] })
},
quotationList: newList if (isEmpty(quotationId)) {
}) return Promise.resolve(newList)
return Promise.resolve(result)
} else { } else {
return Promise.reject(result) const { result, success } = await deleteQuotationAction(quotationId)
if (success) {
return Promise.resolve(result)
} else {
return Promise.reject(result)
}
} }
}, },

@ -144,8 +144,8 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
const datePresets = useDatePresets() const datePresets = useDatePresets()
const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotationById] = const [quotationList, newEmptyQuotation, appendQuotationList, saveOrUpdateQuotation, deleteQuotation] =
useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotationById]) useProductsStore((state) => [state.quotationList, state.newEmptyQuotation, state.appendQuotationList, state.saveOrUpdateQuotation, state.deleteQuotation])
const triggerChange = (changedValue) => { const triggerChange = (changedValue) => {
onChange?.( onChange?.(
@ -180,13 +180,13 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
setBatchSetupModalOpen(false) setBatchSetupModalOpen(false)
} }
const onDeleteQuotation = (quotationId) => { const onDeleteQuotation = (quotation) => {
modal.confirm({ modal.confirm({
title: '请确认', title: '请确认',
icon: <ExclamationCircleFilled />, icon: <ExclamationCircleFilled />,
content: '你要删除这条价格吗?', content: '你要删除这条价格吗?',
onOk() { onOk() {
deleteQuotationById(quotationId) deleteQuotation(quotation)
.catch(ex => { .catch(ex => {
notification.error({ notification.error({
message: 'Notification', message: 'Notification',
@ -236,7 +236,7 @@ const ProductInfoQuotation = ({ editable, ...props }) => {
return ( return (
<Space> <Space>
<Button type='link' disabled={!_rowEditable} onClick={() => onQuotationSeleted(quotation)}>{t('Edit')}</Button> <Button type='link' disabled={!_rowEditable} onClick={() => onQuotationSeleted(quotation)}>{t('Edit')}</Button>
<Button type='link' danger disabled={!_rowEditable} onClick={() => onDeleteQuotation(quotation.id)}>{t('Delete')}</Button> <Button type='link' danger disabled={!_rowEditable} onClick={() => onDeleteQuotation(quotation)}>{t('Delete')}</Button>
</Space> </Space>
) )
}, },

Loading…
Cancel
Save