BaseTeam.js 12.3 KB
let action = null;
layui.config({
    base: "/js/",
    version: 1
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sysU = new system.u(),
        sendData = null,
        areaName = "Configure",
        controllerName = "BaseTeam",
        app = null,
        completState = 90;

    action = {
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Ins`,
                submit: "submit(fromAdd)"
            }
            return options;
        },

        editOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Upd`,
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/DelByIds`,
                keyId: "id"
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${controllerName}/Export`,
                isDefault: false,
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                }
            }
            return options;
        },

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${controllerName}/Export`,
                urlQuery: `/${areaName}/${controllerName}/Load`,
                mainTable: app.data.tableIns
            }
            return options;
        },

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },

        editBefore: function (data, callBack) {
            form.val("modifyForm", data);
            if (callBack != null) callBack();
        },
        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },
        addSaveBefore: function (data, callBack) {
            debugger
            if (callBack != null) callBack();
        },
        //当前行表格双击事件处理
        rowClickOptions: function () {
            debugger
            var options = {
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            /*            layer.msg('hello' + app.data.tableIns.lineCode);*/
            return options;
        },

        customTableRowClick: function (obj, tableId) {
            debugger
            if (tableId == app.data.tableElem) {
                rowData = obj.data;
            }
        },

        //工作中心班组关联表新增删除
        checkboxMethod: function (obj) {
            var workCenter = "".GetUrlParam("page"),
                workCenterCode = "".GetUrlParam("workCenterCode"),
                workKey = "".GetUrlParam("workKey");
            if (workCenter == "Workcenter") {
                var checkBoxData = {
                    teamCode: null,
                    workCenterCode: workCenterCode,
                    checkeds: obj.checked,
                    workKey: workKey
                };
                if (obj.type == "all") {
                    checkBoxData.teamCode = sysU.getTableAllData(app.data.tableElem).GetArrValue("teamCode");
                } else {
                    checkBoxData.teamCode = obj.data.teamCode;
                }
                if (checkBoxData.teamCode == null || checkBoxData.teamCode == "") {
                    layer.alert("checkboxMethod:班组标识【teamCode】为空,请重新关闭后再操作,反复出现请联系管理员", { icon: 2, shadeClose: true, title: "提示" });
                    return false;
                }
                if (checkBoxData.workKey == null) {
                    layer.alert("checkboxMethod:工序标识Id为空,请重新关闭后再操作,反复出现请联系管理员", { icon: 2, shadeClose: true, title: "提示" });
                    return false;
                }
                var ajaxConfig = {
                    data: checkBoxData,
                    url: `/configure/Workcenter/OperateWorkCenterTeam`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return false;
                        layer.msg(result.Message);
                    }
                };
                sysU.ajax(ajaxConfig);
            }

        },

        //分配用户 
        btnStepUser: function (sysU, toolbarId, obj) {
            var checkStatus = table.checkStatus(toolbarId),
                data = checkStatus.data;
            console.log(data);
            if (data.length !== 1) {
                layer.msg("请选择一条要分配的班组");
                return false;
            }
            var ajaxConfig = {
                url: `/${areaName}/${controllerName}/GetTeamCodeUserById?teamCode=` + data[0].teamCode,
                type: "get",
                success: function (result) {
                    debugger
                    if (sysU.successBefore(result)) return;
                    layer.open({
                        title: "为班组【" + data[0].teamName + "】分配人员",
                        type: 2,
                        area: ['1000px', '600px'],
                        content: "/base/SysUser/Index?menuFlag=-2&page=baseTeamUserRel&targetArrValue=" + result.Result.GetArrValue("userId") + "&teamCode=" + data[0].teamCode,

                        cancel: function () {
                            action.actionSuccess("", app.data.tableIns.config.page.index);
                        }
                    });
                }
            };
            sysU.ajax(ajaxConfig);
        },

        //所有动作成功之后
        actionSuccess: (falg) => {
            sysU.refreshTable(app, sysU, null, falg);
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80, hide: true, title: "Id" },
                { field: "keys", width: 80, hide: true, title: "Keys" },
                {
                    field: "teamCode", width: 150, event: 'pageOpen', title: "班组编码", templet: function (d) {
                        return `<a data-type="pageOpen" href="#" data-title="班组名称:${d.teamName} " data-href="/base/SysUser/UserList?menuFlag=-2&teamCode=${d.teamCode}" style="color: cornflowerblue;text-decoration: underline;cursor:pointer">${d.teamCode}</a>`;
                    }
                },


                { field: "otherCode", width: 150, title: "外部编码" },
                { field: "teamName", width: 150, title: "班组名称" },
                { field: "remark", width: 150, title: "备注" },
                { field: "extend1", width: 150, title: "预留字段" },
                { field: "extend2", width: 150, title: "预留字段" },
                { field: "extend3", width: 150, title: "预留字段" },
                { field: "createBy", width: 150, title: "创建者" },
                { field: "createTime", width: 150, title: "创建时间" },
                { field: "updateBy", width: 150, title: "更新者" },
                { field: "updateTime", width: 150, title: "更新时间" },
            ]],
            colsDesc: [[
                //{ checkbox: true, fixed: true },                
                { field: 'teamCode', width: 150, title: '班组编码' },
                { field: 'userId', width: 150, title: '用户标识' },
                { field: 'userName', width: 150, title: '用户名称' },
            ]],
            urlTable: `/${areaName}/${controllerName}/Load`,
            tableIns: null,
            tableInsDesc: null,
            tableElem: "mainList",
            tableElemDesc: "mainListDesc",
            //下拉框配置
            selectOption: {
                //station: {
                //    SelType: "FromUrl",
                //    SelFrom: `/${areaName}/${controllerName}/StationLineSelect`,
                //    SelLabel: "workStationName",
                //    SelValue: "workStationCode",
                //    OptGroup: true,
                //    Dom: [$("[name='stationCode']")]
                //},
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            initTable: function () {
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${controllerName}/Load`,
                    cols: sysU.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: '#toolbarTable',
                    doneExtend: function (res, obj) {
                        debugger;
                        //班组的实时刷新选中
                        var pageFalg = "".GetUrlParam("page"),
                            workCenterCode = "".GetUrlParam("workCenterCode");
                        if (pageFalg == "Workcenter") {
                            let ajaxConfig = {
                                data: { workCenterCode: workCenterCode },
                                url: `/configure/Workcenter/GetWorkCenterTeamCode`,
                                success: function (result) {
                                    if (sysU.successBefore(result)) return false;
                                    var targetArrValue = result.Result.map(function (e) { return e.teamCode; });
                                    var selectColKey = "".GetUrlParam("selectColKeyCustom");
                                    sysU.SetTableCheck(targetArrValue, res, selectColKey, app.data.tableElem);
                                }
                            };
                            sysU.ajax(ajaxConfig);
                        }
                        if (pageFalg == "base_station_team_rel") {
                            let ajaxConfig = {
                                data: { stationId: "".GetUrlParam("stationId") },
                                url: `/Configure/BaseTeam/GetStationTeamByStationId`,
                                success: function (result) {
                                    if (sysU.successBefore(result)) return false;
                                    var targetArrValue = result.Result.map(function (e) { return e.teamCode; });
                                    var selectColKey = "".GetUrlParam("selectColKeyCustom");
                                    sysU.SetTableCheck(targetArrValue, res, selectColKey, app.data.tableElem);
                                }
                            }
                            sysU.ajax(ajaxConfig);
                        }
                    }
                }
                app.data.tableIns = sysU.initTable(options);
            },

            //明细表
            initTableDesc: function (obj) {
                debugger
                sendDataDesc = { teamCode: obj.data.teamCode }
                let opt = {
                    cols: sysU.columnRecord(app.data.tableElemDesc, app.data.colsDesc),
                    elem: "#" + app.data.tableElemDesc,
                    url: `/${areaName}/${controllerName}/LoadDesc`,
                    toolbar: '#toolbarTableDesc',
                    height: "full-56",
                    where: sendDataDesc
                }
                app.data.tableInsDesc = sysU.initTable(opt);
            },

            initSelectTable: function () {

            },

            initFrom() {
                sysU.initSelect(app.data.selectOption);
            }
        },
        registerEvent: function () {

        },
        init: function () {
            app.methods.initTable();
            app.methods.initFrom();
            app.registerEvent();
        }
    };
    app.init();
});