Parcourir la Source

select variance

Prach Pongpanich il y a 2 ans
Parent
commit
d564a5ade5
3 fichiers modifiés avec 140 ajouts et 48 suppressions
  1. 6 35
      android/app/src/main/AndroidManifest.xml
  2. 2 1
      src/api_config.ts
  3. 132 12
      src/components/ProductDetail.vue

+ 6 - 35
android/app/src/main/AndroidManifest.xml

@@ -1,44 +1,15 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
-    package="io.ionic.starter">
4
-
5
-    <application
6
-        android:allowBackup="true"
7
-        android:icon="@mipmap/ic_launcher"
8
-        android:label="@string/app_name"
9
-        android:roundIcon="@mipmap/ic_launcher_round"
10
-        android:supportsRtl="true"
11
-        android:theme="@style/AppTheme"
12
-        android:usesCleartextTraffic="true"
13
-      >
14
-
15
-        <activity
16
-            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
17
-            android:name="io.ionic.starter.MainActivity"
18
-            android:label="@string/title_activity_main"
19
-            android:theme="@style/AppTheme.NoActionBarLaunch"
20
-            android:launchMode="singleTask"
21
-            android:exported="true">
22
-
1
+<?xml version='1.0' encoding='utf-8'?>
2
+<manifest package="io.ionic.starter" xmlns:android="http://schemas.android.com/apk/res/android">
3
+    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true">
4
+        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:exported="true" android:label="@string/title_activity_main" android:launchMode="singleTask" android:name="io.ionic.starter.MainActivity" android:theme="@style/AppTheme.NoActionBarLaunch">
23 5
             <intent-filter>
24 6
                 <action android:name="android.intent.action.MAIN" />
25 7
                 <category android:name="android.intent.category.LAUNCHER" />
26 8
             </intent-filter>
27
-
28 9
         </activity>
29
-
30
-        <provider
31
-            android:name="androidx.core.content.FileProvider"
32
-            android:authorities="${applicationId}.fileprovider"
33
-            android:exported="false"
34
-            android:grantUriPermissions="true">
35
-            <meta-data
36
-                android:name="android.support.FILE_PROVIDER_PATHS"
37
-                android:resource="@xml/file_paths"></meta-data>
10
+        <provider android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true" android:name="androidx.core.content.FileProvider">
11
+            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
38 12
         </provider>
39 13
     </application>
40
-
41
-    <!-- Permissions -->
42
-
43 14
     <uses-permission android:name="android.permission.INTERNET" />
44 15
 </manifest>

+ 2 - 1
src/api_config.ts

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

+ 132 - 12
src/components/ProductDetail.vue

@@ -1,13 +1,12 @@
1 1
 <template>
2 2
   <ion-header>
3 3
     <ion-toolbar>
4
-      <ion-buttons slot="start">
5
-        <ion-button color="medium" @click="cancel">Cancel</ion-button>
6
-      </ion-buttons>
7
-      <ion-title>Modal</ion-title>
8
-      <ion-buttons slot="end">
9
-        <ion-button @click="confirm">Confirm</ion-button>
10
-      </ion-buttons>
4
+			<ion-buttons slot="start">
5
+      	<ion-button @click="cancel">
6
+					<ion-icon :icon="arrowBack"></ion-icon>
7
+				</ion-button>
8
+    	</ion-buttons>
9
+      <ion-title>รายละเอียด</ion-title>
11 10
     </ion-toolbar>
12 11
   </ion-header>
13 12
   <ion-content class="ion-padding">
@@ -33,7 +32,69 @@
33 32
             </ion-col>
34 33
         </ion-row>
35 34
       </ion-grid>
36
-      <h1>{{ product.name }} {{ product.id }}</h1>
35
+
36
+      <h1>{{ product.name }}</h1>
37
+			<ion-item>
38
+				<ion-label color="danger">
39
+					<h1>{{product.price}}  <s>{{product.list_price}}</s></h1>
40
+					<p><b>SKU</b> {{product.sku}} <b>Qty</b> {{product.qty}}  </p>
41
+				</ion-label>
42
+			</ion-item>
43
+
44
+			<ion-grid class="ion-padding">
45
+				<ion-row id="open-vars" expand="block" @click="">
46
+					<ion-col>
47
+						<ion-label><b>ตัวเลือกสินค้า</b></ion-label>
48
+					</ion-col>
49
+					<ion-col>
50
+						<ion-label>{{varsTxt}}</ion-label>
51
+					</ion-col>
52
+				</ion-row>
53
+						<div v-for="pv in product.product_variance_options" :key='pv.id'>
54
+							<ion-row>
55
+								<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>
58
+									</ion-col>
59
+								</div>
60
+							</ion-row>
61
+						</div>
62
+			</ion-grid>
63
+
64
+			<ion-modal ref="modal" trigger="open-vars" :initial-breakpoint="0.80" :breakpoints="[0, 0.80, 0.5, 0.75]">
65
+				<ion-content class="ion-padding">
66
+							
67
+					<ion-grid class="ion-padding">
68
+						<ion-row>
69
+							<ion-col size="auto">
70
+								<div style="width: 100px">
71
+									<img v-if="product.cover" :src="product.cover" />
72
+									<img v-else  src="https://ionicframework.com/docs/img/demos/thumbnail.svg" />
73
+								</div>
74
+							</ion-col>
75
+
76
+							<ion-col>
77
+										<h1>{{product.price}}  <s>{{product.list_price}}</s></h1>
78
+										<p><b>Qty</b> {{product.qty}}  </p>
79
+							</ion-col>
80
+
81
+						</ion-row>
82
+
83
+						<div v-for="pv in product.product_variance_options" :key='pv.id'>
84
+							<ion-label>{{pv.name}}: {{pv.id}}</ion-label>
85
+							<ion-row>
86
+								<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>
90
+									</ion-col>
91
+								</div>
92
+							</ion-row>
93
+						</div>
94
+					</ion-grid>
95
+				</ion-content>
96
+			</ion-modal>
97
+
37 98
       <!--
