欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

abp(net core)+easyui+efcore实现仓储管理系统,入库管理

程序员文章站 2024-01-30 11:16:10
在上面文章abp(net core)+easyui+efcore实现仓储管理系统——入库管理之十(四十六) 的学习之后,我们已经实现了入库单的基本功能,增加,删除,修改。接下来,我们实现添加库位的功能。 ......

、入库单添加库位信息

   入库单的每一条明细数据,会对应一个或多个库位。这就要求能够对某一行的数据进行子表嵌套。在这里通过采用easyui的datagrid-detailview.js插件创建子表格,大致的效果图如下所示:

 abp(net core)+easyui+efcore实现仓储管理系统,入库管理

 

  1. visual studio 2017的“解决方案资源管理器”中,找到“abp.tplms.web.mvc”项目的“views/instock”文件夹,然后鼠标左键双击打开“index.cshtml”文件。在“@section scripts{”节中添加如下代码。
  <script src="~/lib/easyui-1.8/datagrid-detailview.js" asp-append-version="true"></script>

      2. 在visual studio 2017的“解决方案资源管理器”中,找到表示“abp.tplms.web.mvc”项目中的wwwroot\view-resources\instock目录。

       3. 在instock目录中找到index.js文件。在此文件的头部我们要定义两个变量mainindex与editindex,用来定位当前我们选中了哪一行。

var editindex = undefined;
var mainindex = undefined;

       4. 我们在此文件中的showdetail(no)方法中找到datagrid组件,并修改此组件的onclickrow事件中的相关代码。

onclickrow

rowindex, rowdata

当用户点击一行时触发,参数包括:
rowindex:被点击行的索引,从 0 开始
rowdata:被点击行对应的记录

 

 
function showdetail(no) {
    var lastindex;
    $("#dginod").datagrid({
        url: "/instock/getdetail?no=" + no,
        title: "入库单明细",
        pagination: false,     

        fit: true,
        fitcolumns: false,
        loadmsg: "正在加载入库单明细信息...",
        toolbar: [
            { text: '添加明细', iconcls: 'icon-add', handler: function () { showcargoinfo(); } },
            { text: '添加库位', iconcls: 'icon-edit', handler: function () { subgridaddrow(); } },
            { text: '删除', iconcls: 'icon-remove', handler: function () { deviceinfodeleteclick(); } },
            '-'

        ],

        nowarp: false,
        border: false,
        idfield: "id",
        sortname: "id",
        sortorder: "asc",
        singleselect: true,
        iconcls: 'icon-edit',      

        columns: [[
            { title: "编号", field: "seqno", width: 50, sortable: true },
            { title: "入库单号", field: "instockno", width: 100, sortable: true },
            { title: "hscode", field: "hscode", width: 80, sortable: false },
            { title: "货物代码", field: "cargocode", width: 100, sortable: true },
            { title: "货物名称", field: "cargoname", width: 160, sortable: false },
            { title: "规格型号", field: "spcf", width: 80, sortable: false },
            {
                title: "数量", field: "qty", width: 100, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 4

                    }
                }
            },
            {
                title: "长", field: "length", width: 70, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },
            {
                title: "宽", field: "width", width: 70, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },
            {
                title: "高", field: "height", width: 70, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }

            },

            { title: "产销国", field: "country", width: 70, align: 'center' },
            {
                title: "单价", field: "price", width: 100, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },       

            {
                title: "总价", field: "totalamt", width: 100, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },

            { title: "包装", field: "package", width: 70, align: 'center' },
            { title: "计量单位", field: "unit", width: 70, align: 'center' },
            {
                title: "总体积", field: "vol", width: 70, align: 'center', editor: {
                    type: 'numberbox', options: {

                        required: true, min: 0, precision: 4
                    }
                }
            },
           { title: "品牌", field: "brand", width: 70, align: 'center' }

        ]],
        view: detailview,

        detailformatter: function (index, row) {
            return '<div style="padding:2px"><table id="dginoditem-' + index + '"></table></div>';
        },

        onexpandrow: function (index, row) {
            var ddv = $('#dginoditem-' + index);
            ddv.datagrid({
                url: '/instock/getlocs?id=' + row.id,
                fitcolumns: false,

                singleselect: true,
                rownumbers: true,

                loadmsg: '',
                height: 'auto',
                columns: [[
                    { field: 'seqno', title: '序号', width: 50 },
                    {
                        field: 'qty', title: '数量', width: 120, editor: {
                            type: 'numberbox', options: {
                                required: true, min: 0, precision: 2
                            }
                        }
                    },
                    {
                        field: 'loc', title: '库位', width: 150, editor: {

                            type: 'text', options: {
                                required: true
                            }
                        }
                    },

                    { field: 'creationtime', title: '创建时间', hidden: 'true' },

                    { field: 'id', title: 'id', width: 50, hidden: 'true' },
                    { field: 'instockorderdetailid', title: 'inodid', width: 50, hidden: 'true' }
                ]],

                onresize: function () {
                    $('#dginod').datagrid('fixdetailrowheight', index);
                },
                onloadsuccess: function () {
                    settimeout(function () {
                        $('#dginod').datagrid('fixdetailrowheight', index);

                    }, 0);
                    editindex = undefined;//主网格换行
                },
                onafteredit: function (rowindex, rowdata, changes) {
                    editindex = undefined;
                },

                onclickrow: function (index1, row1) {

                    if (editindex != index1) {
                        if (endediting(ddv)) {
                            ddv.datagrid('selectrow', index1).datagrid('beginedit', index1);
                            editindex = index1;

                        }
                        else { ddv.datagrid('selectrow', editindex); }
                    }
                }
            });
            $('#dginod').datagrid('fixdetailrowheight', index);
        }, 

        onclickrow: function (index, rowdata) {
            if (mainindex!=undefined) {
                $('#dginod').datagrid('collapserow', mainindex);

            }           

            if (lastindex != index) {
                $('#dginod').datagrid('endedit', lastindex);
                editrow(index);
            }
            lastindex = index;
            mainindex = index;
        },       

        onbeginedit: function (rowindex, rowdata) {  
            setediting(rowindex);
        }
    });
}

 

