order.js 3.0 KB

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