TBaseAgv.js 8.37 KB
layui.config({
    base: "/js/"
}).use(['form', 'I18nPage', 'element', 'vue', 'layer', 'laydate', 'jquery', 'table', 'hhweb', 'utils', 'Universal', 'formSelects'], 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,
        I18nPage = layui.I18nPage;

    var formSelects = layui.formSelects;

    var AreaName = 'acs';
    var TableName = 'TBaseAgv';

    var cols_arr = I18nPage.GetI18nTable(
        {
            TableNo: AreaName + "-" + TableName,
            TableName: TableName,
            Qel: "#qFields",
            Eel: "#eFields",
        }
    );

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

    var vmq = new Vue({
        el: '#panelSearch',
        data: {
        }
    });

    hhweb.Config = {
        'AgvHeart': vm,

        'qAgvHeart': vmq,
    };
    hhweb.InitUIClass();

    var mainList = {
        Render: function () {
            mainList.Table = table.render({
                elem: '#mainList'
                , url: "/" + AreaName + "/" + TableName + "/Load"
                , method: "post"
                , page: true //开启分页
                , cols: hhweb.ColumnSetting('mainList', cols_arr)
                , id: 'mainList'
                , limit: 20
                , limits: [20, 50, 100, 200, 500, 1000]
                , defaultToolbar: ['filter']
                , toolbar: '#toolbarTable'
                , height: 'full-1'
                , cellMinWidth: 80
                , size: 'sm'
                , done: function (res) { }
            });

            return mainList.Table;
        },
        Load: function () {
            if (mainList.Table == undefined) {
                mainList.Table = this.Render();
                return;
            }
            table.reload('mainList', {});
        }
    };

    //编辑
    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);

        hhweb.RenderSwitch({ vueEdit: { vm: vm, layfilter: 'eform' } });
        //放在此处,避免上面的form.val()会将多选框的内容覆盖
        InitSelects(vm.$data.AgvMap);
    };

    //监听switch控件
    form.on('switch(eform)', function (data) {
        vm.$data[this.name] = data.elem.checked;
    });
    form.on('switch(qform)', function (data) {
        vmq.$data[this.name] = data.elem.checked;
    });

    var selfbtn = {
        //自定义按钮
        ShutDown: function () {
            var checkStatus = table.checkStatus('mainList');
            var count = checkStatus.data.length;
            if (count !== 0) {
                $.ajax({
                    type: "POST",
                    url: "/acs/TBaseAgv/CloseAgv",
                    async: true,
                    data: { ids: checkStatus.data.map(function (e) { return e.Id; }) },
                    dataType: "json",
                    success: function (data) {
                        if (data.Status) {
                            layer.msg("指定AGV关机成功!");
                            mainList.Load();
                        } else {
                            layer.alert(data.Message)
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
                    }
                });
            }
            else
                layer.alert("请至少选择一条操作数据!", { icon: 5, shadeClose: true, title: "错误信息" });
        },
        ShutDownAll: function () {
            $.ajax({
                type: "POST",
                url: "/acs/TBaseAgv/CloseAgvAll",
                async: true,
                data: {},
                dataType: "json",
                success: function (data) {
                    if (data.Status) {
                        layer.msg("整体关机成功!");
                        mainList.Load();
                    } else {
                        layer.alert(data.Message)
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(errorThrown, { icon: 2, shadeClose: true, title: "错误信息" });
                }
            });
        },
        btnAddGroup: function () {
            layer.open({
                title: "AGV群组",
                type: 2,
                area: ['749px', '495px'],
                content: "/task/TAgvGroup/index",
                shadeClose: true,
                success: function (layero, index) {

                },
                end: function () {
                    Universal.BindSelector(vml, selector);
                }
            });
        },
        DomConfig: function (isAdd) {
            if (isAdd) {
                vm.$data.IsEnable = true;
                vm.$data.AgvMap = "";
                $("input:checkbox[name='IsEnable']").prop("checked", vm.$data.IsEnable);
                form.render();
                InitSelects(vm.$data.AgvMap);

                $("#modifyForm input[name='StrAgvNo']")[0].disabled = false;
            }
            else {
                $("#modifyForm input[name='StrAgvNo']")[0].disabled = true;
            }
        },
    };

    var selector = {
        'AgvGroup': {
            SelType: "FromUrl",
            SelFrom: "/task/TAgvGroup/load",
            SelModel: "AgvGroup",
            SelLabel: "AgvGroup",
            SelValue: "AgvGroup",
            Dom: [$("[name='AgvGroup']"), $("[name='qAgvGroup']")]
        },
        'IsEnable': {
            SelType: "FromDict",
            SelFrom: "sys_true_false",
            SelModel: "IsEnable",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='IsEnable']"), $("[name='qIsEnable']")]
        },
        'IsCarry': {
            SelType: "FromDict",
            SelFrom: "sys_true_false",
            SelModel: "IsCarry",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='IsCarry']"), $("[name='qIsCarry']")]
        },
    };

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

    Universal.BindSelector(vml, selector);
    Universal.mmain(AreaName, TableName, vm, vmq, EditInfo, selfbtn, mainList);

    var Maps = {};

    $.ajax({
        type: 'POST',
        url: '/map/Map/GetMaps',
        data: null,
        dataType: 'json',
        success: function (data) {
            $("[name='AgvMap']").html("");
            $("[name='AgvMap']").append("<option style='display: none'></option>");
            $.each(data.data, function (key, value) {
                var option1 = $("<option>").val(value.Id).text(value.Name);
                $("[name='AgvMap']").append(option1);

                Maps[value.Name] = value.Id;
            });
            form.render('select');

            InitSelects();
        }
    });

    function InitSelects(inits) {
        var init = [];
        if (inits !== undefined && inits !== null && inits !== "") {
            var init1 = inits.split(",");
            for (var i = 0; i < init1.length; i++) {
                init.push(Maps[init1[i]]);
            }
        }

        formSelects.selects({
            name: 'select',
            el: 'select[name=AgvMap]',
            filter: 'AgvMap',
            left: '',
            right: '',
            separator: ',',
            init: init,
            change: function (data, arr) {
                GetAgvMaps();
            },
        });
    }

    function GetAgvMaps() {
        var agvMaps = "";
        $.each(formSelects.array('select'), function (key, value) {
            if (agvMaps == "") {
                agvMaps = value.name;
            }
            else {
                agvMaps = agvMaps + "," + value.name;
            }
        });
        vm.$data.AgvMap = agvMaps;
        return agvMaps;
    }
});