/** * 订单模型 */ 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.memo = ''; this.cost = 0; this.bookingDate = ''; this.bookingTime = ''; this.bookingTimeStr = ''; this.address = this.getCache('address', null); this.productType = ''; this.productID = ''; this.productCount = 1; this.petID = ''; this.petName = ''; this.petWeight = ''; this.petPrice = ''; this.couponID = ''; this.stationID = this.getCache('stationID', null, ''); this.cacheReview = this.getCache('cacheReview', null, ''); this.precedence = ''; // 是否加急 this.extraService = []; this.extraServiceType = []; // this.bath = ''; // 药浴 // this.desinsectization = ''; // 驱虫 // this.barbering = ''; // 剃毛 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.petID = ''; this.extraService = []; this.serviceName = ''; this.servicePrice = ''; this.productCount = 1; this.precedence = ''; this.extraServiceType = []; this.beautician = { name: '', id: '' }; }; Order.prototype.addOrder = function (userID, channel, callback) { var that = this; var productParam = [{ product_id: this.productID, count: this.productCount }]; for (var i = 0; i < that.extraService.length; i++) { if(that.extraService[i] && that.extraService[i].product_id) { productParam.push(that.extraService[i]); } }; var extraServiceTypeParam = []; that.extraServiceType.forEach(function(e, i) { if(e !== 100) { extraServiceTypeParam.push(e); } }); // productParam = productParam.concat(that.extraService); var coupons = []; if (this.couponID != '') { coupons.push(this.couponID); } api.addOrder({ products: JSON.stringify(productParam), memo: this.memo, precedence: this.precedence, booking_time: this.bookingDate + ' ' + this.bookingTime + ':00', address_id: this.address.address_id, coupons: JSON.stringify(coupons), station: this.stationID, type: this.productType, 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) { var that = this; api.appendOrder({ order_id: orderID, products: products, user_id: userID }, function(res) { if (res.success) { that.appendID = res.data.id; } if (typeof (callback) == 'function') { callback(res); } }) } return new Order(); })