order.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * 订单模型
  3. */
  4. define(['base', '$', 'native', 'product', 'api'], function (base, $, native, product, api) {
  5. var Order = function () {
  6. if (typeof Order.instance === 'object') {
  7. return Order.instance;
  8. }
  9. Order.instance = this;
  10. this.storagePrefix = 'order_';
  11. this.memo = '';
  12. this.cost = 0;
  13. this.bookingDate = '';
  14. this.bookingTime = '';
  15. this.bookingTimeStr = '';
  16. this.address = this.getCache('address', null);
  17. this.productType = '';
  18. this.productID = '';
  19. this.productCount = 1;
  20. this.petID = '';
  21. this.petName = '';
  22. this.petWeight = '';
  23. this.petPrice = '';
  24. this.couponID = '';
  25. this.stationID = this.getCache('stationID', null, '');
  26. this.cacheReview = this.getCache('cacheReview', null, '');
  27. this.precedence = ''; // 是否加急
  28. this.extraService = [];
  29. this.extraServiceType = [];
  30. // this.bath = ''; // 药浴
  31. // this.desinsectization = ''; // 驱虫
  32. // this.barbering = ''; // 剃毛
  33. this.serviceName = '';
  34. this.servicePrice = '';
  35. this.appendID = '';
  36. this.beautician = { // 保洁师
  37. name: '请选择',
  38. id: ''
  39. };
  40. };
  41. Order.prototype = new base();
  42. Order.prototype.reset = function () {
  43. this.couponID = '';
  44. this.bookingTime = '';
  45. this.bookingTimeStr = '';
  46. this.bookingDate = '';
  47. this.productType = '';
  48. this.productID = '';
  49. this.petID = '';
  50. this.extraService = [];
  51. this.serviceName = '';
  52. this.servicePrice = '';
  53. this.productCount = 1;
  54. this.precedence = '';
  55. this.extraServiceType = [];
  56. this.beautician = {
  57. name: '',
  58. id: ''
  59. };
  60. };
  61. Order.prototype.addOrder = function (userID, channel, callback) {
  62. var that = this;
  63. var productParam = [{
  64. product_id: this.productID,
  65. count: this.productCount
  66. }];
  67. for (var i = 0; i < that.extraService.length; i++) {
  68. if(that.extraService[i] && that.extraService[i].product_id) {
  69. productParam.push(that.extraService[i]);
  70. }
  71. };
  72. var extraServiceTypeParam = [];
  73. that.extraServiceType.forEach(function(e, i) {
  74. if(e !== 100) {
  75. extraServiceTypeParam.push(e);
  76. }
  77. });
  78. // productParam = productParam.concat(that.extraService);
  79. var coupons = [];
  80. if (this.couponID != '') {
  81. coupons.push(this.couponID);
  82. }
  83. api.addOrder({
  84. products: JSON.stringify(productParam),
  85. memo: this.memo,
  86. precedence: this.precedence,
  87. booking_time: this.bookingDate + ' ' + this.bookingTime + ':00',
  88. address_id: this.address.address_id,
  89. coupons: JSON.stringify(coupons),
  90. station: this.stationID,
  91. type: this.productType,
  92. tech_id: this.beautician.id,
  93. user_id: userID,
  94. order_channel: channel
  95. }, function (res) {
  96. if (res.success) {
  97. that.id = res.data.id;
  98. }
  99. if (typeof (callback) == 'function') {
  100. callback(res);
  101. }
  102. })
  103. };
  104. // 追加订单
  105. Order.prototype.appendOrder = function (orderID, userID, products, callback) {
  106. var that = this;
  107. api.appendOrder({
  108. order_id: orderID,
  109. products: products,
  110. user_id: userID
  111. }, function(res) {
  112. if (res.success) {
  113. that.appendID = res.data.id;
  114. }
  115. if (typeof (callback) == 'function') {
  116. callback(res);
  117. }
  118. })
  119. }
  120. return new Order();
  121. })