-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderCompleted.html
228 lines (195 loc) · 11.6 KB
/
OrderCompleted.html
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
<!DOCTYPE html>
<html lang="th">
<head>
<script src="./library/utils.js"></script>
<link rel="stylesheet" href="https://phurich.github.io/phuthon/library/style.css">
<html-header></html-header>
</head>
<body>
<img src="./library/logo600px.png" alt="ภูธรเดลิเวอรี่">
<div id="dialog-overlay" class="dialog-overlay"></div>
<div id="dialog-sky" class="setting-sky sky">
<div class="satellite"></div>
</div>
<form id="completeOrder" name="completeOrder" method="post" accept-charset="UTF-8">
<div class="flexRow">
<label class="col-5">🛵รูปแบบจัดส่ง</label>
<div>
<div>
<input name="delivery" id="delivery_0" type="radio" value="มีผู้รับ" onchange="handleDeliveryChange();">
<label for="delivery_0">มีผู้รับ</label>
</div>
<div>
<input name="delivery" id="delivery_1" type="radio" value="วางหรือห้อยไว้" onchange="handleDeliveryChange();">
<label for="delivery_1">วางหรือห้อยไว้ (แนบหลักฐานจัดส่ง)</label>
</div>
</div>
</div>
<div class="flexRow">
<label class="col-5">💵วิธีชำระเงิน</label>
<div>
<div>
<input name="payment" id="payment_0" type="radio" onchange="document.getElementById('transferBlock').style.display= 'none';" value="เงินสดเต็มจำนวน">
<label for="payment_0">เงินสด</label>
</div>
<div>
<input name="payment" id="payment_1" type="radio" onchange="document.getElementById('transferBlock').style.display= 'none';" value="โอนเต็มจำนวน">
<label for="payment_1">โอน</label>
</div>
<div>
<input name="payment" id="payment_2" type="radio" onchange="document.getElementById('transferBlock').style.display= 'flex';document.getElementById('transfer').value = ''; document.getElementById('transfer').focus();" value="เงินสดและโอน">
<label for="payment_2">เงินสดและโอน</label>
</div>
</div>
</div>
<div id="transferBlock" class="flexRow" style="display: none;">
<label for="transfer" class="col-5">💰ระบุยอดโอน</label>
<div class="col-7">
<input id="transfer" name="transfer" style="width: 100%" type="text" pattern="^\d[\d\.\+\-]*" value="0" aria-describedby="transferHelpBlock">
<span id="transferHelpBlock" class="form-text text-muted">ระบุยอดที่ลูกค้าต้องโอน</span>
</div>
</div>
<div class="flexRow">
<label for="location" class="col-5">🎯พิกัดจัดส่ง <button type="button" class="button button-info button-lg button-space" onclick="getLocation();">🛰️ขอพิกัด</button> </label>
<div class="col-7">
<input id="location" name="location" style="width: 100%" type="text" aria-describedby="locationHelpBlock" readonly>
<span id="locationHelpBlock" class="form-text text-muted">📡 เปิดฟังก์ชั่น GPS เพื่อพิกัดที่แม่นยำ 🛰️</span>
</div>
</div>
<div class="row justify-content-center">
<div class="file-input-container">
<label for="fileInput" id="fileLabel" class="button button-info button-lg">📸 หลักฐานจัดส่ง (jpg)</label>
<input type="file" id="fileInput" name="photo" accept="image/jpeg" capture="environment">
</div>
</div>
<input type="hidden" id="rider" name="rider" value="">
<input type="hidden" id="row" name="row" value="">
<input type="hidden" id="tel" name="tel" value="">
<input type="hidden" id="imageURL" name="imageURL" value="">
<canvas id="canvas" style="display:none;"></canvas>
<img id="photo" alt="Captured Photo" style="display:none;">
<div class="row justify-content-center">
<button name="formSubmit" type="submit" class="button button-primary button-lg">📤ส่งข้อมูล</button>
</div>
<div class="row justify-content-left">
<button name="previous" type="button" class="button button-warning button-lg" onclick="goToUrl();">⏪รับแล้ว💨</button>
</div>
</form>
<script>
document.onreadystatechange = () => {
if (document.readyState === "complete") {
let queryString = decodeURIComponent(window.location.search);
queryString = queryString.replace("?liff.state=", "");
const params = new Proxy(new URLSearchParams(queryString), {
get: (searchParams, prop) => searchParams.get(prop),
});
document.getElementById("rider").value = params.rider;
document.getElementById("row").value = params.row;
document.getElementById("tel").value = params.tel;
document.getElementById('completeOrder').action = currentActionUrl;
//document.getElementById('completeOrder').action = testActionUrl;
getLocation();
}
};
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, getLocationError, { timeout: 4000, enableHighAccuracy: true });
} else {
getLocationError();
}
}
function getLocationError() {
document.getElementById("location").value = "กรุณาเปิดฟังก์ชั่น GPS";
}
function showPosition(position) {
if (document.getElementById("location").value === position.coords.latitude + "," + position.coords.longitude) {
document.getElementById('locationHelpBlock').innerText = "🎯 ยืนยันค่าพิกัดเดิม";
} else {
document.getElementById("location").value = position.coords.latitude + "," + position.coords.longitude;
document.getElementById('locationHelpBlock').innerText = "📡 เปิดฟังก์ชั่น GPS เพื่อพิกัดที่แม่นยำ 🛰️";
}
}
document.getElementById('fileInput').addEventListener('change', mergeImagesVertically);
document.getElementById('completeOrder').addEventListener('submit', handleFormSubmit);
function validateForm() {
let errorMessage = "";
// Validate delivery method
const delivery = document.querySelector('input[name="delivery"]:checked');
if (!delivery) {
errorMessage += "กรุณาเลือกรูปแบบจัดส่ง\n";
}
// Validate payment method
const payment = document.querySelector('input[name="payment"]:checked');
if (!payment) {
errorMessage += "กรุณาเลือกวิธีชำระเงิน\n";
}
// Validate transfer amount if "เงินสดและโอน" is selected
if (payment && payment.id === "payment_2") {
const transferAmount = document.getElementById("transfer").value;
const transferAmountPattern = /^[+-]?(\d+(\.\d{1,2})?)([+-]\d+(\.\d+)?)*$/;
if (transferAmount === "" || !transferAmountPattern.test(transferAmount)) {
errorMessage += "กรุณาระบุยอดโอนที่ถูกต้อง\n";
}
}
// Validate location
/*const location = document.getElementById("location").value;
if (location === "" || location === "กรุณาเปิดฟังก์ชั่น GPS") {
errorMessage += "กรุณาเปิดใช้งาน GPS เพื่อรับพิกัด\n";
}*/
// Validate photo for "วางหรือห้อยไว้" delivery
if (document.getElementById("delivery_1").checked) {
const fileInput = document.getElementById('fileInput');
if (fileInput.files.length === 0) {
errorMessage += "กรุณาแนบหลักฐานจัดส่ง";
}
}
// Display error messages
if (errorMessage) {
swalShowError(errorMessage);
return false; // Prevent form submission
}
return true; // Form is valid
}
function handleDeliveryChange() {
const deliveryOption = document.querySelector('input[name="delivery"]:checked').value;
const paymentOption = document.getElementById("payment_1"); //โอน
if (deliveryOption === document.getElementById("delivery_1").value) {
paymentOption.checked = true;
document.getElementById('transferBlock').style.display = 'none';
}
}
async function handleFormSubmit(event) {
event.preventDefault(); // Always prevent the default form submission
document.getElementsByName('formSubmit')[0].disabled = true;
if (!validateForm()) {
document.getElementsByName('formSubmit')[0].disabled = false;
return false;
}
if (document.getElementById("delivery_1").checked) {
document.getElementById('dialog-sky').style.display = 'block';
document.getElementById('dialog-overlay').style.display = 'block';
const success = await uploadToImgBB("Deli-");
document.getElementById('dialog-sky').style.display = 'none';
document.getElementById('dialog-overlay').style.display = 'none';
if (!success) {
swal({
title: 'อัพโหลดภาพล้มเหลว',
text: 'ไม่มีปัญหา😅 ระบบบันทึกข้อมูลเรียบร้อย กรุณาส่งภาพทางไลน์',
icon: 'warning'
}).then(
function () {
document.getElementById('completeOrder').submit();
}
)
}
}
document.getElementById('completeOrder').submit();
}
function goToUrl() {
var taskParam = "rider=" + document.getElementById("rider").value + "&row=" + document.getElementById("row").value + "&tel=" + document.getElementById("tel").value;
var url = "https://liff.line.me/1656261439-JzOM5yZ6?" + taskParam;
window.location.href = url;
}
</script>
</body>
</html>