5. 除了要修改上面的函数之外,我们还需要添加一些函数方法。下面就给出index.js的全部代码:

//-----------------------系统管理-->入库单管理-----------------------//

var editindex = undefined;
var mainindex = undefined;
//刷新数据

function initable() {
    $("#dginso").datagrid({
        url: "/instock/list",
        title: "入库单管理",
        pagination: true,
        pagesize: 10,
        pagelist: [10, 20, 30],
        fit: true,
        fitcolumns: false,

        loadmsg: "正在加载入库单信息...",

        nowarp: false,
        border: false,
        idfield: "id",
        sortname: "id",
        sortorder: "asc",

        frozencolumns: [[//冻结列
            { field: "ck", checkbox: true, align: "left", width: 50 }           

        ]],
        columns: [[
            { title: "编号", field: "id", width: 50, sortable: true },
            { title: "入库单号", field: "no", width: 100, sortable: true },           

            {title: "状态", field: "status", width: 50            },
            { title: '到货日期', field: 'receivetime',  width: 100, align: 'center' },
            { title: "货主", field: "ownercode", width: 150, sortable: true },
            { title: "预计到货时间", field: "predeliverytime", width: 100, sortable: false },
            { title: '客户', field: 'customername', width: 120, align: 'center' },
            { title: '收货人',field: 'oper', width: 100, align: 'center' },
            { title: '审核人',field: 'checker', width: 120, align: 'center' },
            { title: '件数', field: 'packageqty', width: 100, align: 'center' },
            { title: '创建时间', field: 'creationtime', width: 100, align: 'center' }
        ]]
    }); 

}

