CyclecountHeader.js 13.5 KB
layui.config({
    base: "/js/"
}).use(['form', 'element', 'vue', 'layer', 'laydate', 'jquery', 'table', 'hhweb', 'utils', 'Universal'], function () {
    var DtlShowbool = {};//所有折叠的当前状态
    var Dtl = {};//当前点击All数据
    var Value = {};//主表数据缓存数据
    var Values = new Array();//主表数据缓存数据集合
    var All = new Array();
    var form = layui.form,
        layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        $ = layui.jquery,
        table = layui.table,
        hhweb = layui.hhweb,
        Universal = layui.Universal;

    var AreaName = 'inventory';
    var TableName = 'CyclecountHeader';

    var vm = new Vue({
        el: '#modifyForm'
    });

    var vmq = new Vue({
        el: '#panelSearch',
        data: {
        }
    });
    //明细弹窗
    var vmDtlq = new Vue({
        el: '#Detail_Q',
        data: {
        }
    });
    var mainList = {
        NoData: function () {
            return "<div id='background' style='width:100%;height:100%;background-image:url(../../imagesData.png);background-repeat:no-repeat;background-size:cover;'>.</div>"
        },

        mainList: function () {
            table.reload('mainList', {
                url: "/" + AreaName + "/" + TableName + "/Load"
                , method: "post"
                , text: { none: this.NoData() }
                , done: function (res, curr, count) {
                    if (curr > 1 && res.data.length == 0) {
                        table.reload('mainList', {
                            page: { curr: 1 }// 修改页码
                            , text: { none: mainList.NoData() }
                        });
                    }
                }
            });
        }
    };

    //编辑
    var EditInfo = function (tabledata) {
        data = tabledata;
        vm.$set('$data', data);
        //表单修改时填充需修改的数据
        var list = {};
        $('.ClearSelector_' + TableName).each(function () {
            var selDom = ($(this));
            if ($(selDom)[0].name.search("q") == -1) {
                list[$(selDom)[0].name] = data[$(selDom)[0].name] + "";
            }
        });
        //表单修改时填充需修改的数据
        form.val('modifyForm', list);
    };

    var selfbtn = {
        //自定义按钮
        DtlHeader: function (){
                var checkStatus = table.checkStatus('mainList');
                var count = checkStatus.data.length;
            if (count > 0) {
                layer.confirm('确定要删除所选信息', { icon: 3 }, function (index) {
                    var data = checkStatus.data; //获取选中行的数据
                    $.ajax({
                        url: "/inventory/CyclecountHeader/DelHeader",
                        type: "post",
                        data: { CyclecountHeaders: data },
                        dataType: "json",
                        success: function (result) {
                            console.log(result)
                            if (result.code == 200) {
                                layer.msg('删除成功', { icon: 6, shade: 0.4, time: 1000 });
                                layer.close(index);
                                mainList.mainList();//重载TABLE
                                $('.layui-collapse').hide();
                            }
                            else {
                                layer.msg(result.msg, { icon: 5, shade: 0.4, time: 1000 });
                            }
                        }
                    });
                });
            } else {
                layer.msg("请选择一条数据", { icon: 5, shade: 0.4, time: 1000 });
            }
                
        },
        DtlAdd: function () {
            var checkStatus = table.checkStatus('mainList');
            var count = checkStatus.data.length;//选中的行数
            if (count != 1) {
                layer.msg("请选择一条数据", { icon: 5, shade: 0.4, time: 1000 });
                return;
            }
            var data = checkStatus.data;

            layer.open({
                title: '添加明细',
                area: ["950px", "700px"],
                type: 1,
                content: $('#linventory'),
                end: function () {
                    document.getElementById("FormAddDetail").reset();
                }
            });
        },
        DomConfig: function (AddOrUpdate) {
            if (AddOrUpdate) {
                hhweb.DomEnable($("#modifyForm [name='Code']"));
                hhweb.DomEnable($("#modifyForm [name='Type']"));
                hhweb.DomDisableImportant($("#modifyForm [name='Status']"));
            }
            else {
                hhweb.DomDisable($("#modifyForm [name='Code']"));
                hhweb.DomEnable($("#modifyForm [name='Type']"));
                hhweb.DomDisableImportant($("#modifyForm [name='Status']"));
                hhweb.DomDisableImportant($("#modifyForm [name='Code']"));
            }
        },
        SaveBefore: function (AddOrEditOrDelete) {
            if (AddOrEditOrDelete in { Add: null, Edit: null }) {
                var rtn = hhweb.CheckRequired("#modifyForm", AddOrEditOrDelete);
                return rtn;
            }
        }
    };
    var selector = {
        'Type': {
            SelType: "FromDict",
            SelFrom: "cyclecountType",
            SelModel: "Type",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='Type']"), $("[name='qType']")]
        },
        'InventoryStatus': {
            SelType: "FromDict",
            SelFrom: "inventoryStatus",
            SelModel: "InventoryStatus",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='InventoryStatus']")]
        },
        'Status': {
            SelType: "FromDict",
            SelFrom: "receiptHeaderStatus",
            SelModel: "Status",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='Status']"), $("[name='qStatus']")]
        },
        'Statuss': {
            SelType: "FromDict",
            SelFrom: "inventoryStatus",
            SelModel: "Statuss",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='Status']"), $("[name='qStatus']")]
        },
        'ContainerStatus': {
            SelType: "FromDict",
            SelFrom: "containerStatus",
            SelModel: "ContainerStatus",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='ContainerStatus']"), $("[name='qContainerStatus']")]
        }
       
    };

    //子表逻辑
    var AreaNameDtlCyclecountDetail = 'inventory';
    var TableNameDtlCyclecountDetail = 'CyclecountDetail';
    //{子表字段:主表字段}
    var NameDtlCyclecountDetail = { HeadId: 'Id' };
    //var vmDtlCyclecountDetail = new Vue({
    //    el: '#modifyFormDtl_' + TableNameDtlCyclecountDetail
    //});
    var vmqDtlCyclecountDetail = new Vue({
        data: { HeadId: '' }
    });
    //编辑
    var EditInfoDtlCyclecountDetail = function (tabledata) {
        data = tabledata;
        vmDtlCyclecountDetail.$set('$data', tabledata);
        var list = {};
        $('.ClearSelector_' + TableNameDtlCyclecountDetail).each(function () {
            var selDom = $(this);
            if ($(selDom)[0].name.search("q") == -1) {
                list[$(selDom)[0].name] = data[$(selDom)[0].name] + "";
            }
        });
        //表单修改时填充需修改的数据
        form.val('modifyFormDtl_' + TableNameDtlCyclecountDetail, list);
    };
    //盘点明细表
    var mainListDtl = {
        mainListDtl: function (Id) {
            table.reload('mainListDtl' + TableNameDtlCyclecountDetail, {
                url: "/" + AreaNameDtlCyclecountDetail + "/" + TableNameDtlCyclecountDetail + "/Load"
                , where: { HeadId: Id }
                , method: "post"
                , page: { curr: 1 }
            });
        }
    };
    //库存表
    var mainListInv = {
        mainList: function () {
            table.reload('mainListDtlinventory', {
                url: "/inventory/Inventory/CheckLoad"
                , method: "post"
                , page: { curr: 1 }
            });
        }
    };

    var vml = new Array({
        vm: vm,
        vmq: vmq
    });

    Universal.BindSelector($, form, vml, selector);
    Universal.mmain(AreaName, TableName, table, layer, element, laydate, $, vm, vmq, EditInfo, selfbtn, mainList, form);
    All.push({ AreaNameDtl: AreaNameDtlCyclecountDetail, TableNameDtl: TableNameDtlCyclecountDetail, vmqDtl: vmqDtlCyclecountDetail, EditInfoDtl: EditInfoDtlCyclecountDetail, NameDtl: NameDtlCyclecountDetail });
    Universal.mainDtl(table, layer, element, $, selfbtn, All, form);

    //监听字表弹框中的Table点击
    //批量添加
    table.on('toolbar(mainListDtlinventory)', function (obj) {
        var checkStatusMain = table.checkStatus('mainList');
        var maindata = checkStatusMain.data;

        var checkStatusDtl = table.checkStatus('mainListDtlinventory');
        var data = checkStatusDtl.data;

        var DetailData = new Array();
        for (let i = 0; i < data.length; i++) {
            DetailData[i] = {};
            DetailData[i].headId = maindata[0].Id;
            DetailData[i].code = maindata[0].Code;
            DetailData[i].inventoryId = data[i].Id;
            DetailData[i].locationCode = data[i].LocationCode;
            DetailData[i].MaterialCode = data[i].MaterialCode;
            DetailData[i].MaterialId = data[i].MaterialId;
            DetailData[i].ContainerCode = data[i].ContainerCode;
            DetailData[i].countedQty = 1;
            DetailData[i].gapQty = 0;
            DetailData[i].status = 0;
            DetailData[i].inventoryStatus = data[i].Status;
        }
        
        var layEvent = obj.event;

        if (layEvent === 'batchAdd') {
            if (data.length == 0) {
                layer.msg('至少选择一条数据', { icon: 2, shade: 0.4, time: 1000 });
            }
            else
            $.ajax({
                url: "/" + AreaNameDtlCyclecountDetail + "/" + TableNameDtlCyclecountDetail + "/BatchInsert",
                type: "post",
                data: { Table_Entitys: DetailData },
                dataType: "json",
                success: function (result) {
                    if (result.Status) {
                        mainListInv.mainList();
                        mainListDtl.mainListDtl(maindata[0].Id);//重载TABLE
                        layer.msg('新增成功', { icon: 6, shade: 0.4, time: 1000 });
                    }
                    else {
                        layer.alert("新增失败:" + result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                }
            });
        }
    });
    //单个添加
    table.on('tool(mainListDtlinventory)', function (obj) {
        $(obj.tr[1]).click();

        var checkStatusMain = table.checkStatus('mainList');
        var maindata = checkStatusMain.data;

        var checkStatusDtl = table.checkStatus('mainListDtlinventory');
        var data = checkStatusDtl.data;

        //添加到盘点明细表的数据
        var DetailData = {};
        DetailData.headId = maindata[0].Id;
        DetailData.code = maindata[0].Code;
        DetailData.inventoryId = data[0].Id;
        DetailData.locationCode = data[0].LocationCode;
        DetailData.MaterialCode = data[0].MaterialCode;
        DetailData.MaterialId = data[0].MaterialId;
        DetailData.ContainerCode = data[0].ContainerCode;
        DetailData.countedQty = 1;
        DetailData.gapQty = 0;
        DetailData.status = 0;
        DetailData.inventoryStatus = data[0].Status;

        var layEvent = obj.event;

        if (layEvent === 'AddDtl') {
            //新增明细
            $.ajax({
                url: "/" + AreaNameDtlCyclecountDetail + "/" + TableNameDtlCyclecountDetail + "/Insert",
                type: "post",
                data: { Table_Entity: DetailData },
                dataType: "json",
                success: function (result) {
                    if (result.Status) {
                        layer.msg('新增成功', { icon: 6, shade: 0.4, time: 1000 });
                        mainListInv.mainList();
                        mainListDtl.mainListDtl(maindata[0].Id);//重载TABLE
                    }
                    else {
                        layer.alert("新增失败:" + result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                }
            });
        }
    });

    //子表弹窗条件查询                                
    var active = {
        //检索区的查询按钮
        DtlQuery: function () {
            table.reload('mainListDtlinventory', {
                page: true
                , url: "/inventory/Inventory/CheckLoad"
                , method: "POST"
                , where: vmDtlq.$data
                , text: { none: mainList.NoData() }
            });

        }
    };

    $('#Detail_q').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
});