baserule.standardSort.Index.js 7.44 KB
webpackJsonp([16],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	
	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var GetRequestParams = function() { 
	    var url = location.search; //获取url中"?"符后的字串 
	    var theRequest = {}; 
	    if (url.indexOf("?") != -1) { 
	        var str = url.substr(1);
	        strs = str.split("&"); 
	        for(var i = 0; i < strs.length; i ++) {
	            var paramNameVal = strs[i].split("=");
	            theRequest[paramNameVal[0]] = decodeURIComponent(paramNameVal[1]);
	        } 
	    } 
	    return theRequest; 
	};

	var getSortsJson = function(reqJson){
	    var sortArry = [];
	    sortArry.push({id: reqJson.maxSortId , sortName: reqJson.maxSortName});
	    sortArry.push({id: reqJson.middleSortId, sortName: reqJson.middleSortName});
	    sortArry.push({id: reqJson.smallSortId, sortName: reqJson.smallSortName});
	    return sortArry;
	};


	var tabTree = new common.tabTree("#sortTree");
	tabTree.init(getSortsJson(GetRequestParams()));

	new common.dropDown({
	    el: '#stortTypeId',
	    ajax: 'queryStortType',
	    hash: true,
	    params:function(){
	        return {sortId: smallSortId};
	    }
	});

	var smallSortId = tabTree.selected[2] ? tabTree.selected[2].id : "";

	var g = new common.grid({
	    el: "#basicTable",
	    usepagesize:true,
	    parms: function () {
	        return {
	            sortId: tabTree.selected[2] ? tabTree.selected[2].id : "",
	            sortName: tabTree.selected[2] ? tabTree.selected[2].sortName : ""

	        };
	    },
	    columns: [ {
	        display: 'ID',
	        name: 'id',
	    }, {
	        display: '类别名称',
	        render: function(item) {
	            return item.standardSortName;
	        }
	    },  {
	        display: '所属分类',
	        render: function(item) {
	            var parmList = getAllSortName();            
	            return appendAllSortName(parmList);
	        }
	    },{
	        display: '排序',
	        name: 'orderBy'
	    }, {
	        display: '操作',
	        render: function(items) {
	            var HtmArr = [];
	            HtmArr.push('<a data-index="'+ items.__index+ '" href="JavaScript:;" class="btn btn-info btn-xs edit-class-btn">编辑</a>');
	            HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs del-standardSort">删除</a>');
	            return HtmArr.join('');
	        }
	    }]
	});
	g.init("/erpproduct/standardSort/list");

	//筛选
	$("#filter-btn").click(function () {
	    g.reload(1);
	});

	//删除
	$('tbody').on('click', '.del-standardSort', function() {
	    var item=g.rows[$(this).data("index")];
	    common.dialog.confirm("温馨提示", "你确定要删除吗?", function () {
	        common.util.__ajax({
	            url:'/erpproduct/standardSort/del',
	            data:{id:item.id}
	        },function(){
	            g.reload();
	        });
	    });
	});

	var getAllSortName = function(){
	    var sortNames = [];
	    for (var i = 0; i < 3; i++) {
	        if(tabTree.selected[i]){
	            sortNames.push(tabTree.selected[i].sortName);
	        }
	    }    
	    return sortNames;
	};

	var getAllSort = function(){
	    var sorts = [];
	    for (var i = 0; i < 3; i++) {
	        if(tabTree.selected[i]){
	            sorts.push(tabTree.selected[i]);
	        }
	    }    
	    return sorts;
	};

	var appendAllSortName = function(allSorts){
	    if(allSorts === 'undefined' || allSorts.length === 0){
	        return '';
	    }
	    var sortName="";
	    for (var i = 0;i < allSorts.length; i++) {        
	        sortName = sortName + allSorts[i]+"/";
	    }
	    return sortName.substr(0,sortName.lastIndexOf("/"));
	}
	/**
	修改
	**/
	$(document).on('click', '.edit-class-btn', function () {
	    var item = g.rows[$(this).data("index")];
	    var sortName=appendAllSortName(getAllSortName());
	    
	    var standardSort = {
	        id: item.id,
	        sortId: item.sortId, 
	        standardSortName: item.standardSortName,
	        orderBy: item.orderBy,
	        sortName: sortName,      
	    };
	    common.dialog.confirm("修改参数",
	        common.util.__template2($("#edit-template").html(),standardSort)
	        , function () {
	            var flag=true;
	            var input = $('#standardSortName').val();
	            if (input === '' || $.trim(input) === ''){
	                flag=false;
	                common.util.__tip("参数名称不能为空", "warning");
	            }
	            var orderBy = $('#orderBy').val();
	            if (orderBy < 0)
	            {
	                flag=false;
	                common.util.__tip("排序不能为负数", "warning");
	            }
	            if(flag){
	                common.util.__ajax({
	                    url: '/erpproduct/standardSort/update',
	                    data: (function () {

	                        return {
	                            id: item.id,
	                            standardSortName: $("#standardSortName").val(),
	                            orderBy: $("#orderBy").val(),
	                            sortId: $("#sortId").val()
	                        };
	                    })()
	                }, function () {
	                    g.reload();
	                });
	            }else {
	                return false;
	            }
	        });
	});
	/**
	新增
	**/
	$(document).on('click', '#add-btn', function () {
	    var item = g.rows[$(this).data("index")];
	    var sortName=appendAllSortName(getAllSortName());
	    
	    var smallSortId = tabTree.selected[2] ? tabTree.selected[2].id : "";

	    var standardSort = {
	                sortId: smallSortId, 
	                standardSortName: common.util.__input("standardSortName"),
	                orderBy: common.util.__input("orderBy"),
	                sortName: sortName,   
	            };
	    common.dialog.confirm("新增参数类别",
	        common.util.__template2($("#edit-template").html(),standardSort), 
	        function () {
	            var flag=true;
	            if(smallSortId === 'undefined' || smallSortId <= 0 || smallSortId === null){
	                flag=false;
	                common.util.__tip("请选择分类", "warning");
	            }
	            var standardSortName = $('#standardSortName').val();
	            if (standardSortName === '' || $.trim(standardSortName) === '')
	            {
	                flag=false;
	                common.util.__tip("参数类别名称不能为空", "warning");
	             }
	            var orderBy = $('#orderBy').val();
	            if (orderBy < 0)
	            {
	                flag=false;
	                common.util.__tip("排序不能为负数", "warning");
	             }
	            if(flag){
	                common.util.__ajax({
	                    url: '/erpproduct/standardSort/add',
	                    data: (function () {
	                        return {
	                            sortId: smallSortId,
	                            standardSortName: $("#standardSortName").val(),
	                            orderBy: $("#orderBy").val()
	                        };
	                    })()
	                }, function () {
	                    g.reload();
	                });
	            }else{
	                return false;
	            }
	        });
	    new common.dropDown({
	        el: '#stortTypeId',
	        ajax: 'queryStortType',
	        hash: true,
	        params:function(){
	            return {sortId: smallSortId};
	        }
	    });    
	});





/***/ }
]);