fd-gulp-convert-encoding
Version:
convert file to assigned charset
284 lines (238 loc) • 8.28 kB
JavaScript
define('detail.modules.actionOperator.View',
['jQuery', 'Class', 'lang.Log', 'detail.core.Event',
'detail.lib.util.Util',
'detail.lib.orderValidator.OrderValidator',
'detail.lib.pageDialog.PageDialog',
'detail.modules.actionOperator.Warmhole'],
function($, Class, Log, Event, Util, OrderValidator, PageDialog, Warmhole) {
var log = new Log('detail.modules.actionOperator.View');
return Class({
init: function(view, config) {
this.onEvent = $.os.supportsTouch ? 'tap' : 'click';
this.div = view;
this.config = config;
this.source = '';
this.purchaseData = false;
this.validator = new OrderValidator(config);
this._initPurchasingList();
this._bindActionEvent();
this._initWarmhole();
},
_initPurchasingList: function(){
this.pageDialog = new PageDialog({
module: 'purchasingList',
actionType: 'order',
afterShow: function(){
Event.trigger('hideOrderOperator');
},
afterClose: function(){
Event.trigger('showOrderOperator');
}
});
},
_bindActionEvent: function(){
var $buttons = $('button', this.div),
$orderButtons = $('button.do-order', this.div),
$confirmButton = $('button.do-confirm', this.div),
that = this;
Event.on('hideOrderOperator', function(btnTxt){
var btnTxt = btnTxt || '确定';
$orderButtons.hide();
$confirmButton.text(btnTxt).css('display', 'inline-block');
});
Event.on('showOrderOperator', function(){
$orderButtons.show();
$confirmButton.hide();
});
Event.on('hideAllOperator', function(){
$buttons.hide();
});
Event.on('setCurPageDialog', function(pd, source){
that.curPageDialog = pd;
that.source = source || '';
});
Event.on('showPurchasingListDialog', function(source){
that.source = source;
that.pageDialog.showDialog();
that.curPageDialog = that.pageDialog;
that.openFlag = true;
});
Event.on('closePurchasingListDialog', function(){
that.curPageDialog.closeDialog();
that.openFlag = false;
});
Event.on('back', function() {
if (that.openFlag) {
Event.trigger('closePurchasingListDialog');
return false;
}
});
Event.on('setPurchasingData', function(o){
that.totalAmount = o.totalAmount * 1;
that.totalPrice = o.totalPrice * 1;
that.skuMap = o.skuMap;
that.purchaseData = !!(that.totalAmount > 0 && that.totalPrice > 0);
});
$buttons.on(this.onEvent, function(e){
e.preventDefault();
var elm = $(this),
actionType = elm.data('type');
that._branchAction(actionType);
});
},
_branchAction: function(actionType){
switch (actionType){
case 'cart':
// 加入进货单
this._doCartAction(actionType);
break;
case 'purchase':
// 立即订购
this._doPurchaseAction(actionType);
break;
case 'nonsupport':
// 不支持手机交易
return;
case 'confirm':
// 确定
this._doConfirmAction();
return;
default:
// ...
}
},
_doCartAction: function(actionType){
if (this.purchaseData){
this._doCart();
} else {
// this.source = actionType;
// this.pageDialog.showDialog();
// this.curPageDialog = this.pageDialog;
Event.trigger('showPurchasingListDialog', actionType);
}
},
_doPurchaseAction: function(actionType){
if (this.purchaseData){
this._doPurchase();
} else {
// this.source = actionType;
// this.pageDialog.showDialog();
// this.curPageDialog = this.pageDialog;
Event.trigger('showPurchasingListDialog', actionType);
}
},
_doConfirmAction: function(){
if (this.purchaseData && this.source === 'cart'){
this._doCart();
} else if (this.purchaseData && this.source === 'purchase'){
this._doPurchase();
} else {
// this.curPageDialog.closeDialog();
Event.trigger('closePurchasingListDialog');
}
},
_doCart: function(){
log.info('加入进货单');
if (this.config.isSKUOffer === 'true'){
this._doSkuCart();
} else {
this._doSingleCart();
}
// mock
// this.curPageDialog.closeDialog();
Event.trigger('closePurchasingListDialog');
},
_doPurchase: function(){
var state = this._valid('purchase');
log.info('立即订购');
// loginInfo = Wing.navigator.login.getLoginInfo();
// if (!loginInfo.data.islogin) {
// this._popup();
// return;
// }
if (state !== 10){
return
}
if (this.config.isSKUOffer === 'true'){
this._doSkuPurchase();
} else {
this._doSinglePurchase();
}
// mock
// this.curPageDialog.closeDialog();
Event.trigger('closePurchasingListDialog');
},
// sku加入进货单
_doSkuCart: function(){
var params = {
'type': 'offer',
'cargoIdentity': this.config.offerId,
'specData': JSON.stringify(this._getSubmitSkuData()),
'returnType': 'url',
'needTotalPrice': false,
'promotionSwitch': false,
'_csrf_token': this.config._csrf_token,
't': (new Date()).getTime()
};
Wing.navigator.tooltip(JSON.stringify(params));
// this.cartView.activateBatch(params,this.config.purchaseListUrl);
},
// 单件加入进货单
_doSingleCart: function(){
var url = this.config.purchaseListUrl
+ '?type=offer&cargoIdentity='
+ this.config.offerId
+ '&quantity='
+ this.totalAmount
+ '&returnType=json'
+ '&needTotalPrice=false'
+ '&promotionSwitch='
+ false
+ '&_csrf_token='
+ this.config._csrf_token
+ '&t='
+ (new Date()).getTime();
// this.cartView.activate(url);
Wing.navigator.tooltip(url);
},
// sku立即订购
_doSkuPurchase: function(){
var data = {
'offerId' : this.config.offerId,
'sellerMemberId' : this.config.memberId,
'specData' : JSON.stringify(this._getSubmitSkuData())
};
log.info(data);
// Util.submit(this.config.orderUrl, data);
Wing.navigator.tooltip(JSON.stringify(data));
},
// 单件立即订购
_doSinglePurchase: function(){
var url = this.config.orderUrl
+ '?offerid='
+ this.config.offerId
+ '&tracelog=tpselldetail_order_21623&renderType=alipay_offer_order&buyAmount='
+ this.totalAmount;
// FE.util.goTo(url, '_self');
Wing.navigator.tooltip(url);
},
_getSubmitSkuData: function(){
var submitData = [];
$.each(this.skuMap, function(k, v){
if (v.amount > 0){
submitData.push({
'specId': k,
'amount': v.amount
});
}
});
return submitData;
},
_initWarmhole: function(){
var warmhole = new Warmhole(this.div, this.config);
},
_valid: function(type){
return this.validator.valid(this.totalAmount, this.totalPrice, type);
}
});
});