/** * 购物车模型,目前服务有多种类型,所以通过增加一个购物车对象来缓存用户所选的服务 */ 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: {//洗澡-钟点工 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 2: {//剃光-除螨杀菌 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 3: {//美容-深度清洁 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 4: { // 洁牙-住家保姆 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 5: { // spa-日常清洁 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 6: { //训犬-育儿嫂 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 7: { //断尾-月子套餐 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 8: { // 碳酸浴-金牌月嫂 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', couponName: '', couponId: '', couponVal: '', couponList: [] }, 9: {//驱虫-催乳服务 petID: '', productID: '', petName: '', petWeight: '', petPrice: '', 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(); })