//显示送货单数据
function showcargo() {
    abp.log.warn('货物信息列表日志...');

    $("#dgcargo").datagrid({
        url: "/cargo/list",
        title: "货物管理管理",
        pagination: true,
        pagesize: 10,
        pagelist: [10, 20, 30],

        fit: true,
        fitcolumns: false,
        loadmsg: "正在加载货物信息...",
        nowarp: false,
        border: false,

        idfield: "id",
        sortname: "id",
        sortorder: "asc",

        frozencolumns: [[//冻结列
            { field: "ck", checkbox: true, align: "left", width: 50 }
        ]],

        columns: [[
            { title: "编号", field: "id", width: 50, sortable: true },
            { title: "供应商", field: "supplierid", width: 80, sortable: true },
            { title: "hscode", field: "hscode", width: 100, sortable: true },

            { title: "货物代码", field: "cargocode", width: 100, sortable: true },
            { title: "货物名称", field: "cargoname", width: 80, sortable: false },

            { title: "规格型号", field: "spcf", width: 100, sortable: false },
            { title: "产销国", field: "country", width: 80, sortable: false },
            { title: "计量单位", field: "unit", width: 100, sortable: false },
            { title: "包装", field: "package", width: 100, sortable: false },
            { title: "单价", field: "price", width: 100, sortable: false },
            { title: "币制", field: "curr", width: 80, sortable: false },
            {
                title: "长宽高", field: "length", width: 100, sortable: false, formatter: function (value, row, index) {
                    return row.length + '*' + row.width + '*' + row.height;
                }
            },
            { title: "体积", field: "vol", width: 80, sortable: false },
            { title: "备注", field: "remark", width: 80, sortable: false },
            { title: '创建时间', field: 'creationtime', width: 100, align: 'center' }

        ]]
    });

    abp.log.warn('3货物信息列表日志...');
} 

function showcargoinfo() {  
    $("#divimportcargo").dialog({
            closed: false,
            title: "选择货物信息",
            modal: true,
            width: 820,
            height: 550,
            collapsible: true,
            minimizable: true,
            maximizable: true,
            resizable: true
        });
       showcargo();
       $("#dgcargo").datagrid("clearchecked");
       $("#dgcargo").datagrid("clearselections");
} 

function reloaded() {   //reload
    $("#reload").click(function () {
        //
        $('#dginso').datagrid('reload');
    });}
 

//修改点击按钮事件
function updinsoinfo() {  
    $("#edit").click(function () {      

        //判断选择的中
        var row = $("#dginso").datagrid('getselected');        
        if (row) {         
            $.messager.confirm('编辑', '您想要编辑吗?', function (r) {
                if (r) {                

                     //打开对话框编辑
                    $("#divaddupdino").dialog({
                        closed: false,
                        title: "修改入库单",
                        modal: true,
                        width: 820,
                        height: 550,
                        collapsible: true,
                        minimizable: true,
                        maximizable: true,
                        resizable: true,

                    });    
                    //先绑定                  

                    showino(row);
                    defaulttab();
                    showdetail(row.no);
                }               

            });

            setenabled(row.status);
        } else {
            $.messager.alert('提示', ' 请选择要编辑的行!', 'warning');
        }
    });   
}

//删除
function deleteinso() {
    $("#del").click(function () {
        var rows = $("#dginso").datagrid("getselections");
        if (rows.length > 0) {
            $.messager.confirm("提示", "确定要删除吗?", function (res) {

                if (res) {
                    var codes = []; //重要不是{}
                    for (var i = 0; i < rows.length; i++) {
                        codes.push(rows[i].id);
                    }

                    $.post("/instock/delete", { "ids": codes.join(',') }, function (data) {
                        if (data == "ok") {
                            $.messager.alert("提示", "删除成功!");
                            $("#dginso").datagrid("clearchecked");
                            $("#dginso").datagrid("clearselections");
                            $("#dginso").datagrid("load", {});
                        }                       
                        else if (data == "no") {
                            $.messager.alert("提示", "删除失败!");

                            return;
                        }
                    });
                }
            });
        }
    })
}

//清空文本框
function clearall() {    
    $("#divaddupdino input").each(function () {
            $(this).val("");

        });
    $("#predeliverytimeupdate").val(getnowformatdate());    

    $("#statusupdate").val("0");
    $("#nwtupdate").val("0"); 

    $("#gwtupdate").val("0");
    $("#packageqtyupdate").val("0");
  

}

function getno() {
    $.get(abp.apppath + "api/services/app/instockorder/getno", function (data) {
        $("#updno").val(data);
    });

}

//获取当前时间,格式yyyy-mm-dd
function getnowformatdate() {
    var date = new date();
    var seperator1 = "-";
    var year = date.getfullyear();
    var month = date.getmonth() + 1;

    var strdate = date.getdate();
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }

    if (strdate >= 0 && strdate <= 9) {
        strdate = "0" + strdate;
    }

    var currentdate = year + seperator1 + month + seperator1 + strdate;
    return currentdate;
}


