ts-glitter 20.5.3 → 20.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { Tool } from '../../modules/tool.js';
2
2
  import { BgWidget } from '../../backend-manager/bg-widget.js';
3
3
  import { ApiUser } from '../../glitter-base/route/user.js';
4
+ import { OrderSetting } from '../module/order-setting.js';
4
5
  const html = String.raw;
5
6
  export class DeliveryHTML {
6
7
  static print(ogvc, dataArray, type) {
@@ -40,16 +41,17 @@ export class DeliveryHTML {
40
41
  return gvc.bindView({
41
42
  bind: id,
42
43
  view: () => {
44
+ var _a;
43
45
  if (loading) {
44
46
  return '載入中';
45
47
  }
46
48
  const printMap = {
47
- shipment: this.shipmentHTML(vm, glitter, dataArray),
48
- pick: this.pickHTML(vm, glitter, dataArray),
49
- address: this.addressHTML(vm, dataArray),
50
- shipAddr: this.shipAddrHTML(vm, glitter, dataArray),
49
+ shipment: () => this.shipmentHTML(vm, gvc, dataArray),
50
+ pick: () => this.pickHTML(vm, glitter, dataArray),
51
+ address: () => this.addressHTML(vm, dataArray),
52
+ shipAddr: () => this.shipAddrHTML(vm, gvc, dataArray),
51
53
  };
52
- return html `<div class="container" id="${containerID}">${printMap[type]}</div>`;
54
+ return html `<div class="container" id="${containerID}">${(_a = printMap[type]) === null || _a === void 0 ? void 0 : _a.call(printMap)}</div>`;
53
55
  },
54
56
  divCreate: {
55
57
  style: 'min-height: calc(100vh - 70px); padding: 20px;',
@@ -290,115 +292,140 @@ export class DeliveryHTML {
290
292
  }
291
293
  `);
292
294
  }
293
- static shipmentHTML(vm, glitter, dataArray) {
294
- const section = (data) => {
295
- const orderData = data.orderData;
295
+ static shipmentHeader(vm, glitter) {
296
+ return html `<div class="header">
297
+ <h1 class="subtitle">商店名稱:${vm.store.shop_name}</h1>
298
+ <h1 class="title">${vm.info.title}</h1>
299
+ <h1 class="subtitle">${vm.info.subtitle}時間:${glitter.ut.dateFormat(new Date(), 'yyyy-MM-dd hh:mm')}</h1>
300
+ </div>`;
301
+ }
302
+ static shipmentDetail(glitter, data) {
303
+ const orderData = data.orderData;
304
+ function paymentStatus(cart) {
305
+ const statusMessages = {
306
+ '0': cart.orderData.proof_purchase ? '待核款' : '未付款',
307
+ '1': '已付款',
308
+ '-2': '已退款',
309
+ '3': '部分付款',
310
+ };
311
+ return statusMessages[`${cart.status}`] || '付款失敗';
312
+ }
313
+ return html `<div class="details">
314
+ <table>
315
+ <tr>
316
+ <td>訂單編號:${data.cart_token}</td>
317
+ <td>送貨方式:${OrderSetting.getShippingMethodText(orderData)}</td>
318
+ </tr>
319
+ <tr>
320
+ <td>訂購日期:${glitter.ut.dateFormat(new Date(data.created_time), 'yyyy-MM-dd hh:mm')}</td>
321
+ <td>
322
+ 送貨地址:${[orderData.user_info.city, orderData.user_info.area, orderData.user_info.address]
323
+ .filter(Boolean)
324
+ .join('')}
325
+ </td>
326
+ </tr>
327
+ <tr>
328
+ <td>訂購人帳號:${orderData.email}</td>
329
+ <td>收件人姓名:${orderData.user_info.name}</td>
330
+ </tr>
331
+ <tr>
332
+ <td>付款方式:${OrderSetting.getPaymentMethodText(orderData)}</td>
333
+ <td>收件人電話:${orderData.user_info.phone}</td>
334
+ </tr>
335
+ <tr>
336
+ <td>付款狀態:${paymentStatus(data)}</td>
337
+ <td>收件人信箱:${orderData.user_info.email}</td>
338
+ </tr>
339
+ </table>
340
+ </div>`;
341
+ }
342
+ static shipmentItems(gvc, orderData) {
343
+ return html `<div class="items">
344
+ <table>
345
+ <thead>
346
+ <tr>
347
+ <th class="text-left">項次</th>
348
+ <th class="text-left">圖片</th>
349
+ <th class="text-left">商品名稱</th>
350
+ <th class="text-right">單價</th>
351
+ <th class="text-right">數量</th>
352
+ <th class="text-right">金額</th>
353
+ </tr>
354
+ </thead>
355
+ <tbody>
356
+ ${orderData.lineItems
357
+ .map((item, index) => {
358
+ var _a;
296
359
  return html `
297
- <div class="page">
298
- <div class="header">
299
- <h1 class="subtitle">商店名稱:${vm.store.shop_name}</h1>
300
- <h1 class="title">${vm.info.title}</h1>
301
- <h1 class="subtitle">${vm.info.subtitle}時間:${glitter.ut.dateFormat(new Date(), 'yyyy-MM-dd hh:mm')}</h1>
302
- </div>
303
- <div class="details">
304
- <table>
305
- <tr>
306
- <td>訂單編號:${data.cart_token}</td>
307
- <td>送貨方式:${this.getShippingMethodText(orderData)}</td>
308
- </tr>
309
- <tr>
310
- <td>訂購日期:${glitter.ut.dateFormat(new Date(data.created_time), 'yyyy-MM-dd hh:mm')}</td>
311
- <td>
312
- 送貨地址:${[orderData.user_info.city, orderData.user_info.area, orderData.user_info.address]
313
- .filter(Boolean)
314
- .join('')}
315
- </td>
316
- </tr>
317
- <tr>
318
- <td>訂購人帳號:${orderData.email}</td>
319
- <td>收件人姓名:${orderData.user_info.name}</td>
320
- </tr>
321
- <tr>
322
- <td>付款方式:${this.getPaymentMethodText(orderData)}</td>
323
- <td>收件人電話:${orderData.user_info.phone}</td>
324
- </tr>
325
- <tr>
326
- <td>付款狀態:${this.paymentStatus(data)}</td>
327
- <td>收件人信箱:${orderData.user_info.email}</td>
328
- </tr>
329
- </table>
330
- </div>
331
- <div class="items">
332
- <table>
333
- <thead>
334
360
  <tr>
335
- <th class="text-left">項次</th>
336
- <th class="text-left">商品名稱</th>
337
- <th class="text-right">單價</th>
338
- <th class="text-right">數量</th>
339
- <th class="text-right">金額</th>
361
+ <td class="text-left">${index + 1}</td>
362
+ <td class="text-left">
363
+ ${BgWidget.validImageBox({ gvc, image: (_a = item.preview_image) !== null && _a !== void 0 ? _a : '', width: 40 })}
364
+ </td>
365
+ <td class="text-left">${item.title} ${item.spec.length > 0 ? `(${item.spec.join('/')})` : ''}</td>
366
+ <td class="text-right">${item.sale_price.toLocaleString()}</td>
367
+ <td class="text-right">${item.count}</td>
368
+ <td class="text-right">
369
+ $ ${Tool.floatAdd(item.sale_price * Number(item.count), 0).toLocaleString()}
370
+ </td>
340
371
  </tr>
341
- </thead>
342
- <tbody>
343
- ${orderData.lineItems
344
- .map((item, index) => {
345
- return html `
346
- <tr>
347
- <td class="text-left">${index + 1}</td>
348
- <td class="text-left">
349
- ${item.title} ${item.spec.length > 0 ? `(${item.spec.join('/')})` : ''}
350
- </td>
351
- <td class="text-right">${item.sale_price.toLocaleString()}</td>
352
- <td class="text-right">${item.count}</td>
353
- <td class="text-right">$ ${Tool.floatAdd(item.sale_price * Number(item.count), 0).toLocaleString()}</td>
354
- </tr>
355
- `;
356
- })
357
- .join('')}
358
- </tbody>
359
- </table>
360
- </div>
361
- <div class="summary">
362
- <table>
363
- <tr>
364
- <td>小計:</td>
365
- <td>
366
- $
367
- ${(orderData.total +
368
- orderData.discount -
369
- orderData.shipment_fee +
370
- orderData.use_rebate).toLocaleString()}
371
- </td>
372
- </tr>
373
- <tr>
374
- <td>運費:</td>
375
- <td>${orderData.shipment_fee.toLocaleString()}</td>
376
- </tr>
377
- <tr>
378
- <td>折扣:</td>
379
- <td>-${orderData.discount.toLocaleString()}</td>
380
- </tr>
381
- <tr>
382
- <td>購物金折抵:</td>
383
- <td>-${orderData.use_rebate.toLocaleString()}</td>
384
- </tr>
385
- <tr>
386
- <td>總計:</td>
387
- <td>$ ${orderData.total.toLocaleString()}</td>
388
- </tr>
389
- </table>
390
- </div>
391
- ${orderData.order_note && orderData.order_note.length > 0
392
- ? html ` <div>【訂單備註】</div>
393
- <p class="note">${orderData.order_note.replace(/\n/g, '<br />')}</p>`
394
- : ''}
395
- </div>
396
- `;
397
- };
372
+ `;
373
+ })
374
+ .join('')}
375
+ </tbody>
376
+ </table>
377
+ </div>`;
378
+ }
379
+ static shipmentSummary(orderData) {
380
+ return html `<div class="summary">
381
+ <table>
382
+ <tr>
383
+ <td>小計:</td>
384
+ <td>
385
+ $ ${(orderData.total + orderData.discount - orderData.shipment_fee + orderData.use_rebate).toLocaleString()}
386
+ </td>
387
+ </tr>
388
+ <tr>
389
+ <td>運費:</td>
390
+ <td>$ ${orderData.shipment_fee.toLocaleString()}</td>
391
+ </tr>
392
+ <tr>
393
+ <td>折扣:</td>
394
+ <td>- $ ${orderData.discount.toLocaleString()}</td>
395
+ </tr>
396
+ <tr>
397
+ <td>購物金折抵:</td>
398
+ <td>- $ ${orderData.use_rebate.toLocaleString()}</td>
399
+ </tr>
400
+ <tr>
401
+ <td>總計:</td>
402
+ <td>$ ${orderData.total.toLocaleString()}</td>
403
+ </tr>
404
+ </table>
405
+ </div>`;
406
+ }
407
+ static shipmentNote(orderData) {
408
+ return orderData.order_note && orderData.order_note.length > 0
409
+ ? html ` <div>【訂單備註】</div>
410
+ <p class="note">${orderData.order_note.replace(/\n/g, '<br />')}</p>`
411
+ : '';
412
+ }
413
+ static getShipmentPage(vm, gvc, data) {
414
+ const glitter = gvc.glitter;
415
+ const orderData = data.orderData;
416
+ return [
417
+ this.shipmentHeader(vm, glitter),
418
+ this.shipmentDetail(glitter, data),
419
+ this.shipmentItems(gvc, orderData),
420
+ this.shipmentSummary(orderData),
421
+ this.shipmentNote(orderData),
422
+ ].join('');
423
+ }
424
+ static shipmentHTML(vm, gvc, dataArray) {
398
425
  return dataArray
399
426
  .map(data => {
400
427
  try {
401
- return section(data);
428
+ return html ` <div class="page">${this.getShipmentPage(vm, gvc, data)}</div>`;
402
429
  }
403
430
  catch (e) {
404
431
  const text = `訂單 #${data.cart_token} 列印出貨發生錯誤`;
@@ -501,7 +528,7 @@ export class DeliveryHTML {
501
528
  })
502
529
  .join('');
503
530
  }
504
- static shipAddrHTML(vm, glitter, dataArray) {
531
+ static shipAddrHTML(vm, gvc, dataArray) {
505
532
  const section = (data) => {
506
533
  const orderData = data.orderData;
507
534
  const zipcode = (() => {
@@ -534,104 +561,7 @@ export class DeliveryHTML {
534
561
  </div>
535
562
  <div style="text-align: end">訂單編號: ${data.cart_token}</div>
536
563
  </div>
537
- <div class="header">
538
- <h1 class="subtitle">商店名稱:${vm.store.shop_name}</h1>
539
- <h1 class="title">${vm.info.title}</h1>
540
- <h1 class="subtitle">${vm.info.subtitle}時間:${glitter.ut.dateFormat(new Date(), 'yyyy-MM-dd hh:mm')}</h1>
541
- </div>
542
- <div class="details">
543
- <table>
544
- <tr>
545
- <td>訂單編號:${data.cart_token}</td>
546
- <td>送貨方式:${this.getShippingMethodText(orderData)}</td>
547
- </tr>
548
- <tr>
549
- <td>訂購日期:${glitter.ut.dateFormat(new Date(data.created_time), 'yyyy-MM-dd hh:mm')}</td>
550
- <td>
551
- 送貨地址:${[orderData.user_info.city, orderData.user_info.area, orderData.user_info.address]
552
- .filter(Boolean)
553
- .join('')}
554
- </td>
555
- </tr>
556
- <tr>
557
- <td>訂購人帳號:${orderData.email}</td>
558
- <td>收件人姓名:${orderData.user_info.name}</td>
559
- </tr>
560
- <tr>
561
- <td>付款方式:${this.getPaymentMethodText(orderData)}</td>
562
- <td>收件人電話:${orderData.user_info.phone}</td>
563
- </tr>
564
- <tr>
565
- <td>付款狀態:${this.paymentStatus(data)}</td>
566
- <td>收件人信箱:${orderData.user_info.email}</td>
567
- </tr>
568
- </table>
569
- </div>
570
- <div class="items">
571
- <table>
572
- <thead>
573
- <tr>
574
- <th class="text-left">項次</th>
575
- <th class="text-left">商品名稱</th>
576
- <th class="text-right">單價</th>
577
- <th class="text-right">數量</th>
578
- <th class="text-right">金額</th>
579
- </tr>
580
- </thead>
581
- <tbody>
582
- ${orderData.lineItems
583
- .map((item, index) => {
584
- var _a;
585
- return html `
586
- <tr>
587
- <td class="text-left">${index + 1}</td>
588
- <td class="text-left">
589
- ${item.title} ${item.spec.length > 0 ? `(${item.spec.join('/')})` : ''}
590
- </td>
591
- <td class="text-right">${item.sale_price.toLocaleString()}</td>
592
- <td class="text-right">${item.count}</td>
593
- <td class="text-right">$ ${Tool.floatAdd((_a = item.sale_price * Number(item.count)) !== null && _a !== void 0 ? _a : 0, 0).toLocaleString()}</td>
594
- </tr>
595
- `;
596
- })
597
- .join('')}
598
- </tbody>
599
- </table>
600
- </div>
601
- <div class="summary">
602
- <table>
603
- <tr>
604
- <td>小計:</td>
605
- <td>
606
- $
607
- ${(orderData.total +
608
- orderData.discount -
609
- orderData.shipment_fee +
610
- orderData.use_rebate).toLocaleString()}
611
- </td>
612
- </tr>
613
- <tr>
614
- <td>運費:</td>
615
- <td>${orderData.shipment_fee.toLocaleString()}</td>
616
- </tr>
617
- <tr>
618
- <td>折扣:</td>
619
- <td>-${orderData.discount.toLocaleString()}</td>
620
- </tr>
621
- <tr>
622
- <td>購物金折抵:</td>
623
- <td>-${orderData.use_rebate.toLocaleString()}</td>
624
- </tr>
625
- <tr>
626
- <td>總計:</td>
627
- <td>$ ${orderData.total.toLocaleString()}</td>
628
- </tr>
629
- </table>
630
- </div>
631
- ${orderData.order_note && orderData.order_note.length > 0
632
- ? html ` <div>【訂單備註】</div>
633
- <p class="note">${orderData.order_note.replace(/\n/g, '<br />')}</p>`
634
- : ''}
564
+ ${this.getShipmentPage(vm, gvc, data)}
635
565
  </div>
636
566
  `;
637
567
  };
@@ -648,36 +578,4 @@ export class DeliveryHTML {
648
578
  })
649
579
  .join('');
650
580
  }
651
- static getPaymentMethodText(orderData) {
652
- const paymentMethods = {
653
- POS: '門市POS付款',
654
- off_line: '線下付款',
655
- newWebPay: '藍新金流',
656
- ecPay: '綠界金流',
657
- line_pay: 'Line Pay',
658
- atm: '銀行轉帳',
659
- line: 'Line 轉帳',
660
- cash_on_delivery: '貨到付款',
661
- };
662
- return orderData.orderSource === 'POS'
663
- ? paymentMethods['POS']
664
- : paymentMethods[orderData.customer_info.payment_select] || '線下付款';
665
- }
666
- static getShippingMethodText(orderData) {
667
- const shippingMethods = {
668
- UNIMARTC2C: '7-11店到店',
669
- FAMIC2C: '全家店到店',
670
- OKMARTC2C: 'OK店到店',
671
- HILIFEC2C: '萊爾富店到店',
672
- };
673
- return shippingMethods[orderData.user_info.shipment] || '宅配';
674
- }
675
- static paymentStatus(cart) {
676
- const statusMessages = {
677
- '0': cart.orderData.proof_purchase ? '待核款' : '未付款',
678
- '1': '已付款',
679
- '-2': '已退款',
680
- };
681
- return statusMessages[`${cart.status}`] || '付款失敗';
682
- }
683
581
  }