123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- /**
- * 订单模型
- */
- 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.price = 0; // 单价
- this.couponValue = 0; // 代金券
- this.balance = 0; // 余额支付的费用
- this.payValue = 0; // 微信支付的费用
- this.bookingDate = '';
- this.bookingTime = '';
- this.bookingTimeStr = '';
- this.address = this.getCache('address', null);
- this.productType = ''; // 产品类型
- this.productID = ''; // 产品ID
- 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: ''
- };
- };
- 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, // 产品ID
- count: this.productCount // 产品数量
- }];
- // 优惠券
- var coupons = [];
- if (this.couponID != '') {
- coupons.push(this.couponID);
- }
- // 添加额外的商品
- var extraJson = '';
- if (this.appendID) {
- // 商品id && 商品价格
- extraJson = JSON.stringify([{type: this.appendID, price: this.price}]);
- }
- api.addOrder({
- balance: this.balance,
- 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) {
- 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();
- })
|