/** * 订单模型 */ 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.price = ''; 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: '' }; }; 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: '' }; }; //添加顺序 //channel-渠道 Order.prototype.addOrder = function (userID, channel, callback) { var that = this; var productParam = [{//产品参数 product_id: this.productID, count: this.productCount//产品数 }]; var coupons = [];//优惠券 if (this.couponID != '') { 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); } }) }; // 追加订单 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(); })