diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index 139d030..5e4ccbf 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -10,6 +10,16 @@ export const searchAgencyAction = async (param) => { return errcode !== 0 ? [] : result; }; +/** + * 搜索所有产品, 返回产品列表 + * ! 只有审核通过, 已发布的 + * @param {object} params { keyword, use_year, product_types, travel_agency_id, city } + */ +export const searchPublishedProductsAction = async (param) => { + const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/web_products_search`, param); + return errcode !== 0 ? [] : result; +}; + export const copyAgencyDataAction = async (postbody) => { const formData = new FormData(); Object.keys(postbody).forEach((key) => { diff --git a/src/views/products/Detail/Extras.jsx b/src/views/products/Detail/Extras.jsx index e3e16a3..6446db5 100644 --- a/src/views/products/Detail/Extras.jsx +++ b/src/views/products/Detail/Extras.jsx @@ -2,7 +2,7 @@ import { useEffect, useState, useSyncExternalStore } from 'react'; import { useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { App, Table, Button, Modal, Popconfirm } from 'antd'; -import { getAgencyProductExtrasAction, getAgencyProductsAction, addProductExtraAction, delProductExtrasAction } from '@/stores/Products/Index'; +import { getAgencyProductExtrasAction, searchPublishedProductsAction, addProductExtraAction, delProductExtrasAction } from '@/stores/Products/Index'; import { cloneDeep, pick } from '@/utils/commons'; import SearchForm from '@/components/SearchForm'; @@ -27,10 +27,9 @@ const NewAddonModal = ({ onPick, ...props }) => { const { starttime, endtime, year, ...param } = copyObject; setSearchLoading(true); setSearchResult([]); - // debug: audit_state: '1', const search_year = year || use_year; - const result = await getAgencyProductsAction({ ...param, travel_agency_id, use_year: search_year, audit_state: '0', }); - setSearchResult(result?.products || []); + const result = await searchPublishedProductsAction({ ...param, use_year: search_year, }); + setSearchResult(result); setSearchLoading(false); }; const handleAddExtras = async (item) => { @@ -39,10 +38,10 @@ const NewAddonModal = ({ onPick, ...props }) => { } }; - // todo: 如何显示价格表 const searchResultColumns = [ - { key: 'ptype', dataIndex: ['info', 'product_type_id'], width: '6rem', title: t('products:ProductType'), render: (text, r) => productsTypesMapVal[text].label }, - { key: 'title', dataIndex: ['info', 'title'], width: '16rem', title: t('products:Title') }, + { key: 'ptype', dataIndex: 'type', width: '6rem', title: t('products:ProductType'), render: (text, r) => productsTypesMapVal[text]?.label || text }, + { key: 'code', dataIndex: 'code', width: '6rem', title: t('products:Code') }, + { key: 'title', dataIndex: 'title', width: '16rem', title: t('products:Title') }, // { // title: t('products:price'), // dataIndex: ['quotation', '0', 'adult_cost'], @@ -72,7 +71,7 @@ const NewAddonModal = ({ onPick, ...props }) => { setOpen(false)} destroyOnClose> { const handleNewAddOn = async (item) => { setExtrasData(prev => [].concat(prev, [item])); // todo: 提交后端; 重复绑定同一个 - const _item = pick(item.info, ['id', 'title', 'code']); + const _item = pick(item, ['id', 'title', 'code']); const newSuccess = await addProductExtraAction({ travel_agency_id, id: productId, extras: [_item] }); newSuccess ? message.success(`${t('Success')}`) : message.error(`${t('Failed')}`); await handleGetAgencyProductExtras(); } const handleDelAddon = async (item) => { - const delSuccess = await delProductExtrasAction({ travel_agency_id, id: productId, extras: [item.info.id] }); + const delSuccess = await delProductExtrasAction({ travel_agency_id, id: productId, extras: [item.id] }); delSuccess ? message.success(`${t('Success')}`) : message.error(`${t('Failed')}`); await handleGetAgencyProductExtras(); };