import { View } from '@tarojs/components'; import { Component, ReactNode } from 'react'; import Taro from '@tarojs/taro'; import { ShowElements, TicketInfo, TicketNote, } from '@/pages/TicketDetail/TicketNote'; import pt from '@/plain-text'; import { RequestState } from '@/service'; import { getTicketInfo } from '@/service/ticketsInfo'; import { FixStatus } from '@/common'; import { AtCard, AtSteps } from 'taro-ui'; import NoteList from '../NoteList/NoteList'; interface StepItemData { title: string; } const mapStatusStep: Map = new Map([ [1, 0], [2, 1], [3, 2], [4, 2], [5, 3], ]); interface DetailFrameworkState { current: number; items: Array; ticketInfo: TicketInfo; notes: Array; rs: RequestState; } interface DetailFrameworkProps { middleButton: JSX.Element; id: number; isInfoShow: { [key: string]: boolean }; } 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, }); getTicketInfo(this, this.props.id); } props: Readonly = { middleButton: , id: 0, isInfoShow: { device: true, createdTime: true, description: true, current: true, notelist: true, showAllNotes: true, }, }; render(): ReactNode { if (this.state.rs.loading) { return Loading; } else if (!this.state.rs.success) { return Request failed; } const status = this.state.ticketInfo.status; this.setState({ current: mapStatusStep.get(status) || 0, items: pt.get().ticketDetail.stepItems, }); const elements: ShowElements = { device: this.props.isInfoShow['device'] ? ( {this.state.ticketInfo.device + ' ' + this.state.ticketInfo.deviceModel} ) : ( ), createdTime: this.props.isInfoShow['createdTime'] ? ( {pt.get().common.createdAtText(this.state.ticketInfo.createdTime)} ) : ( ), description: this.props.isInfoShow['description'] ? ( {this.state.ticketInfo.description} ) : ( ), current: this.props.isInfoShow['current'] ? ( {}} /> ) : ( ), notelist: this.props.isInfoShow['notelist'] ? ( this.props.isInfoShow['showAllNotes'] ? ( ) : ( ) ) : ( ), }; return ( {elements.device} {elements.createdTime} {elements.description} {elements.current} {this.props.middleButton} {elements.notelist} ); } }