productOption.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. define(['$', 'template', 'cart'], function ($, template, cart) {
  2. return {
  3. body: '',
  4. init: function (panelData, dtd) {
  5. var $view = this;
  6. var $doc = $(document);
  7. $.newTouch('.option-group', function(event) {
  8. var productId = $(this).attr('data-id');
  9. var petName = $(this).attr('data-name');
  10. var petWeight = $(this).attr('data-weight');
  11. var petMaxWeight = $(this).attr('data-weight-max');
  12. var petMinWeight = $(this).attr('data-weight-min');
  13. var petPrice = $(this).attr('data-price');
  14. var pushData = panelData.pushData;
  15. var productType = pushData.productType;
  16. cart['products'][productType]['productID'] = productId;
  17. cart['products'][productType]['petName'] = petName;
  18. cart['products'][productType]['petWeight'] = petWeight;
  19. cart['products'][productType]['petPrice'] = petPrice;
  20. cart.setCache('products');
  21. // 记录用户选择宠物信息
  22. cart['petInfo']['productID'] = productId;
  23. cart['petInfo']['petName'] = petName;
  24. cart['petInfo']['petWeight'] = petWeight;
  25. cart['petInfo']['petMaxWeight'] = petMaxWeight;
  26. cart['petInfo']['petMinWeight'] = petMinWeight;
  27. cart.setCache('petInfo');
  28. var callback = pushData.callback;
  29. if (callback && $.isFunction(callback.onSelect)) {
  30. callback.onSelect(petName, petWeight, petPrice);
  31. }
  32. $view.trigger('spa:closepanel');
  33. }, $view);
  34. $.newTouch('.btn-cancle', function (event) {
  35. $view.trigger('spa:closepanel');
  36. }, $view)
  37. dtd.resolve();
  38. },
  39. beforeopen: function (panelData, dtd) {
  40. var $view = this;
  41. var pushData = panelData.pushData;
  42. $('.spa-page-bg', $view).css({
  43. opacity: 0
  44. }).transition({
  45. opacity: 0.6
  46. });
  47. var productType = pushData['productType'];
  48. $view.data('productType', productType);
  49. var tpl = template('product/option', {
  50. pets: pushData.pets
  51. });
  52. $view.find('.spa-page-body').html(tpl);
  53. if (pushData.selectedPet) {
  54. selectPet(pushData.selectedPet, pushData.weights);
  55. }
  56. if (pushData.selectedWeight) {
  57. selectWeight(pushData.selectedWeight, pushData.weights);
  58. }
  59. dtd.resolve();
  60. },
  61. beforeclose: function (panelData, dtd) {
  62. var $view = this;
  63. $('.spa-page-bg', $view).transition({
  64. opacity: 0
  65. });
  66. dtd.resolve();
  67. },
  68. afterclose: function (panelData) {
  69. var $view = this;
  70. var pushData = panelData.pushData;
  71. if (panelData.selectOption && pushData.onSelectOption) {
  72. panelData.selectOption = false;
  73. pushData.onSelectOption();
  74. }
  75. }
  76. }
  77. })