app/Plugin/HsdDiscountRate42/Resource/template/default/Product/discount_rate42_show.twig line 1

Open in your IDE?
  1. <script>
  2.     //____________________________
  3.     {
  4.         /*#####################################################
  5.            input[type="hidden"]の要素の value値に変更があった場合
  6.            change イベントを発火させる
  7.         #####################################################*/
  8.         const
  9.             option = {
  10.                 attributes      : true,
  11.                 attributeFilter : ['value']
  12.             },
  13.             handler =
  14.                 function ([mutation]) {
  15.                     let
  16.                         target = mutation.target,
  17.                         doc    = target.ownerDocument,
  18.                         event  = doc.createEvent ('HTMLEvents');
  19.                     event.initEvent ('change', true, true);
  20.                     target.dispatchEvent (event);
  21.                 };
  22.         //_____________________________
  23.         class AddChangeEvent {
  24.             constructor (element = null) {
  25.                 if (null === element)
  26.                     throw new Error ('要素がありません');
  27.                 let observer = new MutationObserver (handler);
  28.                 observer.observe (element, option);
  29.                 this.observer = observer;
  30.             }
  31.         }
  32.         //_____________________________
  33.         this.AddChangeEvent = AddChangeEvent;
  34.     }
  35.     let
  36.         fm = document.querySelector('#form1'),
  37.         hide = fm.elements['ProductClass'];
  38.     //changeイベントの監視
  39.     fm.addEventListener ('change', function (event) {
  40.         let e = event.target;
  41.         if( e.name == 'ProductClass' && e.value != '' ){
  42.             var pcc_ritu = { {{ product_class_id_ritu }} };
  43.             var ritu = pcc_ritu[e.value];
  44.             if( ritu > 0 && ritu <= 100 ){
  45.                 $('.hsd-badge').html('{{ bef_txt }}' + ritu + '%{{ aft_txt }}');
  46.                 $('.hsd-badge').show();
  47.             }else {
  48.                 $('.hsd-badge').hide(); // 割引率が範囲外の場合は非表示
  49.             }
  50.         }else if( e.name == 'ProductClass' && e.value == '' ) {
  51.             $('.hsd-badge').hide(); // 規格が決まっていない場合は非表示
  52.         }
  53.         //console.log([e.name, e.value]);
  54.     }, false);
  55.     new AddChangeEvent (hide);
  56. </script>
  57. <script>
  58.     $(function () {
  59.         {% if is_show == 1 %}
  60.             {% if show_addr == 0 %}
  61.                 $('#hsd_discount_rate_detail').insertAfter($('.ec-productRole__priceRegularTax'));
  62.             {% elseif show_addr == 1 %}
  63.                 $('#hsd_discount_rate_detail').insertAfter($('.ec-productRole__priceRegularTax'));
  64.                 $('<br>').prependTo('#hsd_discount_rate_detail');
  65.             {% elseif show_addr == 2 %}
  66.                 $('#hsd_discount_rate_detail').insertBefore($('.ec-price__price'));
  67.                 $('#hsd_discount_rate_detail').after('<br>');
  68.             {% elseif show_addr == 3 %}
  69.                 $('#hsd_discount_rate_detail').insertAfter($('.ec-price__tax'));
  70.             {% elseif show_addr == 4 %}
  71.                 $('#hsd_discount_rate_detail').insertAfter($('.ec-price__tax'));
  72.                 $('<br>').prependTo('#hsd_discount_rate_detail');
  73.                 $('.ec-price__price').css('padding-left', '0px'); // 販売価格の左側を揃えるため
  74.             {% elseif show_addr == 5 %}
  75.                 $('#hsd_discount_rate_detail').insertBefore($('.ec-price__price'));
  76.             {% endif %}
  77.         {% endif %}
  78.     });
  79. </script>
  80. <span id="hsd_discount_rate_detail" class="hsd-sp-margin">
  81.     <style>
  82.         #hsd_discount_rate_detail{
  83.             position: relative;
  84.         }
  85.         .hsd-badge {
  86.             display: inline-block;
  87.             min-width: 10px;
  88.             padding: 3px 7px;
  89.             font-size: {{ font_rate }}%;
  90.             font-weight: 700;
  91.             line-height: 1;
  92.             color: {{ font_color }};
  93.             text-align: center;
  94.             white-space: nowrap;
  95.             vertical-align: middle;
  96.             background-color: {{ back_color }};
  97.             border-radius: 10px;
  98.             position: relative;
  99.             vertical-align: text-bottom;
  100.         }
  101.         {% if show_addr == 2 %}
  102.             @media (max-width: 767px) {
  103.                 .hsd-sp-margin{
  104.                     position: relative;
  105.                     top: 15px;
  106.                 }
  107.             }
  108.         {% endif %}
  109.     </style>
  110.     {% if has_product_class == 1 %}
  111.         <span class="hsd-badge" style="display: none;"></span>
  112.     {% else %}
  113.         {% if discount_rate_1 > 0 and discount_rate_2 > 0 and discount_rate_1 != discount_rate_2 %}
  114.             <span class="hsd-badge">{{ bef_txt }}{{ discount_rate_1 }}%{{ aft_txt }}</span> 〜 <span class="hsd-badge">{{ discount_rate_2 }}%{{ aft_txt }}</span>
  115.         {% elseif discount_rate_1 > 0 and discount_rate_1 <= 100 %}
  116.             <span class="hsd-badge">{{ bef_txt }}{{ discount_rate_1 }}%{{ aft_txt }}</span>
  117.         {% endif %}
  118.     {% endif %}
  119. </span>