debut ajout tri par prix
This commit is contained in:
parent
6d41983135
commit
4f47f96b4c
3 changed files with 79 additions and 35 deletions
|
@ -23,10 +23,11 @@ class Sort extends Component {
|
|||
<option className="optionSort" value="Ordre Alphabétique">Ordre Alphabétique</option>
|
||||
<option className="optionSort" value="Catégorie">Catégorie</option>
|
||||
<option className="optionSort" value="Quantité">Quantité</option>
|
||||
<option className="optionSort" value="Quantité">Prix</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p id="sortOrder" onClick={this.props.handleChangeSortOrder} hidden={this.props.orderIsVisible}>
|
||||
<p id="sortOrder" onClick={this.props.handleChangeSortOrder} hidden={this.props.orderIsHidden}>
|
||||
{this.props.lowToHigh ? "A-Z" : "Z-A"}
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -17,7 +17,6 @@ import EditCategory from '../Components/EditCategory';
|
|||
import Sort from '../Components/Sort';
|
||||
import { Link } from 'react-router-dom';
|
||||
import Selected from '../Components/Selected';
|
||||
import BarcodeReader from 'react-barcode-reader'
|
||||
|
||||
export default class Stock extends React.Component {
|
||||
|
||||
|
@ -67,8 +66,9 @@ export default class Stock extends React.Component {
|
|||
sortArticles = (sortType) => {
|
||||
|
||||
let sorted;
|
||||
//TRI PAR ORDRE ALPHABETIQUE
|
||||
if (sortType === "name"){
|
||||
this.setState({orderIsVisible: false})
|
||||
this.setState({orderIsHidden: false})
|
||||
if (this.state.lowToHigh) {
|
||||
//ordre alphabétique croissant
|
||||
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
||||
|
@ -77,11 +77,12 @@ export default class Stock extends React.Component {
|
|||
sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name))
|
||||
}
|
||||
} else {
|
||||
this.setState({orderIsVisible: true})
|
||||
this.setState({orderIsHidden: true})
|
||||
this.setState({lowToHigh: false})
|
||||
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
||||
}
|
||||
|
||||
//TRI PAR CATEGORIE
|
||||
if (sortType === 'category_id'){
|
||||
this.setState({articles:sorted},() => {
|
||||
this.setState({onSortedCategories:true})
|
||||
|
@ -92,6 +93,11 @@ export default class Stock extends React.Component {
|
|||
this.setState({onSortedCategories:false})
|
||||
})
|
||||
}
|
||||
|
||||
//TRI PAR PRIX
|
||||
if (sortType === 'price') {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
getArticles = () => {
|
||||
|
@ -161,6 +167,8 @@ export default class Stock extends React.Component {
|
|||
this.sortArticles("category_id")
|
||||
} else if(this.state.sortType === "Quantité"){
|
||||
this.sortArticles("quantity")
|
||||
} else if(this.state.sortType === "Prix"){
|
||||
this.sortArticles("price");
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -216,19 +224,12 @@ export default class Stock extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
handleScan = (data) => {
|
||||
this.setState({code:data},()=>{
|
||||
console.log(this.state.code)
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!sessionStorage.getItem('token')){
|
||||
return (<div id="errorRouteBlock"><div id="errorRouteTitle">ERREUR </div><br/><div id="errorRouteTxt">Vous n'êtes pas connecté</div><br/><Link id="link" to='/'>Retourner à l'Accueil</Link></div>)
|
||||
} else {
|
||||
return (
|
||||
<div id="stock" tabIndex={-1} onKeyDown={this.closeWithEscape}>
|
||||
<BarcodeReader onScan={this.handleScan}/>
|
||||
<Header title='Le Stock'/>
|
||||
<Navbar handleNewArticle={this.handleNewArticle} handleNewCategory={this.handleNewCategory} right="Le Ticket de Caisse" left="Créer" leftLeft="Article" leftMiddle="|" leftRight="Catégorie" redirect="/ticket"/>
|
||||
{this.state.onNewArticle ?
|
||||
|
@ -236,7 +237,7 @@ export default class Stock extends React.Component {
|
|||
: null}
|
||||
<SearchBar handleSubmit={this.handleSubmit} handleSearchChange={this.handleSearchChange}/>
|
||||
<div id="sortBlock">
|
||||
<Sort handleChangeSortType={this.handleChangeSortType} handleChangeSortOrder={this.handleChangeSortOrder} orderIsVisible={this.state.orderIsVisible} lowToHigh={this.state.lowToHigh}/>
|
||||
<Sort handleChangeSortType={this.handleChangeSortType} handleChangeSortOrder={this.handleChangeSortOrder} orderIsHidden={this.state.orderIsHidden} lowToHigh={this.state.lowToHigh}/>
|
||||
</div>
|
||||
<div id="selectedBlock">
|
||||
<Selected counter={this.state.counter}/>
|
||||
|
|
|
@ -6,17 +6,58 @@ import 'react-perfect-scrollbar/dist/css/styles.css';
|
|||
import Footer from '../Components/Footer';
|
||||
import { Link } from 'react-router-dom';
|
||||
import SearchBar from '../Components/SearchBar';
|
||||
import BarcodeReader from 'react-barcode-reader';
|
||||
import axios from 'axios';
|
||||
|
||||
export default class Stock extends React.Component {
|
||||
|
||||
constructor(props){
|
||||
super(props)
|
||||
this.state = {
|
||||
articles: [],
|
||||
scannedCode: ''
|
||||
}
|
||||
|
||||
this.handleScan = this.handleScan.bind(this);
|
||||
}
|
||||
|
||||
|
||||
getArticles = () => {
|
||||
axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles')
|
||||
.then(res => {
|
||||
this.setState({articles : res.data}, () => {
|
||||
console.log(this.state.articles)
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error.response)
|
||||
})
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
}
|
||||
this.getArticles();
|
||||
}
|
||||
|
||||
// RECHERCHE DE L'ARTICLE
|
||||
getArticleByCode() {
|
||||
let i=0;
|
||||
let current = this.state.articles[i];
|
||||
let trouve = current === this.state.scannedCode ? true : false;
|
||||
while(!trouve) {
|
||||
i++;
|
||||
current = this.state.articles[i];
|
||||
if (current.scannedCode === this.state.scannedCode) {
|
||||
trouve = !trouve;
|
||||
}
|
||||
}
|
||||
console.log(current);
|
||||
}
|
||||
|
||||
handleScan(code) {
|
||||
this.setState({result: code}, () => {
|
||||
console.log(this.state.result);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!sessionStorage.getItem('token')){
|
||||
|
@ -26,6 +67,7 @@ export default class Stock extends React.Component {
|
|||
<div id="stock">
|
||||
<Header title='Le Ticket de Caisse'/>
|
||||
<Navbar redirect="/stock" left="Monnaie" right="Le Stock"/>
|
||||
<BarcodeReader onScan={this.handleScan}/>
|
||||
<SearchBar/>
|
||||
<div id="emptyTicketBox">
|
||||
<p id="emptyTicket">
|
||||
|
@ -36,4 +78,4 @@ export default class Stock extends React.Component {
|
|||
</div>
|
||||
)}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue