Просмотр исходного кода

下订单 添加counts extra添加price

jmx 8 лет назад
Родитель
Сommit
f3e000cfae
1 измененных файлов с 75 добавлено и 71 удалено
  1. 75 71
      www/webapp/o2o/js/model/order.js

+ 75 - 71
www/webapp/o2o/js/model/order.js

@@ -2,59 +2,58 @@
  * 订单模型
  */
 define(['base', '$', 'native', 'product', 'api'], function (base, $, native, product, api) {
-  var Order = function () {
-    if (typeof Order.instance === 'object') {
-      return Order.instance;
-    }
-    Order.instance = this;
-    this.storagePrefix = 'order_';
-    this.balance = 0;
-    this.memo = '';
-    this.cost = 0;
-    this.price = 0;
-    this.bookingDate = '';
-    this.bookingTime = '';
-    this.bookingTimeStr = '';
-    this.address = this.getCache('address', null);
-    this.productType = '';
-    this.productID = '';
-    this.productCount = 1;
-    this.price = 0;
-    this.couponID = '';
-    this.stationID = this.getCache('stationID', null, '');
-    this.cacheReview = this.getCache('cacheReview', null, '');
-    this.precedence = ''; // 是否加急
-    this.extraService = [];
-    this.extraServiceType = [];
+    var Order = function () {
+        if (typeof Order.instance === 'object') {
+            return Order.instance;
+        }
+        Order.instance = this;
+        this.storagePrefix = 'order_';
+        this.balance = 0;
+        this.memo = '';
+        this.cost = 0;
+        this.price = 0;
+        this.bookingDate = '';
+        this.bookingTime = '';
+        this.bookingTimeStr = '';
+        this.address = this.getCache('address', null);
+        this.productType = '';
+        this.productID = '';
+        this.productCount = 1;
+        this.couponID = '';
+        this.stationID = this.getCache('stationID', null, '');
+        this.cacheReview = this.getCache('cacheReview', null, '');
+        this.precedence = ''; // 是否加急
+        this.extraService = [];
+        this.extraServiceType = [];
 
-    this.serviceName = '';
-    this.servicePrice = '';
-    this.appendID = '';
-    this.beautician = { // 保洁师
-      name: '请选择',
-      id: ''
+        this.serviceName = '';
+        this.servicePrice = '';
+        this.appendID = '';
+        this.beautician = { // 保洁师
+            name: '请选择',
+            id: ''
+        };
     };
-  };
     Order.prototype = new base();
 
-  Order.prototype.reset = function () {
-    this.couponID = '';
-    this.bookingTime = '';
-    this.bookingTimeStr = '';
-    this.bookingDate = '';
-    this.productType = '';
-    this.productID = '';
-    this.extraService = [];
-    this.serviceName = '';
-    this.servicePrice = '';
-    this.productCount = 1;
-    this.precedence = '';
-    this.extraServiceType = [];
-    this.beautician = {
-      name: '',
-      id: ''
+    Order.prototype.reset = function () {
+        this.couponID = '';
+        this.bookingTime = '';
+        this.bookingTimeStr = '';
+        this.bookingDate = '';
+        this.productType = '';
+        this.productID = '';
+        this.extraService = [];
+        this.serviceName = '';
+        this.servicePrice = '';
+        this.productCount = 1;
+        this.precedence = '';
+        this.extraServiceType = [];
+        this.beautician = {
+            name: '',
+            id: ''
+        };
     };
-  };
 
     //添加顺序
     //channel-渠道
@@ -71,29 +70,34 @@ define(['base', '$', 'native', 'product', 'api'], function (base, $, native, pro
             coupons.push(this.couponID);
         }
 
-    api.addOrder({
-      products: JSON.stringify(productParam),
-      memo: this.memo,
-      precedence: '0',
-      booking_time: this.bookingDate + ' ' + this.bookingTime + ':00',
-      address_id: this.address.address_id,
-      coupons: JSON.stringify(coupons),
-      station: this.stationID,
-      type: this.productType,
-      counts:'1',
-      extra:JSON.stringify([{ type: this.appendID }]),
-      tech_id: this.beautician.id,
-      user_id: userID,
-      order_channel: channel
-    }, function (res) {
-      if (res.success) {
-        that.id = res.data.id;
-      }
-      if (typeof (callback) == 'function') {
-        callback(res);
-      }
-    })
-  };
+        var extraJson = '';
+        if (this.appendID) {
+            extraJson = JSON.stringify([{type: this.appendID, price: this.price}]);
+        }
+
+        api.addOrder({
+            products: JSON.stringify(productParam),
+            memo: this.memo,
+            precedence: '0',
+            booking_time: this.bookingDate + ' ' + this.bookingTime + ':00',
+            address_id: this.address.address_id,
+            coupons: JSON.stringify(coupons),
+            station: this.stationID,
+            type: this.productType,
+            counts: this.productCount,
+            extra: extraJson,
+            tech_id: this.beautician.id,
+            user_id: userID,
+            order_channel: channel
+        }, function (res) {
+            if (res.success) {
+                that.id = res.data.id;
+            }
+            if (typeof (callback) == 'function') {
+                callback(res);
+            }
+        })
+    };
 
     // 追加订单
     Order.prototype.appendOrder = function (orderID, userID, products, callback) {