備考2 | 特長:いすの背面にセットし脱いだ上着をきれいにかけられます、高さ調節可能なので服が床にすれることがありません
Copyright © YAMADA DENKI CO., LTD. if ($('.app-container').length) {
new PerfectScrollbar(".app-container")
}
jQuery.datetimepicker.setLocale("ja");
$(document).on('click', 'a[data-ajax-popup="true"], button[data-ajax-popup="true"]', function(e) {
var title = $(this).data('title');
var size = ($(this).data('size') == '') ? 'md' : $(this).data('size');
var url = $(this).data('url');
$("#commonModal .modal-title").html(title);
$("#commonModal .modal-dialog").addClass('modal-' + size);
$.ajax({
url: url,
cache: false,
success: function(data) {
$('#commonModal .modal-body').html(data);
$("#commonModal").modal('show');
},
error: function(data) {
data = data.responseJSON;
}
});
e.stopImmediatePropagation();
return false;
});
$(document).on('input paste', 'input[type=text]', function() {
$(this).val($(this).val().trimStart());
});
$(document).ready(function() {
function setCurrentSlide(ele, index) {
$(".swiper1 .swiper-slide").removeClass("selected");
ele.addClass("selected");
}
if ($("#gallary [data-fancybox]").length) {
Fancybox.bind("#gallary [data-fancybox]", {
groupAll: true,
Thumbs: {
type: "modern",
},
});
}
if ($(".swiper1").length) {
var swiper1 = new Swiper(".swiper1", {
spaceBetween: 10,
leftedSlides: true,
slidesPerView: "auto",
touchRatio: 0.2,
slideToClickedSlide: true,
loop: false,
loopedSlides: 1,
});
swiper1.slides.each(function(index, val) {
var ele = $(this);
ele.on("click", function() {
setCurrentSlide(ele, index);
swiper2.slideTo(index, 500, false);
});
});
var swiper2 = new Swiper(".swiper2", {
autoHeight: true,
nextButton: ".swiper-button-next",
prevButton: ".swiper-button-prev",
onSlideChangeEnd: function(swiper) {
var n = swiper.activeIndex;
setCurrentSlide($(".swiper1 .swiper-slide").eq(n), n);
swiper1.slideTo(n, 500, false);
},
});
}
})
$(document).on('click', '.per-page', function() {
let perPage = parseInt($(this).data('page'))
$('#perPage').val(perPage)
updateTableData()
})
$(document).on('click', '.sort-products', function() {
getOtherFilterDataVar.sort = $(this).data('sort')
updateTableData()
})
$(document).on('click', '.product-view-type', function() {
getOtherFilterDataVar.view_type = $(this).data('view-type')
updateTableData()
})
$(document).on('click', '.previous-page, .next-page', function() {
var currentUrl = new URL(window.location.href);
currentUrl.searchParams.set('page', parseInt($(this).data('page')));
window.history.pushState({}, '', currentUrl); // Update URL without reloading
updateTableData(parseInt($(this).data('page')))
});
window.isLikeDislikeAjaxInProgress = false;
$(document).on('click', '.like-dislike-btn', async function(e) {
e.preventDefault();
if (!isLikeDislikeAjaxInProgress) {
isLikeDislikeAjaxInProgress = true;
let $this = $(this);
let productId = $this.find('img').data('product-id');
let url = $this.hasClass('like-img') ? '/products-like/' + productId : '/products-dislike/' +
productId;
await $.ajax({
url: url,
type: 'GET',
success: function(response) {
if (response.success) {
if ($this.hasClass('like-img')) {
$this.removeClass('like-img').addClass('dislike-img')
} else {
$this.removeClass('dislike-img').addClass('like-img')
}
$this.parent().find('img').toggleClass('d-none');
$('.totalLikedProducts').text(response.data.count)
isLikeDislikeAjaxInProgress = false;
}
},
error: function(error) {
isLikeDislikeAjaxInProgress = false;
},
statusCode: {
500: function() {
isLikeDislikeAjaxInProgress = false;
}
}
});
}
});
$(document).on('click', '.remove-like-btn', function(e) {
e.preventDefault();
let productId = $(this).data('product-id');
let $element = $(this)
$.ajax({
url: '/products-dislike/' + productId,
type: 'GET',
success: function(response) {
if (response.success) {
$element.parents('.product-card').remove();
$('.totalLikedProducts').text(response.data.count)
if (!$('.recommended-products-like-cart.remove-like-btn').length) {
$('.product-container').addClass('d-none');
$('.product-empty-container').removeClass('d-none');
}
}
}
});
});
$(document).on("focusout", ".product-all-select-number", function() {
let value = $(this).val();
if (value == '' || !Number.isInteger(parseInt(value)) || parseFloat(value) < 1) {
$(this).val(1)
}
value = $(this).val();
$("#productAllSelectNumber").val(value)
$(".product-all-select-number-span").text(value)
let price = $("#productPrice").val();
countTotalItemPrice($("#totalItemPrice"), price, parseInt(value));
$("#plusProductBtn").prop("disabled", false);
$("#minusProductBtn").prop("disabled", false);
});
$(document).on("keypress", ".product-all-select-number", function() {
let value = $(this).val();
$('#addToCartBtnText').text('見積カートに入れる');
$('#addToCartBtn').prop('disabled', false).css('background',
'linear-gradient(90deg, #6a11cb 0%, #2575fc 100%)')
});
$(document).on("input paste", ".product-all-select-number", function() {
let value = $(this).val();
if (value == '') {
value = 1
}
if (parseFloat(value) < 1) {
$(this).val(1);
value = 1
}
$(this).val(parseInt(value));
$("#productAllSelectNumber").val(value)
$(".product-all-select-number-span").text(value)
let price = $("#productPrice").val();
countTotalItemPrice($("#totalItemPrice"), price, parseInt(value));
$("#plusProductBtn").prop("disabled", false);
$("#minusProductBtn").prop("disabled", false);
if ($('.insurance-product:checked').length) {
$('.insurance-product:checked').trigger('change');
}
});
$(document).on("click", "#plusProductBtn", function() {
let count = parseInt($("#productAllSelectNumber").val());
let buttonDisabled = false;
$("#minusProductBtn").prop("disabled", false);
count++;
if (isNaN(count)) {
count = 1;
}
if (count > 10000) {
count = 10000;
$(this).prop("disabled", true);
}
$(".product-all-select-number").val(count);
$(".product-all-select-number-span").text(count);
$("#productAllSelectNumber").val(count);
let price = $("#productPrice").val();
countTotalItemPrice($("#totalItemPrice"), price, count);
if (!buttonDisabled) {
$('#addToCartBtnText').text('見積カートに入れる');
$('#addToCartBtn').prop('disabled', false).css('background',
'linear-gradient(90deg, #6a11cb 0%, #2575fc 100%)')
}
if ($('.insurance-product:checked').length) {
$('.insurance-product:checked').trigger('change');
}
});
$(document).on("click", "#minusProductBtn", function() {
let count = parseInt($("#productAllSelectNumber").val());
$(this).prop("disabled", false);
$("#plusProductBtn").prop("disabled", false);
if (count <= 2) {
$(this).prop("disabled", true);
if (count == 1) {
return;
}
}
count--;
if (isNaN(count) || count <= 0) {
count = 1;
}
$(".product-all-select-number").val(count);
$(".product-all-select-number-span").text(count);
$("#productAllSelectNumber").val(count);
let price = $("#productPrice").val();
countTotalItemPrice($("#totalItemPrice"), price, count);
$('#addToCartBtnText').text('見積カートに入れる');
$('#addToCartBtn').prop('disabled', false).css('background',
'linear-gradient(90deg, #6a11cb 0%, #2575fc 100%)')
if ($('.insurance-product:checked').length) {
$('.insurance-product:checked').trigger('change');
}
});
function countTotalItemPrice(inputField, price, count) {
inputField.text(currency(price * count));
}
window.showMessage = true;
window.updateCart = async function(isAddToCart = false) {
await $.ajax({
method: "GET",
url: '/update-cart',
data: {
meta: $("#cartData").val(),
isAddToCart: isAddToCart
},
success: function(response) {
if (!response.success) {
if (response.data.url) {
setTimeout(() => {
location.href = response.data.url
}, 400);
} else {
displayErrorMessage(response.data.message)
showMessage = false
}
} else {
showMessage = true
}
},
});
};
window.countTotalItem = function() {
const cartData = JSON.parse($("#cartData").val()) || [];
let totalItems = 0;
$.each(cartData, function(index, element) {
totalItems += 1;
});
return totalItems;
};
$(document).on("change", '.insurance-product', async function() {
if (!$('#cartScreen').length) {
$('#addToCartBtnText').text('見積カートに入れる');
$('#addToCartBtn').prop('disabled', false).css('background',
'linear-gradient(90deg, #6a11cb 0%, #2575fc 100%)');
let productId = $("#productId").val();
let price = $("#productPrice").val();
let totalItem = parseInt($("#productAllSelectNumber").val())
$('.insurance-product-total').text(0);
if ($(this).data('attached') == 1) {
let percentage = parseInt($(this).data('percentage'));
let key = $(this).data('key');
let totalInsuranceValue = (parseInt((price * percentage) / 100)) * parseInt(totalItem);
$('.insurance-product-total[data-key="' + key + '"][data-percentage="' + percentage + '"]')
.text(currency(totalInsuranceValue));
}
} else {
let productId = $(this).attr('data-insurance-product-id');
let price = parseInt($('.table-product-item[data-product-id="' + productId + '"]').attr(
'data-price'));
let totalItem = parseInt($('.table-product-item[data-product-id="' + productId + '"]').val());
$('.total-product-price[data-insurance-product-id="' + productId + '"]').text(currency(0));
$('.table-product-item[data-insurance-product-id="' + productId + '"]').val(0);
let isInsurance = false
let percentage = $(this).data('percentage');
let totalInsuranceValue = 0;
let key = 0
if ($(this).data('attached') == 1) {
isInsurance = true;
key = $(this).data('key');
totalInsuranceValue = (parseInt((price * percentage) / 100)) * parseInt(totalItem);
$('.total-product-price[data-percentage="' + percentage + '"][data-insurance-product-id="' +
productId + '"]').text(currency(totalInsuranceValue));
$('.table-product-item[data-percentage="' + percentage + '"][data-insurance-product-id="' +
productId + '"]').val(totalItem);
}
await addToCart(productId, price, totalItem, isInsurance, key, percentage, totalInsuranceValue);
await updateCart();
updateCardData();
}
});
$(document).on("click", "#addToCartBtn", async function() {
$(this).prop('disabled', true);
let productId = $("#productId").val();
let price = $("#productPrice").val();
let isInsurance = $('.insurance-product:checked').data('attached') == 1
let percentage = parseInt($('.insurance-product:checked').data('percentage'));
let key = $('.insurance-product:checked').data('key');
let totalInsuranceValue = 0;
if ($('.insurance-product:checked').data('attached') == 1) {
totalInsuranceValue = (parseInt((price * percentage) / 100)) * parseInt(
$("#productAllSelectNumber").val());
}
await addToCart(
productId, price,
parseInt($("#productAllSelectNumber").val()),
isInsurance, key, percentage, totalInsuranceValue
);
await updateCart(true);
let totalItemCount = parseInt($(".total-item-count").text());
$(this).prop('disabled', false);
});
function removeElementByProductId(array, productId) {
// Find the index of the element with the specified productId
const indexToRemove = array.findIndex(
(item) => item.productId == productId
);
// If the element is found, remove it from the array
if (indexToRemove !== -1) {
array.splice(indexToRemove, 1);
}
return array;
}
window.addToCart = function(
productId, price, totalItem = 1,
isInsurance, key, percentage, totalInsuranceValue
) {
// Retrieve existing cart data from cartData or initialize an empty array
let cartData = JSON.parse($("#cartData").val()) || [];
// Check if the product is already in the cart
let existingProductIndex = cartData.findIndex(
(item) => item.productId == productId
);
if (existingProductIndex !== -1) {
// If the product is already in the cart, update the totalItem
cartData[existingProductIndex].totalItem = totalItem;
cartData[existingProductIndex].totalPrice = price * totalItem;
cartData[existingProductIndex].isInsurance = isInsurance;
cartData[existingProductIndex].key = key;
cartData[existingProductIndex].percentage = percentage;
cartData[existingProductIndex].totalInsuranceValue = totalInsuranceValue;
// Remove element from json if totalItem is 0
if (totalItem == 0) {
cartData = removeElementByProductId(cartData, productId);
}
} else if (totalItem >= 1) {
// If the product is not in the cart, add a new entry
cartData.push({
productId: productId,
price: price,
totalItem: totalItem,
totalPrice: price * totalItem,
position: cartData.length + 1,
isInsurance: isInsurance,
key: key,
percentage: percentage,
totalInsuranceValue: totalInsuranceValue,
});
}
// Save the updated cart data to localStorage
$("#cartData").val(JSON.stringify(cartData));
};
$(document).on("click", ".item-decrement", async function() {
let element = $(this).next();
let value = parseInt(element.val());
let min = parseInt(element.attr("min"));
element.next().css({
"background-color": "unset",
"cursor": "pointer"
});
if (value <= min + 1) {
$(this).css({
"background-color": "#ededed",
"cursor": "default"
});
}
if (value - 1 == 0) {
value++;
}
element.val(value - 1).trigger("input");
});
$(document).on("click", ".item-increment", async function() {
let element = $(this).prev();
let value = parseInt(element.val());
let max = parseInt(element.attr("max"));
element.prev().css({
"background-color": "unset",
"cursor": "pointer"
});
if (value >= max - 1) {
$(this).css({
"background-color": "#ededed",
"cursor": "default"
});
element.val(max).trigger('input')
return
}
element.val(value + 1).trigger("input");
});
$(document).on("input paste keydown", ".table-product-item", async function() {
let productId = $(this).data("product-id");
if (!productId) {
return
}
let price = $(this).data("price");
let totalItem = $(this).val();
if (totalItem == "") {
totalItem = 1;
}
if (!Number.isInteger(parseInt(totalItem))) {
totalItem = 1;
}
if ($(this).attr("min") == 1 && parseInt(totalItem) < 1) {
totalItem = 1;
}
if ($(this).attr("data-last-value") == totalItem) {
return false;
}
if ($(this).prev().css('cursor') == 'default') {
$(this).prev().css({
"background-color": "unset",
"cursor": "pointer"
});
}
console.log($(this).next().css('cursor'));
if ($(this).next().css('cursor') == 'default') {
$(this).next().css({
"background-color": "unset",
"cursor": "pointer"
});
}
$(this).attr("data-last-value", totalItem);
if (totalItem == 0) {
$(this).parents("tr").remove();
}
let inputField = $(this).parents('.products-multiple-data-table').find(
'.total-product-price[data-product-id="' + productId + '"]');
await countTotalItemPrice(inputField, price, totalItem);
let percentage = parseInt($('.insurance-product[data-insurance-product-id="' + productId +
'"]:checked').attr('data-percentage'));
let key = $('.insurance-product[data-insurance-product-id="' + productId + '"]:checked')
.attr('data-key');
let totalInsuranceValue = 0;
let isInsurance = false;
if ($('.total-product-price[data-insurance-product-id="' + productId + '"]').length &&
$('.insurance-product[data-insurance-product-id="' + productId +
'"][data-attached="1"]:checked').length) {
isInsurance = true;
percentage = parseInt($('.insurance-product[data-insurance-product-id="' + productId +
'"]:checked')
.attr('data-percentage'));
totalInsuranceValue = (parseInt((price * percentage) / 100)) * totalItem;
$('.table-product-item[data-insurance-product-id="' + productId + '"][data-percentage="' +
percentage + '"]').val(totalItem)
$('.total-product-price[data-insurance-product-id="' + productId + '"][data-percentage="' +
percentage + '"]').text(
totalInsuranceValue)
}
await addToCart(productId, price, totalItem,
isInsurance, key, percentage, totalInsuranceValue);
await updateCart();
updateCardData();
});
document.addEventListener('click', function(event) {
var $target = $(event.target);
if (!$target.closest('.table-product-item').length) {
$('.table-product-item').not('[data-percentage]').each(function() {
if ($(this).val() == '' || $(this).val() == 0) {
$(this).val(1)
}
})
}
});
function updateCardData() {
let cartData = JSON.parse($("#cartData").val());
let totalPriceSum = 0;
let totalItemSum = 0;
$.each(cartData, function(index, element) {
totalItemSum += parseFloat(element.totalItem);
totalPriceSum += parseFloat(element.totalPrice) + parseFloat(element.totalInsuranceValue);
});
$(".totalItem").text(totalItemSum);
$(".totalProductItemAmount").text(currency(totalPriceSum));
}
$(document).on("click", ".delete-item-btn", async function() {
let productId = $(this).data("product-id");
let cartData = JSON.parse($("#cartData").val());
cartData = await removeElementByProductId(cartData, productId);
if ($(".products-multiple-data-table").length - 1 == 0) {
$(".product-empty-container").removeClass("d-none");
$(".product-container").addClass("d-none");
}
$(this).parents(".products-multiple-data-table").remove();
$("#cartData").val(JSON.stringify(cartData));
await updateCart();
$(".total-item-count").text(countTotalItem());
updateCardData();
});
$(document).on("click", "#quotationConfirmedBtn", function(e) {
if (($('#submitQuotationForm input[name="post_code_1"]').val() === '' || $(
'#submitQuotationForm input[name="post_code_2"]').val() === '') && $(
'input[name="not_decided_yet"]').val() != 'true')
displayErrorMessage('create delivery address')
else
$("#submitQuotationForm").submit()
});
$(document).on("click", "#sendQuotationRequest", function(e) {
e.preventDefault();
$(this).prop('disabled', true);
$.ajax({
method: "POST",
url: '/quotation/send',
data: new FormData($('#submitQuotationForm')[0]),
processData: false,
contentType: false,
success: function(response) {
if (response.success) {
location.href = '/quotation/success'
} else {
displayErrorMessage(response.data.message)
$('#sendQuotationRequest').prop('disabled', false);
}
},
error: function(error) {
$('#sendQuotationRequest').prop('disabled', false);
},
statusCode: {
500: function() {
$('#sendQuotationRequest').prop('disabled', false);
}
}
});
});
$(document).on("click", "#changeDeliveryAddress", function(e) {
e.preventDefault();
$('input[name="first_name"]').attr('placeholder', '');
$('input[name="last_name"]').attr('placeholder', '');
$('#createDelivery').prop('disabled', false)
$.ajax({
method: "GET",
url: '/quotation/get-delivery-address',
success: function(response) {
if (response.success && response.data.count) {
$('#deliveryAddress').addClass('d-none')
$('#deliverySelectionSection').empty()
$('#deliverySelectionSection').append(response.data.view)
}
},
});
});
$(document).on("click", "#editDelivery", function(e) {
$('#submitDelivery').removeClass('d-none')
$(this).addClass('d-none')
$('#collapsewithlinks input').each(function() {
$(this).prop('readonly', false)
})
$('input[name="submit_delivery"]').val(false);
});
$(document).on("click", "#createDelivery", function(e) {
$(this).prop('disabled', true)
$('.saveDelivery').removeClass('d-none')
$('.cancelDelivery').removeClass('d-none')
$('#collapsewithlinks input').each(function() {
$(this).prop('readonly', false)
$(this).val('')
})
$('#collapsewithlinks .address-label').each(function() {
$(this).addClass('required')
})
$('#quotationConfirmedBtn').prop('disabled', true)
$('input[name="first_name"]').attr('placeholder', '姓');
$('input[name="last_name"]').attr('placeholder', '名');
});
function expandSection() {
var collapseElement = document.getElementById('collapsewithlinks');
if (!collapseElement.classList.contains('show')) {
collapseElement.classList.add('show');
$('a[href="#collapsewithlinks"]').removeClass('collapsed');
}
}
$(document).on("click", "#not_decided_yet", function(e) {
$('#decided_yet').removeClass('d-none')
$(this).addClass('d-none')
$('input[name="save_delivery_id"]').val(0);
$('input[name="not_decided_yet"]').val(true);
$('.saveDelivery').addClass('d-none')
$('.cancelDelivery').addClass('d-none')
$('#createDelivery').prop('disabled', false)
$('#quotationConfirmedBtn').prop('disabled', false)
$('#changeDeliveryAddress').prop('disabled', true)
getDefaultAddress()
});
$(document).on("click", "#decided_yet", function(e) {
$('#not_decided_yet').removeClass('d-none')
$(this).addClass('d-none')
$('.saveDelivery').addClass('d-none')
$('.cancelDelivery').addClass('d-none')
$('#createDelivery').prop('disabled', false)
$('input[name="not_decided_yet"]').val(false);
$('#collapsewithlinks input').each(function() {
$(this).prop('readonly', true)
$(this).removeClass('error')
})
$('#collapsewithlinks span').each(function() {
$(this).addClass('d-none')
})
$('#changeDeliveryAddress').prop('disabled', true)
getDefaultAddress()
$('#quotationConfirmedBtn').prop('disabled', false)
$('#collapsewithlinks .address-label').each(function() {
$(this).removeClass('required')
})
});
$(document).on("input paste", "#collapsewithlinks input", function(e) {
if ($(this).val() != '' && ($(this).attr('name') != 'post_code_1' && $(this).attr('name') !=
'post_code_2')) {
$(this).removeClass('error')
$('.' + $(this).attr('name') + '-error').addClass('d-none')
}
if ($(this).attr('name') != 'post_code_1' || $(this).attr('name') != 'post_code_2') {
if ($('input[name="post_code_1"]').val().length == 3 &&
$('input[name="post_code_2"]').val().length == 4) {
$('.post_code_1-error').addClass('d-none')
}
}
});
let debounceTimeout;
$(document).on('input paste', 'input[name="post_code_1"], input[name="post_code_2"]', function() {
clearTimeout(debounceTimeout);
$('#submitDelivery').prop('disabled', true);
$('#saveDelivery').prop('disabled', true);
debounceTimeout = setTimeout(async function() {
$('input[name="prefectures"]').val('');
$('input[name="municipalities"]').val('');
const zipcode = $('input[name="post_code_1"]').val().trim() + $(
'input[name="post_code_2"]').val().trim().substring(0, 4);
if (zipcode.length > 6) {
try {
const response = await $.ajax({
url: '/google-maps-proxy',
data: {
url: 'https://maps.googleapis.com/maps/api/geocode/json?address=' +
zipcode +
'&components=country:JP&key=AIzaSyBsJd80fZiA6cmzovoq45Zt-WT6Z4isQ_k&language=ja',
},
method: "GET"
});
const parsedResponse = JSON.parse(response);
let postcode = $('input[name="post_code_1"]').val().trim() + $(
'input[name="post_code_2"]').val().trim().substring(0, 4);
if (parsedResponse.status === 'OK' && postcode.length > 6) {
const res0 = parsedResponse.results[0];
if (res0.address_components.length > 1) {
$('input[name="post_code_1"]').removeClass('error');
$('input[name="post_code_2"]').removeClass('error');
$('.prefectures-error').addClass('d-none');
$('.municipalities-error').addClass('d-none');
if (res0.address_components.at(-2)) {
$('input[name="prefectures"]').val(res0.address_components.at(-2)
.long_name).removeClass('error');
}
if (res0.address_components.at(-3)) {
$('input[name="municipalities"]').val(res0.address_components.at(-3)
.long_name).removeClass('error');
}
} else {
$('input[name="post_code_1"]').addClass('error');
$('input[name="post_code_2"]').addClass('error');
$('input[name="prefectures"]').val('');
$('input[name="municipalities"]').val('');
}
}
} catch (error) {
$('input[name="prefectures"]').val('');
$('input[name="municipalities"]').val('');
}
} else {
$('input[name="prefectures"]').val('');
$('input[name="municipalities"]').val('');
}
$('#submitDelivery').prop('disabled', false);
$('#saveDelivery').prop('disabled', false);
}, 200);
});
$(document).on("click", "#submitDelivery", function(e) {
let postCode1 = $('input[name="post_code_1"]');
let postCode2 = $('input[name="post_code_2"]');
let prefectures = $('input[name="prefectures"]');
let municipalities = $('input[name="municipalities"]');
let streetAddress = $('input[name="street_address"]');
// let buildingName = $('input[name="building_name"]');
let error = false;
if (postCode1.hasClass('error')) {
error = true;
}
if (postCode2.hasClass('error')) {
error = true;
}
if (postCode1.val().length < 3) {
postCode1.addClass('error');
if (postCode2.val() == '') {
$('.post_code_1-error').removeClass('d-none').text('必須項目です。');
} else {
$('.post_code_1-error').removeClass('d-none').text('3桁で入力してください');
}
error = true;
}
if (postCode2.val().length < 3) {
postCode2.addClass('error');
if (postCode2.val() == '') {
$('.post_code_1-error').removeClass('d-none').text('必須項目です。');
} else {
$('.post_code_1-error').removeClass('d-none').text('4桁で入力してください');
}
error = true;
}
if (prefectures.val().length < 1) {
prefectures.addClass('error');
$('.prefectures-error').removeClass('d-none');
error = true;
}
if (municipalities.val().length < 1) {
municipalities.addClass('error');
$('.municipalities-error').removeClass('d-none');
error = true;
}
if (streetAddress.val().length < 1) {
streetAddress.addClass('error');
$('.street_address-error').removeClass('d-none');
error = true;
}
// if (buildingName.val().length < 1) {
// buildingName.addClass('error');
// error = true;
// }
if (!error) {
$('#editDelivery').removeClass('d-none')
$(this).addClass('d-none')
$('#collapsewithlinks input').each(function() {
$(this).prop('readonly', true)
})
$('#quotationConfirmedBtn').prop('disabled', false)
$('input[name="submit_delivery"]').val(true);
}
});
$(document).on("click", "#saveDelivery", function(e) {
let corporate_name = $('input[name="corporate_name"]');
let first_name = $('input[name="first_name"]');
let last_name = $('input[name="last_name"]');
let department_name = $('input[name="department_name"]');
let phone_number_1 = $('input[name="phone_number_1"]');
let phone_number_2 = $('input[name="phone_number_2"]');
let phone_number_3 = $('input[name="phone_number_3"]');
let postCode1 = $('input[name="post_code_1"]');
let postCode2 = $('input[name="post_code_2"]');
let prefectures = $('input[name="prefectures"]');
let municipalities = $('input[name="municipalities"]');
let streetAddress = $('input[name="street_address"]');
let buildingName = $('input[name="building_name"]');
let error = false;
$('.phone_number_1-error').addClass('d-none');
if (postCode1.hasClass('error')) {
error = true;
}
if (postCode2.hasClass('error')) {
error = true;
}
if (phone_number_1.val().length < 1) {
phone_number_1.addClass('error');
$('.phone_number_1-error').removeClass('d-none');
error = true;
} else if (phone_number_1.val().length < 2) {
phone_number_1.addClass('error');
$('.phone_number_2-error').removeClass('d-none');
error = true;
}
if (phone_number_2.val().length < 1) {
phone_number_2.addClass('error');
$('.phone_number_1-error').removeClass('d-none');
error = true;
}
if (phone_number_3.val().length < 1) {
phone_number_3.addClass('error');
$('.phone_number_1-error').removeClass('d-none');
error = true;
} else if (phone_number_3.val().length < 4) {
phone_number_3.addClass('error');
$('.phone_number_2-error').removeClass('d-none');
error = true;
}
if (corporate_name.val().length < 1) {
corporate_name.addClass('error');
$('.corporate_name-error').removeClass('d-none');
error = true;
}
if (department_name.val().length < 1) {
department_name.addClass('error');
$('.department_name-error').removeClass('d-none');
error = true;
}
if (postCode1.val().length < 3) {
postCode1.addClass('error');
if (postCode2.val() == '') {
$('.post_code_1-error').removeClass('d-none').text('必須項目です。');
} else {
$('.post_code_1-error').removeClass('d-none').text('3桁で入力してください');
}
error = true;
}
if (postCode2.val().length < 3) {
postCode2.addClass('error');
if (postCode2.val() == '') {
$('.post_code_1-error').removeClass('d-none').text('必須項目です。');
} else {
$('.post_code_1-error').removeClass('d-none').text('4桁で入力してください');
}
error = true;
}
if (prefectures.val().length < 1) {
prefectures.addClass('error');
$('.prefectures-error').removeClass('d-none');
error = true;
}
if (municipalities.val().length < 1) {
municipalities.addClass('error');
$('.municipalities-error').removeClass('d-none');
error = true;
}
if (streetAddress.val().length < 1) {
streetAddress.addClass('error');
$('.street_address-error').removeClass('d-none');
error = true;
}
// if (buildingName.val().length < 1) {
// buildingName.addClass('error');
// error = true;
// }
if (!error) {
$(this).prop('disabled', true);
$.ajax({
method: "POST",
url: '/quotation/saveDeliveryAddress',
data: {
corporate_name: corporate_name.val(),
first_name: first_name.val(),
last_name: last_name.val(),
department_name: department_name.val(),
contact_number_1: $('input[name="phone_number_1"]').val(),
contact_number_2: $('input[name="phone_number_2"]').val(),
contact_number_3: $('input[name="phone_number_3"]').val(),
post_code_1: postCode1.val(),
post_code_2: postCode2.val(),
prefectures: prefectures.val(),
municipalities: municipalities.val(),
street_address: streetAddress.val(),
building_name: buildingName.val(),
},
dataType: "json",
success: function(response) {
if (response.success) {
displaySuccessMessage(response.data.message)
$('#saveDelivery').prop('disabled', false);
$('.saveDelivery').addClass('d-none')
$('.cancelDelivery').addClass('d-none')
$('#createDelivery').prop('disabled', false)
$('#collapsewithlinks input').each(function() {
$(this).prop('readonly', true)
})
$('input[name="save_delivery_id"]').val(response.data.id);
$('#quotationConfirmedBtn').prop('disabled', false)
$('#collapsewithlinks .address-label').each(function() {
$(this).removeClass('required')
})
$('#changeDeliveryAddress').prop('disabled', false)
}
},
error: function(error) {
$('#saveDelivery').prop('disabled', false);
}
});
}
});
$(document).on("click", "#cancelDelivery", function(e) {
$('.saveDelivery').addClass('d-none')
$('.cancelDelivery').addClass('d-none')
$('#collapsewithlinks .address-label').each(function() {
$(this).removeClass('required')
})
$('#collapsewithlinks input').each(function() {
$(this).prop('readonly', true)
$(this).removeClass('error')
})
$('#collapsewithlinks span').each(function() {
$(this).addClass('d-none')
})
$('#changeDeliveryAddress').prop('disabled', true)
$('#createDelivery').prop('disabled', false)
getDefaultAddress()
});
function getDefaultAddress() {
$('input[name="first_name"]').attr('placeholder', '');
$('input[name="last_name"]').attr('placeholder', '');
$.ajax({
method: "GET",
url: '/carts',
success: function(response) {
if (response.success) {
delivery = response.data.delivery;
var postCode = delivery.post_code || '';
var postCodeParts = postCode.split('-');
var phone_number = delivery.phone_number || '';
var phone_numberParts = phone_number.split('-');
$('input[name="corporate_name"]').val(delivery.corporate_name ?? '');
$('input[name="first_name"]').val(delivery.first_name ?? '');
$('input[name="last_name"]').val(delivery.last_name ?? '');
$('input[name="department_name"]').val(delivery.department_name ?? '');
$('input[name="phone_number_1"]').val(phone_numberParts[0] || '')
$('input[name="phone_number_2"]').val(phone_numberParts[1] || '')
$('input[name="phone_number_3"]').val(phone_numberParts[2] || '')
$('input[name="post_code_1"]').val(postCodeParts[0] || '')
$('input[name="post_code_2"]').val(postCodeParts[1] || '');
$('input[name="prefectures"]').val(delivery.prefectures ?? '');
$('input[name="municipalities"]').val(delivery.municipalities ?? '');
$('input[name="street_address"]').val(delivery.street_address ?? '');
$('input[name="building_name"]').val(delivery.building_name ?? '');
if (($('input[name="post_code_1"]').val() != '' && $(
'input[name="post_code_2"]')
.val() != '')) {
$('#changeDeliveryAddress').prop('disabled', false)
}
}
},
});
}
$(document).on("click", ".select-delivery-address", function(e) {
let delivery = $(this).data('delivery');
let phone_number = $('.phone_number[data-delivery="' + delivery + '"]').val();
let corporate_name = $('.corporate_name[data-delivery="' + delivery + '"]').val();
let first_name = $('.first_name[data-delivery="' + delivery + '"]').val();
let last_name = $('.last_name[data-delivery="' + delivery + '"]').val();
let department_name = $('.department_name[data-delivery="' + delivery + '"]').val();
let postcode = $('.post-code[data-delivery="' + delivery + '"]').val();
let prefectures = $('.prefectures[data-delivery="' + delivery + '"]').val();
let municipalities = $('.municipalities[data-delivery="' + delivery + '"]').val();
let streetAddress = $('.street-address[data-delivery="' + delivery + '"]').val();
let buildingName = $('.building-name[data-delivery="' + delivery + '"]').val();
$('input[name="corporate_name"]').val(corporate_name);
$('input[name="first_name"]').val(first_name);
$('input[name="last_name"]').val(last_name);
$('input[name="department_name"]').val(department_name);
$('input[name="post_code"]').val(postcode);
$('input[name="prefectures"]').val(prefectures);
$('input[name="municipalities"]').val(municipalities);
$('input[name="street_address"]').val(streetAddress);
$('input[name="building_name"]').val(buildingName);
$('input[name="post_code_1"]').val(postcode.split('-')[0]);
$('input[name="post_code_2"]').val(postcode.split('-')[1]);
$('input[name="phone_number_1"]').val(phone_number.split('-')[0]);
$('input[name="phone_number_2"]').val(phone_number.split('-')[1]);
$('input[name="phone_number_3"]').val(phone_number.split('-')[2]);
$('#deliveryAddress').removeClass('d-none')
$('#deliverySelectionSection').empty()
$('#collapsewithlinks input').each(function() {
$(this).prop('readonly', true)
$(this).removeClass('error')
})
$('#collapsewithlinks span').each(function() {
$(this).addClass('d-none')
})
$('.street_address-error').addClass('d-none')
$('.post_code_1-error').addClass('d-none').text('必須項目です。');
$('.prefectures-error').addClass('d-none');
$('.municipalities-error').addClass('d-none');
$('.street_address-error').addClass('d-none');
$('.saveDelivery').addClass('d-none')
$('.cancelDelivery').addClass('d-none')
$(".first_name-error").addClass('d-none');
$('#collapsewithlinks .address-label').each(function() {
$(this).removeClass('required')
})
$('#quotationConfirmedBtn').prop('disabled', false)
$('input[name="save_delivery_id"]').val(0);
});
window.allowNumber = function(evt) {
evt = (evt) ? evt : window.event;
if (evt.which == 45) {
return true;
}
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
$(document).on('input', 'input', function() {
let name = $(this).attr('name');
switch (name) {
case "post_code_1":
case "post_code_2":
$(".post_code_1-error").addClass('d-none');
break;
case "phone_number_1":
case "phone_number_2":
case "phone_number_3":
$(".phone_number_1-error").addClass('d-none');
$(".phone_number_2-error").addClass('d-none');
break;
default:
$('#' + name + '-error').remove();
}
});
window.addEventListener('popstate', function() {
const queryParams = new URLSearchParams(window.location.search);
const page = queryParams.get('page');
updateTableData(page)
});
RenderCKEditor(['description'])
|