app/Plugin/QuantityDiscountDx/Resource/template/admin/Product/qd_area_js.twig line 1

Open in your IDE?
  1. <script>
  2.     const QD_TYPE_PRICE = "{{ constant('Plugin\\QuantityDiscountDx\\Entity\\QdProductClass::QD_TYPE_PRICE') }}";
  3.     const QD_TYPE_RATE = "{{ constant('Plugin\\QuantityDiscountDx\\Entity\\QdProductClass::QD_TYPE_RATE') }}";
  4.     $(function () {
  5.         $('#qd_area_title').tooltip();
  6.         // 追加ボタンイベント追加
  7.         let qdCollectionHolder = $('#qd_area_body');
  8.         let qdCollectionIndex = $('.qd_area_row').length - 1;
  9.         // 追加
  10.         $('#qd_add_btn').on('click', function () {
  11.             let prototype = qdCollectionHolder.data('prototype');
  12.             qdCollectionIndex++;
  13.             var newForm = prototype.replace(/__name__/g, qdCollectionIndex);
  14.             var $lastRow = $('.qd_area_row:last')
  15.             $lastRow.after(newForm);
  16.         });
  17.         // 削除
  18.         $(document).on('click', '.qd_del_btn', function() {
  19.             let key = $(this).data('key');
  20.             $('#qd_area_row_' + key).hide();
  21.             $('#admin_product_class_QdProductClasses_' + key + '_del_flg').val(1);
  22.         });
  23.         // type変更
  24.         $(document).on('change', '.qd_type_radio', function () {
  25.             changeType($(this));
  26.         });
  27.         // 初期処理
  28.         $('input[id^="admin_product_class_QdProductClasses_0_qd_type_"]:checked').each(function () {
  29.             changeType($(this));
  30.         });
  31.     });
  32.     function changeType(checkObj) {
  33.         let parent = checkObj.parent().parent();
  34.         let target_index = parent.data('target_index');
  35.         if(checkObj.val() == QD_TYPE_PRICE) {
  36.             $('#qd_price_' + target_index).removeClass('d-none');
  37.             $('#qd_rate_' + target_index).addClass('d-none');
  38.         } else {
  39.             $('#qd_price_' + target_index).addClass('d-none');
  40.             $('#qd_rate_' + target_index).removeClass('d-none');
  41.         }
  42.     }
  43. </script>