refactor ticket detail
parent
e1c3b464a6
commit
0dac2ad185
|
|
@ -0,0 +1,3 @@
|
||||||
|
export default {
|
||||||
|
component: true,
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
import { View } from '@tarojs/components';
|
||||||
|
import { AtCard, AtSteps } from 'taro-ui';
|
||||||
|
import { Component, ReactNode } from 'react';
|
||||||
|
import Taro from '@tarojs/taro';
|
||||||
|
import { TicketInfo, TicketNote } from '@/pages/TicketDetail/TicketNote';
|
||||||
|
import NoteList from '@/components/NoteList/NoteList';
|
||||||
|
import PageFooter from '@/components/PageFooter/PageFooter';
|
||||||
|
import pt from '@/plain-text';
|
||||||
|
import { RequestState } from '@/service';
|
||||||
|
import { getTicketInfo } from '@/service/ticketsInfo';
|
||||||
|
import { FixStatus } from '@/common';
|
||||||
|
|
||||||
|
const mapStatusStep: Map<FixStatus, 0 | 1 | 2 | 3> = new Map([
|
||||||
|
[1, 0],
|
||||||
|
[2, 1],
|
||||||
|
[3, 2],
|
||||||
|
[4, 2],
|
||||||
|
[5, 3],
|
||||||
|
]);
|
||||||
|
|
||||||
|
interface StepItemData {
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DetailFrameworkState {
|
||||||
|
current: number;
|
||||||
|
items: Array<StepItemData>;
|
||||||
|
ticketInfo: TicketInfo;
|
||||||
|
notes: Array<TicketNote>;
|
||||||
|
rs: RequestState;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DetailFrameworkProps {
|
||||||
|
middleButton: JSX.Element;
|
||||||
|
id: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class DetailFramework extends Component<
|
||||||
|
DetailFrameworkProps,
|
||||||
|
DetailFrameworkState
|
||||||
|
> {
|
||||||
|
state = {
|
||||||
|
current: 0,
|
||||||
|
items: [],
|
||||||
|
ticketInfo: new TicketInfo(),
|
||||||
|
notes: [new TicketNote()],
|
||||||
|
rs: new RequestState(),
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount(): void {
|
||||||
|
const navBar = pt.get().navBar;
|
||||||
|
Taro.setNavigationBarTitle({
|
||||||
|
title: navBar.ticketDetail,
|
||||||
|
});
|
||||||
|
const items = pt.get().ticketDetail.stepItems;
|
||||||
|
this.setState({
|
||||||
|
items: items,
|
||||||
|
});
|
||||||
|
getTicketInfo(this, this.props.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
props: Readonly<DetailFrameworkProps> = {
|
||||||
|
middleButton: <View></View>,
|
||||||
|
id: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
render(): ReactNode {
|
||||||
|
if (this.state.rs.loading) {
|
||||||
|
return <View>Loading</View>;
|
||||||
|
} else if (!this.state.rs.success) {
|
||||||
|
return <View>Request failed</View>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = this.state.ticketInfo.status;
|
||||||
|
this.setState({
|
||||||
|
current: mapStatusStep.get(status) || 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View>
|
||||||
|
<View className='at-article__h1'>
|
||||||
|
{this.state.ticketInfo.device +
|
||||||
|
' ' +
|
||||||
|
this.state.ticketInfo.deviceModel}
|
||||||
|
</View>
|
||||||
|
<View className='at-article__info'>
|
||||||
|
{pt.get().common.createdAtText(this.state.ticketInfo.createdTime)}
|
||||||
|
</View>
|
||||||
|
<View style={{ marginTop: 10, marginBottom: 10 }}>
|
||||||
|
<AtCard title={pt.get().ticketDetail.descTitle}>
|
||||||
|
<View className='at-article__h3'>
|
||||||
|
{this.state.ticketInfo.description}
|
||||||
|
</View>
|
||||||
|
</AtCard>
|
||||||
|
</View>
|
||||||
|
<View style={{ padding: 10 }}>
|
||||||
|
<AtSteps
|
||||||
|
items={this.state.items}
|
||||||
|
current={this.state.current}
|
||||||
|
onChange={() => {}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{this.props.middleButton}
|
||||||
|
|
||||||
|
<View style={{ padding: 10 }}>
|
||||||
|
<NoteList noteList={this.state.notes} />
|
||||||
|
</View>
|
||||||
|
<PageFooter />
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,119 +1,51 @@
|
||||||
import { Component, ReactNode } from 'react';
|
import { Component, ReactNode } from 'react';
|
||||||
import { View } from '@tarojs/components';
|
import { View } from '@tarojs/components';
|
||||||
import { getCurrentInstance } from '@tarojs/runtime';
|
import { getCurrentInstance } from '@tarojs/runtime';
|
||||||
import Taro from '@tarojs/taro';
|
|
||||||
import pt from '@/plain-text';
|
import pt from '@/plain-text';
|
||||||
import { AtCard, AtSteps, AtButton } from 'taro-ui';
|
import { AtButton } from 'taro-ui';
|
||||||
import { RequestState } from '@/service';
|
import DetailFramework from '@/components/DetailFramework/DetailFramework';
|
||||||
import { getTicketInfo } from '@/service/ticketsInfo';
|
|
||||||
import { FixStatus } from '@/common';
|
|
||||||
import PageFooter from '@/components/PageFooter/PageFooter';
|
|
||||||
import NoteList from '@/components/NoteList/NoteList';
|
|
||||||
import { TicketNote, TicketInfo } from './TicketNote';
|
|
||||||
|
|
||||||
const mapStatusStep: Map<FixStatus, 0 | 1 | 2 | 3> = new Map([
|
|
||||||
[1, 0],
|
|
||||||
[2, 1],
|
|
||||||
[3, 2],
|
|
||||||
[4, 2],
|
|
||||||
[5, 3],
|
|
||||||
]);
|
|
||||||
|
|
||||||
interface StepItemData {
|
|
||||||
title: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TicketDetailState {
|
interface TicketDetailState {
|
||||||
current: number;
|
id: number;
|
||||||
items: Array<StepItemData>;
|
|
||||||
ticketInfo: TicketInfo;
|
|
||||||
notes: Array<TicketNote>;
|
|
||||||
rs: RequestState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class TicketDetail extends Component<{}, TicketDetailState> {
|
export default class TicketDetail extends Component<{}, TicketDetailState> {
|
||||||
state = {
|
state: Readonly<TicketDetailState> = {
|
||||||
current: 0,
|
id: 0,
|
||||||
items: [],
|
|
||||||
ticketInfo: new TicketInfo(),
|
|
||||||
notes: [new TicketNote()],
|
|
||||||
rs: new RequestState(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount(): void {
|
componentDidMount(): void {
|
||||||
const navBar = pt.get().navBar;
|
|
||||||
Taro.setNavigationBarTitle({
|
|
||||||
title: navBar.ticketDetail,
|
|
||||||
});
|
|
||||||
const { router } = getCurrentInstance();
|
const { router } = getCurrentInstance();
|
||||||
const id = router?.params.id as number;
|
const id = router?.params.id as number;
|
||||||
const items = pt.get().ticketDetail.stepItems;
|
|
||||||
this.setState({
|
this.setState({
|
||||||
items: items,
|
id: id,
|
||||||
});
|
});
|
||||||
|
|
||||||
getTicketInfo(this, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render(): ReactNode {
|
render(): ReactNode {
|
||||||
if (this.state.rs.loading) {
|
const middleButton = (
|
||||||
return <View>Loading</View>;
|
<View
|
||||||
} else if (!this.state.rs.success) {
|
className='at-row'
|
||||||
return <View>Request failed</View>;
|
style={{ paddingTop: 10, paddingBottom: 10, width: '100%' }}
|
||||||
}
|
>
|
||||||
|
<View
|
||||||
const status = this.state.ticketInfo.status;
|
className='at-col'
|
||||||
this.setState({
|
style={{ marginLeft: 10, paddingRight: 5, width: '50%' }}
|
||||||
current: mapStatusStep.get(status) || 0,
|
>
|
||||||
});
|
<AtButton type='primary'>{pt.get().ticketDetail.tookAway}</AtButton>
|
||||||
|
</View>
|
||||||
|
<View
|
||||||
|
className='at-col'
|
||||||
|
style={{ marginRight: 10, paddingLeft: 5, width: '50%' }}
|
||||||
|
>
|
||||||
|
<AtButton type='secondary'>{pt.get().ticketDetail.addNote}</AtButton>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<View className='at-article__h1'>
|
<DetailFramework middleButton={middleButton} id={this.state.id} />
|
||||||
{this.state.ticketInfo.device +
|
|
||||||
' ' +
|
|
||||||
this.state.ticketInfo.deviceModel}
|
|
||||||
</View>
|
|
||||||
<View className='at-article__info'>
|
|
||||||
{pt.get().common.createdAtText(this.state.ticketInfo.createdTime)}
|
|
||||||
</View>
|
|
||||||
<View style={{ marginTop: 10, marginBottom: 10 }}>
|
|
||||||
<AtCard title={pt.get().ticketDetail.descTitle}>
|
|
||||||
<View className='at-article__h3'>
|
|
||||||
{this.state.ticketInfo.description}
|
|
||||||
</View>
|
|
||||||
</AtCard>
|
|
||||||
</View>
|
|
||||||
<View style={{ padding: 10 }}>
|
|
||||||
<AtSteps
|
|
||||||
items={this.state.items}
|
|
||||||
current={this.state.current}
|
|
||||||
onChange={() => {}}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
<View
|
|
||||||
className='at-row'
|
|
||||||
style={{ paddingTop: 10, paddingBottom: 10, width: '100%' }}
|
|
||||||
>
|
|
||||||
<View
|
|
||||||
className='at-col'
|
|
||||||
style={{ marginLeft: 10, paddingRight: 5, width: '50%' }}
|
|
||||||
>
|
|
||||||
<AtButton type='primary'>{pt.get().ticketDetail.tookAway}</AtButton>
|
|
||||||
</View>
|
|
||||||
<View
|
|
||||||
className='at-col'
|
|
||||||
style={{ marginRight: 10, paddingLeft: 5, width: '50%' }}
|
|
||||||
>
|
|
||||||
<AtButton type='secondary'>
|
|
||||||
{pt.get().ticketDetail.addNote}
|
|
||||||
</AtButton>
|
|
||||||
</View>
|
|
||||||
</View>
|
|
||||||
<View style={{ padding: 10 }}>
|
|
||||||
<NoteList noteList={this.state.notes} />
|
|
||||||
</View>
|
|
||||||
<PageFooter />
|
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import TicketDetail from '@/pages/TicketDetail/TicketDetail';
|
|
||||||
import { TicketInfo, TicketNote } from '@/pages/TicketDetail/TicketNote';
|
import { TicketInfo, TicketNote } from '@/pages/TicketDetail/TicketNote';
|
||||||
|
import DetailFramework from '@/components/DetailFramework/DetailFramework';
|
||||||
import Taro from '@tarojs/taro';
|
import Taro from '@tarojs/taro';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { getUrl } from '.';
|
import { getUrl } from '.';
|
||||||
|
|
||||||
export function getTicketInfo(that: TicketDetail, id: number) {
|
export function getTicketInfo(that: DetailFramework, id: number) {
|
||||||
Taro.request({
|
Taro.request({
|
||||||
url: getUrl('/tickets/info'),
|
url: getUrl('/tickets/info'),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue