StationUserRel.js 6.68 KB

let action = null;
let $this = null;
layui.config({
    base: "/js/",
    version: 55
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        table = layui.table,
        layer = layui.layer,
        tableSelect = layui.tableSelect,
        system = layui.system,
        u = new system.u(),
        areaName = 'configure',
        tableName = 'StationUserRel';
      
    action = {
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Ins`,
                submit: "submit(fromAdd)"
            }
            return options;
        },

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

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

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

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

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/Import`
            }
            return options;
        },
        addBefore: function (callBack) {
            app.methods.initSelectTable();
            if (callBack != null) callBack();
        },
        editBefore: function (data, callBack) {
            app.methods.initSelectTable();
            form.val("modifyForm", data);
            $("input[name=stationId]").attr("ts-selected", data.stationId);
            $("input[name=userId]").attr("ts-selected", data.userId);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            data.field["userids"] = data.field.userId;
            data.field.userId = -1;
            if (callBack != null) callBack();
        },
        customTableRowClick: function (obj, tableId) {
            debugger;
             $this = $(this).find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
            $("a[lay-event=btnPeopleStation]").click(); 
        },
        //工位人员分配
        btnPeopleStation: function (sysU, toolbarId, obj) {
            var checkStatus = table.checkStatus(toolbarId),
                 data = checkStatus.data;
            if (data.length !== 1) {
                layer.msg("请选择一条要分配的工位");
                return false;
            }
            var ajaxConfig = {
                url: `/${areaName}/${tableName}/GetStationUserById?stationId=` + data[0].id,
                type: "get",
                success: function (result) {
                    debugger
                    if (u.successBefore(result)) return;
                    layer.open({
                        title: "为工位【" + data[0].workStationName + "】分配人员",
                        type: 2,
                        area: ['1000px', '600px'],
                        content: "/base/SysUser/Index?menuFlag=-2&page=stationUserRel&targetArrValue=" + result.Result.GetArrValue("userId") + "&stationId=" + data[0].id,

                        cancel: function () {
                            action.actionSuccess("", app.data.tableIns.config.page.index);
                            console.log($this);
                        }
                    });
                }
            };
            u.ajax(ajaxConfig);
        },
 

        //所有动作成功之后
        actionSuccess: (falg, curr) => {
            debugger;
            app.data.tableIns.config.where = {};
            app.data.tableIns.config.page.curr = curr;
            app.data.tableIns.reload("mainList", {});
     
        }
    }

    var app = {
        data: {
            cols: [[
                { type: "radio",  fixed: true },
                { field: 'id', width: 80,   title: 'id' },
                { field: 'lineName', width: 200,   title: '线体名称' },
                { field: 'workStationName', width: 200,   title: '工位名称', noExel: true },
                { field: 'peopleStation', width: 300, title: '工位人员' },

                { field: 'createTime', width: 150,  title: '建立时间' },
                { field: 'createBy', width: 100,   title: '建立者' },
                { field: 'updateTime', width: 150,   title: '更新时间' },
                { field: 'updateBy', width: 100,   title: '更新者' }
            ]],
            tableIns: null,
            tableElem: "mainList"

        },
        methods: {
            initTable: function () {
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: '#toolbarTable'
                    
                }
                app.data.tableIns = u.initTable(options);
            },

            initSelectTable: function () {
                var opt = {
                    elem: ".stationId",
                    checkedKey: "id",
                    doneKey: {
                        key: "id",
                        lableName: "input[name=stationName]",
                        lableValue: "name"
                    }
                };
                u.initSelectStation(opt);

                var opt1 = {
                    elem: ".userId",
                    checkedKey: "id",
                    doneKey: {
                        key: "id",
                        lableName: "input[name=userName]",
                        lableValue: "name"
                    }
                };
                u.initSelectUser(opt1);
            }
        },
        registerEvent: function () {

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

  
        }
    };
   
    app.init();

});