order.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.price = 0; // 单价
  14. this.couponValue = 0; // 代金券
  15. this.balance = 0; // 余额支付的费用
  16. this.payValue = 0; // 微信支付的费用
  17. this.bookingDate = '';
  18. this.bookingTime = '';
  19. this.bookingTimeStr = '';
  20. this.address = this.getCache('address', null);
  21. this.productType = ''; // 产品类型
  22. this.productID = ''; // 产品ID
  23. this.productCount = 1; // 产品数量
  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.serviceName = '';
  31. this.servicePrice = '';
  32. this.appendID = '';
  33. this.beautician = { // 保洁师
  34. name: '请选择',
  35. id: ''
  36. };
  37. };
  38. Order.prototype = new base();
  39. Order.prototype.reset = function () {
  40. this.couponID = '';
  41. this.bookingTime = '';
  42. this.bookingTimeStr = '';
  43. this.bookingDate = '';
  44. this.productType = '';
  45. this.productID = '';
  46. this.extraService = [];
  47. this.serviceName = '';
  48. this.servicePrice = '';
  49. this.productCount = 1;
  50. this.precedence = '';
  51. this.extraServiceType = [];
  52. this.beautician = {
  53. name: '',
  54. id: ''
  55. };
  56. };
  57. //添加顺序
  58. //channel-渠道
  59. Order.prototype.addOrder = function (userID, channel, callback) {
  60. var that = this;
  61. // 产品参数
  62. var productParam = [{
  63. product_id: this.productID, // 产品ID
  64. count: this.productCount // 产品数量
  65. }];
  66. // 优惠券
  67. var coupons = [];
  68. if (this.couponID != '') {
  69. coupons.push(this.couponID);
  70. }
  71. // 添加额外的商品
  72. var extraJson = '';
  73. if (this.appendID) {
  74. // 商品id && 商品价格
  75. extraJson = JSON.stringify([{type: this.appendID, price: this.price}]);
  76. }
  77. api.addOrder({
  78. balance: this.balance,
  79. products: JSON.stringify(productParam),
  80. memo: this.memo,
  81. precedence: '0',
  82. booking_time: this.bookingDate + ' ' + this.bookingTime + ':00',
  83. address_id: this.address.address_id,
  84. coupons: JSON.stringify(coupons),
  85. station: this.stationID,
  86. type: this.productType,
  87. counts: this.productCount,
  88. extra: extraJson,
  89. tech_id: this.beautician.id,
  90. user_id: userID,
  91. order_channel: channel
  92. }, function (res) {
  93. if (res.success) {
  94. that.id = res.data.id;
  95. }
  96. if (typeof (callback) == 'function') {
  97. callback(res);
  98. }
  99. })
  100. };
  101. // 追加订单
  102. Order.prototype.appendOrder = function (orderID, userID, products, callback) {
  103. var that = this;
  104. api.appendOrder({
  105. order_id: orderID,
  106. products: products,
  107. user_id: userID
  108. }, function (res) {
  109. if (res.success) {
  110. that.appendID = res.data.id;
  111. }
  112. if (typeof (callback) == 'function') {
  113. callback(res);
  114. }
  115. })
  116. }
  117. return new Order();
  118. })