//将表单数据转为json
function form2json(id) {
    var arr = $("#" + id).serializearray()

    var jsonstr = ""; 

    jsonstr += '{';
    for (var i = 0; i < arr.length; i++) {
        jsonstr += '"' + arr[i].name + '":"' + arr[i].value + '",'

    }
    jsonstr = jsonstr.substring(0, (jsonstr.length - 1));

    jsonstr += '}' 

    var json = json.parse(jsonstr)
    return json

} 

function setenabled(status) {
    if (status == "提交") {
        $("#btnsave").prop('disabled', true);
    }

    else {
        $("#btnsave").removeattr("disabled");

    }
}
 

function defaulttab() {
    //默认显示第一个tab
    $('#box').tabs('select', "入库单");

}

//弹出 导入送货单的的对话框

function showinsodialog() {
    $("#add").click(function () {     

            $.messager.confirm('编辑', '您想要创建入库单吗?', function (r) {

                if (r) {
                    //打开对话框编辑
                    $("#divaddupdino").dialog({
                        closed: false,
                        title: "新增入库单",
                        modal: true,
                        width: 820,
                        height: 550,
                        collapsible: true,
                        minimizable: true,
                        maximizable: true,
                        resizable: true,

                    });                  

                }
                defaulttab();
                getno();
                clearall();
                showdetail("");
            });       

    });  

    $("#btnsave").click(function () {    

        //保存
        var id = $("#idupdate").val();
        if (id == "" || id == undefined) {
            //验证
            $.messager.confirm('确认', '您确认要保存吗?', function (r) {
                if (r) {                   

                    var postdata = getino();                    

                    if (postdata.no == "" || postdata.customercode == "" || postdata.customername=="" || postdata.ownername=="") {
                        $.messager.alert('提示', ' 请填写相关必填项!', 'warning');

                        return;
                    }                   

                    $.post("/instock/add", postdata, function (data) {
                        if (data == "ok") {
                            $.messager.alert("提示", "保存成功!");

                            initable();
                            collapserows();
                        }

                        else if (data == "no") {
                            $.messager.alert("提示", "保存失败!");
                            return;

                        }

                    });
                }
            })
        }

        else {
            savedetail();
            initable();
            collapserows();

        }

    });
}
//添加明细
function showdetail(no) {
    var lastindex;
    $("#dginod").datagrid({
        url: "/instock/getdetail?no=" + no,
        title: "入库单明细",
        pagination: false,      
        fit: true

        fitcolumns: false,
        loadmsg: "正在加载入库单明细信息...",
        toolbar: [
            { text: '添加明细', iconcls: 'icon-add', handler: function () { showcargoinfo(); } },
            { text: '添加库位', iconcls: 'icon-edit', handler: function () { subgridaddrow(); } },
            { text: '删除', iconcls: 'icon-remove', handler: function () { deviceinfodeleteclick(); } },
            '-'
        ],

        nowarp: false,

        border: false,

        idfield: "id",

        sortname: "id",

        sortorder: "asc",
        singleselect: true,
        iconcls: 'icon-edit',      

        columns: [[
            { title: "编号", field: "seqno", width: 50, sortable: true },
            { title: "入库单号", field: "instockno", width: 100, sortable: true },

            { title: "hscode", field: "hscode", width: 80, sortable: false },
            { title: "货物代码", field: "cargocode", width: 100, sortable: true },
            { title: "货物名称", field: "cargoname", width: 160, sortable: false },
            { title: "规格型号", field: "spcf", width: 80, sortable: false },
            {
                title: "数量", field: "qty", width: 100, align: 'center', editor: {
                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 4
                    }
                }
            },
            {
                title: "长", field: "length", width: 70, align: 'center', editor: {
                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },
            {
                title: "宽", field: "width", width: 70, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },
            {
                title: "高", field: "height", width: 70, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },
            { title: "产销国", field: "country", width: 70, align: 'center' },
            {
                title: "单价", field: "price", width: 100, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2

                    }
                }
            },       

            {
                title: "总价", field: "totalamt", width: 100, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 2
                    }
                }
            },
            { title: "包装", field: "package", width: 70, align: 'center' },
            { title: "计量单位", field: "unit", width: 70, align: 'center' },
            {
                title: "总体积", field: "vol", width: 70, align: 'center', editor: {

                    type: 'numberbox', options: {
                        required: true, min: 0, precision: 4

                    }
                }
            },
            { title: "品牌", field: "brand", width: 70, align: 'center' }

        ]],

        view: detailview,

        detailformatter: function (index, row) {
            return '<div style="padding:2px"><table id="dginoditem-' + index + '"></table></div>';

        },

        onexpandrow: function (index, row) {
            var ddv = $('#dginoditem-' + index);
            ddv.datagrid({
                url: '/instock/getlocs?id=' + row.id,
                fitcolumns: false,
                singleselect: true,
                rownumbers: true,
                loadmsg: '',
                height: 'auto',
                columns: [[                   //[{"instockorderdetailid":24,"seqno":1,"loc":"a121","qty":121.00,"creationtime":"2020-02-17 16:37:05","id":1}]
                    { field: 'seqno', title: '序号', width: 50 },
                    {
                        field: 'qty', title: '数量', width: 120, editor: {
                            type: 'numberbox', options: {
                                required: true, min: 0, precision: 2
                            }
                        }
                    },
                    {
                        field: 'loc', title: '库位', width: 150, editor: {
                            type: 'text', options: {
                                required: true
                            }
                        }
                    },

                    { field: 'creationtime', title: '创建时间', hidden: 'true' }, 

                    { field: 'id', title: 'id', width: 50, hidden: 'true' },
                    { field: 'instockorderdetailid', title: 'inodid', width: 50, hidden: 'true' }
                ]],

                onresize: function () {
                    $('#dginod').datagrid('fixdetailrowheight', index);
                },

                onloadsuccess: function () {
                    settimeout(function () {
                        $('#dginod').datagrid('fixdetailrowheight', index);

                    }, 0);
                    editindex = undefined;//主网格换行
                },
                onafteredit: function (rowindex, rowdata, changes) {

                    editindex = undefined;
                },

                onclickrow: function (index1, row1) {
                    if (editindex != index1) {
                        if (endediting(ddv)) {
                       ddv.datagrid('selectrow', index1).datagrid('beginedit', index1);
                            editindex = index1;

                        }
                        else { ddv.datagrid('selectrow', editindex); }

                    }
                }
            });
            $('#dginod').datagrid('fixdetailrowheight', index);

        },

        onclickrow: function (index, rowdata) {
            if (mainindex!=undefined) {
                $('#dginod').datagrid('collapserow', mainindex);

            }          

            if (lastindex != index) {
                $('#dginod').datagrid('endedit', lastindex);
                editrow(index);
            }

            lastindex = index;
            mainindex = index;
        },        

        onbeginedit: function (rowindex, rowdata) { 
            setediting(rowindex);
        }
    });
}

