Commit d47eebb0 authored by Wahyu Adjie Prasetyo's avatar Wahyu Adjie Prasetyo

ini perubahan menu selection

parent 03cdc02e
This diff is collapsed.
import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native';
import { connect } from 'react-redux';
class Item extends React.Component {
render() {
const { item } = this.props
......
import React from 'react';
import { View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, TextInput } from 'react-native';
import { connect } from 'react-redux';
class ItemShoping extends React.Component {
render() {
const { item } = this.props
console.log("ini id itemnya "+item.id)
return (
<View style={{ flex: 1, margin: 10 }} key={item.id} ref={this.props._scrollView}>
<ScrollView ref={view => this._scrollView = view}>
{item.code == 'CATEGORY' ? (
<Text style={{ fontSize: 20, color: '#c9af6d' }}>{item.name}</Text>
): (
<View style={{ flexDirection: 'row' }}>
<View >
<Image source={{ uri: item.image }} style={{ height: 100, width: 100, borderRadius: 5, top: 5 }}></Image>
</View>
<View >
<Text style={{ fontSize: 20, margin: 5, marginRight: 10, fontWeight: 'bold' }}>{item.name}</Text>
<Text style={{ fontSize: 15, margin: 5, marginRight: 10 }}>Rp. {item.price}</Text>
<View style={{ flexDirection: 'row', flex: 1 }}>
<View style={styles.shadowEdit}></View>
<View style={styles.shadowAdd}>
<TouchableOpacity onPress={() => this.props.handleMin()}>
<Text style={{ fontSize: 20, margin: 2 }}> - </Text>
</TouchableOpacity>
<TextInput
style={{ height: 25, padding: 2, textAlign: 'center', margin: 2 }}
autoCapitalize="none">
{item.qty}
</TextInput>
<TouchableOpacity onPress={() => this.props.handleAdd()}>
<Text style={{ fontSize: 20, margin: 2 }}> + </Text>
</TouchableOpacity>
</View>
</View>
</View>
</View>
)}
</ScrollView>
</View>
)
}
}
const styles = StyleSheet.create({
shadowEdit: {
height: 30,
width: 25,
borderWidth: 1,
borderRadius: 2,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 1,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
},
shadowAdd: {
height: 30,
width: 75,
borderWidth: 1,
borderRadius: 2,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 1,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
flexDirection: 'row'
},
shadowMin: {
height: 20,
width: 20,
borderWidth: 1,
borderRadius: 2,
borderColor: '#ddd',
borderBottomWidth: 0,
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.8,
shadowRadius: 2,
elevation: 1,
marginLeft: 5,
marginRight: 5,
marginTop: 10,
}
})
const mapStateToProps = (state) => {
console.log(state)
return {
session_id: state.session_id,
outlet_id: state.outlet_id,
order_quantity: state.order_quantity,
order_total: state.order_total,
quantity: state.quantity,
}
}
export default connect(mapStateToProps)(Item)
......@@ -53,11 +53,19 @@ class MenuSelection extends React.Component {
const row = data.menu[i];
// cari sudah ada belum di redux
let is_xist = this.props.order_item.find(item => row.id == item.id)
if (is_xist) {
row['qty'] = is_xist.quantity
} else {
row['qty'] = 0
}
if (last_category != row.category.name) {
let category = {
"id":row.category.id,
"id": row.category.id,
"name": row.category.name,
"code" : "CATEGORY"
"code": "CATEGORY"
}
list_menu.push(category)
list_menu.push(row)
......@@ -67,12 +75,12 @@ class MenuSelection extends React.Component {
}
}
this.state.listMenu.map((i => {
i.qty=0
}))
// this.state.listMenu.map((i => {
// i.qty = 0
// }))
console.log('After : ' + JSON.stringify(list_menu))
this.setState({
listMenu:list_menu
listMenu: list_menu
})
})
......@@ -121,6 +129,7 @@ class MenuSelection extends React.Component {
}
handleAdd(item, index) {
console.log('TAMPILIN NIH')
const order_item = {
id: item.id,
name: item.name,
......@@ -130,23 +139,36 @@ class MenuSelection extends React.Component {
this.props.addToChart(order_item)
// console.log("ORDER ITEM " + this.props.order_item)
const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id)
let quantity = 0
for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i];
if (row.id == item.id) {
quantity = row.quantity
}
// for (let i = 0; i < list_order_item.length; i++) {
// const row = list_order_item[i];
// if (row.id == item.id) {
// quantity = row.quantity
// }
// }
if (is_xist) {
quantity = is_xist.quantity
}
const listMenu = [...this.state.listMenu]
// console.log("INI COY YYYY QUANTITY " + quantity)
listMenu[index].qty = quantity
this.setState({
listMenu
})
}
handleMin(item, index) {
clearNegatif(item,index){
const list_order_item = this.props.order_item;
for (let i = 0; i < list_order_item.length; index++) {
const row = list_order_item[i];
if (row.quantity !== 0) {
const order_item = {
id: item.id,
name: item.name,
......@@ -154,13 +176,29 @@ class MenuSelection extends React.Component {
}
this.props.reduceQuantityItem(order_item)
}
}
}
handleMin(item, index) {
const list_order_item = this.props.order_item;
let is_xist = list_order_item.find(row => row.id == item.id)
if (is_xist) {
if (is_xist.quantity != 0) {
const order_item = {
id: item.id,
name: item.name,
price: item.price,
}
this.props.reduceQuantityItem(order_item)
let quantity = 0
if (item.qty == 0) {
item.qty = 0
}else{
for (let i = 0; i < list_order_item.length; i++) {
const row = list_order_item[i];
const qty = list_order_item[i];
if (row.id == item.id) {
quantity = row.quantity
}
......@@ -171,6 +209,10 @@ class MenuSelection extends React.Component {
})
}
}
}
// this.clearNegatif(item,index)
// ini buat update list menu
}
......@@ -188,6 +230,7 @@ class MenuSelection extends React.Component {
</View>
<View style={{ flex: 3 }}>
<FlatList
data={this.state.listMenu}
renderItem={({ item, index }) => (
<Item navigation={this.props.navigation}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment