/** * 购物车模型,目前服务有多种类型,所以通过增加一个购物车对象来缓存用户所选的服务 */ define(['base', '$', 'native', 'product'], function(base, $, native, product) { var Cart = function() { if (typeof Cart.instance === 'object') { return Cart.instance; } Cart.instance = this; this.storagePrefix = 'cart_'; this.products = this.getCache('products', null, { 1: { productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 2: { productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 3: { productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 4: { // 洁牙 productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 5: { // spa productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 6: { // 训犬 productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 7: { // 断尾 productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 8: { // 碳酸浴 productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 9: { productID: '', price: '', couponName: '', couponId: '', couponVal: '', couponList: [] } }); this.petInfo = this.getCache('petInfo', null, { petID: '', productID: '', petName: '', petWeight: '', petPrice: '' }); }; Cart.prototype = new base(); Cart.prototype.precheck = function(type, callback) { var productID = this.products[type]['productID']; var productParam = [{product_id: productID, count: 1}]; api.precheck({ products: JSON.stringify(productParam) }, function(res) { if (typeof(callback) == 'function') { callback(res); } }) }; return new Cart(); })