import React, { Component } from 'react' import { TouchableOpacity, TextInput, StyleSheet, View, ScrollView, Alert, Image, Slider, ImageBackground, FlatList, Modal } from 'react-native' import Icon from "../../components/Icon"; import { CustomButton } from '../../components/CustomButton'; import { Button, Card, Body, Badge, ListItem, Left, Right,CheckBox, } from 'native-base' import { BackgroundImage } from '../../components/BackgroundImage' import Text from '../../components/Text'; import LinearGradient from 'react-native-linear-gradient'; import GetWidthHeightDevice from '../../components/GetWidthHeightDevice' import Color from '../../../src/color'; import { t } from 'src/utils/i18n' import {getRepairById, postEvaluateRepair} from "../../api/UserApi"; import IndicatorLoading from '../../components/IndicatorLoading'; import { StackActions, NavigationActions } from 'react-navigation'; import moment from 'moment'; function ConfirmEvaluate({isVisible, onPress, onCancel, points}) { return ยืนยันการประเมินให้คะแนน คุณต้องการจะให้คะแนน "{points} คะแนน" หรือไม่ ? กด "ยืนยัน" หากต้องการดำเนินการต่อ {t('cancel')} ยืนยัน } export default class RepairServiceDetail extends Component { constructor(props) { super(props); this.state = { isLoading: true, value: 2, point_selected: 0, rating_point: [0,0,0,0,0], visibleConfirm: false } this.sendEvaluate = this.sendEvaluate.bind(this) } componentDidMount() { const { navigation } = this.props const id = navigation.getParam('id', 'NO-DATA') this.getRepairData(id) }; visibleConfirm = () => { this.setState({ visibleConfirm: !this.state.visibleConfirm }) } getRepairData(id){ this.setState({ isLoading: true }, () => { getRepairById(id) .then(res => { console.log('repair data -------------> ',res.data.data) this.setState({ repair: res.data.data, order_list: res.data.data.services, isLoading: false }) this.props.navigation.setParams({statusRepair: res.data.data.status}) }) }) } sendEvaluate(){ let params = { id: this.state.repair.id, point: this.state.point_selected } if(this.state.point_selected === 0){ Alert.alert('กรุณาเลือกระดับความพึงพอใจ', null, [{text: t('ok')}]) return } this.setState({ //isLoading: true, visibleConfirm: false }, () => { postEvaluateRepair(params) .then(res => { if(res.data.success){ this.setState({ isLoading: false, }, () => { setTimeout(() => Alert.alert('ให้คะแนนสำเร็จ', null, [ { text: t('ok'), onPress: () => { //this.getRepairData(this.state.repair.id) this.props.navigation.dispatch(StackActions.reset({ index: 3, actions: [ NavigationActions.navigate({ routeName: 'BottomTab', action: NavigationActions.navigate({ routeName: 'ServiceScreen' }) }), NavigationActions.navigate({ routeName: 'RepairService' }), NavigationActions.navigate({ routeName: 'RepairHistory' }), NavigationActions.navigate({ routeName: 'RepairHistoryDetail', params: { repair_id: this.state.repair.id } }) ] })) } } ]), 500) }) }else { this.setState({ isLoading: false }, () => { Alert.alert('ให้คะแนนไม่สำเร็จ กรุณาลองใหม่อีกครั้งภายหลัง', null, [{text: t('ok')}]) }) } }) }) } setRating = (index) => { let rating_star = [0, 0, 0, 0, 0]; for(let i=0; i<=index; i++){ rating_star[i] = 1; } this.setState({ rating_point: rating_star, point_selected: index + 1 }) } renderItem = (item) => { return {item.name} {item.service_fee} {t('baht')} } render() { const {value, isLoading} = this.state; return ( {t('room')} {this.state.repair && this.state.repair.room_no} #{this.state.repair && this.state.repair.id} {this.state.repair && this.state.repair.project_name ? t('project') + this.state.repair.project_name : ''} {t('make_appoint')} {t('date')} {this.state.repair && moment(this.state.repair.date, 'YYYY-MM-DD').format('DD-MM-YYYY')} เวลา {this.state.repair && this.state.repair.time.slice(0, -3)} {t('status')} ซ่อมสำเร็จ {t('information')} this.renderItem(item)} pagingEnabled={true} extraData={this.state} keyExtractor={this._keyExtractor} /> {t('estimate_charge')} {this.state.repair && this.state.repair.total} {t('baht')} { !isLoading && {t('rating')} { this.state.rating_point.map((point, index) => point === 0 ? {index + 1} this.state.repair.point === 0 || this.state.repair.points === null ? this.setRating(index) : {}} > : {index + 1} this.state.repair.point === 0 || this.state.repair.points === null ? this.setRating(index) : {}} > ) } } { !isLoading && this.state.repair && (this.state.repair.points === null || this.state.repair.points === 0) && {this.visibleConfirm()}} disabled={this.state.point_selected === 0} title={'ส่งประเมิน'} /> } this.sendEvaluate()} onCancel={() => this.setState({visibleConfirm: false})} points={this.state.point_selected} /> ) } } const styles = { containerHeadbar: { flex: 1, flexDirection: 'column', //height: GetWidthHeightDevice.HeightContainer, padding:16, fontStyle: "normal", justifyContent:'space-between' }, hairline: { marginVertical: 17, backgroundColor: '#EAEAF4', height: 1, width: '100%' }, button_style: { backgroundColor: '#145EB3', height: 40, borderRadius: 5, width: "100%", }, row: { flex: 1, flexDirection: "row", }, info_order_view:{ paddingVertical:5, flexDirection: 'row', justifyContent:'space-between' }, AlertWarningContainer: { backgroundColor: 'rgba(0,0,0,0.6)', justifyContent: 'center', alignItems: 'center', position: 'absolute', width: '100%', height: '100%', flex: 1 }, AlertWarning: { backgroundColor: 'white', justifyContent: 'center', alignItems: 'center', borderRadius: 5, marginHorizontal: 25, paddingVertical: 20, paddingHorizontal: 20, maxWidth: 300, width: '100%' } }