StampItem.1.js
15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
import { useState } from 'react';
import {post,get} from 'axios'
import {Dimensions, View,Text,Image,TextInput,StyleSheet,TouchableOpacity,TouchableHighlight,Alert} from 'react-native'
import * as React from 'react'
import moment from 'moment'
import Modal from 'react-native-modal';
import Options from '../assets/Options.svg'
import Available from '../assets/available.svg'
import {SERVER} from '../common/servername'
import QRCode from 'react-native-qrcode-svg';
import {Share as Share_} from 'react-native'
export default ({ item,myStore, height,update, handleHeight,index,setItemNum,store,user }) => {
const [stamp,setStamp] = React.useState(["","","","","","","","","","","",""])
const [tempHeight,setTempHeight] = React.useState(0)
const [num,setNum] = React.useState("")
const [isMyStore,SetisMyStore] = React.useState(false)
const [Item,setItem] = React.useState([{}])
const [isModalVisible,setIsModalVisible] = React.useState(false)
const [isModalVisible_Present,setIsModalVisible_Present] = React.useState(false)
const [isModalVisible_Use,setIsModalVisible_Use] = React.useState(false)
const [storeData,setStoreData] = React.useState([])
const [maxNum, setMaxNum] = React.useState([])
const [indStampNum,setIndStampNum] = useState([])
const [useNum,setUseNum] = React.useState(0)
React.useEffect(() => {
if(index==2) {
SetisMyStore(myStore.map((e,i) => e.id).indexOf(store.id)<0?false:true)
handleHeight(tempHeight)
}
},[index,tempHeight])
const toggleModal = () => {
if(isModalVisible == true) {
setIsModalVisible(false)
}
else {
setIsModalVisible(true)
}
};
const toggleModal_Present= () => {
if(isModalVisible_Present == true) {
setIsModalVisible_Present(false)
}
else {
setIsModalVisible_Present(true)
}
};
const toggleModal_Use= () => {
if(isModalVisible_Use == true) {
setIsModalVisible_Use(false)
}
else {
setIsModalVisible_Use(true)
}
};
React.useEffect(() => {
if(!item[0]) {
if(myStore.map((e,i) => e.id).indexOf(store.id)>=0) {
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
setItem(res.data.data)
setItemNum(res.data.data.map((e,i) =>e.totalCount-e.totalUsedCount ))
if(res.data.data.length==0) setItemNum(0)
setIndStampNum([...Array(res.data.data.length)].map((el,j) => res.data.data[j].totalCount-res.data.data[j].totalUsedCount))
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
if(res.data.success) {
setStoreData(res.data.data)
setMaxNum([...Array(res.data.data.length)].map(() => 0))
}
})
})
}
else {
get(`http://${SERVER}/stamps/${store.id}`,{UserId:user.id?user.id:7,StoreId:store.id}).then(e => {
setItem(e.data.data)
setItemNum(e.data.data.map((e,i) =>e.totalCount-e.totalUsedCount ))
console.log('read',e.data.data)
if(e.data.data.length==0) setItemNum(0)
setIndStampNum([...Array(e.data.data.length)].map((el,j) => e.data.data[j].totalCount-e.data.data[j].totalUsedCount))
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
if(res.data.success) {
setStoreData(res.data.data)
setMaxNum([...Array(res.data.data.length)].map(() => 0))
}
})
})
}
}
else {
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
if(res.data.success) {
setStoreData(res.data.data)
setMaxNum([...Array(res.data.data.length)].map(() => 0))
}
})
setItem(item)
}
},[])
React.useEffect(() => {
if(!item[0]) {
if(myStore.map((e,i) => e.id).indexOf(store.id)>=0) {
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
setItem(res.data.data)
setItemNum(res.data.data.map((e,i) =>e.totalCount-e.totalUsedCount ))
if(res.data.data.length==0) setItemNum(0)
setIndStampNum([...Array(res.data.data.length)].map((el,j) => res.data.data[j].totalCount-res.data.data[j].totalUsedCount))
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
if(res.data.success) {
setStoreData(res.data.data)
setMaxNum([...Array(res.data.data.length)].map(() => 0))
}
})
})
}
else {
post(`http://${SERVER}/stamps/read`,{UserId:user.id?user.id:7,StoreId:store.id}).then(e => {
setItem(e.data.data)
setItemNum(e.data.data.map((e,i) =>e.totalCount-e.totalUsedCount ))
console.log('read',e.data.data)
if(e.data.data.length==0) setItemNum(0)
setIndStampNum([...Array(e.data.data.length)].map((el,j) => e.data.data[j].totalCount-e.data.data[j].totalUsedCount))
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
if(res.data.success) {
setStoreData(res.data.data)
setMaxNum([...Array(res.data.data.length)].map(() => 0))
}
})
})
}
}
else {
get(`http://${SERVER}/stamps/${store.id}`).then(res => {
if(res.data.success) {
setStoreData(res.data.data)
setMaxNum([...Array(res.data.data.length)].map(() => 0))
}
})
setItem(item)
}
},[update])
React.useEffect(() => {
storeData.forEach((e,i,arr) => {
e.StampConditions.map((el,j,arr1) => {
if(maxNum[i] < el.conditionCount) {
const temp = (el.conditionCount/4).toString().split(".")[1]
setMaxNum([
...maxNum.slice(0,i),
el.conditionCount + (temp=="25"?3:temp=="5"?2:temp=="75"?1:0),
...maxNum.slice(i+1,maxNum.length)
])
}
})
})
},[maxNum])
const onShare = async (e) => {
try {
const result = await Share_.share({
message:
`상가톡에서 스탬프를 이용해주세요!\n[${user.nickname}]님 으로부터 소중한 스탬프가 도착했습니다!\n\n아래 링크를 클릭하여 스탬프를 받아주세요!\n[https://sangatalk.page.link/?link=https://sanggatalk.io/app/stamp?params=${store.id},${e.id},${num}&apn=com.sangatalk]\n\n상가톡 서비스 문의는 아래 링크를 참고해주세요 ^~^\n상가톡 채널 바로가기 : [ http://sanggatalk.io ]\n상가톡 고객센터 바로가기 : [ http://sanggatalk.io/ClilentCenter ]\n`,
}).then(({action,activityType}) => {
if (action === Share_.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share_.dismissedAction) {
// dismissed
}
})
} catch (error) {
alert(error.message);
}
};
return (
<View onLayout={(e) => {
setTempHeight(e.nativeEvent.layout.height)}} style={{paddingLeft:16,paddingRight:16,paddingBottom:24,backgroundColor:"white"}}>
{storeData.map((e,j) => {
return (
<View>
<View>
{isMyStore?<TouchableOpacity onPress={() => toggleModal_Present(true)} style={{position:"absolute",right:16,top:16,padding:5.5,borderWidth:1,borderColor:"#FFD63A"}}>
<Text style={{color:"#FFD63A",fontSize:14,fontWeight:"bold",lineHeight:16}}>
선 물
</Text>
<Text style={{color:"#FFD63A",fontSize:14,fontWeight:"bold",lineHeight:16}}>
하 기
</Text>
</TouchableOpacity>:undefined}
<View style={{paddingTop:13,paddingBottom:11.5}}>
<View style={{flexDirection:"row"}}>
<Text style={{fontSize:15}}>
{store?store.name:Item[0]&&Item[0].storeName}
</Text>
<TouchableOpacity onPress={() => toggleModal()} style={{marginLeft:"auto",marginRight:80}}>
<Text style={{color:"#979292",fontSize:11}}>사용가능 { Math.floor((indStampNum[j]+1) / 10)}</Text>
</TouchableOpacity>
</View>
<View style={{width:"50%"}}>
{e.StampConditions.map((el,i,arr) => {
return (
<Text style={[{color:"#615F5F",fontSize:11},i==0?{marginTop:9}:i==arr.length-1?{marginBottom:15}:{}]}>
{"스탬프 "+ el.conditionCount + "개 모으면 " + el.reward}
</Text>)
})}
<Text style={{color:"#615F5F",fontSize:11,marginTop:9,marginBottom:15}}>
</Text>
</View>
</View>
<View style={{flexWrap:"wrap",flexDirection:"row",justifyContent:"space-between"}}>
{[...Array(maxNum[j])].map((el,i) =>
<View>
<View style={[indStampNum[j]> maxNum-i-1? {width:60,height:60,borderColor:"#615F5F",
borderWidth:1,borderRadius:100,marginRight:14,marginLeft:14,
justifyContent:"center",marginBottom:18,backgroundColor:"#FFD63A"}:{width:60,height:60,borderColor:"#615F5F",
borderWidth:1,borderRadius:100,marginRight:14,marginLeft:14,
justifyContent:"center",marginBottom:18},indStampNum[j] >= e.StampConditions[j].conditionCount && maxNum[j]-i === e.StampConditions[j].conditionCount ? {backgroundColor:"white"}:{}
]}>
{indStampNum[j] >= e.StampConditions[j].conditionCount && maxNum[j]-i === e.StampConditions[j].conditionCount ? <Available onPress={() => {toggleModal()
setUseNum(maxNum[j]-i)}} style={{marginLeft:-3}} width={65}height={65}/>
:
<Text style={ [{textAlign:"center",fontSize:28,fontWeight:"bold",color:"#615F5F"},
indStampNum>maxNum[j]-i-1?{color:"white"}:{},e.StampConditions.map((e,i) => e.conditionCount).indexOf(maxNum[j]-i)>=0?{fontSize:14} :{}]}>
{e.StampConditions.map((e,i) => e.conditionCount).indexOf(maxNum[j]-i)>=0? "사용\n가능":maxNum[j]-i}
</Text>
}
</View>
{Item[maxNum[j]-i-1]?<View style={{margin:"auto",position:"absolute",bottom:3,justifyContent:"center",width:"100%"}}>
<Text style={{fontSize:12,color:"#979292",textAlign:"center",justifyContent:"center"}}>
{moment(Item[maxNum[j]-i-1].createdAt).format("MM.DD")}
</Text>
</View>:undefined}
</View>)}
</View>
<Modal onBackdropPress={() => toggleModal_Present()} isVisible={isModalVisible_Present}>
<View>
<View style={{ width:"90%",backgroundColor:"white",alignSelf:"center",paddingLeft:24,paddingTop:24,paddingBottom:24,paddingRight:24}}>
<Text style={{fontSize:16,color:"#615F5F",fontWeight:"bold",textAlign:"center",marginBottom:3}}>
선물할 스탬프 수량
</Text>
<View style={{marginTop:25,marginBottom:24,flexDirection:"row",marginLeft:"auto",marginRight:"auto"}}>
<TextInput value={num} onChangeText={(e) => {
setNum(e)
}} keyboardType="number-pad" style={{textAlign:"center",width:"33%",paddingTop:9,paddingBottom:9,fontSize:16,fontWeight:"bold",borderColor:"#FFD63A",borderWidth:1,}}/>
<Text style={{alignSelf:"center",marginLeft:16,color:"#615F5F",fontSize:16,fontWeight:"bold"}}>
개
</Text>
</View>
</View>
<View style={{flexDirection:"row",alignSelf:"center"}}>
<TouchableOpacity onPress={() => {toggleModal_Present()
onShare(e)}} style={{paddingTop:12,paddingBottom:15,backgroundColor:"#FFD63A",width:"45%",alignSelf:"center"}}>
<Text style={{textAlign:"center",color:"black",fontSize:14}}>
선물하기
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => toggleModal_Present()} style={{paddingTop:12,paddingBottom:15,backgroundColor:"white",width:"45%",alignSelf:"center"}}>
<Text style={{textAlign:"center",color:"black",fontSize:14}}>
취소
</Text>
</TouchableOpacity>
</View>
</View>
</Modal>
<Modal onBackButtonPress={() => setIsModalVisible(false)} onBackdropPress={() => toggleModal()} isVisible={isModalVisible}>
<View>
<View style={{ width:"80%",backgroundColor:"white",alignSelf:"center",paddingLeft:24,paddingTop:24,paddingBottom:24,paddingRight:24}}>
<Text style={{fontSize:16,color:"#615F5F",fontWeight:"bold",textAlign:"center",marginBottom:25}}>
이 스탬프를 사용하시겠습니까?
</Text>
<Text style={{fontSize:15,color:"black",textAlign:"center"}}>
{store.name}
</Text>
<Text style={{fontSize:15,color:"#615F5F",textAlign:"center",marginTop:9}}>
{e.useCondition}
</Text>
</View>
</View>
<View style={{flexDirection:"row",alignSelf:"center"}}>
<TouchableOpacity onPress={() => {toggleModal()
toggleModal_Use()}} style={{paddingTop:12,paddingBottom:15,backgroundColor:"#FFD63A",width:"40%",alignSelf:"center"}}>
<Text style={{textAlign:"center",color:"black",fontSize:14}}>
사용하기
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => toggleModal()} style={{paddingTop:12,paddingBottom:15,backgroundColor:"white",width:"40%",alignSelf:"center"}}>
<Text style={{textAlign:"center",color:"black",fontSize:14}}>
취소
</Text>
</TouchableOpacity>
</View>
</Modal>
<Modal onBackButtonPress={() => toggleModal_Use()} onBackdropPress={() => toggleModal_Use()} isVisible={isModalVisible_Use}>
<View>
<View style={{ width:"80%",backgroundColor:"white",alignSelf:"center",paddingLeft:24,paddingTop:24,paddingBottom:24,paddingRight:24,justifyContent:"center"}}>
<Text style={{fontSize:16,color:"#615F5F",fontWeight:"bold",textAlign:"center",marginBottom:25}}>
QR코드를 점원에게 제시해주세요.
</Text>
<View style={{alignSelf:"center",marginLeft:"auto",marginRight:"auto"}} >
<QRCode size={120} value={JSON.stringify({url:`http://${SERVER}/stamps/use`,StoreId:`${store.id}`,StampId:`${e.id}`,UserId:`${user.id}`,count:`${useNum}`})}/>
</View>
</View>
</View>
</Modal>
</View>
</View>
)
})}
</View>
)
}
const style = StyleSheet.create({
text:{
color:"#707070",
fontSize:11,
fontWeight:"900"
}
})