import React from 'react'; import {Container, Segment, Button, Table} from 'semantic-ui-react'; import {getRequest} from '../../../../actions'; import ListItem from './ListItem'; import LocationModal from './LocationModal'; const stateDefault = ()=>({ list: [], modal: { open: false, type: 0, data: {} } }) class Location extends React.Component { state = { ...stateDefault() } componentDidMount() { this.getList(); } getList = () => { let {showDialog, toggleLoading} = this.props; toggleLoading(1); fetch('/api/wristband/getlocationlist', getRequest()) .then(response=>response.json()) .then(json => { toggleLoading(0); if(json.status != 1) return showDialog(json.message); this.setState({ list: json.data.record || [] }) }) } openModal = (type, data = {}) =>{ this.setState({ modal: { open: true, type, data } }) } closeModal = () => { this.setState({ modal:{ ...stateDefault().modal } }) } submitModal = (type, data) => { let {showDialog} = this.props; if(type == 1 && !data.id) return showDialog('資料取得失敗'); if(type == 0 && !data.sn) return showDialog('請填寫裝置序號'); let url = type == 1 ? '/api/wristband/editlocation' : '/api/wristband/addlocation'; fetch(url, getRequest(data)) .then(response => response.json()) .then(json => { if(json.status != 1) return showDialog(json.message); this.setState({ modal: { ...stateDefault().modal } }, ()=>{ this.getList(); }) }) } delLocation = (id) => { if(!id) return ; let {showDialog, callConfirm} = this.props; callConfirm('確定要刪除這筆定位點資料?', ()=>{ fetch('/api/wristband/dellocation', getRequest({id})) .then(response => response.json()) .then(json => { if(json.status != 1) return showDialog(json.message); this.getList(); }) }) } render() { let {i18n} = this.props; return (