//计算报价小计

function setediting(rowindex) {
    var editors = $('#dginod').datagrid('geteditors', rowindex);
    var priceeditor = editors[4];
    var qtyeditor = editors[0];
    var lengtheditor = editors[1];
    var widtheditor = editors[2];
    var heighteditor = editors[3];
    var totalvoleditor = editors[6];

    var totalamteditor = editors[5];
    priceeditor.target.numberbox({
        onchange: function () { calculate();}

    });

    qtyeditor.target.numberbox({
        onchange: function () {
            calculate();
            calculatevol();
        }

    });

    lengtheditor.target.numberbox({
        onchange: function () { calculatevol(); }
    });

    widtheditor.target.numberbox({
        onchange: function () { calculatevol(); }

    });

    heighteditor.target.numberbox({
        onchange: function () { calculatevol(); }
    });

    function calculate() {
        var cost = (priceeditor.target.val()) * (qtyeditor.target.val());

        console.log(cost);
        totalamteditor.target.numberbox("setvalue", cost);
    }

    function calculatevol() {
        var vol = (lengtheditor.target.val() / 100.0) * (widtheditor.target.val() / 100.0) * (heighteditor.target.val() / 100.0)*
 (qtyeditor.target.val());
        console.log(vol);
        totalvoleditor.target.numberbox("setvalue", vol);
    }

}

function editrow(index) {
    $('#dginod').datagrid('selectrow', index)
        .datagrid('beginedit', index);
}

