define(['$', 'template', 'cart'], function ($, template, cart) { return { body: '', init: function (panelData, dtd) { var $view = this; var $doc = $(document); $.newTouch('.option-group', function(event) { var productId = $(this).attr('data-id'); var petName = $(this).attr('data-name'); var petWeight = $(this).attr('data-weight'); var petMaxWeight = $(this).attr('data-weight-max'); var petMinWeight = $(this).attr('data-weight-min'); var petPrice = $(this).attr('data-price'); var pushData = panelData.pushData; var productType = pushData.productType; cart['products'][productType]['productID'] = productId; cart['products'][productType]['petName'] = petName; cart['products'][productType]['petWeight'] = petWeight; cart['products'][productType]['petPrice'] = petPrice; cart.setCache('products'); // 记录用户选择宠物信息 cart['petInfo']['productID'] = productId; cart['petInfo']['petName'] = petName; cart['petInfo']['petWeight'] = petWeight; cart['petInfo']['petMaxWeight'] = petMaxWeight; cart['petInfo']['petMinWeight'] = petMinWeight; cart.setCache('petInfo'); var callback = pushData.callback; if (callback && $.isFunction(callback.onSelect)) { callback.onSelect(petName, petWeight, petPrice); } $view.trigger('spa:closepanel'); }, $view); $.newTouch('.btn-cancle', function (event) { $view.trigger('spa:closepanel'); }, $view) dtd.resolve(); }, beforeopen: function (panelData, dtd) { var $view = this; var pushData = panelData.pushData; $('.spa-page-bg', $view).css({ opacity: 0 }).transition({ opacity: 0.6 }); var productType = pushData['productType']; $view.data('productType', productType); var tpl = template('product/option', { pets: pushData.pets }); $view.find('.spa-page-body').html(tpl); if (pushData.selectedPet) { selectPet(pushData.selectedPet, pushData.weights); } if (pushData.selectedWeight) { selectWeight(pushData.selectedWeight, pushData.weights); } dtd.resolve(); }, beforeclose: function (panelData, dtd) { var $view = this; $('.spa-page-bg', $view).transition({ opacity: 0 }); dtd.resolve(); }, afterclose: function (panelData) { var $view = this; var pushData = panelData.pushData; if (panelData.selectOption && pushData.onSelectOption) { panelData.selectOption = false; pushData.onSelectOption(); } } } })