diff --git a/src/views/products/Audit.jsx b/src/views/products/Audit.jsx index 43cadb0..873942c 100644 --- a/src/views/products/Audit.jsx +++ b/src/views/products/Audit.jsx @@ -17,47 +17,123 @@ import { ClockCircleFilled, ClockCircleOutlined, PlusCircleFilled, PlusCircleOut const parseJson = (str) => { let result; if (str === null || str === undefined || str === '') { - return []; + return {}; } try { result = JSON.parse(str); - return result; + return Array.isArray(result) ? result.reduce((acc, cur) => ({ ...acc, ...cur }), {}) : result; } catch (e) { - return []; + return {}; } }; - const columnsSets = t => [ - { key: 'adult', title: t('AgeType.Adult'), width: '12rem', render: (_, { adult_cost, currency, unit_id, unit_name, lastedit_changed }) => { - const _changed = parseJson(lastedit_changed)?.reduce((acc, cur) => ({...acc, ...cur}), {}); - const preValue = isNotEmpty(_changed.adult_cost) ?
{_changed.adult_cost}
: null; - return (
{preValue}{`${adult_cost} ${currency} / ${t(`PriceUnit.${unit_id}`)}`}
)} }, - { key: 'child', title: t('AgeType.Child'), width: '12rem', render: (_, { child_cost, currency, unit_id, unit_name, lastedit_changed }) => { - const _changed = parseJson(lastedit_changed)?.reduce((acc, cur) => ({...acc, ...cur}), {}); - const preValue = isNotEmpty(_changed.child_cost) ?
{_changed.child_cost}
: null; - return
{preValue}{`${child_cost} ${currency} / ${t(`PriceUnit.${unit_id}`)}`}
; - } }, + const columnsSets = (t, colorize = true) => [ + { + key: 'adult', + title: t('AgeType.Adult'), + width: '12rem', + render: (_, { adult_cost, currency, unit_id, unit_name, audit_state_id, lastedit_changed }) => { + const _changed = parseJson(lastedit_changed); + const ifCompare = colorize && ![-1, 1, 2].includes(audit_state_id); + const ifData = isNotEmpty(_changed.adult_cost) || isNotEmpty(_changed.unit_id) || isNotEmpty(_changed.currency); + const preValue = + ifCompare && ifData ? ( +
{`${_changed.adult_cost} ${_changed.currency || currency} / ${t(`PriceUnit.${_changed.unit_id || unit_id}`)}`}
+ ) : null; + const editCls = ifCompare && ifData ? 'text-danger' : ''; + return ( +
+ {preValue} + {`${adult_cost} ${currency} / ${t(`PriceUnit.${unit_id}`)}`} +
+ ); + }, + }, + { + key: 'child', + title: t('AgeType.Child'), + width: '12rem', + render: (_, { child_cost, currency, unit_id, unit_name, audit_state_id, lastedit_changed }) => { + const _changed = parseJson(lastedit_changed); + const ifCompare = colorize && ![-1, 1, 2].includes(audit_state_id); + const ifData = isNotEmpty(_changed.child_cost) || isNotEmpty(_changed.unit_id) || isNotEmpty(_changed.currency); + const preValue = + ifCompare && ifData ? ( +
{`${_changed.child_cost} ${_changed.currency || currency} / ${t(`PriceUnit.${_changed.unit_id || unit_id}`)}`}
+ ) : null; + const editCls = ifCompare && ifData ? 'text-danger' : ''; + return ( +
+ {preValue} + {`${child_cost} ${currency} / ${t(`PriceUnit.${unit_id}`)}`} +
+ ); + }, + }, // {key: 'unit', title: t('Unit'), }, { key: 'groupSize', dataIndex: ['group_size_min'], - title: t('group_size'), width: '6rem', + title: t('group_size'), + width: '6rem', render: (_, { audit_state_id, group_size_min, group_size_max, lastedit_changed }) => { - const _changed = parseJson(lastedit_changed)?.reduce((acc, cur) => ({...acc, ...cur}), {}); - const preValue = ![-1, 1, 2].includes(audit_state_id) && (isNotEmpty(_changed.group_size_min) || isNotEmpty(_changed.group_size_max)) ?
{`${_changed.group_size_min ?? group_size_min} - ${_changed.group_size_max ?? group_size_max}`}
: null; - return
{preValue}{formatGroupSize(group_size_min, group_size_max)}
; - } + const _changed = parseJson(lastedit_changed); + const preValue = + colorize && ![-1, 1, 2].includes(audit_state_id) && (isNotEmpty(_changed.group_size_min) || isNotEmpty(_changed.group_size_max)) ? ( +
{`${_changed.group_size_min ?? group_size_min} - ${_changed.group_size_max ?? group_size_max}`}
+ ) : null; + const editCls = colorize && ![-1, 1, 2].includes(audit_state_id) && (isNotEmpty(_changed.group_size_min) || isNotEmpty(_changed.group_size_max)) ? 'text-danger' : ''; + return ( +
+ {preValue} + {formatGroupSize(group_size_min, group_size_max)} +
+ ); + }, }, { key: 'useDates', dataIndex: ['use_dates_start'], - title: t('use_dates'), width: '12rem', - render: (_, { use_dates_start, use_dates_end, weekdays }) => `${use_dates_start} ~ ${use_dates_end}`, // + (weekdays ? `, ${t('OnWeekdays')}${weekdays}` : ''), + title: t('use_dates'), + width: '12rem', + render: (_, { use_dates_start, use_dates_end, weekdays, audit_state_id, lastedit_changed }) => { + const _changed = parseJson(lastedit_changed); + const preValue = + colorize && ![-1, 1, 2].includes(audit_state_id) && (isNotEmpty(_changed.use_dates_start) || isNotEmpty(_changed.use_dates_end)) ? ( +
+ {isNotEmpty(_changed.use_dates_start) ? {_changed.use_dates_start} : use_dates_start} ~{' '} + {isNotEmpty(_changed.use_dates_end) ? {_changed.use_dates_end} : use_dates_end} +
+ ) : null; + const editCls = colorize && ![-1, 1, 2].includes(audit_state_id) && (isNotEmpty(_changed.use_dates_start) || isNotEmpty(_changed.use_dates_end)) ? 'text-danger' : ''; + return ( +
+ {preValue} + {`${use_dates_start} ~ ${use_dates_end}`} +
+ ); + }, + }, + { + key: 'weekdays', + dataIndex: ['weekdays'], + title: t('Weekdays'), + width: '6rem', + render: (text, { weekdays, audit_state_id, lastedit_changed }) => { + const _changed = parseJson(lastedit_changed); + const ifCompare = colorize && ![-1, 1, 2].includes(audit_state_id); + const ifData = !isEmpty((_changed.weekdayList || []).filter(s => s)); + const preValue = + ifCompare && ifData ? ( +
{_changed.weekdayList}
+ ) : null; + const editCls = ifCompare && ifData ? 'text-danger' : ''; + return
{preValue}{text || t('Unlimited')}
; + }, }, - { key: 'weekdays', dataIndex: ['weekdays'], title: t('Weekdays'), width: '6rem', render: (text, r) => text || t('Unlimited') }, ]; -const PriceLogPopover = ({ title, fetchData, ...props}) => { +const PriceLogPopover = ({ title, fetchData, triggerProps={}, ...props}) => { const { t } = useTranslation('products'); const [open, setOpen] = useState(false); const [logData, setLogData] = useState([]); @@ -65,7 +141,7 @@ const PriceLogPopover = ({ title, fetchData, ...props}) => { const data = await fetchData(); setLogData(data); }; - const columns = [...columnsSets(t), { title: '时间', dataIndex: 'updatetime', key: 'updatetime'}]; + const columns = [...columnsSets(t, false), { title: '时间', dataIndex: 'updatetime', key: 'updatetime'}]; return ( { } content={ <> - +
} trigger={['click']} @@ -89,7 +165,7 @@ const PriceLogPopover = ({ title, fetchData, ...props}) => { onOpenChange={(v) => { setOpen(v); }}> - @@ -186,20 +262,21 @@ const PriceTable = ({ productType, dataSource, refresh }) => { }, { title: '', - key: 'action2', width: '6rem', + key: 'action2', width: '6rem', className: 'bg-white', onCell: (r, index) => ({ rowSpan: r.rowSpan, }), render: (_, r) => { const showPublicBtn = null; // r.pendingQuotation ? : null; - const btn2 = ( + const btn2 = r.pendingQuotation ? ( getRunning({ travel_agency_id, product_id: r.info.id, price_id: r.id })} {...{ travel_agency_id, product_id: r.info.id, price_id: r.id }} /> - ); - return
{btn2}
; + ) : null; + return
{btn2}
; }, } ];