function endedit() {
    var rows = $('#dginod').datagrid('getrows');
    if (rows==undefined) {
        return;
    }
    for (var i = 0; i < rows.length; i++) {

        $('#dginod').datagrid('endedit', i);
    }
}

//获取入库单明细的库位数据

function setsubgridloc(effectrow) {
    var ddv = $('#dginoditem-' + mainindex);
    var dgcnt = ddv.datagrid().length;
    if (mainindex != undefined && dgcnt>0) {

        endeditsub(ddv);
        var changes = ddv.datagrid('getchanges');
        if (changes.length) {
            var insed = ddv.datagrid('getchanges', "inserted");
            var deled = ddv.datagrid('getchanges', "deleted");
            var upded = ddv.datagrid('getchanges', "updated");

            if (insed.length) {
                effectrow["locsinserted"] = json.stringify(insed);
            }

            if (deled.length) {
                effectrow["locsdeleted"] = json.stringify(deled);
            }

            if (upded.length) {
                effectrow["locsupdated"] = json.stringify(upded);
            }
        }
    }
    return effectrow;

}

//设置入库单明细数据

function setgriddetail(effectrow) { 

    if ($('#dginod').datagrid('getchanges').length) { 

        var inserted = $('#dginod').datagrid('getchanges', "inserted");
        var deleted = $('#dginod').datagrid('getchanges', "deleted");
        var updated = $('#dginod').datagrid('getchanges', "updated");      

        if (inserted.length) {
            effectrow["inserted"] = json.stringify(inserted);
        }

        if (deleted.length) {
            effectrow["deleted"] = json.stringify(deleted);
        }

        if (updated.length) {
            effectrow["updated"] = json.stringify(updated);
        }
     }
    return effectrow;

}

function endeditsub(ddv) {    
    if (mainindex != undefined) {
        var rows = ddv.datagrid('getrows');
        if (rows!=undefined) {
            for (var i = 0; i < rows.length; i++) {
                ddv.datagrid('endedit', i);
            }  
        }          

    }
}

function savedetail() {
    endedit();
    $.messager.confirm('确认', '您确认要修改吗?', function (r) {
        var effectrow = new object();
        var postdata = getino();
        if (postdata.id) {
            effectrow["postdata"] = json.stringify(postdata);
        }

        effectrow = setsubgridloc(effectrow);
        effectrow = setgriddetail(effectrow);
        $.post("/instock/update", effectrow, function (data) {
           //  alert(data);
            if (data.success) {
                $.messager.alert("提示", data.result);
                $('#dginod').datagrid('acceptchanges');
               }

            else {
                $.messager.alert("提示", data.result);
                return;
            }

        }, "json") ;      

        })    

}

function init() {
    $("#predeliverytimeupdate").val(getnowformatdate());
    $("#creationtimeupdate").val(getnowformatdate());
    $("#btncancle").click(function () {      
        $("#divaddupdino").dialog("close");  
        $('#dginso').datagrid('reload');

    });

    $("#btncancledo").click(function () {
        $("#divimportcargo").dialog("close");
        $('#dginso').datagrid('reload');

    });

 

    $("#btnimportdo").click(function () {
        //保存
        var rows = $('#dgcargo').datagrid('getselections');
        if (rows.length > 0) {
            //验证
            $.messager.confirm('确认', '您确认要保存所选择的货物信息吗?', function (r) {

                if (r) {

                    var obj_no = $("#updno").val();
                    var ids = [];//重要不是{}
                    for (var i = 0; i < rows.length; i++) {
                        ids.push(rows[i].id);
                    }

                    var postdata = {
                        "ids": ids.join(','),
                        "no": obj_no
                    };

                    $.post("/instock/importcargo", postdata, function (data) {

                        if (data == "ok") {
                            $.messager.alert("提示", "保存货物信息成功!");
                            showdetail(obj_no);
                        }

                        else if (data == "no") {
                            $.messager.alert("提示", "保存货物信息失败!");
                            return;
                        }
                    }); 

                }
            })
        } 

    });

    $("#btnsubmit").click(function () {
        //保存
        var id = $("#idupdate").val();
        if (id == "" || id == undefined) {
            $.messager.alert("提示", "入库单没有保存,请先保存!");
            return;
        }
            //验证
            $.messager.confirm('确认', '您确认要提交入库单吗?', function (r) {
                if (r) {                  
                    var postdata = {
                        "id": id                       

                    };

                    $.post("/instock/submit", postdata, function (data) {
                        if (data == "ok") {
                            $.messager.alert("提示", "入库单已经提交成功!");                          

                            $("#statusupdate").val("提交");
                            setenabled("提交");
                        }

                        else if (data == "no") {
                            $.messager.alert("提示", "入库单提交失败!");
                            return;
                        }
                    });
                }
            })
    });
}
 

