From f8ffaf899d77dd7d106a31a8328da09e3dcf82e3 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Wed, 19 Jun 2024 15:55:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=A7=E5=93=81=E7=AE=A1=E7=90=86:?= =?UTF-8?q?=20=E5=AE=A2=E6=9C=8D=E5=AE=A1=E6=A0=B8=E4=BA=A7=E5=93=81,=20?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/locales/en/products.json | 7 +++ public/locales/zh/products.json | 7 +++ src/stores/Products/Index.js | 64 ++++++++++++++++++------ src/views/products/Audit.jsx | 87 +++++++++++++++++++++++++++------ 4 files changed, 134 insertions(+), 31 deletions(-) diff --git a/public/locales/en/products.json b/public/locales/en/products.json index 35c6d67..6033e89 100644 --- a/public/locales/en/products.json +++ b/public/locales/en/products.json @@ -16,6 +16,13 @@ "Rejected": "Rejected", "Published": "Published" }, + "auditStateAction": { + "New": "New", + "Pending": "Pending", + "Approved": "Approve", + "Rejected": "Rejecte", + "Published": "Publish" + }, "Status": "Status", "State": "State", diff --git a/public/locales/zh/products.json b/public/locales/zh/products.json index d4d640d..01f7836 100644 --- a/public/locales/zh/products.json +++ b/public/locales/zh/products.json @@ -16,6 +16,13 @@ "Rejected": "已拒绝", "Published": "已发布" }, + "auditStateAction": { + "New": "新增", + "Pending": "待审核", + "Approved": "审核通过", + "Rejected": "审核拒绝", + "Published": "发布上线" + }, "Status": "状态", "State": "状态", diff --git a/src/stores/Products/Index.js b/src/stores/Products/Index.js index ecd1fe1..544c478 100644 --- a/src/stores/Products/Index.js +++ b/src/stores/Products/Index.js @@ -1,32 +1,53 @@ import { create } from 'zustand'; import { devtools } from 'zustand/middleware'; -import { fetchJSON } from '@/utils/request'; +import { fetchJSON, postForm } from '@/utils/request'; import { HT_HOST } from '@/config'; import { groupBy } from '@/utils/commons'; -const searchAgencyAction = async (param) => { +export const searchAgencyAction = async (param) => { const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, param); return errcode !== 0 ? [] : result; }; -const getAgencyProducts = async (param) => { - const { errcode, Result, Result1 } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/products_search`, param); +export const getAgencyProductsAction = async (param) => { + const { errcode, result } = await fetchJSON(`${HT_HOST}/Service_BaseInfoWeb/travel-agency-products`, param); + return errcode !== 0 ? [] : result; +}; + +export const postProductsQuoteAudit = async (auditState, quoteRow) => { + const postbody = { + audit_state: auditState, + id: quoteRow.id, + travel_agency_id: quoteRow.info.travel_agency_id, + }; + const formData = new FormData(); + Object.keys(postbody).forEach((key) => { + formData.append(key, postbody[key]); + }); + const json = await postForm(`${HT_HOST}/Service_BaseInfoWeb/travel-agency-products-quote-audit`, formData); + return json; + // return errcode !== 0 ? {} : result; +}; + +export const postProductsAudit = async (auditState, infoRow) => { + const postbody = { + audit_state: auditState, + id: infoRow.id, + travel_agency_id: infoRow.travel_agency_id, + }; + const formData = new FormData(); + Object.keys(postbody).forEach((key) => { + formData.append(key, postbody[key]); + }); + const json = await postForm(`${HT_HOST}/Service_BaseInfoWeb/travel-agency-products-audit`, formData); + return json; + // const { errcode, result } = json; + // return errcode !== 0 ? {} : result; }; const initialState = { loading: false, - agencyList: [ - { - 'audit_date': '2001-03-03', - 'travel_agency_name': '新油低外', - 'travel_agency_id': '650000200301029585', - 'created_by': '冯丽', - 'create_date': '1989-06-20', - 'lastedit_memo': 'nostrud ad eu', - 'audited_by': '黎静', - 'audit_state': '1', - }, - ], + agencyList: [], activeAgency: {}, agencyProducts: groupBy([ { @@ -280,6 +301,17 @@ export const useProductsStore = create( setAgencyList(res); setLoading(false); }, + + getAgencyProducts: async (param) => { + const { setLoading, setActiveAgency, setAgencyProducts } = get(); + setLoading(true); + const res = await getAgencyProductsAction(param); + const productsData = groupBy(res, row => row.info.type); + setAgencyProducts(productsData); + setActiveAgency(res[0].info); + setLoading(false); + }, + })) ); export default useProductsStore; diff --git a/src/views/products/Audit.jsx b/src/views/products/Audit.jsx index cbc8fdb..3a4f3e6 100644 --- a/src/views/products/Audit.jsx +++ b/src/views/products/Audit.jsx @@ -1,14 +1,31 @@ -import { createContext, useContext, useEffect, useState } from 'react'; -import { Link, useLocation, } from 'react-router-dom'; -import { Button, Collapse, Table, Tabs, Typography, Space, } from 'antd'; -import { useProductsTypes, useProductsAuditStatesMapVal, useProductsAuditStates } from '@/hooks/useProductsSets'; +import { useEffect, useState } from 'react'; +import { useParams, } from 'react-router-dom'; +import { App, Button, Collapse, Table, Space, } from 'antd'; +import { useProductsTypes, useProductsAuditStatesMapVal } from '@/hooks/useProductsSets'; import SecondHeaderWrapper from '@/components/SecondHeaderWrapper'; import { useTranslation } from 'react-i18next'; -import useProductsStore from '@/stores/Products/Index'; +import useProductsStore, { postProductsQuoteAudit } from '@/stores/Products/Index'; import { isEmpty } from '@/utils/commons'; -const Header = ({title, ...props}) => { +const Header = ({ title, agency, ...props}) => { const { t } = useTranslation(); + const { message, notification } = App.useApp(); + const handleAuditItem = (state, row) => { + postProductsQuoteAudit(state, row) + .then((json) => { + if (json.errcode === 0) { + message.success('✔'); + } + }) + .catch((ex) => { + notification.error({ + message: 'Notification', + description: ex.message, + placement: 'top', + duration: 4, + }); + }); + }; return (
@@ -16,15 +33,37 @@ const Header = ({title, ...props}) => {
{/* */} {/* */} - + + {/* todo: export */} +
); }; const PriceTable = ({dataSource, loading}) => { const { t } = useTranslation('products'); + const { message, notification } = App.useApp(); const stateMapVal = useProductsAuditStatesMapVal(); + const handleAuditPriceItem = (state, row) => { + postProductsQuoteAudit(state, row) + .then((json) => { + if (json.errcode === 0) { + message.success('✔'); + } + }) + .catch((ex) => { + notification.error({ + message: 'Notification', + description: ex.message, + placement: 'top', + duration: 4, + }); + }); + }; + const columns = [ { key: 'title', dataIndex: ['info', 'title'], title: t('Title'), onCell: (r, index) => ({ rowSpan: r.rowSpan }) }, { key: 'value', title: t('Quotation'), render: (_, { value, currency, unit }) => `${value} ${currency} / ${unit}` }, @@ -55,10 +94,10 @@ const PriceTable = ({dataSource, loading}) => { { title: '', key: 'action', - render: () => ( + render: (_, r) => ( - - + + ), }, @@ -76,11 +115,19 @@ const TypesPanels = () => { const [activeKey, setActiveKey] = useState([]); const [showTypes, setShowTypes] = useState([]); useEffect(() => { - // 只显示有产品的类型 + // 只显示有产品的类型; 展开产品的价格表, 合并名称列 const hasDataTypes = Object.keys(agencyProducts); const _show = productsTypes .filter((kk) => hasDataTypes.includes(kk.value)) - .map((ele) => ({ ...ele, children: r.concat(c.quotation.map((q, i) => ({ ...q, info: c.info, rowSpan: i=== 0 ? c.quotation.length : 0 }))), [])} /> })); + .map((ele) => ({ + ...ele, + children: ( + r.concat(c.quotation.map((q, i) => ({ ...q, info: c.info, rowSpan: i === 0 ? c.quotation.length : 0 }))), [])} + /> + ), + })); setShowTypes(_show); setActiveKey(isEmpty(_show) ? [] : [_show[0].key]); @@ -97,14 +144,24 @@ const TypesPanels = () => { } const Audit = ({ ...props }) => { - // const [loading, agencyProducts] = useProductsStore((state) => [state.loading, state.agencyProducts]); + const { agencyId: travel_agency_id } = useParams(); + const [activeAgency, getAgencyProducts] = useProductsStore((state) => [state.activeAgency, state.getAgencyProducts]); + + const handleGetAgencyProducts = () => { + getAgencyProducts({ travel_agency_id }); + } + + useEffect(() => { + handleGetAgencyProducts(); + + return () => {}; + }, [travel_agency_id]) return ( <> - }> + }>
- {/* */}
);