ReceiptContainerHeader.js 15.1 KB
layui.config({
    base: "/js/"
}).use(['form', 'element', 'vue', 'layer', 'laydate', 'jquery', 'table', 'hhweb', 'utils', 'Universal'], function () {
    var form = layui.form,
        layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        $ = layui.jquery,
        table = layui.table,
        Universal = layui.Universal;

    var AreaName = 'receipt';
    var TableName = 'ReceiptDetail';

    var vm = new Vue({
    });

    var vmq = new Vue({
    });

    var mainList = {
        //NoData: function () {
        //    return "<div id='background' style='width:100%;height:100%;background-image:url(../../images/NoData.png);background-repeat:no-repeat;background-size:cover;'>.</div>"
        //},
        mainList: function (svm) {
            table.reload('mainList', {
                url: "/" + AreaName + "/" + TableName + "/FindReceiptDetail"
                , where: svm.$data
                , method: "post"
                //, text: { none: this.NoData() }
            });
        }
    };

    //回车监听
    function keylisten() {
        $('#keyword').bind("keydown", function (e) {
            if (e.which == 13) {
                $('#searchDetail').click();
                RefreshStatus();
            }
        });
    } 

    //头工具栏事件
    table.on('toolbar(mainList)', function (obj) {
        switch (obj.event) {
            case 'searchDetail':  //跳转至单据页面,新增数据
                var str = $('#keyword').val();
                if (str != "") {
                    vm.$set('ReceiptCode', str);
                    mainList.mainList(vm);
                    $('#keyword').val(str)

                    RefreshStatus();
                }
                else {
                    layer.alert("必须填写入库单号!", { icon: 5, shadeClose: true, title: "错误信息" });
                    $('#keyword').focus();
                }

                keylisten();
                break;
        }
    });

    keylisten();

    var selector = {
        'InventoryStatus': {
            SelType: "FromDict",
            SelFrom: "inventoryStatus",
            SelModel: "InventoryStatus",
        },
        'Status': {
            SelType: "FromDict",
            SelFrom: "receiptHeaderStatus",
            SelModel: "Status",
        },
        'WarehouseType': {
            SelType: "FromDict",
            SelFrom: "warehouseType",
            SelModel: "WarehouseType",
        },
        'IStatus': {
            SelType: "FromDict",
            SelFrom: "inventoryStatus",
            SelModel: "IStatus",
        },
        'LStatus': {
            SelType: "FromDict",
            SelFrom: "locationStatus",
            SelModel: "LStatus",
        },
        'ContainerStatus': {
            SelType: "FromDict",
            SelFrom: "containerStatus",
            SelModel: "ContainerStatus",
        }, 
        'Type': {
            SelType: "FromDict",
            SelFrom: "warehouseType",
            SelModel: "Type",
        }, 
    };

    //相同物料仓位
    var All = new Array();
    var AreaNameDtlInventory = 'inventory';
    var TableNameDtlInventory = 'Inventory';
    //{子表字段:主表字段}
    var NameDtlInventory = { MaterialCode: 'MaterialCode' };
    var vmDtlInventory = new Vue({
        el: '#modifyFormDtl_' + TableNameDtlInventory
    });
    var vmqDtlInventory = new Vue({
        data: { MaterialCode: ''}
    });

    All.push({ AreaNameDtl: AreaNameDtlInventory, TableNameDtl: TableNameDtlInventory, vmqDtl: vmqDtlInventory, vmDtl: vmDtlInventory, NameDtl: NameDtlInventory });

    //空栈板
    var AreaNameDtlLocation = 'general';
    var TableNameDtlLocation = 'Location';
    //{子表字段:主表字段}
    var NameDtlLocation = {};
    var vmDtlLocation = new Vue({
        el: '#modifyFormDtl_' + TableNameDtlLocation
    });
    var vmqDtlLocation = new Vue({
        data: { Status: 'emptycontainer', Type: $('#Type').val()}
    });

    All.push({ AreaNameDtl: AreaNameDtlLocation, TableNameDtl: TableNameDtlLocation, vmqDtl: vmqDtlLocation, vmDtl: vmDtlLocation, NameDtl: NameDtlLocation });

    var vml = new Array({
        vmDtlLocation: vmDtlLocation,
        vmDtlInventory: vmDtlInventory
    });
    Universal.BindSelector($, form, vml, selector);

    var DtlShowbool = {};//所有折叠的当前状态
    var Dtl = {};//当前点击All数据
    var Value = {};//主表数据缓存数据
    //所有折叠状态初始化
    for (i = 0; i < All.length; i++) {
        DtlShowbool[All[i].TableNameDtl] = false;
    }
    //监听单元格点击
    table.on('tool(mainList)', function (obj) {
        var Dtlbtn = {};
        var mainListDtl;
        for (i = 0; i < All.length; i++) {
            if (obj.event === All[i].TableNameDtl) {
                Dtl = All[i];
            }
        }
        if (Dtl != {}) {
            //主表数据赋值
            Value = obj.data;
            for (i = 0; i < Object.keys(Dtl.NameDtl).length; i++) {
                //重载赋值(防止主子表字段名不一样)
                Dtl.vmqDtl.$data[Object.keys(Dtl.NameDtl)[i]] = obj.data[Dtl.NameDtl[Object.keys(Dtl.NameDtl)[i]]];
            }
            //重载方法
            mainListDtl = {
                mainListDtl: function (mainDtl) {
                    var url = "Load";
                    if (mainDtl.AreaNameDtl == "inventory") {
                        url = "FindInventory";
                    }
                    table.reload('mainListDtl' + mainDtl.TableNameDtl, {
                        url: "/" + mainDtl.AreaNameDtl + "/" + mainDtl.TableNameDtl + "/" + url
                        , where: mainDtl.vmqDtl.$data
                        , method: "post"
                    });
                }
            };

            var mainListDtlClear = {
                Clear: function () {
                    table.reload('mainListDtlLocation', {
                        url: "/general/Location/Load"
                        , where: { Status: "####" }
                        , method: "post"
                    });
                    table.reload('mainListDtlInventory', {
                        url: "/inventory/Inventory/FindInventory"
                        , where: { MaterialCode: "####" }
                        , method: "post"
                    });
                }
            };
            //监听折叠
            element.on('collapse(DisplayDtl)', function (data) {
                //记录当前折叠状态
                DtlShowbool[data.title[0].id.split('_')[1]] = data.show;
                //单元格事件
                table.on('tool(mainListDtl' + data.title[0].id.split('_')[1] + ')', function (obj) {
                    for (i = 0; i < All.length; i++) {
                        if (obj.event.split('_')[1] === All[i].TableNameDtl) {
                            Dtlbtn = All[i];
                        }
                    }
                    if (Dtlbtn != {}) {
                        switch (obj.event) {
                            case 'btnReceipt_Inventory':  //收货
                                layer.open({
                                    type: 1
                                    , title:"收货"
                                    , content: $('#Receipt')
                                    , btnAlign: 'c'
                                    , area: ['300px', '150px']
                                    , btn: ['收货', '取消']
                                    , success: function (index) {
                                        $('#Num').val(Value.Qty - Value.QtyDivided);
                                    }
                                    , yes: function (index, layero) {
                                        if ($('#Num').val() > (Value.Qty - Value.QtyDivided)) {
                                            layer.alert("失败:分配数量必须小于等于系统数量", { icon: 5, shadeClose: true, title: "错误信息" });
                                        } else {
                                            $.ajax({
                                                async: true,
                                                type: "post",
                                                data: { receiptdetail: Value, inv: obj.data, num: $('#Num').val() },
                                                url: "/receipt/ReceiptHeader/HandDivide_Inventory",
                                                dataType: "json",
                                                success: function (result) {
                                                    if (result.code == 200) {
                                                        layer.msg(result.msg, { icon: 6, shade: 0.4, time: 1000 });
                                                        mainList.mainList(vm);
                                                        RefreshStatus();
                                                        mainListDtlClear.Clear();
                                                        //for (i = 0; i < All.length; i++) {
                                                        //    mainListDtl.mainListDtl(All[i]);
                                                        //}
                                                    } else {
                                                        layer.alert("失败:" + result.msg, { icon: 5, shadeClose: true, title: "错误信息" });
                                                    }
                                                },
                                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                                                }
                                            });
                                        }
                                        layer.close(index);
                                    }
                                    , cancel: function (index) {
                                        layer.close(index);
                                    }
                                });
                                break;
                            case 'btnReceipt_Location':  //收货
                                layer.open({
                                    type: 1
                                    , title: "收货"
                                    , content: $('#Receipt')
                                    , btnAlign: 'c'
                                    , btn: ['收货', '取消']
                                    , success: function (index) {
                                        $('#Num').val(Value.Qty - Value.QtyDivided);
                                    }
                                    , yes: function (index, layero) {
                                        if ($('#Num').val() > (Value.Qty - Value.QtyDivided)) {
                                            layer.alert("失败:分配数量必须小于等于系统数量", { icon: 5, shadeClose: true, title: "错误信息" });
                                        } else {
                                            $.ajax({
                                                async: true,
                                                type: "post",
                                                data: { receiptdetail: Value, loc: obj.data, num: $('#Num').val() },
                                                url: "/receipt/ReceiptHeader/HandDivide_Location",
                                                dataType: "json",
                                                success: function (result) {
                                                    if (result.code == 200) {
                                                        layer.msg(result.msg, { icon: 6, shade: 0.4, time: 1000 });
                                                        mainList.mainList(vm);
                                                        RefreshStatus();
                                                        mainListDtlClear.Clear();
                                                        //for (i = 0; i < All.length; i++) {
                                                        //    mainListDtl.mainListDtl(All[i]);
                                                        //}
                                                    } else {
                                                        layer.alert("失败:" + result.msg, { icon: 5, shadeClose: true, title: "错误信息" });
                                                    }
                                                },
                                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                                                }
                                            });
                                        }
                                        layer.close(index);
                                    }
                                    , cancel: function (index) {
                                        layer.close(index);
                                    }
                                });
                                break;
                        }
                    }
                });
            });
            //显示折叠
            $('#DisplayDtl' + Dtl.TableNameDtl).show();
            for (i = 0; i < Object.keys(DtlShowbool).length; i++) {
                if (DtlShowbool[Object.keys(DtlShowbool)[i]] == true && Object.keys(DtlShowbool)[i] != DtlShowbool[Dtl.TableNameDtl]) {
                    //关闭其他折叠
                    $('#title_' + Object.keys(DtlShowbool)[i]).click();
                    DtlShowbool[Object.keys(DtlShowbool)[i]] = false;
                }
            }
            if (DtlShowbool[Dtl.TableNameDtl] == false) {
                //打开当前数据对应折叠
                $('#title_' + Dtl.TableNameDtl).click();
            }
            for (i = 0; i < All.length; i++) {
                for (x = 0; x < Object.keys(All[i].NameDtl).length; x++) {
                    //重载赋值(防止主子表字段名不一样)
                    All[i].vmqDtl.$data[Object.keys(All[i].NameDtl)[x]] = Value[All[i].NameDtl[Object.keys(All[i].NameDtl)[x]]];
                }
                mainListDtl.mainListDtl(All[i]);
            }
        }
    });

    if ($('#keyword').val() != '') {
        $('#searchDetail').click();
    }

    function RefreshStatus() {
        $.ajax({
            async: true,
            type: "post",
            data: { Code: $('#keyword').val() },
            url: "/receipt/ReceiptContainerHeader/GetReceiptStatus",
            dataType: "json",
            success: function (result) {
                if (result.count > 0) {
                    $("#TotalLines").html(result.data.TotalLines);
                    $("#TotalQty").html(result.data.TotalQty);
                    $("#TotalQtyDivided").html(result.data.TotalQtyDivided);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert(errorThrown, { icon: 2, title: '提示' });
            }
        });
    }
});