function subgridaddrow() {
    var ddv = $('#dginoditem-' + mainindex);
    var row = $('#dginod').datagrid('getselected');
    if (mainindex != undefined && editindex!=undefined) {

        ddv.datagrid('endedit', editindex);
    }

    if (editindex == undefined) {
        var seqno = ddv.datagrid("getrows").length + 1;
        ddv.datagrid('insertrow', {
            index: 0,
            row: { instockorderdetailid: row.id, seqno: seqno}
        });
        ddv.datagrid('beginedit', 0);
        editindex = 0;
    }

}
 

function endediting(ddv) {

    var changes = ddv.datagrid('getchanges');
    if (editindex == undefined) { return true }
    if (ddv.datagrid('validaterow', editindex)) {
        //验证前一行
        //返回编辑器,结束编辑
        ddv.datagrid('endedit', editindex);
        editindex = undefined;
        return true;

    } else { return false; }
}
 

function collapserows() {
    var rows = $('#dginod').datagrid('getrows');
    $.each(rows, function (i, k) {
        //获取当前所有展开的子网格
        var expander = $('#dginod').datagrid('getexpander', i);
        if (expander.length && expander.hasclass('datagrid-row-collapse')) {
            if (k.id != row.id) {
                //折叠上一次展开的子网格
                $('#dginod').datagrid('collapserow', i);
            }
        }
    });

} 

function getino() {
    var postdata = {
        "no": $("#updno").val(),
        "deliveryno": "",
        "predeliverytime": $("#predeliverytimeupdate").val(),
        "customercode": $("#customercodeupdate").val(),
        "ownername": $("#ownernameupdate").val(),
        "ownercode": $("#ownercodeupdate").val(),
        "customername": $("#customernameupdate").val(),

        "creationtime": $("#creationtimeupdate").val(),
        "checktime": $("#checktimeupdate").val(),
        "warehousetype": $("#warehousetypeupdate").val(),

        "warehouseno": $("#warehousenoupdate").val(),
        "oper": $("#operupdate").val(),
        "receiver": $("#receiverupdate").val(),

        "nwt": $("#nwtupdate").val(),
        "remark": $("#remarkupdate").val(),
        "receivetime": $("#receivetimeupdate").val(),      

        "status": $("#statusupdate").val(),
        "gwt": $("#gwtupdate").val(),
        "checker": $("#checkerupdate").val(),
        "packageqty": $("#packageqtyupdate").val(),

        "lastupdatetime": "",
        "lastoper":""

    };
    var id = $("#idupdate").val();
    if (!(id=="" || id==undefined)) {
        postdata.id = id;
    }
    return postdata;

} 

function showino(row) {     

    $("#idupdate").val(row.id);
    $("#updno").val(row.no);
    $("#predeliverytimeupdate").val(row.predeliverytime);
    $("#customercodeupdate").val(row.customercode);

    $("#packageqtyupdate").val(row.packageqty);
    $("#customernameupdate").val(row.customername);
    $("#ownercodeupdate").val(row.ownercode);
    $("#ownernameupdate").val(row.ownername);

    $("#creationtimeupdate").val(row.creationtime);
    $("#checktimeupdate").val(row.checktime);
    $("#warehousetypeupdate").val(row.warehousetype);

    $("#warehousenoupdate").val(row.warehouseno);
    $("#operupdate").val(row.oper);

    $("#receiverupdate").val(row.receiver);
    $("#nwtupdate").val(row.nwt);

    $("#remarkupdate").val(row.remark);
    $("#receivetimeupdate").val(row.receivetime);
    $("#statusupdate").val(row.status);   

    $("#gwtupdate").val(row.gwt);
    $("#checkerupdate").val(row.checker);
}

//------------------------系统管理-->入库单管理结束------------------------//