ShipmentContainerHeader.js 16.3 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 = 'shipment';
    var TableName = 'ShipmentDetail';

    var vm = new Vue({
        data: { ShipmentCode: 'ShipmentCode' }
    });

    var vmq = new Vue({
    });
    //Universal.BindSelector($, form, vm, vmq);
    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 + "/LoadForDivide"
                , where: svm.$data
                , method: "post"
                , text: { none: this.NoData() }
            });
        }
    };

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

                if (str != "") {
                    vm.$set('ShipmentCode', str);
                    mainList.mainList(vm);
                    $('#keyword').val(str)

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

                keylisten();
                break;
        }
    });

    //回车监听
    $('#keyword').on('keypress', function (event) {
        if (event.keyCode == 13) {
            var str = $('#keyword').val();
            vm.$set('ShipmentCode', str);
            mainList.mainList(vm);
            $('#keyword').val(str)
        }
    });

    function keylisten() {
        $('#keyword').bind("keydown", function (e) {
            if (e.which == 13) {
                $('#searchDetail').click();
                RefreshStatus();
            }
        });
    } 
    keylisten();
    var selector = {
        'InventoryStatus': {
            SelType: "FromDict",
            SelFrom: "inventoryStatus",
            SelModel: "InventoryStatus"
        },
        'Status': {
            SelType: "FromDict",
            SelFrom: "shipmentContainerHeaderStatus",
            SelModel: "Status"
        },
        'WarehouseType': {
            SelType: "FromDict",
            SelFrom: "warehouseType",
            SelModel: "WarehouseType"
        },
        'IStatus': {
            SelType: "FromDict",
            SelFrom: "inventoryStatus",
            SelModel: "IStatus"
        },
        'ContainerStatus': {
            SelType: "FromDict",
            SelFrom: "containerStatus",
            SelModel: "ContainerStatus"
        }
    };

    //相同物料仓位
    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: ''}
    });

    var vml = new Array({
        vmDtlInventory: vmDtlInventory
    });
    Universal.BindSelector($, form, vml, selector);
    All.push({ AreaNameDtl: AreaNameDtlInventory, TableNameDtl: TableNameDtlInventory, vmqDtl: vmqDtlInventory, vmDtl: vmDtlInventory, NameDtl: NameDtlInventory });


    var selfbtn = {};

    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;
        if (obj.data.QtyDivided == '' || obj.data.QtyDivided == null) {
            obj.data.QtyDivided = 0;
        }

        $("input[name='DDqty']").val(obj.data.Qty);
        $("input[name='DqtyDivided']").val(obj.data.QtyDivided);
        $("input[name='DqtyDivide']").val(obj.data.Qty - obj.data.QtyDivided);

        var id = obj.data.Id;
        var dqty = obj.data.Qty;
        var ydqty = obj.data.QtyDivided;
        var sdqty = obj.data.Qty - obj.data.QtyDivided;
        var shipdetail = obj.data;
        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 = {
                NoData: function () {
                    return "<div id='backgroundDtl'" + Dtl.TableNameDtl + " style='width:100%;height:100%;background-image:url(../../images/NoData.png);background-repeat:no-repeat;background-size:cover;'>.</div>"
                },
                mainListDtl: function (mainDtl) {
                    table.reload('mainListDtl' + mainDtl.TableNameDtl, {
                        url: "/" + mainDtl.AreaNameDtl + "/" + mainDtl.TableNameDtl + "/Load"
                        , where: mainDtl.vmqDtl.$data
                        , method: "post"
                        , text: { none: this.NoData() }
                    });
                }
            };
            //监听折叠
            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 'btnShipment_' + Dtlbtn.TableNameDtl:  //分配
                                //layer.alert(JSON.stringify(obj.data) + ' Id:' + Value.Id, {
                                //    title: '当前行数据:'
                                //});
                                $("input[name='DqtyDivide']").focus();


                                //读取托盘在库存中数量(除去已经被其它单据分的后的托盘库存数量)
                                $.ajax({
                                    url: "/shipment/ShipmentContainerHeader/GetContainerQty",
                                    type: "post",
                                    data: { invt: obj.data },
                                    dataType: "json",
                                    success: function (result) {
                                        if (result.code == 200) {

                                            if (result.data.yqty > 0) {
                                                $("input[name='DIqty']").val(result.data.yqty);
                                                if ($("input[name='DqtyDivide']").val() > result.data.yqty) {
                                                    $("input[name='DqtyDivide']").val(result.data.yqty);
                                                }

                                                layer.open({
                                                    type: 1,
                                                    // skin: 'layui-layer-lan',
                                                    btnAlign: 'c',
                                                    title: "出库分配确认",
                                                    area: ['670px', '260px'],
                                                    content: $('#divideForm'),
                                                    btn: ['确定', '取消'],
                                                    yes: function (index) {
                                                        if ($("input[name='DqtyDivide']").val() <= sdqty && $("input[name='DqtyDivide']").val() <= result.data.yqty ) {

                                                            //分配数据写入任务表
                                                            $.ajax({
                                                                url: "/shipment/ShipmentContainerHeader/DivideContainer",
                                                                type: "post",
                                                                data: { shipmentdt: shipdetail, invt: obj.data, dvqty: $("input[name='DqtyDivide']").val() },
                                                                dataType: "json",
                                                                success: function (result) {
                                                                    if (result.code == 200) {
                                                                        //  $('.layui-collapse').hide();
                                                                        mainList.mainList(vm);
                                                                        var url = "/" + AreaName + "/" + TableName + "/Load";
                                                                        var urlData = { 'Id': id };
                                                                        $.post(url, urlData, function (result) {
                                                                            $("input[name='DqtyDivided']").val(result.data[0].QtyDivided);
                                                                            $("input[name='DqtyDivide']").val(dqty - result.data[0].QtyDivided);
                                                                            shipdetail = result.data[0];
                                                                            if (result.data[0].QtyDivided == dqty) {
                                                                                table.reload('mainListDtlInventory', {
                                                                                    url: '/inventory/Inventory/Load'
                                                                                    , where: { 'MaterialCode': 'no' }
                                                                                    , method: "post"
                                                                                    , text: { none: "此物料已全部分配完成,请分配其它项此的物料!" }
                                                                                });
                                                                            };

                                                                        }, "json");
                                                                        RefreshStatus();
                                                                        layer.msg(result.msg, { icon: 7, shade: 0.4, time: 1000 });
                                                                        layer.close(index);
                                                                    } else {
                                                                        layer.msg('分配失败:' + result.msg, { icon: 7, shade: 0.4, time: 2000 });
                                                                    }
                                                                },
                                                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                                                                    $("input[name='DqtyDivide']").focus();
                                                                }
                                                            })

                                                        } else {
                                                            layer.msg('超出可分配数量,请重新分配!', { icon: 7, shade: 0.4, time: 2000 });
                                                        }

                                                        //table.reload('mainList', {
                                                        //    url: '/shipment/ShipmentContainerHeader/Load'
                                                        //    , where: { shipNo: $("input[name='SourceCode']").val() }
                                                        //    , text: { none: "未查找到匹配的数据,请确认输入数据是否有误!" }
                                                        //});

                                                    },
                                                    cancel: function (index) {
                                                        layer.close(index);
                                                    }
                                                });

                                            } else {
                                                layer.msg('此托盘的此物料已被全部分配完成,没有可被再分配的数量!', { icon: 7, shade: 0.4, time: 2000 });
                                            }




                                        } else {
                                            layer.msg('请求返回失败:' + result.msg, { icon: 7, shade: 0.4, time: 2000 });
                                        }
                                    },
                                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                                        layer.alert(errorThrown, { icon: 2, title: '提示' });
                                    }
                                })

                                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') != '') {
        $('#searchDetail').click();
    }

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

});