<script>
//____________________________
{
/*#####################################################
input[type="hidden"]の要素の value値に変更があった場合
change イベントを発火させる
#####################################################*/
const
option = {
attributes : true,
attributeFilter : ['value']
},
handler =
function ([mutation]) {
let
target = mutation.target,
doc = target.ownerDocument,
event = doc.createEvent ('HTMLEvents');
event.initEvent ('change', true, true);
target.dispatchEvent (event);
};
//_____________________________
class AddChangeEvent {
constructor (element = null) {
if (null === element)
throw new Error ('要素がありません');
let observer = new MutationObserver (handler);
observer.observe (element, option);
this.observer = observer;
}
}
//_____________________________
this.AddChangeEvent = AddChangeEvent;
}
let
fm = document.querySelector('#form1'),
hide = fm.elements['ProductClass'];
//changeイベントの監視
fm.addEventListener ('change', function (event) {
let e = event.target;
if( e.name == 'ProductClass' && e.value != '' ){
var pcc_ritu = { {{ product_class_id_ritu }} };
var ritu = pcc_ritu[e.value];
if( ritu > 0 && ritu <= 100 ){
$('.hsd-badge').html('{{ bef_txt }}' + ritu + '%{{ aft_txt }}');
$('.hsd-badge').show();
}else {
$('.hsd-badge').hide(); // 割引率が範囲外の場合は非表示
}
}else if( e.name == 'ProductClass' && e.value == '' ) {
$('.hsd-badge').hide(); // 規格が決まっていない場合は非表示
}
//console.log([e.name, e.value]);
}, false);
new AddChangeEvent (hide);
</script>
<script>
$(function () {
{% if is_show == 1 %}
{% if show_addr == 0 %}
$('#hsd_discount_rate_detail').insertAfter($('.ec-productRole__priceRegularTax'));
{% elseif show_addr == 1 %}
$('#hsd_discount_rate_detail').insertAfter($('.ec-productRole__priceRegularTax'));
$('<br>').prependTo('#hsd_discount_rate_detail');
{% elseif show_addr == 2 %}
$('#hsd_discount_rate_detail').insertBefore($('.ec-price__price'));
$('#hsd_discount_rate_detail').after('<br>');
{% elseif show_addr == 3 %}
$('#hsd_discount_rate_detail').insertAfter($('.ec-price__tax'));
{% elseif show_addr == 4 %}
$('#hsd_discount_rate_detail').insertAfter($('.ec-price__tax'));
$('<br>').prependTo('#hsd_discount_rate_detail');
$('.ec-price__price').css('padding-left', '0px'); // 販売価格の左側を揃えるため
{% elseif show_addr == 5 %}
$('#hsd_discount_rate_detail').insertBefore($('.ec-price__price'));
{% endif %}
{% endif %}
});
</script>
<span id="hsd_discount_rate_detail" class="hsd-sp-margin">
<style>
#hsd_discount_rate_detail{
position: relative;
}
.hsd-badge {
display: inline-block;
min-width: 10px;
padding: 3px 7px;
font-size: {{ font_rate }}%;
font-weight: 700;
line-height: 1;
color: {{ font_color }};
text-align: center;
white-space: nowrap;
vertical-align: middle;
background-color: {{ back_color }};
border-radius: 10px;
position: relative;
vertical-align: text-bottom;
}
{% if show_addr == 2 %}
@media (max-width: 767px) {
.hsd-sp-margin{
position: relative;
top: 15px;
}
}
{% endif %}
</style>
{% if has_product_class == 1 %}
<span class="hsd-badge" style="display: none;"></span>
{% else %}
{% if discount_rate_1 > 0 and discount_rate_2 > 0 and discount_rate_1 != discount_rate_2 %}
<span class="hsd-badge">{{ bef_txt }}{{ discount_rate_1 }}%{{ aft_txt }}</span> 〜 <span class="hsd-badge">{{ discount_rate_2 }}%{{ aft_txt }}</span>
{% elseif discount_rate_1 > 0 and discount_rate_1 <= 100 %}
<span class="hsd-badge">{{ bef_txt }}{{ discount_rate_1 }}%{{ aft_txt }}</span>
{% endif %}
{% endif %}
</span>