Task.js 14.2 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,
        hhweb = layui.hhweb,
        Universal = layui.Universal;
    
    var AreaName = 'task';
    var TableName = 'Task';
    
    var vm = new Vue({
        el: '#modifyForm'
    });
    
    var vmq = new Vue({
        el: '#panelSearch',
        data: {
        }
    });
 
    //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 () {
    //        table.reload('mainList', {
    //            url: "/" + AreaName + "/" + TableName + "/Load"
    //            , method: "post"
    //            , text: { none: this.NoData() }
    //        });
    //    }
    //};

    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 = {
        //删除任务
        DelTask: function () {
            var checkStatus = table.checkStatus('mainList');
            var count = checkStatus.data.length;//选中的行数
            var data1 = checkStatus.data;
            var Isout;
            if (count != 1) {
                layer.alert("请选择一条数据", { icon: 5, shade: 0.4 });
                return;
            }
            console.log(data1[0].Id);
            layer.open({
                title: '删除任务'
                , content: '是否删除'
                , btn: ['库内', '库外']
                , yes: function (index, layero) {
                    Isout = 0;//库内
                    layer.close(index);
                    $.ajax({
                        async: false,
                        url: "/" + "task" + "/" + "Task" + "/DelTask",
                        type: "post",
                        data: {
                            Id: data1[0].Id,
                            Isout: Isout,
                        },
                        dataType: "json",
                        success: function (result) {
                            if (result.code == 200) {
                                layer.msg('任务删除成功', { icon: 6, shade: 0.4, time: 1000 });
                                mainList.mainList();
                            }
                            else {
                                layer.alert("失败:" + result.msg, { icon: 2, title: '提示' });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(errorThrown, { icon: 2, title: '提示' });
                        }
                    });
                }
                , btn2: function (index, layero) {
                    Isout = 1;//库外
                    layer.close(index);
                    $.ajax({
                        async: false,
                        url: "/" + "task" + "/" + "Task" + "/DelTask",
                        type: "post",
                        data: {
                            Id: data1[0].Id,
                            Isout: Isout,
                        },
                        dataType: "json",
                        success: function (result) {
                            if (result.code == 200) {
                                layer.msg('任务删除成功', { icon: 6, shade: 0.4, time: 1000 });
                                mainList.mainList();
                            }
                            else {
                                layer.alert("失败:" + result.msg, { icon: 2, title: '提示' });
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(errorThrown, { icon: 2, title: '提示' });
                        }
                    });
                }
            });
        },
        //空托盘入库
        PalletIn: function () {
            layer.open({
                title: '空托盘入库',
                area: ["750px", "450px"],
                type: 1,
                content: $('#PalletInForm'),
                btn: ['提交', '关闭'],
                yes: function (index) {
                    layer.msg('空托盘入库任务创建成功', { icon: 6, shade: 0.4, time: 1000 });
                    mainList.mainList();
                },
                btn2: function (index) {
                    layer.close(index);
                    mainList.mainList();
                }
            });
        },
        PalletOut: function () {
            layer.open({
                title: '空托盘出库',
                area: ["750px", "450px"],
                type: 1,
                content: $('#PalletOutForm'),
                btn: ['提交', '关闭'],
                yes: function (index) {
                    layer.msg('空托盘出库任务创建成功', { icon: 6, shade: 0.4, time: 1000 });
                    mainList.mainList();
                },
                btn2: function (index) {
                    layer.close(index);
                    mainList.mainList();
                }
            });
        },
        TaskFinish: function () {
            var checkStatus = table.checkStatus('mainList');
            var count = checkStatus.data.length;//选中的行数
            if (count > 0) {
                layer.confirm('确定要执行所选任务', { icon: 3 }, function (index) {
                    layer.msg('执行成功', { icon: 6, shade: 0.4, time: 1000 });
                });
            }
            else
                layer.alert("请至少选择一条数据", { icon: 5, shadeClose: true, title: "错误信息" });

        },
        TaskCancel: function () {
            var checkStatus = table.checkStatus('mainList');
            var count = checkStatus.data.length;//选中的行数
            var data = checkStatus.data;
            if (count > 0) {
                layer.confirm('确定要取消所选任务', { icon: 3 }, function (index) {
                    //取消所选任务
                    $.ajax({
                        url: "/task/Task/TaskCancel",
                        type: "post",
                        data: { tasklist: data },
                        dataType: "json",
                        // async: false,
                        success: function (result) {
                            if (result.code = 200) {
                                mainList.mainList(vm);
                                layer.msg(result.msg, { icon: 1, shade: 0.4, time: 2000 });
                            } else {
                                layer.msg('任务取消失败:' + result.msg, { icon: 7, shade: 0.4, time: 3000 });
                            }
                        },
                        error: function (error) {
                            layer.alert(error.responseText, { icon: 2, title: '提示' });
                        }
                    })

                }, function () {
                    layer.close();
                });
            }
            else
                layer.alert("请至少选择一条数据", { icon: 5, shadeClose: true, title: "错误信息" });
        },
        DomConfig: function (AddOrUpdate) {
            if (AddOrUpdate) {
                hhweb.DomEnable($("#modifyForm [name='OrderCode']"));
                hhweb.DomEnable($("#modifyForm [name='FirstStatus']"));
                hhweb.DomEnable($("#modifyForm [name='LastStatus']"));
            }
            else {
                hhweb.DomDisable($("#modifyForm [name='OrderCode']"));
                hhweb.DomDisable($("#modifyForm [name='FirstStatus']"));
                hhweb.DomDisable($("#modifyForm [name='LastStatus']"));
            }
        },
        SaveBefore: function (AddOrEditOrDelete) {
            if (AddOrEditOrDelete in { Add: null, Edit: null }) {
                var rtn = hhweb.CheckRequired("#modifyForm", AddOrEditOrDelete);
                return rtn;
            }
        },
        DomConfig_TaskDetail: function (AddOrUpdate) {
            if (AddOrUpdate) {
                hhweb.DomDisableImportant($("#modifyFormDtl_TaskDetail [name='TaskNo']"));
                hhweb.DomDisableImportant($("#modifyFormDtl_TaskDetail [name='OrderCode']"));
                hhweb.DomEnable($("#modifyFormDtl_TaskDetail [name='OderQty']"));
            }
            else {
                hhweb.DomDisableImportant($("#modifyFormDtl_TaskDetail [name='TaskNo']"));
                hhweb.DomDisableImportant($("#modifyFormDtl_TaskDetail [name='OrderCode']"));
                hhweb.DomDisable($("#modifyFormDtl_TaskDetail [name='OderQty']"));
            }
        },
        SaveBefore_TaskDetail: function (AddOrEditOrDelete) {
            if (AddOrEditOrDelete in { Add: null, Edit: null }) {
                var rtn = hhweb.CheckRequired("#modifyFormDtl_TaskDetail", AddOrEditOrDelete);
                return rtn;
            }
        }
    };

    var selector = {
        'BusinessType': {
            SelType: "FromDict",
            SelFrom: "businessType",
            SelModel: "BusinessType",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='BusinessType']"), $("[name='qBusinessType']")]
        },
        'FirstStatus': {
            SelType: "FromDict",
            SelFrom: "taskStatus",
            SelModel: "FirstStatus",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='FirstStatus']"), $("[name='qFirstStatus']")]
        },
        'LastStatus': {
            SelType: "FromDict",
            SelFrom: "taskStatus",
            SelModel: "LastStatus",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='LastStatus']"), $("[name='qLastStatus']")]
        },
        'Status': {
            SelType: "FromDict",
            SelFrom: "taskStatus",
            SelModel: "Status",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='Status']")]
        },
        'TaskType': {
            SelType: "FromDict",
            SelFrom: "taskType",
            SelModel: "TaskType",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='TaskType']")]
        },
        'Station': {
            SelType: "FromUrl",
            SelFrom: "/general/Station/Load",
            SelModel: "Station",
            SelLabel: "Name",
            SelValue: "Code",
            Dom: [$("[name='Station']"), $("[name='qStation']")]
        },
        'SourceLocation': {
            SelType: "FromUrl",
            SelFrom: "/general/Station/Load",
            SelModel: "SourceLocation",
            SelLabel: "Name",
            SelValue: "Code",
            Dom: [$("[name='SourceLocation']"), $("[name='qSourceLocation']")]
        },
        'DestinationLocation': {
            SelType: "FromUrl",
            SelFrom: "/general/Station/Load",
            SelModel: "DestinationLocation",
            SelLabel: "Name",
            SelValue: "Code",
            Dom: [$("[name='DestinationLocation']"), $("[name='qDestinationLocation']")]
        },
    };

    //子表逻辑
    var All = new Array();
    var AreaNameDtlTaskDetail = 'task';
    var TableNameDtlTaskDetail = 'TaskDetail';
    //{子表字段:主表字段}
    var NameDtlTaskDetail = { TaskNo: 'TaskNo', OrderCode: 'OrderCode' };
    var vmDtlTaskDetail = new Vue({
        el: '#modifyFormDtl_' + TableNameDtlTaskDetail
    });
    var vmqDtlTaskDetail = new Vue({
        data: { TaskNo: '', OrderCode: '' }
    });
    //编辑
    var EditInfoDtlTaskDetail = function (tabledata) {
        data = tabledata;
        vmDtlTaskDetail.$set('$data', tabledata);
        var list = {};
        $('.ClearSelector_' + TableNameDtlTaskDetail).each(function () {
            var selDom = ($(this));
            if ($(selDom)[0].name.search("q") == -1) {
                list[$(selDom)[0].name] = data[$(selDom)[0].name] + "";
            }
        });
        //表单修改时填充需修改的数据
        form.val('modifyFormDtl_' + TableNameDtlTaskDetail, list);
    };


    var vml = new Array({
        vm: vm,
        vmq: vmq,
        vmDtlTaskDetail: vmDtlTaskDetail
    });
    
    Universal.BindSelector($, form, vml, selector);
    Universal.mmain(AreaName, TableName, table, layer, element, laydate, $, vm, vmq, EditInfo, selfbtn, mainList, form);
    All.push({ AreaNameDtl: AreaNameDtlTaskDetail, TableNameDtl: TableNameDtlTaskDetail, vmqDtl: vmqDtlTaskDetail, vmDtl: vmDtlTaskDetail, EditInfoDtl: EditInfoDtlTaskDetail, NameDtl: NameDtlTaskDetail });
    Universal.mainDtl(table, layer, element, $, selfbtn, All, form);
});