order.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.price = '';
  21. this.couponID = '';
  22. this.stationID = this.getCache('stationID', null, '');
  23. this.cacheReview = this.getCache('cacheReview', null, '');
  24. this.precedence = ''; // 是否加急
  25. this.extraService = [];
  26. this.extraServiceType = [];
  27. this.serviceName = '';
  28. this.servicePrice = '';
  29. this.appendID = '';
  30. this.beautician = { // 保洁师
  31. name: '请选择',
  32. id: ''
  33. };
  34. };
  35. Order.prototype = new base();
  36. Order.prototype.reset = function () {
  37. this.couponID = '';
  38. this.bookingTime = '';
  39. this.bookingTimeStr = '';
  40. this.bookingDate = '';
  41. this.productType = '';
  42. this.productID = '';
  43. this.extraService = [];
  44. this.serviceName = '';
  45. this.servicePrice = '';
  46. this.productCount = 1;
  47. this.precedence = '';
  48. this.extraServiceType = [];
  49. this.beautician = {
  50. name: '',
  51. id: ''
  52. };
  53. };
  54. //添加顺序
  55. //channel-渠道
  56. Order.prototype.addOrder = function (userID, channel, callback) {
  57. var that = this;
  58. var productParam = [{//产品参数
  59. product_id: this.productID,
  60. count: this.productCount//产品数
  61. }];
  62. var coupons = [];//优惠券
  63. if (this.couponID != '') {
  64. coupons.push(this.couponID);
  65. }
  66. api.addOrder({
  67. products: JSON.stringify(productParam),
  68. memo: this.memo,
  69. precedence: '0',
  70. booking_time: this.bookingDate + ' ' + this.bookingTime + ':00',
  71. address_id: this.address.address_id,
  72. coupons: JSON.stringify(coupons),
  73. station: this.stationID,
  74. type: this.productType,
  75. counts:'1',
  76. extra:JSON.stringify("[type:"+this.appendID+"]"),
  77. tech_id: this.beautician.id,
  78. user_id: userID,
  79. order_channel: channel
  80. }, function (res) {
  81. if (res.success) {
  82. that.id = res.data.id;
  83. }
  84. if (typeof (callback) == 'function') {
  85. callback(res);
  86. }
  87. })
  88. };
  89. // 追加订单
  90. Order.prototype.appendOrder = function (orderID, userID, products, callback) {
  91. var that = this;
  92. api.appendOrder({
  93. order_id: orderID,
  94. products: products,
  95. user_id: userID
  96. }, function (res) {
  97. if (res.success) {
  98. that.appendID = res.data.id;
  99. }
  100. if (typeof (callback) == 'function') {
  101. callback(res);
  102. }
  103. })
  104. }
  105. return new Order();
  106. })