Edit.js 6.85 KB
'use strict';
var $ = require('jquery'),
	common = require('../../../common/common');
//require('../util/custom.js');
/*
 *	获取业务数据
 */
window.NETSALEDATA= window.ViewModel.data;
console.log(window.NETSALEDATA);

var promotionEdit={
    batchIds:[],
    
    buildCheckboxHtml:function(_class,_data_index,_checked){
        var _checkBox="<input type='checkbox'";        
        var _end="/>";
        if(_class){
            _checkBox+=" class='"+_class+"'";
        }
        if(_data_index){
            _checkBox+=" data-index='"+_data_index+"'";
        }
        if(_checked){
            _checkBox+=" checked='"+_checked+"'";
        }
        _checkBox+=_end;
        return _checkBox;
    },
    getParam:function(){
        
        var _buildCheckboxHtml = 
            function (item) {                        
                var htmlContent = "";
                var _class="wqt_checkbox";
                if(this.batchIds.length === 0 ){
                    //htmlContent = "<input type='checkbox' class='wqt_checkbox' data-index='"+item.__index+"'>";
                    htmlContent = this.buildCheckboxHtml(_class,item.__index);
                }else{
                    $.each(this.batchIds,function(n,value) {
                        if(item.id == value){
                            //htmlContent = "<input type='checkbox' checked='checked'  class='wqt_checkbox' data-index='"+item.__index+"'>";
                            htmlContent = this.buildCheckboxHtml(_class,item.__index,"checked");
                            return false
                        }else{
                            htmlContent = "<input type='checkbox'  class='wqt_checkbox' data-index='"+item.__index+"'>";
                            htmlContent = this.buildCheckboxHtml(_class,item.__index);
                        }
                    })
                }
                return htmlContent;
            };
        var param={
            el: '#basicTable_promotion',
            size: 10,
            parms: function() {
                return {           
                    startTime: common.util.__input('startTime'),
                    endTime:common.util.__input("endTime")            
                };
            },
            columns: [
                
                {
                    display: '',
                    type: 'checkbox',
                    render: function (item) {                        
                        return _buildCheckboxHtml(item);
                    }
                },{
                    display: "ID",
                    name: "id"
                }, {
                    display: "促销名称",
                    name: "title"        
                }, {
                    display: '优先级',
                    name: "priority"
                }, {
                    display: '开始时间',
                    name: "startTime",
                    render: function(item) {
                        var date = new Date(item.startTime * 1000);
                        return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
                    }
                }, {
                    display: '结束时间',
                    name: "endTime",
                    render: function(item) {
                        var date = new Date(item.endTime * 1000);
                        return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
                    }
                }, {
                    display: '是否启用',
                    name: "status",
                    render: function(item) {
                        if(item.status==1){
                            var name ="已启用" ;
                        }else {
                            var name ="未启用" ;
                        }
                        return name;
                    }
                },  {
                    display: '优惠券限制使用',
                    name: "status",
                    render: function(item) {
                        if(item.status==1){
                            var name ="是" ;
                        }else {
                            var name ="否" ;
                        }
                        return name;
                    }
                }]
        };
        return param;
    },
    bindGrid: function(param){
        return new common.grid(param);
    },
    grid: undefined,
    init: function(){
        var g=this,
            _param=this.getParam();
        this.grid=g.bindGrid(_param);
        this.grid.init("/promotionInfo/list");
    },
    reload:function(){
        var g=this,
        _grid=this.grid;
        _grid.reload(1);
    }
}

var ENUM = {   
    status: {
        '0': '已下架',
        '1': '已上架',
        '2': '待审核',
        '3': '上架驳回',
        '4': '通过',
        '5': '再上架待审核',
        '6': '再上架驳回',
        '7': '再上架通过',
        '8': '待上架',
        '9': '下架驳回',
        '10':'下架待审核'
    },    
    tab: {
        '1': 0,
        '2': 0,
        '3': 0,
        '4': 0,
        '5': 0
    },	
	tabName:[
		{en:"baseinfo",cn:"基本信息"},
		{en:"condition",cn:"促销条件"},
		{en:"operation",cn:"促销操作"},
		{en:"limit",cn:"促销限制"},
		{en:"reject",cn:"互斥促销"},
		{en:"display",cn:"促销显示"},]
};

//tab 页组件
var t = new common.tab2({
    el: "#basicTab",
    active: 6,
    click: function () {
        var columnname = t.options.columns[t.options.active].name;
        
        if (columnname === ENUM.tabName[0].en) {
           var html_baseinfo=$("#fm_baseInfo").html();
		   $("#tab_body").html(html_baseinfo);
        }else if(columnname === ENUM.tabName[1].en) {
            
		} else if(columnname === ENUM.tabName[2].en) {
			
		}else if(columnname === ENUM.tabName[3].en) {
			
		}else if(columnname === ENUM.tabName[4].en) {
			// 加载促销列表
            var html_promotions=$("#fm_reject").html();
            $("#tab_body").html(html_promotions);
            promotionEdit.init();
		}else if(columnname === ENUM.tabName[5].en) {
			
        }       
        
    },
    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
    }]
}).init(ENUM.tab);