ut.get('min'), max: input.get('max'), 'default': value, store: getQuantity(p, 'stock'), callback: window.quantityCallback }); } //== 商品数量输入框正确性检测 function inputCheck(input, options) { if (!input) return false; options = options || {}; if (isNaN(options.min)) options.min = 1; if (isNaN(options.max)) options.max = 999999; options['default'] = options['default'] || options.min; var value = +input.value; var tips = new Tips(input); var pre = ''; var msg = ''; if (options.store && options.store - value <= 0) { pre = '库存有限,'; } if (value < options.min) { input.value = options.min; msg = '此商品的最小购买数量为' + options.min + '件'; } else if (value > options.max) { input.value = options.max; msg = pre + '此商品最多只能购买' + options.max + '件'; } else if (isNaN(value)) { input.value = options['default']; msg = '只允许输入数字'; } if (msg) { tips.show(msg); return false; } tips.hide(); if (options.callback) options.callback(input, options['default']); return true; } //== 商品详情图片延迟加载,并缩放到合适大小 var sectionWidth = section.getStyle('width').toInt(); new DataLazyLoad({ containers: section, textarea: 'action-lazyload', onCallback: function() { section.getElements('img').each(function(img) { img.zoomImg(sectionWidth); }); } }); //== 异步加载商品详情tab var param = { goodsDiscussInit: { update: section, name: 'product_comment_init', onSuccess: function() { storeAjaxConfig('product_comment_init', '.action-submit-reply', '.reply-list'); } }, goodsConsultInit: { update: section, name: 'product_consult_init', onSuccess: function() { storeAjaxConfig('product_consult_init', '.action-submit-reply', '.answer-list'); } }, goodsDiscuss: { append: section, name: 'product_comment', require: 'product_comment_init', onSuccess: function() { storeAjaxConfig('product_comment', '.action-submit-reply', '.reply-list'); } }, goodsConsult: { append: section, name: 'product_consult', require: 'product_comment', onSuccess: function() { storeAjaxConfig('product_consult', '.action-submit-reply', '.answer-list'); storeAjaxConfig('product_consult', '.action-submit-post', 'consult_content', true); } }, goodsSellLoglist: { append: section, name: 'product_saleslog', require: 'product_consult' }, goodsLink: { append: section, name: 'product_related', require: 'product_consult' } }, queue_items = []; Object.each(param, function(v, k) { queue_items.push(Object.append({ url: '/index.php/product-' + k + '-231.html' }, v)); }); var lazyload = new LayoutRequest(queue_items); //== 为商品详情生成tab section.getElements('.tags-hd').inject(new Element('.product-tags.clearfix').inject(section, 'before')); new Tabs('main', { eventType: 'click', triggersBox: '.product-tags', panels: '.product-section', onSwitch: function(e) { queue_items.each(function(q) { if (q.name === this.panels[e.currentIndex].id) { lazyload.request.call(lazyload, q); } }, this); } }); //== 处理评论咨询回复异步请求 function storeAjaxConfig(cont, handle, area, type) { // $(cont).getElements(trigger).each(function(handle){ var update; var element = $(cont).getElement(handle); element.retrieve('_ajax_config') || element.store('_ajax_config', { onSuccess: function(rs) { rs = rs[0]; if (rs && rs.success && rs.data) { update = $(area); if (!update) { var active = element.getParent('.mod').getElement('.active-handle'); update = active.getParent(area); closeReply(element); } rs.html = rs.data.stripScripts(function(script) { rs.javascript = script; }); update.set('html', rs.html); Browser.exec(rs.javascript); Message.success(rs.success); if (type) location.href = '#' + cont; resetForm(element.getParent('form')); storeAjaxConfig(cont, handle, area, type); } } }); // }); } //== 重置提交表单 function resetForm(form) { form.reset(); form.blur(); try { form.getElement('img.verify-code').addClass('hide'); } catch(e) {} } //== 处理商品基本信息交互 function attachAction(id) { //== 伦理电影手机在线观看和库存异步加载 Query.price({ id: id }); Query.stock({ id: id }); //== 商品相册图放大镜 window.addEvent('domready', function() { new AlbumZoom('product_album', { zoomable: false, zoomsSize: { x: 400, y: 300 } }); }); } var ajax; var state; /** preterchan del **/ $('col-main').addEvents({ 'click:relay(.action-addtocart)': function(e) { var form = this.getParent('form'); var target = form.retrieve('target'); form.getElement('input[name=btype]').value = ''; if (target) form.target = target; } }); /** preterchan del **/ container.addEvents({ 'click:relay(.action-slidedown)': function(e) { var panel = this.getParent('.switchable-panel'); var top = panel.getElement('.panel-top'); var cont = this.getParent('.product-promotion'); if (!panel.hasClass('unfold')) { top && top.setStyle('height', 'auto'); panel.addClass('unfold'); } else { top && top.setStyle('height', 82); panel.removeClass('unfold'); } toggleText(this.getElement('.icon')); toggleText(this.getElement('.text')); }, 'mouseenter:relay(.action-handle)': function(e) { var menu = this.getNext('.pop-body'); if (menu) { clearTimeout(menu.timer); menu.show(); } }, 'mouseenter:relay(.pop-body)': function(e) { clearTimeout(this.timer); }, 'mouseleave:relay(.pop-wrapper)': function(e) { var menu = this.getElement('.pop-body'); menu.timer = menu.hide.delay(200, menu); }, 'click:relay(.pop-close)': function(e) { this.getParent('.pop-body').hide(); }, 'click:relay(.action-buynow)': function(e) { var form = this.getParent('form'); if (form.getElement('input[name=goods[num]]').value == 0) { Message.error('商品数量不能为0!'); e.stop(); return; } form.getElement('input[name=btype]').value = 'is_fastbuy'; form.store('target', form.target).target = ''; }, 'click:relay(.action-addtocart)': function(e) { var form = this.getParent('form'); if (form.getElement('input[name=goods[num]]').value == 0) { Message.error('商品数量不能为0!'); e.stop(); return; } var form = this.getParent('form'); var target = form.retrieve('target'); //form.getElement('input[name=btype]').value = ''; if (target) form.target = target; }, 'click:relay(.action-notify)': function(e) { var dialog = new Dialog($('product_notify').wrapped(), { title: '咨询申请', width: 450, modal: { 'class': 'cover' }, onLoad: function() { var content = this.content; content.getElement('[rel=_request]').store('_ajax_config', { onSuccess: function(rs) { if (rs && rs[0]) { if (rs[0]['true']) { content.getElement('.product-notify').innerHTML = '
%联系方式已经成功提交,拉卡拉客服随后会联系您,请保持手机畅通。
'; dialog.hide.delay(3000, dialog); } } } }); } }); } /* , 'click:relay(.spec-attr)': function(e){ if(this.hasClass('selected')) return; var a = this.getElement('a'); var url = a.href; var id = a.rel; if(!id) return; if (window.history && history.pushState) { e.stop(); if(ajax){ ajax.cancel(); } else { state = {title: document.title, html: container.innerHTML, url: location.href, id: id}; } ajax = Query.send(Router.basic(id), { method: 'post', onSuccess: function(rs) { try{ rs = JSON.decode(rs); if(rs.error) { return Message.error(rs.error); } }catch(e) { updateBasic(rs, id, url); } } }); } } */ }); if ('onpopstate' in window) { window.onpopstate = function(event) { if (ajax == null) return; var data; if (event && event.state) { data = event.state; } else { data = state; } document.title = data.title; updateBasic(data.html, data.id); } } function updateBasic(rs, id, url) { container.innerHTML = rs; attachAction(id); url && history.pushState({ url: url, title: document.title, html: rs, id: id }, document.title, url); //迷你购物车 formToCart(); } $(document.body).addEvents({ 'click:relay(.btn-caution)': function(e) { if (this.hasClass('disabled')) return; var data = this.getParent('.form'); if (!validate(data, 'all')) { e.stop(); return; } }, 'click:relay(.inter-handle)': function(e) { e.preventDefault(); var parent = this.getParent('.mod'); var item = this.getParent('.comment-item') || this.getParent('.consult-item'); var action = this.getParent('.reply-action') || this.getParent('.answer-action'); var active = action.hasClass('active-handle'); var reply = parent.getElement('.action-post-reply'); var toggle = parent.getElement('.active-handle'); if (toggle) { closeReply(toggle); } var id = item.getElement('input[name=id]').value; reply.getElement('input[name=id]').value = id; /*reply.removeClass('hide').setStyles({ width: action.getSize().x - reply.getPatch('padding','border').x }).position({ target:this, from: 'rt',