carts.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //dever 购物车组件
  2. var carts = {
  3. init: function (page, save, path) {
  4. var self = this;
  5. self.page = page;
  6. self.save = save;
  7. self.data = {};
  8. self.price = 0;
  9. self.total = 0;
  10. self.path = path;
  11. self.dever = self.page.dever;
  12. self.dever.log('carts init', save);
  13. //初始化公共方法
  14. page.addCarts = function (event)
  15. {
  16. self.dever.log('event', event);
  17. var data = self.dever.getData(event);
  18. if (data && data.id) {
  19. self.dever.log('carts add', data.name + '(' + data.id + ')');
  20. if (!self.data[data.id]) {
  21. self.data[data.id] = data;
  22. self.data[data.id]['num'] = 1;
  23. } else {
  24. self.data[data.id]['num']++;
  25. }
  26. self.total++;
  27. self.dever.log('carts data', self.data);
  28. self.dever.set(self.page, 'carts_total', self.total);
  29. self.dever.save('carts', self.data);
  30. //调取购物车后端接口
  31. if (self.save) {
  32. }
  33. if (self.path) {
  34. self.dever.location(self.path);
  35. }
  36. }
  37. }
  38. return self;
  39. }
  40. }
  41. module.exports = {
  42. load:carts.init
  43. }