Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
rich-maker
Commits
d4207d12
Commit
d4207d12
authored
Aug 04, 2021
by
Soo Hyun Kim
Browse files
0804 select form 머지 전 푸쉬
parent
45a9945d
Changes
4
Hide whitespace changes
Inline
Side-by-side
PostMoney.js
View file @
d4207d12
...
...
@@ -9,17 +9,17 @@ import moneyApi from './db/postMoney.api';
import
{
getDate
}
from
'
./utils/dateFunction
'
const
INIT_ASSETSTYPE
=
{
id
:
0
,
id
:
1
,
value
:
''
,
}
const
INIT_CATEGORY
=
{
id
:
0
,
id
:
1
,
value
:
''
,
}
const
INIT_SUBCATEGORY
=
{
id
:
0
,
id
:
1
,
value
:
''
,
foreign_id
:
0
,
}
...
...
@@ -28,7 +28,7 @@ const PostMoney = ({navigation}) => {
const
[
selectedIndex
,
setSelectedIndex
]
=
useState
(
0
)
const
[
date
,
setDate
]
=
useState
(
getDate
())
const
[
contents
,
setContents
]
=
useState
(
''
)
const
[
price
,
setPrice
]
=
useState
(
0
)
const
[
price
,
setPrice
]
=
useState
(
''
)
const
[
asset_type
,
setAsset_type
]
=
useState
([])
const
[
selected_asset_type
,
setSelected_asset_type
]
=
useState
(
INIT_ASSETSTYPE
)
const
[
selected_deposit_asset_type
,
setSelected_deposit_asset_type
]
=
useState
(
INIT_ASSETSTYPE
)
...
...
@@ -36,6 +36,8 @@ const PostMoney = ({navigation}) => {
const
[
selected_cat
,
setSelected_cat
]
=
useState
(
INIT_CATEGORY
)
const
[
subcategories
,
setSubcategories
]
=
useState
([])
const
[
selected_subcat
,
setSelected_subcat
]
=
useState
(
INIT_SUBCATEGORY
)
const
[
success
,
setSuccess
]
=
useState
(
false
)
useEffect
(()
=>
{
loadCat
()
...
...
@@ -47,7 +49,7 @@ const PostMoney = ({navigation}) => {
const
initData
=
()
=>
{
setDate
(
getDate
())
setContents
(
''
)
setPrice
(
0
)
setPrice
(
''
)
setSelected_asset_type
(
INIT_ASSETSTYPE
)
setSelected_cat
(
INIT_CATEGORY
)
setSelected_subcat
(
INIT_SUBCATEGORY
)
...
...
@@ -59,15 +61,20 @@ const PostMoney = ({navigation}) => {
'
| contents:
'
,
contents
,
'
| price:
'
,
price
,
'
| selected_asset_type:
'
,
selected_asset_type
.
id
,
(
selectedIndex
===
2
?
{
[
'
selected_deposit_asset_type
'
]:
selected_deposit_asset_type
.
id
}
:
null
),
'
| 이동일 때
'
,
(
selectedIndex
===
2
?
{
[
'
selected_deposit_asset_type
'
]:
selected_deposit_asset_type
.
id
}
:
null
),
'
| selected_cat:
'
,
selected_cat
.
id
,
'
| selected_subcat:
'
,
selected_subcat
.
id
)
const
insertData
=
async
()
=>
{
try
{
let
type
=
selectedIndex
+
1
;
const
result
=
await
moneyApi
.
insertMoney
([
type
,
date
,
contents
,
price
,
selected_asset_type
.
id
,
selected_cat
.
id
,
selected_subcat
.
id
])
console
.
log
(
result
)
if
(
type
===
3
)
{
await
moneyApi
.
insertMoney
([
type
,
date
,
contents
,
-
price
,
selected_asset_type
.
id
,
selected_cat
.
id
,
selected_subcat
.
id
])
await
moneyApi
.
insertMoney
([
type
,
date
,
contents
,
price
,
selected_deposit_asset_type
.
id
,
selected_cat
.
id
,
selected_subcat
.
id
])
}
else
{
await
moneyApi
.
insertMoney
([
type
,
date
,
contents
,
price
,
selected_asset_type
.
id
,
selected_cat
.
id
,
selected_subcat
.
id
])
}
setSuccess
(
true
)
}
catch
(
error
)
{
console
.
log
(
'
error in insert data
'
,
error
)
}
...
...
@@ -110,6 +117,11 @@ const PostMoney = ({navigation}) => {
navigation
.
navigate
(
'
EditOption
'
,
0
)
}
if
(
success
){
initData
()
setSuccess
(
false
)
}
return
(
<
View
>
<
View
>
...
...
@@ -125,6 +137,7 @@ const PostMoney = ({navigation}) => {
<
InputBox
inputTitle
=
"
내용
"
placeholder
=
"
내용을 입력하세요
"
value
=
{
contents
}
onChangeText
=
{
(
contents
)
=>
setContents
(
contents
)
}
...
...
@@ -133,6 +146,7 @@ const PostMoney = ({navigation}) => {
<
InputBox
inputTitle
=
"
금액
"
placeholder
=
"
금액을 입력하세요
"
value
=
{
price
}
onChangeText
=
{
(
price
)
=>
setPrice
(
price
)
}
...
...
components/SelectForm.js
View file @
d4207d12
...
...
@@ -3,7 +3,7 @@ import { StyleSheet, TouchableOpacity, TouchableWithoutFeedback, View, Text, Mod
import
MaterialCommunityIcons
from
'
react-native-vector-icons/MaterialCommunityIcons
'
;
const
INIT_SUBCATEGORY
=
{
id
:
0
,
id
:
1
,
value
:
''
,
foreign_id
:
0
,
}
...
...
@@ -60,6 +60,7 @@ const SelectForm = ({
onSubValueChange
(
INIT_SUBCATEGORY
)
modalClose
()
}
else
{
newOption
.
unshift
({
id
:
1
,
value
:
'
기타
'
})
if
(
newOption
.
length
%
3
==
0
)
{
setSubOption
(
newOption
)
setSubOptionShow
(
true
)
...
...
db/postMoney.api.js
View file @
d4207d12
...
...
@@ -9,7 +9,7 @@ const insertMoney = async (moneyData) => {
return
new
Promise
((
resolve
,
reject
)
=>
{
db
.
transaction
((
tx
)
=>
{
console
.
log
(
"
데이터 삽입하기
"
);
tx
.
executeSql
(
'
INSERT INTO Money (type, date, contents, price, asset
_type
, category, subcategory) VALUES (?,?,?,?,?,?,?);
'
,
tx
.
executeSql
(
'
INSERT INTO Money (type
_id
, date, contents, price, asset
s_id
, category
_id
, subcategory
_id
) VALUES (?,?,?,?,?,?,?);
'
,
moneyData
,
(
error
)
=>
console
.
log
(
error
))
resolve
(
'
데이터 삽입 완료
'
);
...
...
@@ -25,7 +25,8 @@ const selectCategories = async (type_id) => {
const
[
txn
,
results
]
=
await
tx
.
executeSql
(
`SELECT * FROM categories WHERE type_id=
${
type_id
}
`
);
console
.
log
(
'
item length
'
,
results
.
rows
.
length
);
const
temp
=
[];
for
(
let
i
=
0
;
i
<
3
*
(
Math
.
ceil
(
results
.
rows
.
length
/
3
));
i
++
)
{
temp
.
push
({
id
:
1
,
value
:
'
기타
'
});
for
(
let
i
=
0
;
i
<
3
*
(
Math
.
ceil
((
results
.
rows
.
length
+
1
)
/
3
))
-
1
;
i
++
)
{
if
(
i
<
results
.
rows
.
length
){
const
tempId
=
results
.
rows
.
item
(
i
).
category_id
;
const
tempName
=
results
.
rows
.
item
(
i
).
category_name
;
...
...
@@ -68,7 +69,7 @@ const selectAssetsType = async () => {
const
[
txn
,
results
]
=
await
tx
.
executeSql
(
'
SELECT * FROM assets_type
'
);
console
.
log
(
'
item length
'
,
results
.
rows
.
length
);
const
temp
=
[];
for
(
let
i
=
0
;
i
<
3
*
(
Math
.
ceil
(
results
.
rows
.
length
/
3
));
i
++
)
{
for
(
let
i
=
0
;
i
<
3
*
(
Math
.
ceil
(
(
results
.
rows
.
length
)
/
3
));
i
++
)
{
if
(
i
<
results
.
rows
.
length
){
const
tempId
=
results
.
rows
.
item
(
i
).
assets_id
;
const
tempName
=
results
.
rows
.
item
(
i
).
assets_name
;
...
...
utils/dateFunction.js
View file @
d4207d12
export
function
getDate
()
{
const
date
=
new
Date
();
const
tempY
=
date
.
getFullYear
();
let
tempM
=
date
.
getMonth
();
let
tempM
=
date
.
getMonth
()
+
1
;
tempM
=
tempM
>
9
?
tempM
:
"
0
"
+
tempM
;
let
tempD
=
date
.
getDate
();
tempD
=
tempD
>
9
?
tempD
:
"
0
"
+
tempD
;
console
.
log
(
`
${
tempY
}
-
${
tempM
}
-
${
tempD
}
`
)
return
`
${
tempY
}
-
${
tempM
}
-
${
tempD
}
`
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment