Prach Pongpanich пре 2 година
родитељ
комит
d8697cc0d4
5 измењених фајлова са 243 додато и 31 уклоњено
  1. 2 2
      src/api_config.ts
  2. 111 28
      src/components/ProductDetail.vue
  3. 10 1
      src/router/index.ts
  4. 50 0
      src/views/CartPage.vue
  5. 70 0
      src/views/LoginPage.vue

+ 2 - 2
src/api_config.ts

@@ -1,4 +1,4 @@
1
-//export const API_URL = "http://192.168.100.180:8000/api/"
2
-export const API_URL = "http://192.168.116.166:8000/api/"
1
+export const API_URL = "http://192.168.1.56:8000/api/"
2
+//export const API_URL = "http://192.168.116.166:8000/api/"
3 3
 //export const API_URL = "https://kacee.simplico.net/api/"
4 4
 

+ 111 - 28
src/components/ProductDetail.vue

@@ -1,22 +1,20 @@
1 1
 <template>
2 2
   <ion-header>
3 3
     <ion-toolbar>
4
-			<ion-buttons slot="start">
4
+			<ion-buttons>
5 5
       	<ion-button @click="cancel">
6 6
 					<ion-icon :icon="arrowBack"></ion-icon>
7 7
 				</ion-button>
8
-    	</ion-buttons>
9 8
       <ion-title>รายละเอียด</ion-title>
9
+      <ion-button slot="end" id='cartBtn' @click="cancel" router-link="/cart">
10
+        <ion-icon  :icon="cart" slot='start'></ion-icon>
11
+        <ion-badge slot="end" id='bd'>22</ion-badge>
12
+      </ion-button>
13
+    	</ion-buttons>
10 14
     </ion-toolbar>
11 15
   </ion-header>
12 16
   <ion-content class="ion-padding">
13
-    <!--<ion-item>-->
14
-      <!--<ion-label position="stacked">Your name</ion-label>-->
15
-      <!--{{ name }}-->
16 17
 
17
-      <!--<strong>{{ pid }}</strong>-->
18
-      <!--<ion-input v-model="name" placeholder="Your name" label='xx'></ion-input>-->
19
-    <!--</ion-item>-->
20 18
     <template v-if="product">
21 19
       <swiper>
22 20
       <swiper-slide v-for="p in product.product_photos">
@@ -40,27 +38,33 @@
40 38
 					<p><b>SKU</b> {{product.sku}} <b>Qty</b> {{product.qty}}  </p>
41 39
 				</ion-label>
42 40
 			</ion-item>
43
-
44
-			<ion-grid class="ion-padding">
45
-				<ion-row id="open-vars" expand="block" @click="">
41
+			<ion-grid class="ion-padding" id="open-vars" expand="block" @click="">
42
+				<ion-row >
46 43
 					<ion-col>
47 44
 						<ion-label><b>ตัวเลือกสินค้า</b></ion-label>
48 45
 					</ion-col>
49 46
 					<ion-col>
50
-						<ion-label>{{varsTxt}}</ion-label>
47
+						<ion-label v-if="myOrder"><p v-for="(m, i) in myOrder.values">{{myOrder.keys[i]}}: {{m}}</p></ion-label>
48
+						<ion-label v-else>{{varsTxt}}</ion-label>
51 49
 					</ion-col>
52 50
 				</ion-row>
53 51
 						<div v-for="pv in product.product_variance_options" :key='pv.id'>
54 52
 							<ion-row>
55 53
 								<div v-for="(var_value, idx) in pv.var_values">
56
-									<ion-col>
57
-										<ion-img v-if="var_value.image" :src="var_value.image" style="height:40px" class="ion-padding-end" @click="vSelect(var_value, product.prod_vars)"></ion-img>
54
+									<ion-col size="6">
55
+										<ion-img v-if="var_value.image" :src="var_value.image" style="height:40px;" 
56
+														class="ion-padding-end" 
57
+														:class="isSelect(var_value) ? 'img-active' : ''"
58
+														@click=""
59
+										></ion-img>
58 60
 									</ion-col>
59 61
 								</div>
60 62
 							</ion-row>
61 63
 						</div>
62 64
 			</ion-grid>
63 65
 
66
+
67
+
64 68
 			<ion-modal ref="modal" trigger="open-vars" :initial-breakpoint="0.80" :breakpoints="[0, 0.80, 0.5, 0.75]">
65 69
 				<ion-content class="ion-padding">
66 70
 							
@@ -75,22 +79,42 @@
75 79
 
76 80
 							<ion-col>
77 81
 										<h1>{{product.price}}  <s>{{product.list_price}}</s></h1>
78
-										<p><b>Qty</b> {{product.qty}}  </p>
82
+										<p v-if="product.qty"><b>Qty</b> {{product.qty}}  </p>
79 83
 							</ion-col>
80 84
 
81 85
 						</ion-row>
82 86
 
83 87
 						<div v-for="pv in product.product_variance_options" :key='pv.id'>
84
-							<ion-label>{{pv.name}}: {{pv.id}}</ion-label>
88
+							<ion-label>{{pv.name}}</ion-label>
85 89
 							<ion-row>
86 90
 								<div v-for="(var_value, idx) in pv.var_values">
87
-									<ion-col>
88
-										<ion-img v-if="var_value.image" :src="var_value.image" style="height:40px" class="ion-padding-end" @click="vSelect(var_value, product.prod_vars)"></ion-img>
89
-										<ion-button v-else :color="isSelect(var_value)" @click="vSelect(var_value, product.prod_vars)">{{var_value.value}}</ion-button>
91
+									<ion-col size="6">
92
+										<ion-img v-if="var_value.image" :src="var_value.image" style="height:40px;" :class="isSelect(var_value) ? 'img-active' : ''" class="ion-padding-end" @click="vSelect(var_value, product.prod_vars)"></ion-img>
93
+										<ion-button v-else :color=" isSelect(var_value) ? 'primary' : 'light' " @click="vSelect(var_value, product.prod_vars)">{{var_value.value}}</ion-button>
90 94
 									</ion-col>
91 95
 								</div>
92 96
 							</ion-row>
93 97
 						</div>
98
+						<hr/>
99
+							<ion-item lines="none">
100
+								<ion-label>จำนวน</ion-label>
101
+								<ion-button  slot="end" @click="stepQty(false)">
102
+									<ion-icon slot="icon-only" :icon="removeOutline"></ion-icon>
103
+								</ion-button>
104
+							 <ion-input
105
+									slot="end"
106
+									aria-label="" 
107
+									class="custom"
108
+									:maxlength="3"
109
+									v-model="qty"
110
+								></ion-input>
111
+								<ion-button slot="end" @click="stepQty(true)">
112
+									<ion-icon slot="icon-only" :icon="addOutline"></ion-icon>
113
+								</ion-button>
114
+							</ion-item>
115
+							<ion-item lines="none">
116
+								<ion-button  color="danger">Add to cart</ion-button>
117
+							</ion-item>
94 118
 					</ion-grid>
95 119
 				</ion-content>
96 120
 			</ion-modal>
@@ -130,9 +154,10 @@ import {
130 154
 	IonListHeader,
131 155
   IonModal,
132 156
   IonAvatar,
157
+	IonBadge
133 158
 } from '@ionic/vue';
134 159
 
135
-import { arrowBack } from 'ionicons/icons';
160
+import { arrowBack, removeOutline, addOutline, cart } from 'ionicons/icons';
136 161
 import { VueShowdown } from 'vue-showdown';
137 162
 import { ReadMore } from 'vue-read-more';
138 163
 import { ref, onMounted } from 'vue'
@@ -159,6 +184,8 @@ let myItem = ref([]);
159 184
 let myOrder	= ref(null);
160 185
 let varsTxt = ref("");
161 186
 
187
+const qty = ref(0)
188
+
162 189
 //console.log(pid)
163 190
 
164 191
 let name = ref("xxx")
@@ -200,17 +227,37 @@ function vSelect(var_value, prod_vars){
200 227
 }
201 228
 
202 229
 function isSelect(v){
203
-	console.log('SSSSSS',myItem.value);
204
-	console.log(v);
205
-	let rs = myItem.value.findIndex(({var_value}) => var_value === v.value);
230
+	//console.log('SSSSSS',myItem.value);
231
+	//console.log('vvvv',v);
232
+	let rs = myItem.value.findIndex((el) => el.var_value === v.value && el.product_variance === v.product_variance);
206 233
 	if(rs >= 0) {
207 234
 		console.log('my found')
208
-		return 'primary';
235
+		return true;
209 236
 	} else {
210
-		return 'light'
237
+		return false;
211 238
 	}
212 239
 }
213 240
 
241
+function stepQty(isUp) {
242
+
243
+	if(isUp && product.value['qty'] && qty.value < product.value['qty']) {
244
+		qty.value++
245
+		console.log('step up')
246
+	}
247
+
248
+	if(!isUp && qty.value > 0 ) {
249
+		qty.value--
250
+	}
251
+		console.log('step down')
252
+}
253
+
254
+function addCart() {
255
+}
256
+
257
+function goCartPage() {
258
+}
259
+
260
+
214 261
 onMounted(async () => {
215 262
 //onIonViewWillEnter(() => {
216 263
   console.log("on mounted")
@@ -227,12 +274,48 @@ onMounted(async () => {
227 274
   let sd  = truncateMarkdown(res.data.description, { limit: 300, ellipsis: true })
228 275
   short_desc.value = marked(sd)
229 276
 
230
-	for(let pv of product.value.product_variance_options){
231
-			varsTxt.value = varsTxt.value + ' ' + pv.var_values.length + ' ' + pv.name;
232
-			console.log(pv.name.toString());
277
+	let i = 0
278
+	for( let pv of product.value.product_variance_options ){
279
+		if(i == 0){
280
+			myItem.value.push({ 'product_variance': pv.var_values[0].product_variance, 'var_value' : pv.var_values[0].value});
281
+			product.value['cover'] = pv.var_values[0].image;
282
+			console.log('img = ',pv.var_values[0].image)
283
+			console.log(pv);
284
+		}
285
+		i++
286
+		varsTxt.value = varsTxt.value + ' ' + pv.var_values.length + ' ' + pv.name;
287
+		console.log(pv.name.toString());
233 288
 	}
289
+
234 290
 	console.log(varsTxt)
235 291
   //console.log(description.value)
236 292
 })
237 293
 
238 294
 </script>
295
+
296
+
297
+<style>
298
+	.img-active {
299
+		 border: 2px solid red;
300
+	}
301
+
302
+	hr {
303
+		margin-top: 1rem;
304
+		margin-bottom: 1rem;
305
+		border: 0;
306
+		border-top: 1px solid rgba(0, 0, 0, 0.1);
307
+	}
308
+
309
+  ion-input.custom {
310
+
311
+    background: #d9d9d9;
312
+    color: #000;
313
+		width: 50px;
314
+		height: 50px;
315
+		text-align: center;
316
+    padding-bottom: 1px;
317
+    padding-end: 1px;
318
+    padding-start: 1px;
319
+    padding-top: 1px;
320
+  }
321
+</style>

+ 10 - 1
src/router/index.ts

@@ -3,6 +3,7 @@ import { RouteRecordRaw } from 'vue-router';
3 3
 import TabsPage from '../views/TabsPage.vue';
4 4
 import Tab2Page from '../views/TabsPage.vue';
5 5
 import HelloPage from '../views/HelloPage.vue';
6
+import CartPage from '../views/CartPage.vue';
6 7
 
7 8
 const routes: Array<RouteRecordRaw> = [
8 9
   {
@@ -14,6 +15,10 @@ const routes: Array<RouteRecordRaw> = [
14 15
     component: HelloPage
15 16
   },
16 17
   {
18
+    path: '/cart', 
19
+    component: CartPage
20
+  },
21
+  {
17 22
     path: '/tabs/',
18 23
     component: TabsPage,
19 24
     children: [
@@ -48,7 +53,11 @@ const routes: Array<RouteRecordRaw> = [
48 53
       {
49 54
         path: 'tab2/prod_list/:cat',
50 55
         component: () => import('@/views/ProductListPage.vue')
51
-      }
56
+      },
57
+      {
58
+        path: '/login',
59
+        component: () => import('@/views/LoginPage.vue')
60
+      },
52 61
     ]
53 62
   }
54 63
 ]

+ 50 - 0
src/views/CartPage.vue

@@ -0,0 +1,50 @@
1
+<template>
2
+<ion-page>
3
+  <ion-header>
4
+    <ion-toolbar>
5
+      <ion-buttons slot="start">
6
+        <ion-back-button></ion-back-button>
7
+      </ion-buttons>
8
+      <ion-title>รถเข็น</ion-title>
9
+    </ion-toolbar>
10
+  </ion-header>
11
+	<ion-content class='ion-padding'>
12
+		<ion-item>
13
+			<ion-thumbnail slot="start">
14
+				<img alt="Silhouette of mountains" src="https://ionicframework.com/docs/img/demos/thumbnail.svg" />
15
+			</ion-thumbnail>
16
+			<ion-label>Item Thumbnail</ion-label>
17
+		</ion-item>
18
+	</ion-content>
19
+</ion-page>
20
+</template>
21
+
22
+<script setup lang="ts">
23
+import { 
24
+	IonItem,
25
+	IonLabel,
26
+	IonThumbnail,
27
+	IonButtons,
28
+	IonButton,
29
+	IonHeader,
30
+	IonToolbar,
31
+	IonPage,
32
+	IonTitle,
33
+	IonContent,
34
+	IonBackButton,
35
+	onIonViewWillEnter,
36
+
37
+} from '@ionic/vue';
38
+
39
+import axios from 'axios';
40
+import { API_URL } from '../api_config';
41
+import { useRoute } from 'vue-router';
42
+import { ref, onMounted } from 'vue'
43
+
44
+const route = useRoute();
45
+
46
+onIonViewWillEnter( async() => {
47
+})
48
+	
49
+</script>
50
+

+ 70 - 0
src/views/LoginPage.vue

@@ -0,0 +1,70 @@
1
+<template>
2
+  <ion-page>
3
+    <form @submit.prevent="handleLogin">
4
+      <ion-card>
5
+        <ion-item>
6
+          <h3>Please Sign In!</h3>
7
+        </ion-item>
8
+				<ion-item>
9
+					<ion-input
10
+						ref="input"
11
+						type="text"
12
+						v-model="user"
13
+						label="Username"
14
+						label-placement="floating"
15
+					></ion-input>
16
+				</ion-item>
17
+
18
+				<ion-item>
19
+					<ion-input
20
+						ref="input"
21
+						v-model="pass"
22
+						type="password"
23
+						label="Password"
24
+						label-placement="floating"
25
+					></ion-input>
26
+				</ion-item>
27
+
28
+        <ion-item>
29
+          <ion-button type="submit" shape="round">
30
+            Sign In
31
+            <ion-icon slot="end" :icon="logIn"></ion-icon>
32
+          </ion-button>
33
+        </ion-item>
34
+        <ion-item>
35
+          <p>Or</p>
36
+        </ion-item>
37
+        <ion-item>
38
+          <ion-button type="button" shape="round" router-link="/signup">
39
+            Sign Up
40
+            <ion-icon slot="end" :icon="personAdd"></ion-icon>
41
+          </ion-button>
42
+        </ion-item>
43
+      </ion-card>
44
+    </form>
45
+  </ion-page>
46
+</template>
47
+
48
+<script setup lang="ts">
49
+import { IonPage, IonCard, IonItem, IonLabel, IonButton, IonInput, alertController, IonIcon } from '@ionic/vue'
50
+import { logIn, personAdd } from 'ionicons/icons';
51
+import { ref, onMounted } from 'vue'
52
+
53
+
54
+import { API_URL } from '../api_config';
55
+import axios from 'axios';
56
+
57
+
58
+
59
+const user =  ref()
60
+const pass =  ref()
61
+
62
+function handleLogin() {
63
+	let login = {"username": user.value, "password": pass.value}
64
+  // POST request using axios with async/await
65
+//  const res = axios.post(API_URL+`mylogin`, login);
66
+  const res = axios.get(`http://192.168.1.56:8000/cart/fn/`);
67
+	console.log(res)
68
+}
69
+
70
+</script>