Spaces:
Running
Running
File size: 23,793 Bytes
ccfecbb | 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 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | // Supplier QC Tracker System - Main JavaScript
document.addEventListener('DOMContentLoaded', function() {
// Initialize Lucide icons
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
// Check if user is logged in before running main script
const currentUser = localStorage.getItem('qc-user');
if (!currentUser) {
// Not logged in, script won't run (auth.js will handle login)
return;
}
// Sample orders data
const orders = [
{
id: 'ORD-001',
name: 'Plastic Containers',
description: 'Food-grade plastic containers with lids',
type: 'ready-made',
status: 'approved',
supplier: 'ABC Manufacturing Co.',
responsible: 'China Staff',
orderDate: '2023-10-15',
expectedShipDate: '2023-11-05',
qcPhotos: 0,
hasDiscrepancy: false,
discrepancyNotes: ''
},
{
id: 'ORD-002',
name: 'Custom Metal Brackets',
description: 'Custom fabricated steel brackets',
type: 'custom',
status: 'qc-required',
supplier: 'Precision Components Inc.',
responsible: 'China Staff',
orderDate: '2023-10-20',
expectedShipDate: '2023-11-15',
qcPhotos: 2,
hasDiscrepancy: false,
discrepancyNotes: ''
},
{
id: 'ORD-003',
name: 'Electronic Components',
description: 'Standard resistors and capacitors',
type: 'ready-made',
status: 'shipped',
supplier: 'Global Parts Ltd.',
responsible: 'China Staff',
orderDate: '2023-10-10',
expectedShipDate: '2023-10-30',
qcPhotos: 1,
hasDiscrepancy: false,
discrepancyNotes: ''
},
{
id: 'ORD-004',
name: 'Custom Packaging Boxes',
description: 'Custom printed cardboard boxes',
type: 'custom',
status: 'discrepancy',
supplier: 'XYZ Industrial Supplies',
responsible: 'China Staff',
orderDate: '2023-09-28',
expectedShipDate: '2023-10-25',
qcPhotos: 3,
hasDiscrepancy: true,
discrepancyNotes: 'Wrong dimensions received at warehouse'
},
{
id: 'ORD-005',
name: 'Office Chairs',
description: 'Ergonomic office chairs',
type: 'ready-made',
status: 'received',
supplier: 'ABC Manufacturing Co.',
responsible: 'China Staff',
orderDate: '2023-09-15',
expectedShipDate: '2023-10-10',
qcPhotos: 0,
hasDiscrepancy: false,
discrepancyNotes: ''
},
{
id: 'ORD-006',
name: 'Custom Display Stands',
description: 'Acrylic display stands with branding',
type: 'custom',
status: 'in-progress',
supplier: 'Precision Components Inc.',
responsible: 'China Staff',
orderDate: '2023-10-25',
expectedShipDate: '2023-11-30',
qcPhotos: 0,
hasDiscrepancy: false,
discrepancyNotes: ''
}
];
// DOM Elements
const ordersTable = document.getElementById('orders-table');
const newOrderBtn = document.getElementById('new-order-btn');
const newOrderModal = document.getElementById('new-order-modal');
const cancelOrderBtn = document.getElementById('cancel-order-btn');
const nextStepBtn = document.getElementById('next-step-btn');
const prevStepBtn = document.getElementById('prev-step-btn');
const qcUploadArea = document.getElementById('qc-upload-area');
const qcPhotosInput = document.getElementById('qc-photos');
const fileList = document.getElementById('file-list');
const uploadedFilesDiv = document.getElementById('uploaded-files');
// Get current language
const currentLanguage = localStorage.getItem('qc-language') || 'en';
// New order form steps
const steps = ['step-1', 'step-2', 'step-3', 'step-4', 'step-5'];
let currentStep = 0;
let uploadedFiles = [];
// Language-specific status texts
const statusTranslations = {
'en': {
'pending': 'Pending',
'in-progress': 'In Progress',
'qc-required': 'QC Required',
'approved': 'Approved',
'shipped': 'Shipped',
'received': 'Received',
'discrepancy': 'Discrepancy',
'Custom': 'Custom',
'Ready-made': 'Ready-made',
'Discrepancy': 'Discrepancy',
'View': 'View',
'Edit': 'Edit',
'Next Step': 'Next Step',
'Create Order': 'Create Order',
'Previous': 'Previous',
'Cancel': 'Cancel'
},
'zh': {
'pending': '待处理',
'in-progress': '进行中',
'qc-required': '需要QC审核',
'approved': '已批准',
'shipped': '已发货',
'received': '已收货',
'discrepancy': '差异',
'Custom': '定制',
'Ready-made': '现成产品',
'Discrepancy': '差异',
'View': '查看',
'Edit': '编辑',
'Next Step': '下一步',
'Create Order': '创建订单',
'Previous': '上一步',
'Cancel': '取消'
}
};
// Get localized text
function getLocalizedText(key) {
return statusTranslations[currentLanguage][key] || key;
}
// Render orders table
function renderOrdersTable() {
if (!ordersTable) return;
ordersTable.innerHTML = '';
orders.forEach(order => {
const statusClass = getStatusClass(order.status);
const statusText = getLocalizedText(order.status);
const typeText = getLocalizedText(order.type === 'custom' ? 'Custom' : 'Ready-made');
const typeBadgeClass = order.type === 'custom' ?
'bg-purple-100 text-purple-800' : 'bg-green-100 text-green-800';
const discrepancyText = getLocalizedText('Discrepancy');
const discrepancyBadge = order.hasDiscrepancy ?
`<span class="ml-2 px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800">${discrepancyText}</span>` : '';
const viewText = getLocalizedText('View');
const editText = getLocalizedText('Edit');
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
${order.id}
${discrepancyBadge}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<div class="font-medium text-gray-900">${order.name}</div>
<div class="text-gray-500 text-xs">${order.description}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${typeBadgeClass}">
${typeText}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap">
<span class="${statusClass} px-2 inline-flex text-xs leading-5 font-semibold rounded-full">
${statusText}
</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<div class="flex items-center">
<div class="h-6 w-6 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 text-xs font-medium mr-2">CS</div>
${order.responsible}
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<button class="text-blue-600 hover:text-blue-900 mr-3 view-order-btn" data-order-id="${order.id}">
<i data-lucide="eye" class="h-4 w-4 inline"></i> ${viewText}
</button>
<button class="text-indigo-600 hover:text-indigo-900 edit-order-btn" data-order-id="${order.id}">
<i data-lucide="edit" class="h-4 w-4 inline"></i> ${editText}
</button>
</td>
`;
ordersTable.appendChild(row);
});
// Re-initialize icons
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
// Add event listeners to view buttons
document.querySelectorAll('.view-order-btn').forEach(btn => {
btn.addEventListener('click', function() {
const orderId = this.getAttribute('data-order-id');
viewOrderDetails(orderId);
});
});
// Add event listeners to edit buttons
document.querySelectorAll('.edit-order-btn').forEach(btn => {
btn.addEventListener('click', function() {
const orderId = this.getAttribute('data-order-id');
editOrder(orderId);
});
});
}
// Get status class for styling
function getStatusClass(status) {
switch(status) {
case 'pending': return 'status-pending';
case 'in-progress': return 'status-in-progress';
case 'qc-required': return 'status-qc-required';
case 'approved': return 'status-approved';
case 'shipped': return 'status-shipped';
case 'received': return 'status-received';
case 'discrepancy': return 'status-discrepancy';
default: return 'status-pending';
}
}
// View order details
function viewOrderDetails(orderId) {
const order = orders.find(o => o.id === orderId);
if (!order) return;
const typeText = order.type === 'custom' ?
(currentLanguage === 'zh' ? '定制产品' : 'Custom Fabrication') :
(currentLanguage === 'zh' ? '现成产品' : 'Ready-made');
const message = currentLanguage === 'zh' ?
`订单详情:\n\n` +
`订单号: ${order.id}\n` +
`名称: ${order.name}\n` +
`描述: ${order.description}\n` +
`类型: ${typeText}\n` +
`状态: ${getLocalizedText(order.status)}\n` +
`供应商: ${order.supplier}\n` +
`负责人: ${order.responsible}\n` +
`订单日期: ${order.orderDate}\n` +
`预计发货日期: ${order.expectedShipDate}\n` +
`QC照片: ${order.qcPhotos}\n` +
`差异: ${order.hasDiscrepancy ? '是 - ' + order.discrepancyNotes : '否'}`
:
`Order Details:\n\n` +
`Order ID: ${order.id}\n` +
`Name: ${order.name}\n` +
`Description: ${order.description}\n` +
`Type: ${typeText}\n` +
`Status: ${getLocalizedText(order.status)}\n` +
`Supplier: ${order.supplier}\n` +
`Responsible: ${order.responsible}\n` +
`Order Date: ${order.orderDate}\n` +
`Expected Ship Date: ${order.expectedShipDate}\n` +
`QC Photos: ${order.qcPhotos}\n` +
`Discrepancy: ${order.hasDiscrepancy ? 'Yes - ' + order.discrepancyNotes : 'No'}`;
alert(message);
}
// Edit order
function editOrder(orderId) {
const message = currentLanguage === 'zh' ?
`编辑订单 ${orderId}。完整实现中,这将打开编辑表单。` :
`Editing order ${orderId}. In a full implementation, this would open an edit form.`;
alert(message);
}
// New order modal functions
function showNewOrderModal() {
newOrderModal.classList.remove('hidden');
resetNewOrderForm();
showStep(0);
}
function hideNewOrderModal() {
newOrderModal.classList.add('hidden');
}
function resetNewOrderForm() {
currentStep = 0;
uploadedFiles = [];
// Reset form fields
document.getElementById('order-name').value = '';
document.getElementById('order-description').value = '';
document.getElementById('order-specs').value = '';
document.getElementById('ready-made').checked = true;
document.getElementById('supplier-select').value = '';
document.getElementById('supplier-link').value = '';
document.getElementById('final-approval').checked = false;
// Reset file display
fileList.innerHTML = '';
uploadedFilesDiv.classList.add('hidden');
// Update button text
nextStepBtn.textContent = getLocalizedText('Next Step');
prevStepBtn.textContent = getLocalizedText('Previous');
cancelOrderBtn.textContent = getLocalizedText('Cancel');
}
function showStep(stepIndex) {
// Hide all steps
steps.forEach(stepId => {
const stepElement = document.getElementById(stepId);
if (stepElement) {
stepElement.classList.add('hidden');
}
});
// Show current step
const currentStepElement = document.getElementById(steps[stepIndex]);
if (currentStepElement) {
currentStepElement.classList.remove('hidden');
}
// Update button visibility
prevStepBtn.classList.toggle('hidden', stepIndex === 0);
// Update next button text
if (stepIndex === steps.length - 1) {
nextStepBtn.textContent = getLocalizedText('Create Order');
} else {
nextStepBtn.textContent = getLocalizedText('Next Step');
}
// Update QC requirements based on item type
if (stepIndex === 3) {
updateQCRequirements();
}
}
function updateQCRequirements() {
const isCustom = document.getElementById('custom-fabrication').checked;
const qcInfoDiv = document.querySelector('#step-4 .bg-blue-50 p');
if (isCustom) {
if (currentLanguage === 'zh') {
qcInfoDiv.innerHTML = `根据您选择的<strong class="font-semibold">定制产品</strong>,QC照片在发货批准前是<strong class="font-semibold">必需的</strong>。请上传制造进度照片和最终产品照片。`;
} else {
qcInfoDiv.innerHTML = `Based on your selection of <strong class="font-semibold">Custom Fabrication</strong>, QC photos are <strong class="font-semibold">required</strong> before shipment approval. Please upload fabrication progress photos and final product photos.`;
}
} else {
if (currentLanguage === 'zh') {
qcInfoDiv.innerHTML = `根据您选择的<strong class="font-semibold">现成产品</strong>,QC照片是<strong class="font-semibold">可选但推荐</strong>的。对于定制产品,QC照片在发货批准前是必需的。`;
} else {
qcInfoDiv.innerHTML = `Based on your selection of <strong class="font-semibold">Ready-made</strong> items, QC photos are <strong class="font-semibold">optional but recommended</strong>. For custom fabrication, QC photos would be required before shipment approval.`;
}
}
}
function goToNextStep() {
if (currentStep < steps.length - 1) {
currentStep++;
showStep(currentStep);
} else {
// Create the order
createNewOrder();
}
}
function goToPrevStep() {
if (currentStep > 0) {
currentStep--;
showStep(currentStep);
}
}
function createNewOrder() {
// Get form values
const orderName = document.getElementById('order-name').value;
const orderDescription = document.getElementById('order-description').value;
const orderSpecs = document.getElementById('order-specs').value;
const itemType = document.querySelector('input[name="item-type"]:checked').value;
const supplier = document.getElementById('supplier-select').value;
const supplierLink = document.getElementById('supplier-link').value;
const finalApproval = document.getElementById('final-approval').checked;
// Validation
if (!orderName || !orderDescription || !supplier) {
const errorMsg = currentLanguage === 'zh'
? '请填写所有必填字段。'
: 'Please fill in all required fields.';
alert(errorMsg);
return;
}
if (!finalApproval && currentStep === steps.length - 1) {
const errorMsg = currentLanguage === 'zh'
? '请在创建订单前确认批准。'
: 'Please confirm approval before creating the order.';
alert(errorMsg);
return;
}
// Create new order object
const newOrder = {
id: `ORD-${String(orders.length + 1).padStart(3, '0')}`,
name: orderName,
description: orderDescription,
type: itemType,
status: itemType === 'custom' ? 'qc-required' : 'pending',
supplier: document.getElementById('supplier-select').options[document.getElementById('supplier-select').selectedIndex].text,
responsible: 'China Staff',
orderDate: new Date().toISOString().split('T')[0],
expectedShipDate: new Date(Date.now() + 20 * 24 * 60 * 60 * 1000).toISOString().split('T')[0], // 20 days from now
qcPhotos: uploadedFiles.length,
hasDiscrepancy: false,
discrepancyNotes: ''
};
// Add to orders array
orders.unshift(newOrder);
// Re-render table
renderOrdersTable();
// Hide modal
hideNewOrderModal();
// Show success message
if (currentLanguage === 'zh') {
alert(`订单 ${newOrder.id} 创建成功!\n\n已建立责任跟踪。${itemType === 'custom' ? '发货前需要QC照片。' : '对于此现成产品,QC照片是可选的。'}`);
} else {
alert(`Order ${newOrder.id} created successfully!\n\nAccountability trail established. ${itemType === 'custom' ? 'QC photos are required before shipment.' : 'QC photos are optional for this ready-made item.'}`);
}
}
// File upload handling
function handleFileUpload(files) {
for (let i = 0; i < files.length; i++) {
const file = files[i];
// Check if file is an image
if (!file.type.startsWith('image/')) {
const errorMsg = currentLanguage === 'zh'
? 'QC照片只允许上传图像文件。'
: 'Only image files are allowed for QC photos.';
alert(errorMsg);
continue;
}
// Add to uploaded files array
uploadedFiles.push({
name: file.name,
size: file.size,
type: file.type,
url: URL.createObjectURL(file)
});
}
// Update file list display
updateFileListDisplay();
}
function updateFileListDisplay() {
if (uploadedFiles.length === 0) {
uploadedFilesDiv.classList.add('hidden');
return;
}
fileList.innerHTML = '';
uploadedFiles.forEach((file, index) => {
const fileSize = file.size > 1024 * 1024 ?
`${(file.size / (1024 * 1024)).toFixed(1)} MB` :
`${(file.size / 1024).toFixed(1)} KB`;
const fileItem = document.createElement('div');
fileItem.className = 'flex items-center justify-between p-2 bg-gray-50 rounded';
fileItem.innerHTML = `
<div class="flex items-center">
<i data-lucide="image" class="h-5 w-5 text-gray-500 mr-3"></i>
<div>
<p class="text-sm font-medium text-gray-900 truncate max-w-xs">${file.name}</p>
<p class="text-xs text-gray-500">${fileSize}</p>
</div>
</div>
<button class="text-red-500 hover:text-red-700 remove-file-btn" data-index="${index}">
<i data-lucide="trash-2" class="h-4 w-4"></i>
</button>
`;
fileList.appendChild(fileItem);
});
uploadedFilesDiv.classList.remove('hidden');
// Re-initialize icons
if (typeof lucide !== 'undefined') {
lucide.createIcons();
}
// Add event listeners to remove buttons
document.querySelectorAll('.remove-file-btn').forEach(btn => {
btn.addEventListener('click', function() {
const index = parseInt(this.getAttribute('data-index'));
uploadedFiles.splice(index, 1);
updateFileListDisplay();
});
});
}
// Event Listeners
newOrderBtn.addEventListener('click', showNewOrderModal);
cancelOrderBtn.addEventListener('click', hideNewOrderModal);
nextStepBtn.addEventListener('click', goToNextStep);
prevStepBtn.addEventListener('click', goToPrevStep);
// Close modal when clicking outside
newOrderModal.addEventListener('click', function(e) {
if (e.target === this) {
hideNewOrderModal();
}
});
// File upload event listeners
qcUploadArea.addEventListener('click', () => {
qcPhotosInput.click();
});
qcUploadArea.addEventListener('dragover', (e) => {
e.preventDefault();
qcUploadArea.classList.add('dragover');
});
qcUploadArea.addEventListener('dragleave', () => {
qcUploadArea.classList.remove('dragover');
});
qcUploadArea.addEventListener('drop', (e) => {
e.preventDefault();
qcUploadArea.classList.remove('dragover');
const files = e.dataTransfer.files;
handleFileUpload(files);
});
qcPhotosInput.addEventListener('change', (e) => {
handleFileUpload(e.target.files);
e.target.value = ''; // Reset input
});
// Item type change listener to update QC requirements
document.querySelectorAll('input[name="item-type"]').forEach(radio => {
radio.addEventListener('change', updateQCRequirements);
});
// Initialize the page
renderOrdersTable();
// Add keyboard shortcuts
document.addEventListener('keydown', (e) => {
// Escape key closes modal
if (e.key === 'Escape' && !newOrderModal.classList.contains('hidden')) {
hideNewOrderModal();
}
// Ctrl/Cmd + N creates new order
if ((e.ctrlKey || e.metaKey) && e.key === 'n') {
e.preventDefault();
showNewOrderModal();
}
});
}); |