diff --git a/src/components/DetailFramework/DetailFramework.tsx b/src/components/DetailFramework/DetailFramework.tsx index 796b896..950e6a6 100644 --- a/src/components/DetailFramework/DetailFramework.tsx +++ b/src/components/DetailFramework/DetailFramework.tsx @@ -1,38 +1,21 @@ 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 { ShowElements } from '@/pages/TicketDetail/TicketNote'; 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 = new Map([ - [1, 0], - [2, 1], - [3, 2], - [4, 2], - [5, 3], -]); - -interface StepItemData { - title: string; -} interface DetailFrameworkState { - current: number; - items: Array; - ticketInfo: TicketInfo; - notes: Array; rs: RequestState; + elements: ShowElements; } interface DetailFrameworkProps { middleButton: JSX.Element; id: number; + isInfoShow: { [key: string]: boolean }; } export default class DetailFramework extends Component< @@ -40,11 +23,8 @@ export default class DetailFramework extends Component< DetailFrameworkState > { state = { - current: 0, - items: [], - ticketInfo: new TicketInfo(), - notes: [new TicketNote()], rs: new RequestState(), + elements: new ShowElements(), }; componentDidMount(): void { @@ -52,16 +32,20 @@ export default class DetailFramework extends Component< Taro.setNavigationBarTitle({ title: navBar.ticketDetail, }); - const items = pt.get().ticketDetail.stepItems; - this.setState({ - items: items, - }); - getTicketInfo(this, this.props.id); + getTicketInfo(this, this.props.id, this.props.isInfoShow); } props: Readonly = { middleButton: , id: 0, + isInfoShow: { + device: true, + createdTime: true, + description: true, + current: true, + notelist: true, + showAllNotes: true, + }, }; render(): ReactNode { @@ -71,41 +55,14 @@ export default class DetailFramework extends Component< return Request failed; } - const status = this.state.ticketInfo.status; - this.setState({ - current: mapStatusStep.get(status) || 0, - }); - return ( - - {this.state.ticketInfo.device + - ' ' + - this.state.ticketInfo.deviceModel} - - - {pt.get().common.createdAtText(this.state.ticketInfo.createdTime)} - - - - - {this.state.ticketInfo.description} - - - - - {}} - /> - - + {this.state.elements.device} + {this.state.elements.createdTime} + {this.state.elements.description} + {this.state.elements.current} {this.props.middleButton} - - - - + {this.state.elements.notelist} ); diff --git a/src/pages/TicketDetail/TicketDetail.tsx b/src/pages/TicketDetail/TicketDetail.tsx index 68977c9..ac2bf9a 100644 --- a/src/pages/TicketDetail/TicketDetail.tsx +++ b/src/pages/TicketDetail/TicketDetail.tsx @@ -43,9 +43,22 @@ export default class TicketDetail extends Component<{}, TicketDetailState> { ); + const isInfoShow = { + device: true, + createdTime: true, + description: true, + current: true, + notelist: true, + showAllNotes: true, + }; + return ( - + ); } diff --git a/src/pages/TicketDetail/TicketNote.ts b/src/pages/TicketDetail/TicketNote.ts index 4cde4e5..b5d894c 100644 --- a/src/pages/TicketDetail/TicketNote.ts +++ b/src/pages/TicketDetail/TicketNote.ts @@ -18,4 +18,12 @@ export class TicketNote { createdTime: moment.Moment; } +export class ShowElements { + device: JSX.Element; + createdTime: JSX.Element; + description: JSX.Element; + current: JSX.Element; + notelist: JSX.Element; +} + export type StatusStr = '1' | '2' | '3' | '4' | '5'; diff --git a/src/service/ticketsInfo.ts b/src/service/ticketsInfo.ts deleted file mode 100644 index 9e6c42d..0000000 --- a/src/service/ticketsInfo.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { TicketInfo, TicketNote } from '@/pages/TicketDetail/TicketNote'; -import DetailFramework from '@/components/DetailFramework/DetailFramework'; -import Taro from '@tarojs/taro'; -import moment from 'moment'; -import { getUrl } from '.'; - -export function getTicketInfo(that: DetailFramework, id: number) { - Taro.request({ - url: getUrl('/tickets/info'), - method: 'GET', - data: { - id: id, - }, - }) - .then((res) => { - let former = that.state.rs; - if (!res.data.success) { - that.setState({ - rs: former.trans(false), - }); - } else { - const data = res.data.data; - const ticketDetail: TicketInfo = { - id: data.id, - type: data.type, - device: data.device, - deviceModel: data.deviceModel, - description: data.description, - createdTime: moment(data.createdTime as string), - status: data.status, - }; - const notes: Array = []; - data.notes.map((item) => { - notes.push({ - id: item.id, - op: item.op, - type: item.type, - content: item.content, - createdTime: moment(item.createdTime as string), - }); - }); - that.setState({ - ticketInfo: ticketDetail, - notes: notes, - rs: former.trans(true), - }); - } - }) - .catch((reason) => { - let former = that.state.rs; - that.setState({ - rs: former.trans(false), - }); - console.error(reason); - }); -} diff --git a/src/service/ticketsInfo.tsx b/src/service/ticketsInfo.tsx new file mode 100644 index 0000000..ad6a292 --- /dev/null +++ b/src/service/ticketsInfo.tsx @@ -0,0 +1,132 @@ +import { + TicketInfo, + TicketNote, + ShowElements, +} from '@/pages/TicketDetail/TicketNote'; +import DetailFramework from '@/components/DetailFramework/DetailFramework'; +import Taro from '@tarojs/taro'; +import { View } from '@tarojs/components'; +import pt from '@/plain-text'; +import { AtCard, AtSteps } from 'taro-ui'; +import moment from 'moment'; +import NoteList from '@/components/NoteList/NoteList'; +import { FixStatus } from '@/common'; +import { getUrl } from '.'; + +const mapStatusStep: Map = new Map([ + [1, 0], + [2, 1], + [3, 2], + [4, 2], + [5, 3], +]); + +interface StepItemData { + title: string; +} + +export function getTicketInfo( + that: DetailFramework, + id: number, + isInfoShow: { [key: string]: boolean }, +) { + const items: Array = pt.get().ticketDetail.stepItems; + Taro.request({ + url: getUrl('/tickets/info'), + method: 'GET', + data: { + id: id, + }, + }) + .then((res) => { + let former = that.state.rs; + if (!res.data.success) { + that.setState({ + rs: former.trans(false), + }); + } else { + const data = res.data.data; + const ticketDetail: TicketInfo = { + id: data.id, + type: data.type, + device: data.device, + deviceModel: data.deviceModel, + description: data.description, + createdTime: moment(data.createdTime as string), + status: data.status, + }; + const notes: Array = []; + data.notes.map((item) => { + notes.push({ + id: item.id, + op: item.op, + type: item.type, + content: item.content, + createdTime: moment(item.createdTime as string), + }); + }); + const elements: ShowElements = { + device: isInfoShow['device'] ? ( + + {ticketDetail.device + ' ' + ticketDetail.deviceModel} + + ) : ( + + ), + createdTime: isInfoShow['createdTime'] ? ( + + {pt.get().common.createdAtText(ticketDetail.createdTime)} + + ) : ( + + ), + description: isInfoShow['description'] ? ( + + + + {ticketDetail.description} + + + + ) : ( + + ), + current: isInfoShow['current'] ? ( + + {}} + /> + + ) : ( + + ), + notelist: isInfoShow['notelist'] ? ( + isInfoShow['showAllNotes'] ? ( + + + + ) : ( + + + + ) + ) : ( + + ), + }; + that.setState({ + rs: former.trans(true), + elements: elements, + }); + } + }) + .catch((reason) => { + let former = that.state.rs; + that.setState({ + rs: former.trans(false), + }); + console.error(reason); + }); +}