"use strict"; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } $(function () { $('.is_check').hide(); $('#submit').prop("disabled", true); var array_cake = ['cake551','cake561','cake563','cake564','cake521','cake566','cake567','cake568','cake572','cake50','cake242','cake424','cake243','cake247','cake248','cake249','cake253','cake252','cake212','cake213','cake547','cake257','cake217','cake220','cake258','cake261','cake263','cake262','cake559','cake295','cake296','cake267','cake526','cake471','cake548','cake363','cake456','cake308','cake438','cake457','cake465','cake283','cake280']; $("#btn_check").on('click', function () { var check = new error_check(); var error = []; var inputText = $('.input_num').map(function (index, el) { return $(this).val(); }); var cakenum = 0; for (var i = 0; i < inputText.length; i++) { cakenum += Number(inputText[i]); } error.push(check.check_cake(cakenum, '商品を選択してください')); error.push(check.check_kana('kana', 'フリガナをご入力ください', 'ひらがな 又は カタカナ でご入力ください')); error.push(check.check_txt('fullname', 'お名前をご入力ください')); error.push(check.check_txt('postalcode', '郵便番号をご入力ください')); error.push(check.check_txt('address', '住所をご入力ください')); error.push(check.check_txt('booking_time', 'お渡し日をご指定ください')); error.push(check.check_txt('booking_timezone', 'ご希望時間をご指定ください')); error.push(check.check_tel('tel', '電話番号をご入力ください', '電話番号は半角数字とハイフン(-)でご入力ください')); error.push(check.check_mail('mail', 'メールアドレスをご入力ください', '正しいメールアドレスを入力してください')); error.push(check.check_txt('free-txt', '')); check.display_control(error); onClickHandler(error); var verifi = new verification(array_cake, '#register'); verifi.output(); var send = new sendvalue(array_cake); send.output(); }); $("#btn_back").on('click', function () { $('.is_input').show(); $('.is_check').hide(); $('#check_cake').html(''); onClickHandler(); }); function comma(num) { return String(num).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,'); } //エラー箇所に戻る動き function onClickHandler(error) { var target_obj = $('.wpcf7-form'); var target = []; if (typeof error !== 'undefined') { error.forEach(function (row, i) { var colIndex = row.indexOf(0); if (colIndex < 0) { target.push(i); return true; } }); if (target[0]) { var _i = target[0]; target_obj = error[_i][1]; } } var mql = window.matchMedia('screen and (min-width: 768px)'); setTimeout(function () { var errorPoint = target_obj.eq(0).offset().top; var height = 170; if (mql.matches) { var _height = 170; } var errorPos = errorPoint - height; $('html,body').animate({ scrollTop: errorPos }, 'easeInOutQuad'); return false; }, 300); } var error_check = /*#__PURE__*/function () { function error_check() { _classCallCheck(this, error_check); } _createClass(error_check, [{ key: "html_replace", value: function html_replace(str) { return String(str).replace(/&/g, "&").replace(/"/g, """).replace(//g, ">"); } }, { key: "error_txt", value: function error_txt(msg) { return '
' + msg + '
'; } }, { key: "display_control", value: function display_control(error) { var error_sum = 0; for (var _i2 = 0; _i2 < error.length; _i2++) { error_sum += error[_i2][0]; } if (error_sum > 0) { $('#submit').prop("disabled", true); } else { $('.is_input').hide(); $('.is_check').show(); $('#submit').prop("disabled", false); } } }, { key: "check_cake", value: function check_cake(cakenum, msg_error) { var error = 0; $('.input_num').on('blur change', function () { var cakenum2 = 0; $('#check_cake').html(); var inputText = $('.input_num').map(function (index, el) { return $(this).val(); }); for (var i = 0; i < inputText.length; i++) { cakenum2 += Number(inputText[i]); } if (cakenum2 > 0) { $('#check_cake').html(''); } else { $('#check_cake').html('

' + msg_error + '

'); } }); if (cakenum === 0) { $('#check_cake').html('

' + msg_error + '

'); error = 1; } return [error, 0]; } }, { key: "check_txt", value: function check_txt(name) { var msg_error = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; var count = 0; var msg = ''; var obj = $('#check_' + name + ''); var target_obj = $('#input_form_block [name="' + name + '"]'); obj.html(''); if (msg_error) { msg = msg_error; var error_txt = this.error_txt(msg_error); $(target_obj).parent().find('.error-message').remove(); if (target_obj.val()) { msg = this.html_replace(target_obj.val()); } else { count++; target_obj.parent().prepend(error_txt); } target_obj.on('blur change', function () { target_obj.parent().find('.error-message').remove(); if (!$(this).val()) { target_obj.parent().prepend(error_txt); } }); } else { if (target_obj.val()) { msg = this.html_replace(target_obj.val()); } } obj.html(msg); return [count, target_obj]; } }, { key: "check_select", value: function check_select(name, msg_error) { var count = 0; var obj = $('#check_' + name + ''); var target_obj = $('#input_form_block [name="' + name + '"]'); var msg = msg_error; var error_txt = this.error_txt(msg_error); obj.html(''); $(target_obj).parent().find('.error-message').remove(); if (target_obj.val()) { msg = this.html_replace(target_obj.val()); } else { count++; target_obj.parent().prepend(error_txt); } obj.html(msg); target_obj.on('blur change', function () { target_obj.parent().find('.error-message').remove(); if (!$(this).val()) { target_obj.parent().prepend(error_txt); } }); return [count, target_obj]; } }, { key: "check_radio", value: function check_radio(name, msg_error) { var count = 0; var obj = $('#check_' + name + ''); var target_obj = $('#input_form_block input[name="' + name + '"]'); var msg = msg_error; var error_txt = this.error_txt(msg_error); var check_trigger = $('input[name="' + name + '"]:checked').map(function () { return $(this).val(); }).get(); obj.html(''); target_obj.parent().parent().parent().find('.error-message').remove(); if (check_trigger[0]) { msg = check_trigger[0]; } else { count++; target_obj.parent().parent().parent().prepend(error_txt); } obj.html(msg); target_obj.on('blur change', function () { target_obj.parent().parent().parent().find('.error-message').remove(); if (!$('input:radio[name="' + name + '"]:checked').val()) { target_obj.parent().parent().parent().prepend(error_txt); } }); return [count, target_obj]; } }, { key: "check_kana", value: function check_kana(name, msg_error1, msg_error2) { var count = 0; var obj = $('#check_' + name + ''); var target_obj = $('#input_form_block input[name="' + name + '"]'); var msg = msg_error1; var error_txt1 = this.error_txt(msg_error1); var error_txt2 = this.error_txt(msg_error2); obj.html(''); target_obj.parent().find('.error-message').remove(); if (target_obj.val()) { if (!target_obj.val().match(/^[\u30a0-\u30ff  \r\n\t]*$/) && !target_obj.val().match(/^[\u3040-\u309f  \r\n\t]*$/)) { count++; target_obj.parent().prepend(error_txt2); } else { msg = this.html_replace(target_obj.val()); } } else { count++; target_obj.parent().prepend(error_txt1); } obj.html(msg); target_obj.on('blur change', function () { target_obj.parent().find('.error-message').remove(); if (!$(this).val()) { target_obj.parent().prepend(error_txt1); } else if (!$(this).val().match(/^[\u30a0-\u30ff  \r\n\t]*$/) && !$(this).val().match(/^[\u3040-\u309f  \r\n\t]*$/)) { target_obj.parent().prepend(error_txt2); } }); return [count, target_obj]; } }, { key: "check_tel", value: function check_tel(name, msg_error1, msg_error2) { var count = 0; var obj = $('#check_' + name + ''); var target_obj = $('#input_form_block input[name="' + name + '"]'); var msg = msg_error1; var error_txt1 = this.error_txt(msg_error1); var error_txt2 = this.error_txt(msg_error2); obj.html(''); target_obj.parent().find('.error-message').remove(); if (target_obj.val()) { if (!target_obj.val().match(/^(0{1}\d{1,4}-{0,1}\d{1,4}-{0,1}\d{4})$/)) { count++; target_obj.parent().prepend(error_txt2); } else { msg = this.html_replace(target_obj.val()); } } else { count++; target_obj.parent().prepend(error_txt1); } obj.html(msg); target_obj.on('blur change', function () { target_obj.parent().find('.error-message').remove(); if (!$(this).val()) { target_obj.parent().prepend(error_txt1); } else if (!$(this).val().match(/^(0{1}\d{1,4}-{0,1}\d{1,4}-{0,1}\d{4})$/)) { target_obj.parent().prepend(error_txt2); } }); return [count, target_obj]; } }, { key: "check_mail", value: function check_mail(name, msg_error1, msg_error2) { var count = 0; var obj = $('#check_' + name + ''); var target_obj = $('#input_form_block input[name="' + name + '"]'); var msg = msg_error1; var error_txt1 = this.error_txt(msg_error1); var error_txt2 = this.error_txt(msg_error2); obj.html(''); $(target_obj).parent().find('.error-message').remove(); if (target_obj.val()) { if (!target_obj.val().match(/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/)) { count++; $(target_obj).parent().prepend(error_txt2); } else { msg = this.html_replace(target_obj.val()); } } else { count++; target_obj.parent().prepend(error_txt1); } obj.html(msg); target_obj.on('blur change', function () { target_obj.parent().find('.error-message').remove(); if (!$(this).val()) { target_obj.parent().prepend(error_txt1); } else if (!$(this).val().match(/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/)) { target_obj.parent().prepend(error_txt2); } }); return [count, target_obj]; } }]); return error_check; }(); //配列・HTML生成 var create_value = /*#__PURE__*/function () { function create_value() { _classCallCheck(this, create_value); } _createClass(create_value, [{ key: "value", value: function value(id, key) { var html = ''; var cake_array = []; for (var i = 0; i < $(id + ' .' + key).length; i++) { var list = i + 1; //var num = $('.' + key + ' input[name="num' + list + '"]').val(); var num = $('.' + key + ' select[name="num' + list + '"]').val(); var size = $('.' + key + ' input[name="size' + list + '"]').val(); var price = $('.' + key + ' input[name="price' + list + '"]').val(); if (num > 0) { html += this.cell_html(price, num, size); var obj = { size: size, num: num, price: price }; cake_array.push(obj); } } return [html, cake_array]; } }, { key: "cell_html", value: function cell_html(price, num, size) { var html = ''; html += '
'; html += '
' + size + '
'; html += '
' + num + '
'; html += '
' + comma(price) + '円
'; html += '
' + comma(price * num) + '円
'; html += '
'; return html; } }]); return create_value; }(); //配列・HTML生成 var create_value2 = /*#__PURE__*/function () { function create_value2() { _classCallCheck(this, create_value2); } _createClass(create_value2, [{ key: "value", value: function value(id, key) { var cake_array = []; for (var i = 0; i < $(id + ' .' + key).length; i++) { var list = i + 1; //var num_val = $('.' + key + ' input[name="num' + list + '"]').val(); var num_val = $('.' + key + ' select[name="num' + list + '"]').val(); var size_val = $('.' + key + ' input[name="size' + list + '"]').val(); var price_val = $('.' + key + ' input[name="price' + list + '"]').val(); if (num_val > 0) { var obj = { key: list, num: num_val }; cake_array.push(obj); } } return cake_array; } }]); return create_value2; }(); //確認画面出力 var verification = /*#__PURE__*/function () { function verification(array_cake, id) { _classCallCheck(this, verification); this.array_cake = array_cake; this.id = id; } _createClass(verification, [{ key: "header_html", value: function header_html() { var html = ''; html += '
'; html += '
商品名
'; html += '
'; html += '
号数
'; html += '
個数
'; html += '
価格
'; html += '
金額
'; html += '
'; html += '
'; return html; } }, { key: "wrap_html", value: function wrap_html(title, html) { var wrap = ''; wrap += '
'; wrap += '

' + title + '

'; wrap += '
'; wrap += html; wrap += '
'; wrap += '
'; return wrap; } }, { key: "loop", value: function loop(array_cake) { var wrap = ''; var id = this.id; for (var i = 0; i < array_cake.length; i++) { var key = array_cake[i]; var cake_array = []; var create_html = new create_value(); var html = create_html.value(id, key)[0]; if (html) { var title = $(id + ' #' + key + ' h2').html(); wrap += this.wrap_html(title, html); } } return wrap; } }, { key: "output", value: function output() { var loop = ''; var header = ''; var array_cake = this.array_cake; if (array_cake) { loop += this.loop(array_cake); } if (loop) { header += this.header_html(); } if (header + loop) { $('#verification').html(header + loop); } } }]); return verification; }(); //inputタグの出力 var sendvalue = /*#__PURE__*/function () { function sendvalue(array_cake) { _classCallCheck(this, sendvalue); this.array_cake = array_cake; } _createClass(sendvalue, [{ key: "html", value: function html(num, size, price, name) { var input = ''; if (num) { input += ''; input += ''; input += ''; } return input; } }, { key: "html2", value: function html2(num, name) { var input = ''; if (num) { input += ''; } return input; } }, { key: "loop", value: function loop(array, name) { var size = ''; var num = ''; var price = ''; var price_calc = 0; for (var _i3 = 0; _i3 < array.length; ++_i3) { if (_i3 + 1 != array.length) { size += array[_i3]['size'] + ','; num += array[_i3]['num'] + ','; price += array[_i3]['price'] + ','; } else { size += array[_i3]['size']; num += array[_i3]['num']; price += array[_i3]['price']; } price_calc = Number(array[_i3]['price']) * Number(array[_i3]['num']) + price_calc; } var input = this.html(num, size, price, name); return [input, price_calc]; } }, { key: "loop2", value: function loop2(array, name) { var num = ''; for (var _i4 = 0; _i4 < array.length; ++_i4) { if (_i4 + 1 != array.length) { num += array[_i4]['key'] + '_' + array[_i4]['num'] + ','; } else { num += array[_i4]['key'] + '_' + array[_i4]['num']; } } var input = this.html2(num, name); return input; } }, { key: "output", value: function output() { var input = ''; var total = 0; var array_cake = this.array_cake; if (array_cake) { for (var i = 0; i < array_cake.length; i++) { var key = array_cake[i]; var create_array = new create_value2(); var array = create_array.value('#register', key); input += this.loop2(array, key); total = this.loop(array, key)[1] + total; } } if (input) { $('#verification_input').html(input); } if (total) { $('#verification_total').html(comma(total) + '円'); } } }]); return sendvalue; }(); });