layui.define(['layer'], function(exports) {
    var layer = layui.layer;
    var dialog = {
        dialogArray: [],
        dialogData: {},
        dialogTreeData: {
            apiUri: null,
            method: null,
            primaryKey: null,
            autoParams: null,
            otherParams: null,
            defaultParams: null,
            resultType: null,
            dataFilter: null,
            rootNode: null,
            data: null,
            check: null,
            selectedNodes: []
        },
        maxFileCount: null,
        close: function (index) {
            layer.close(index);
        },
        msg: function (msg, args, callback) {
            return layer.msg(msg, args, callback);
        },
        confirm: function (msg, callback) {
            var self = this;
            return top.layer.msg(msg, {
                time: 0,
                btn: ['确定', '取消'],
                shade: 0.3,
                yes: function (index) {
                    callback(index);
                },
                btn1: function () {
                    self.closeBox();
                }
            });
        },
        open: function (opt) {
            var self = this;
            var index = top.layer.open({
                type: 2,
                icon: 1,
                title: opt.title,
                shadeClose: false,
                maxmin: false,
                resize: false,
                shade: 0.3,
                area: [opt.width, opt.height],
                content: opt.url,
                cancel: function (index) {
                    self.closeBox();
                },
                end: opt.onClose
            });
            this.dialogArray.push(index);
            return index;
        },
        closeBox: function () {
            top.layer.close(this.dialogArray[this.dialogArray.length - 1]);
            this.dialogArray.pop();
        }
    };
    exports('dialog', dialog);
});