12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //dever 购物车组件
- var carts = {
- init: function (page, save, path) {
- var self = this;
- self.page = page;
- self.save = save;
- self.data = {};
- self.price = 0;
- self.total = 0;
- self.path = path;
- self.dever = self.page.dever;
- self.dever.log('carts init', save);
- //初始化公共方法
- page.addCarts = function (event)
- {
- self.dever.log('event', event);
- var data = self.dever.getData(event);
- if (data && data.id) {
- self.dever.log('carts add', data.name + '(' + data.id + ')');
- if (!self.data[data.id]) {
- self.data[data.id] = data;
- self.data[data.id]['num'] = 1;
- } else {
- self.data[data.id]['num']++;
- }
- self.total++;
- self.dever.log('carts data', self.data);
- self.dever.set(self.page, 'carts_total', self.total);
- self.dever.save('carts', self.data);
- //调取购物车后端接口
- if (self.save) {
- }
- if (self.path) {
- self.dever.location(self.path);
- }
- }
- }
- return self;
- }
- }
- module.exports = {
- load:carts.init
- }
|