import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import ClipLoader from 'react-spinners/ClipLoader'; import {ExportCSV} from '../ExportCSV'; import DatatableParkir from './../DatatableParkir'; import DatatablePelbagai from './../DatatablePelbagai'; export default class ConfiscatedCompoundDatatable extends Component { constructor(props) { super(props); this.state = { current_id: this.props.current_id, dataCompound: [], loading: 'null', current_url: 'null', total:{ baru: this.props.baru, invest: this.props.invest, notice: this.props.notice, inven: this.props.inven, collap: this.props.collap, comp: this.props.comp }, check: { kpd: true, date: true, faulty: true, enforcer: true, platno: false, companyno: false, nric: false, }, form: { modul: this.props.modul, status: this.props.status, type: 'Parkir', kpd: '', start_date: new Date().getFullYear() + '-' + (new Date().getMonth()+1) + '-' + new Date().getDate(), end_date: new Date().getFullYear() + '-' + (new Date().getMonth()+1) + '-' + new Date().getDate(), faulty: 'All', enforcer: 'All', plate_no: '', company_no: '', nric: '', }, list_enforcer: JSON.parse(this.props.enforcer), list_faulty: JSON.parse(this.props.faulty), }; this.onCheckKpd = this.onCheckKpd.bind(this); this.onCheckDate = this.onCheckDate.bind(this); this.onCheckPlateNo = this.onCheckPlateNo.bind(this); this.onCheckCompanyNo = this.onCheckCompanyNo.bind(this); this.onCheckNric = this.onCheckNric.bind(this); this.onChangeKpd = this.onChangeKpd.bind(this); this.onChangeType = this.onChangeType.bind(this); this.onChangeStart = this.onChangeStart.bind(this); this.onChangeEnd = this.onChangeEnd.bind(this); this.onChangeFaulty = this.onChangeFaulty.bind(this); this.onChangeEnforcer = this.onChangeEnforcer.bind(this); this.onChangePlateNo = this.onChangePlateNo.bind(this); this.onChangeCompanyNo = this.onChangeCompanyNo.bind(this); this.onChangeNric = this.onChangeNric.bind(this); this.onSubmit = this.onSubmit.bind(this); } onCheckKpd(e){ this.setState(prevState => ({ check: { ...prevState.check, kpd: !this.state.check.kpd }, })) } onCheckDate(e){ this.setState(prevState => ({ check: { ...prevState.check, date: !this.state.check.date } })) } onCheckPlateNo(e){ this.setState(prevState => ({ check: { ...prevState.check, platno: !this.state.check.platno } })) } onCheckCompanyNo(e){ this.setState(prevState => ({ check: { ...prevState.check, companyno: !this.state.check.companyno } })) } onCheckNric(e){ this.setState(prevState => ({ check: { ...prevState.check, nric: !this.state.check.nric } })) } onChangeKpd(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, kpd: value } })); } onChangeType(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, type: value }, loading: 'null', dataCompound: [] })); } onChangeStart(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, start_date: value } })); } onChangeEnd(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, end_date: value } })); } onChangeFaulty(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, faulty: value } })); } onChangeEnforcer(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, enforcer: value } })); } onChangePlateNo(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, plate_no: value } })); } onChangeCompanyNo(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, company_no: value } })); } onChangeNric(e){ let value = e.target.value; this.setState(prevState => ({ form: { ...prevState.form, nric: value } })); } onSubmit(e){ e.preventDefault(); this.setState({ loading: true }); let formData = { type: this.state.form.type, enforcer: this.state.form.enforcer, faulty: this.state.form.faulty, modul: this.state.form.modul, status: this.state.form.status, }; if(this.state.check.date){ formData = { ...formData, start_date: this.state.form.start_date, end_date: this.state.form.end_date, } }else{ formData = { ...formData, start_date: '', end_date: '', } } if(this.state.check.kpd){ formData = { ...formData, kpd: this.state.form.kpd, } }else if(this.state.check.platno){ formData = { ...formData, plate_no: this.state.form.plate_no, } }else if(this.state.check.companyno){ formData = { ...formData, company_no: this.state.form.company_no, } }else if(this.state.check.nric){ formData = { ...formData, nric: this.state.form.nric, } } let queryString = Object.keys(formData).map(key => key + '=' + formData[key]).join('&'); fetch('/api/list/compound?'+queryString).then(response => { response.json().then(res => { this.setState({ dataCompound: res.data, loading: false, current_url: '/api/list/compound?'+queryString }); }) }) } render() { return (