Edit.js 8.51 KB
'use strict';
var $ = require('jquery'),
	common = require('../../../common/common'),
    rejectPromotions=require('./partials/edit_reject');
var baseInfoEdit=require('./partials/edit_baseinfo');
var date_util=require('./partials/_date_util');
var operationEdit=require('./partials/edit_operation');
var conditionEdit=require('./partials/edit_condition');
var displayEdit=require('./partials/edit_display');
var limitEdit=require('./partials/edit_limit');
var multiEdit=require('./partials/edit_multi')

/*
 *	获取业务数据
 */
window.PromotionInfo=window.ViewModel.data;
console.log(window.PromotionInfo);


var ENUM = {          
    tab: {
        '1': 0,
        '2': 0,
        '3': 0,
        '4': 0,
        '5': 0,
        '6': 0
    },	
	tabName:[
		{en:"baseinfo",cn:"基本信息"},
		{en:"condition",cn:"促销条件"},
		{en:"operation",cn:"促销操作"},
		{en:"limit",cn:"促销限制"},
		{en:"reject",cn:"互斥促销"},
		{en:"display",cn:"促销显示"},
        {en:"multi",cn:"多档"}
        ]
};
var fixDateTime=function(){
    if(PromotionInfo.startTime&&PromotionInfo.startTime>0){
        PromotionInfo.startTimeStr=date_util.getDateStr(PromotionInfo.startTime);
    }
    if(PromotionInfo.endTime&&PromotionInfo.endTime>0){
        PromotionInfo.endTimeStr=date_util.getDateStr(PromotionInfo.endTime);
    }
}
//修复日期格式,只修改一次即可
fixDateTime();
var tabLoader={

    loadTabHtml:function(columnname){
        var _g=this;
        var default_html="<a href='#'>bad error</a>";
        var config_data={
                tabLoader:_g,
                columnName:columnname,
                promotionId : PromotionInfo.id
            };
        if (columnname === ENUM.tabName[0].en) {//baseinfo        
            var html_baseinfo=common.util.__template2($("#fm_baseInfo").html(), PromotionInfo);
            $("#tab_body").html(html_baseinfo);
            baseInfoEdit.load(config_data);
        }else if(columnname === ENUM.tabName[1].en) {//condition
            var html_condition = $("#fm_condition").html()||default_html;
            $("#tab_body").html(html_condition);       
            conditionEdit.load(config_data);
        } else if(columnname === ENUM.tabName[2].en) {//operation
            var html_operation = $("#fm_operation").html()||default_html;
            var operationData = buildOperationData(); 
            html_operation= common.util.__template2(html_operation, operationData);      
            $("#tab_body").html(html_operation);

            operationEdit.load($.extend(operationData,config_data));
        }else if(columnname === ENUM.tabName[3].en) {//limit
            var html_limit = $("#fm_limit").html()||default_html;
            var _data= { promotionId: PromotionInfo.id};
            
            if(PromotionInfo.promotionParams && PromotionInfo.promotionParams.limitParam){
                _data["limitParam"] = PromotionInfo.promotionParams.limitParam;
            }
        
            html_limit=common.util.__template2(html_limit, _data);
            $("#tab_body").html(html_limit);
            limitEdit.load( $.extend(_data,config_data));

        }else if(columnname === ENUM.tabName[4].en) {//reject
            // 加载促销列表
            var html_promotions=$("#fm_reject").html();
            $("#tab_body").html(html_promotions);
            var _rejectData=buildRejectData();        
            rejectPromotions.init( $.extend(_rejectData,config_data));
        }else if(columnname === ENUM.tabName[5].en) {//display
            
            var html_display = common.util.__template2($("#fm_display").html(),PromotionInfo);
            
            $("#tab_body").html(html_display);

            displayEdit.load(config_data);
        }else if(columnname === ENUM.tabName[6].en) {//multi
            // 加载促销列表
            var html_promotions=$("#fm_multi").html();
            $("#tab_body").html(html_promotions);
            var _multiData=buildMultiData();
            multiEdit.init( $.extend(_multiData,config_data));
        }
    }
};
/*
//加载显示tab页内容
var loadTabHtml=function(columnname){    
    var default_html="<a href='#'>bad error</a>";
    if (columnname === ENUM.tabName[0].en) {//baseinfo        
        var html_baseinfo=common.util.__template2($("#fm_baseInfo").html(), PromotionInfo);
        $("#tab_body").html(html_baseinfo);
        baseInfoEdit.load({promotionId : PromotionInfo.id});
    }else if(columnname === ENUM.tabName[1].en) {//condition
        var html_condition = $("#fm_condition").html()||default_html;
        $("#tab_body").html(html_condition);       
        conditionEdit.load({promotionId : PromotionInfo.id});
    } else if(columnname === ENUM.tabName[2].en) {//operation
        var html_operation = $("#fm_operation").html()||default_html;
        var operationData = buildOperationData(); 
        html_operation= common.util.__template2(html_operation, operationData);      
        $("#tab_body").html(html_operation);
        operationEdit.load(operationData);
    }else if(columnname === ENUM.tabName[3].en) {//limit
        var html_limit = $("#fm_limit").html()||default_html;
        var _data= { promotionId: PromotionInfo.id};
        
        if(PromotionInfo.promotionParams && PromotionInfo.promotionParams.limitParam){
            _data["limitParam"] = PromotionInfo.promotionParams.limitParam;
        }
       
        html_limit=common.util.__template2(html_limit, _data);
        $("#tab_body").html(html_limit);
        limitEdit.load(_data);

    }else if(columnname === ENUM.tabName[4].en) {//reject
        // 加载促销列表
        var html_promotions=$("#fm_reject").html();
        $("#tab_body").html(html_promotions);
        var _rejectData=buildRejectData();        
        rejectPromotions.init(_rejectData);
    }else if(columnname === ENUM.tabName[5].en) {//display
        
        var html_display = common.util.__template2($("#fm_display").html(),PromotionInfo);
        
        $("#tab_body").html(html_display);

        displayEdit.load({promotionId : PromotionInfo.id});
    }
}
*/
//build Reject Data
var buildRejectData=function(){
    var _reject=[];
    if(PromotionInfo.promotionParams&&PromotionInfo.promotionParams.rejectParam){
        _reject=JSON.parse(PromotionInfo.promotionParams.rejectParam);
    }
    return {
            promotionId : PromotionInfo.id,
            reject:_reject,
            startTimeStr: PromotionInfo.startTimeStr,
            endTimeStr: PromotionInfo.endTimeStr    
        };
}

