var calc_2 =
{
init: function()
{
$('.calc-change').on('change keyup', calc_2.render);
$('input[name=tabletop]').on('change', calc_2.clearCabs);
calc_2.$ = $('.main-container .constructor-container-img');
},
tableRow: function(name, num, price)
{
return '
| '+name+' | '+num+' | '+price+' | '+(num*price)+' |
';
},
clearCabs: function()
{
$('select[name=left_cabinet] option:first-child, select[name=right_cabinet] option:first-child').prop('selected', true);
$('select.style-dropdown').trigger('liszt:updated');
calc_2.render();
},
render: function()
{
calc_2.workbenchRender();
calc_2.tableRender();
},
workbenchRender: function()
{
calc_2.$.find('img').hide();
var $tabletop = $('input[name=tabletop]').filter(':checked');
if($tabletop.size())
{
calc_2.$.find($tabletop.data('selector')).show();
//$('#show_additional').addClass('active');
$('select[name=left_cabinet], select[name=right_cabinet]').prop('disabled', false);
}
else
{
//$('#show_additional').removeClass('active');
$('select[name=left_cabinet], select[name=right_cabinet]').prop('disabled', true);
}
$('select[name=left_cabinet], select[name=right_cabinet]').trigger('liszt:updated');
if($tabletop.data('cab-required') == 1)
$('.main-container .cab-message').show().text('Для выбранной столешницы обязательно должна быть выбрана тумба.');
else if($tabletop.data('cab-required') == 2)
$('.main-container .cab-message').show().text('Для выбранной столешницы обязательно использование обеих тумб.');
else
$('.main-container .cab-message').hide();
var $cabL = $('select[name=left_cabinet] option').filter(':selected'),
$cabR = $('select[name=right_cabinet] option').filter(':selected');
calc_2.$.find('.cab').hide();
if($cabL.val())
calc_2.$.find($cabL.data('selector')+'.cab-l').show();
if($cabR.val())
calc_2.$.find($cabR.data('selector')+'.cab-r').show();
if($tabletop.data('cab-max') == 1)
{
if($cabL.val())
{
$('select[name=right_cabinet]').prop('disabled', true).trigger('liszt:updated');
}
else if($cabR.val())
{
$('select[name=left_cabinet]').prop('disabled', true).trigger('liszt:updated');
}
else
{
$('select[name=left_cabinet]').prop('disabled', false).trigger('liszt:updated');
$('select[name=right_cabinet]').prop('disabled', false).trigger('liszt:updated');
}
}
if($('input[name=perforated_screen]').is(':checked'))
{
calc_2.$.find('.shield').show();
$('#constructorForm input[name=perforated_screen_2]').prop('disabled', false);
}
else
{
calc_2.$.find('.shield').hide();
$('#constructorForm input[name=perforated_screen_2]').prop('checked', false);
$('#constructorForm input[name=perforated_screen_2]').prop('disabled', true);
}
if($('input[name=perforated_screen_2]').is(':checked'))
{
calc_2.$.find('.shield_2').show();
calc_2.$.find('.shield_light').css('top','-52px');
//$('#constructorForm input[name=perforated_screen_light]').prop('disabled', false);
}
else
{
calc_2.$.find('.shield_2').hide();
calc_2.$.find('.shield_light').css('top','44px');
//$('#constructorForm input[name=perforated_screen_light]').prop('checked', false);
//$('#constructorForm input[name=perforated_screen_light]').prop('disabled', true);
}
if($('input[name=perforated_screen_2]').is(':checked')||$('input[name=perforated_screen]').is(':checked'))
{
//calc_2.$.find('.shield_2').show();
$('#constructorForm input[name=perforated_screen_light]').prop('disabled', false);
}
else
{
//calc_2.$.find('.shield_2').hide();
$('#constructorForm input[name=perforated_screen_light]').prop('checked', false);
$('#constructorForm input[name=perforated_screen_light]').prop('disabled', true);
}
if($('input[name=perforated_screen_light]').is(':checked'))
calc_2.$.find('.shield_light').show();
else
calc_2.$.find('.shield_light').hide();
$('input.accessory-count').each(function()
{
var $img = calc_2.$.find($(this).data('selector'));
if($(this).val() > 0) $img.show();
});
},
tableRender: function()
{
var $tabletop = $('input[name=tabletop]').filter(':checked');
var num = $('.num-benches').val();
var html = '';
if($tabletop.size())
{
html += calc_2.tableRow($tabletop.data('name'), 1, $tabletop.val());
if($('input[name=perforated_screen]').is(':checked'))
{
html += calc_2.tableRow('Экран', 1, $tabletop.data('shield-price'));
}
if($('input[name=perforated_screen_2]').is(':checked'))
{
html += calc_2.tableRow('Второй экран', 1, $tabletop.data('shield-2-price'));
}
if($('input[name=perforated_screen_light]').is(':checked'))
{
html += calc_2.tableRow('Комплект светодиодного освещения', 1, $tabletop.data('shield-light-price'));
}
}
var $cabL = $('select[name=left_cabinet] option:selected'),
$cabR = $('select[name=right_cabinet] option:selected');
if($cabL.val()) html += calc_2.tableRow($cabL.text(), 1, $cabL.val());
if($cabR.val()) html += calc_2.tableRow($cabR.text(), 1, $cabR.val());
var sup = 2;
if($tabletop.data('cab-required'))
{
sup -= $tabletop.data('cab-required');
if($tabletop.data('cab-required') == 1 && $cabL.val() && $cabR.val()) --sup;
}
else
{
if($cabL.val()) --sup;
if($cabR.val()) --sup;
}
if(sup && $tabletop.size()) html += calc_2.tableRow('Опора WF-1', sup, 1050);
var size = $tabletop.data('size');
if(size === '1200x26х700' && (!$cabL.val() && !$cabR.val()))
{
html += calc_2.tableRow('Полка и Стенка WSh-120/0', 1, 1150);
}
else if(size === '1200x26х700' && $cabL.val())
{
html += calc_2.tableRow('Полка и Стенка WSh-120/1', 1, 1150);
}
else if(size === '1400x26х700')
{
html += calc_2.tableRow('Полка и Стенка WSh-140/1', 1, 1250);
}
else if(size === '1600x26х700' && ($cabL.val() && $cabR.val()))
{
html += calc_2.tableRow('Полка и Стенка WSh-160/2', 1, 1350);
}
else if(size === '1600x26х700')
{
html += calc_2.tableRow('Полка и Стенка WSh-160/1', 1, 1350);
}
else if(size === '1800x26х700')
{
html += calc_2.tableRow('Полка и стенка WSh-180/2', 1, 1550);
}
$('input.accessory-count').each(function()
{
var count = $(this).val();
if(count > 0)
{
html += calc_2.tableRow($(this).data('name'), count, $(this).data('price'));
}
});
if( ! html) html += calc_2.tableRow('-', 0, 0);
$('#result .product-table-description tbody').html(html);
calc_2.calcSum();
},
calcSum: function()
{
var $price = $('#totalBlock .price'),
$totalPrice = $('#totalBlock .total-price');
$price.text(0);
$('#result .product-table-description .fprice').each(function()
{
var val = Number($(this).text());
var sum = Number($price.text());
$price.text(val+sum);
});
$totalPrice.text( $price.text() * $('.num-benches').val() );
},
buy: function()
{
var data = {};
data.username = $.trim($('.popup input[name=buy_name]').val());
data.email = $.trim($('.popup input[name=buy_email]').val());
data.phone = $.trim($('.popup input[name=buy_phone]').val());
data.text = $.trim($('#el_buy_text').val());
data.table = $('form#ord').html();
data.count = $('input[name=count]').val();
data.price = $('.price').text();
data.totalPrice = $('.total-price').text();
$.post('order.php', data, function(response)
{
if(response === 'ok')
{
alert('Заказ отправлен');
popupClose();
}
else
{
alert('Ошибка');
}
});
},
popupOpen: function()
{
$tabletop = $('input[name=tabletop]').filter(':checked');
if($tabletop.size())
{
if($tabletop.data('cab-required') == 1)
{
if( !$('select[name=left_cabinet]').val() && !$('select[name=right_cabinet]').val())
{
alert('Выберите тумбу');
return;
}
}
else if($tabletop.data('cab-required') == 2)
{
if( !$('select[name=left_cabinet]').val() || !$('select[name=right_cabinet]').val())
{
alert('Выберите две тумбы');
return;
}
}
$('.popup-overlay').find('input:text, input[type=email], input[type=tel], textarea').val('');
$('.popup-overlay').show(500);
$('.popup-overlay input').first().focus();
}
else
{
alert('Выберите столешницу');
}
},
popupClose: function()
{
$('.popup-overlay').hide(500);
},
clearAll: function()
{
$('#constructorForm input:radio').prop('checked', false);
$('#constructorForm select option').prop('selected', false);
$('#constructorForm select option').first().prop('selected', true);
$('#constructorForm select').trigger('liszt:updated');
//$('#constructorForm .additional').removeClass('visible');
$('#constructorForm input[name=perforated_screen]').prop('checked', false);
$('#constructorForm input[name=perforated_screen_2]').prop('checked', false);
$('#constructorForm input[name=perforated_screen_2]').prop('disabled', true);
$('#constructorForm input[name=perforated_screen_light]').prop('checked', false);
$('#constructorForm input[name=perforated_screen_light]').prop('disabled', true);
$('#constructorForm .prog_acsessory input').val(0).trigger('change');
$('input.num-benches').val(1).trigger('change');
calc_2.render();
}
}
$(function()
{
$('#constructorForm .style-dropdown').chosen({
disable_search: true,
width: '190px'
});
$('#constructorForm *[title]').tipTip({
activation: 'hover',
edgeOffset: 30,
maxWidth: 600,
defaultPosition: 'right',
fadeIn: 0,
delay: 0
});
$('.btn-minus').on('click', function()
{
var $input = $(this).next();
var val = $.trim($input.val()) - 1;
if(val < 0) val = 0;
$input.val(val).trigger('change');
});
$('.btn-plus').on('click', function()
{
var $input = $(this).prev();
var val = Number($.trim($input.val())) + 1;
if(val > 999) val = 999;
$input.val(val).trigger('change');
});
$('input.num').on('change', function()
{
if ($(this).val() > 998) {
$(this).siblings('.add-quantity').addClass('disabled');
} else {
$(this).siblings('.add-quantity').removeClass('disabled');
}
if ($(this).val() == 0) {
$(this).siblings('.delete-quantity').addClass('disabled');
} else {
$(this).siblings('.delete-quantity').removeClass('disabled');
}
});
/*$('#constructorForm').on('click', '#show_additional.active', function()
{
//$('.additional').toggleClass('visible');
});*/
$('#constructorForm input, #constructorForm select').change(function(){
var elem = $(this).parents('li');
if(!elem.hasClass('active')){
$('.clac-list-form li').removeClass('active');
elem.addClass('active');
}
});
//calc_2.clearAll();
calc_2.init();
});