Index.js 6.52 KB
'use strict';
var $ = require('jquery'),
    common = require('../../../common/common');

window.batchOperateShelve = [];

$("#add-btn").hide();
$("#standardType-btn").hide();

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

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.standardSort.standardSortName;
        }
    }, {
        display: '参数名称',
        name: 'standardName',
    }, {
        display: '参数值',
        render: function(item) {
            var parmList= item.parameterMakeList;
            var parm=[];
            if(parmList!=null){
                for (var j = 0; j < parmList.length; j++) {
                    if(parmList[j].parameterValue!=null){
                        parm.push(parmList[j].parameterValue);
                    }
                }
            }
            return parm.join('<br/>');
        }
    },{
        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-standard">删除</a>');
            return HtmArr.join('');
        }
    }]
});
g.init("/erpproduct/prodcutparm/list");

//筛选
$("#filter-btn").click(function () {
    g.reload(1);
    var smallSortId=tabTree.selected[2] ? tabTree.selected[2].id : "";
    if(smallSortId>0){
        $("#add-btn").show();
        $("#standardType-btn").show();
    }
});

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

$(document).on('click', '.edit-class-btn', function () {
    var item = g.rows[$(this).data("index")];
    var sortName="";
    if(tabTree.selected[0]){
        sortName=sortName+tabTree.selected[0].sortName+"/";
    }
    if(tabTree.selected[1]){
        sortName=sortName+tabTree.selected[1].sortName+"/";
    }
    if(tabTree.selected[2]){
        sortName=sortName+tabTree.selected[2].sortName;
    }
   var smallSortId =tabTree.selected[2] ? tabTree.selected[2].id : "";
        common.dialog.confirm("修改参数",
        common.util.__template2($("#template").html(),
            {id: item.id, standardName: item.standardName,
            orderBy:item.orderBy, stortTypeName:sortName,standardSortName:item.standardSort.standardSortName
            ,standardSortId:item.standardSortId})
        , function () {
                var input = $('#standardName').val();
                if (input === '' || $.trim(input) === '')
                {
                    common.util.__tip("参数名称不能为空", "warning");
                    return false;
                }
                var stortTypeId = $('#stortTypeId').val();
                if (stortTypeId === '' || $.trim(stortTypeId) === ''||stortTypeId<1)
                {
                    common.util.__tip("参数类别不能为空", "warning");
                    return false;
                }
            common.util.__ajax2({
                url: '/erpproduct/standard/update',
                data: (function () {
                    return {
                        id: item.id,
                        standardName: $("#standardName").val(),
                        orderBy: $("#orderBy").val(),
                        standardSortId:$("#stortTypeId").val()
                    };
                })()
            }, function () {
                g.reload();
            });
        });
    new common.dropDown({
        el: '#stortTypeId',
        ajax: 'queryStortType',
        hash: true,
        params:function(){
            return {sortId: smallSortId};
        }
    });

    $('#stortTypeName').attr("disabled", true);
});

$(document).on('click', '#add-btn', function () {
    var item = g.rows[$(this).data("index")];
    var sortName="";
    if(tabTree.selected[0]){
        sortName=sortName+tabTree.selected[0].sortName+"/";
    }
    if(tabTree.selected[1]){
        sortName=sortName+tabTree.selected[1].sortName+"/";
    }
    if(tabTree.selected[2]){
        sortName=sortName+tabTree.selected[2].sortName;
    }
    var smallSortId=tabTree.selected[2] ? tabTree.selected[2].id : "";
    common.dialog.confirm("新增参数",
        common.util.__template2($("#template").html(),
            {standardName:  common.util.__input("standardName"),
                orderBy: common.util.__input("orderBy"), stortId:smallSortId,stortTypeName:sortName
                ,standardSortId:common.util.__input("standardSortId")})
        , function () {
            common.util.__ajax({
                url: '/erpproduct/standard/add',
                data: (function () {
                    var input = $('#standardName').val();
                    if (input === '' || $.trim(input) === '')
                    {
                        common.util.__tip("参数名称不能为空", "warning");
                        return;
                    }
                    var stortTypeId = $('#stortTypeId').val();
                    if (stortTypeId === '' || $.trim(stortTypeId) === ''||stortTypeId<1)
                    {
                        common.util.__tip("参数类别不能为空", "warning");
                        return;
                    }
                    return {
                        sortId:smallSortId,
                        standardName: $("#standardName").val(),
                        orderBy: $("#orderBy").val(),
                        standardSortId:$("#stortTypeId").val()
                    };
                })()
            }, function () {
                g.reload();
            });
        });
    new common.dropDown({
        el: '#stortTypeId',
        ajax: 'queryStortType',
        hash: true,
        params:function(){
            return {sortId: smallSortId};
        }
    });

    $('#stortTypeName').attr("disabled", true);
});