cart.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /**
  2. * 购物车模型,目前服务有多种类型,所以通过增加一个购物车对象来缓存用户所选的服务
  3. */
  4. define(['base', '$', 'native', 'product'], function (base, $, native, product) {
  5. var Cart = function () {
  6. if (typeof Cart.instance === 'object') {
  7. return Cart.instance;
  8. }
  9. Cart.instance = this;
  10. this.storagePrefix = 'cart_';//存储前缀
  11. this.products = this.getCache('products', null, {
  12. 1: {//洗澡-钟点工
  13. petID: '',
  14. productID: '',
  15. petName: '',
  16. petWeight: '',
  17. petPrice: '',
  18. couponName: '',
  19. couponId: '',
  20. couponVal: '',
  21. couponList: []
  22. },
  23. 2: {//剃光-除螨杀菌
  24. petID: '',
  25. productID: '',
  26. petName: '',
  27. petWeight: '',
  28. petPrice: '',
  29. couponName: '',
  30. couponId: '',
  31. couponVal: '',
  32. couponList: []
  33. },
  34. 3: {//美容-深度清洁
  35. petID: '',
  36. productID: '',
  37. petName: '',
  38. petWeight: '',
  39. petPrice: '',
  40. couponName: '',
  41. couponId: '',
  42. couponVal: '',
  43. couponList: []
  44. },
  45. 4: { // 洁牙-住家保姆
  46. petID: '',
  47. productID: '',
  48. petName: '',
  49. petWeight: '',
  50. petPrice: '',
  51. couponName: '',
  52. couponId: '',
  53. couponVal: '',
  54. couponList: []
  55. },
  56. 5: { // spa-日常清洁
  57. petID: '',
  58. productID: '',
  59. petName: '',
  60. petWeight: '',
  61. petPrice: '',
  62. couponName: '',
  63. couponId: '',
  64. couponVal: '',
  65. couponList: []
  66. },
  67. 6: { //训犬-育儿嫂
  68. petID: '',
  69. productID: '',
  70. petName: '',
  71. petWeight: '',
  72. petPrice: '',
  73. couponName: '',
  74. couponId: '',
  75. couponVal: '',
  76. couponList: []
  77. },
  78. 7: { //断尾-月子套餐
  79. petID: '',
  80. productID: '',
  81. petName: '',
  82. petWeight: '',
  83. petPrice: '',
  84. couponName: '',
  85. couponId: '',
  86. couponVal: '',
  87. couponList: []
  88. },
  89. 8: { // 碳酸浴-金牌月嫂
  90. petID: '',
  91. productID: '',
  92. petName: '',
  93. petWeight: '',
  94. petPrice: '',
  95. couponName: '',
  96. couponId: '',
  97. couponVal: '',
  98. couponList: []
  99. },
  100. 9: {//驱虫-催乳服务
  101. petID: '',
  102. productID: '',
  103. petName: '',
  104. petWeight: '',
  105. petPrice: '',
  106. couponName: '',
  107. couponId: '',
  108. couponVal: '',
  109. couponList: []
  110. }
  111. });
  112. this.petInfo = this.getCache('petInfo', null, {
  113. petID: '',
  114. productID: '',
  115. petName: '',
  116. petWeight: '',
  117. petPrice: ''
  118. });
  119. };
  120. Cart.prototype = new base();
  121. //预检
  122. Cart.prototype.precheck = function (type, callback) {
  123. var productID = this.products[type]['productID'];
  124. var productParam = [{product_id: productID, count: 1}];//产品参数
  125. api.precheck({
  126. products: JSON.stringify(productParam)//产品
  127. }, function (res) {
  128. if (typeof(callback) == 'function') {
  129. callback(res);
  130. }
  131. })
  132. };
  133. return new Cart();
  134. })