38 99
         {{ readmore }} -->
39 100
       <ion-text v-html="short_desc" v-if="!readmore" />
@@ -63,9 +124,15 @@ import {
63 124
   IonText,
64 125
   modalController,
65 126
   onIonViewWillEnter, 
66
-  IonThumbnail
127
+  IonThumbnail,
128
+	IonIcon,
129
+	IonList,
130
+	IonListHeader,
131
+  IonModal,
132
+  IonAvatar,
67 133
 } from '@ionic/vue';
68 134
 
135
+import { arrowBack } from 'ionicons/icons';
69 136
 import { VueShowdown } from 'vue-showdown';
70 137
 import { ReadMore } from 'vue-read-more';
71 138
 import { ref, onMounted } from 'vue'
@@ -88,6 +155,10 @@ let description = ref(null)
88 155
 let short_desc = ref(null)
89 156
 let readmore = ref(false)
90 157
 
158
+let myItem = ref([]);
159
+let myOrder	= ref(null);
160
+let varsTxt = ref("");
161
+
91 162
 //console.log(pid)
92 163
 
93 164
 let name = ref("xxx")
@@ -97,6 +168,49 @@ function cancel(){
97 168
 function confirm(){
98 169
   return modalController.dismiss(name.value, 'confirm');
99 170
 }
171
+
172
+function vSelect(var_value, prod_vars){
173
+
174
+	let rs = myItem.value.findIndex(({product_variance}) => product_variance === var_value.product_variance);
175
+	if (rs >= 0){
176
+	  myItem.value[rs] = { 'product_variance': var_value.product_variance, 'var_value' : var_value.value};
177
+	} else {
178
+		myItem.value.push({ 'product_variance': var_value.product_variance, 'var_value' : var_value.value});
179
+	}
180
+	console.log(rs);
181
+	let vars = myItem.value.map((e) => e.var_value);
182
+	console.log(myItem);
183
+	console.log(vars);
184
+	let stock = prod_vars.find(({values}) => JSON.stringify(values.sort()) === JSON.stringify(vars.sort()));
185
+	console.log(stock);
186
+	if(var_value.image) {
187
+		product.value['cover'] = var_value.image;
188
+	}
189
+	if(stock){
190
+		console.log('stock found');
191
+		myOrder.value = stock;
192
+		product.value['qty'] = stock.qty;
193
+		product.value['price'] = stock.price;
194
+		product.value['list_price'] = stock.list_price;
195
+		product.value['sku'] = stock.sku;
196
+		product.value['currency'] = stock.currency;
197
+	}
198
+
199
+  return "ok";
200
+}
201
+
202
+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);
206
+	if(rs >= 0) {
207
+		console.log('my found')
208
+		return 'primary';
209
+	} else {
210
+		return 'light'
211
+	}
212
+}
213
+
100 214
 onMounted(async () => {
101 215
 //onIonViewWillEnter(() => {
102 216
   console.log("on mounted")
@@ -105,14 +219,20 @@ onMounted(async () => {
105 219
   product.value = res.data
106 220
   pid.value  = props.pid
107 221
   console.log("description")
108
-  console.log(description)
222
+  //console.log(description)
109 223
   //readmore(description)
110
-  console.log(res.data)
224
+  //console.log(res.data)
111 225
   description.value = marked(res.data.description)
112 226
   short_desc.value = truncateMarkdown(res.data.description, { limit: 300, ellipsis: true })
113 227
   let sd  = truncateMarkdown(res.data.description, { limit: 300, ellipsis: true })
114 228
   short_desc.value = marked(sd)
115
-  console.log(description.value)
229
+
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());
233
+	}
234
+	console.log(varsTxt)
235
+  //console.log(description.value)
116 236
 })
117 237
 
118 238
 </script>