var buildMultiData=function(){
    var _multi=[];
    if(PromotionInfo.promotionParams&&PromotionInfo.promotionParams.multiParam){
        _multi=JSON.parse(PromotionInfo.promotionParams.multiParam);
    }
    var _promotionType;
    if(PromotionInfo.promotionParams&&PromotionInfo.promotionParams.promotionType){
        _promotionType=PromotionInfo.promotionParams.promotionType;
    }
    return {
        promotionId : PromotionInfo.id,
        multi:_multi,
        promotionType:_promotionType
    };
}
//build Operation Data
var buildOperationData=function(){
    var _promotionType;
    if(PromotionInfo.promotionParams&&PromotionInfo.promotionParams.promotionType){
        _promotionType=PromotionInfo.promotionParams.promotionType;
    }
    var _actionParam;
    if(PromotionInfo.promotionParams&&PromotionInfo.promotionParams.actionParam){
        _actionParam=JSON.parse(PromotionInfo.promotionParams.actionParam);
    }
    return {
        promotionType : _promotionType,
        actionParam : _actionParam,
        promotionId : PromotionInfo.id
    };

}

//tab 页组件
var t = new common.tab2({
    el: "#basicTab",
    active: 0,
    click: function () {
        var columnname = t.options.columns[t.options.active].name;
        tabLoader.loadTabHtml(columnname);       
    },
    columns: [{
        name: ENUM.tabName[0].en,
        value: '8',
        display: ENUM.tabName[0].cn
    }, {
        name: ENUM.tabName[1].en,
        value: '1',
        display: ENUM.tabName[1].cn
    }, {
        name: ENUM.tabName[2].en,
        value: '1',
        display: ENUM.tabName[2].cn
    }, {
        name: ENUM.tabName[3].en,
        value: '1',
        display: ENUM.tabName[3].cn
    },  {
        name: ENUM.tabName[4].en,
        value: '0',
        display: ENUM.tabName[4].cn
    },{
        name: ENUM.tabName[5].en,
        value: 'all',
        display: ENUM.tabName[5].cn
    },{
        name: ENUM.tabName[6].en,
        value: '0',
        display: ENUM.tabName[6].cn
    }]
}).init(ENUM.tab);
//默认加载
tabLoader.loadTabHtml(t.options.columns[t.options.active].name);

document.PromotionEditor=conditionEdit;