"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var _ = require("lodash");
var index_1 = require("../index");
var utils_1 = require("../../utils");
var antd_1 = require("antd");
var default_1 = /** @class */ (function (_super) {
    __extends(default_1, _super);
    function default_1() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.table = null;
        _this.lastShow = false;
        _this.queryField = '';
        _this.queryValue = '';
        return _this;
    }
    default_1.prototype._getQuery = function () {
        var param = {};
        if (this.queryField && this.queryValue) {
            param[this.queryField] = this.queryValue;
        }
        return param;
    };
    default_1.prototype.export = function () {
        var _this = this;
        utils_1.Ajax.POST(this.props.export, _.extend({}, this.props.param, this._getQuery()), function (json) {
            if (json.code == '0') {
                utils_1.Events.call('download', json);
                if (_.has(_this.props, 'onCancel')) {
                    _this.props.onCancel(null);
                }
            }
            else {
                antd_1.message.error('导出失败');
            }
        });
    };
    default_1.prototype.search = function (value) {
        this.queryValue = value;
        var param = this._getQuery();
        this.table.cleanAndQuery(param);
    };
    default_1.prototype.componentDidUpdate = function () {
        if (this.lastShow === false && this.props.show === true && _.has(this.table, 'query')) {
            this.table.cleanAndQuery(this.props.param);
        }
        this.lastShow = this.props.show;
    };
    default_1.prototype.render = function () {
        var _this = this;
        var param = {};
        param.visible = this.props.show;
        param.footer = null;
        param.className = this.props.className ? 'vap-table-modal ' + this.props.className : 'vap-table-modal';
        param.title = [];
        if (this.props.export) {
            param.title.push(React.createElement(index_1.Button, { size: "small", icon: "export", style: { marginRight: 6 }, onClick: function (e) { return _this.export(); } }, "\u5BFC\u51FA"));
        }
        if (this.props.search) {
            this.queryField = this.props.search[0].field;
            param.title.push(React.createElement(index_1.Input.Search, { style: {
                    maxWidth: 250,
                    marginRight: 6,
                }, size: "small", addonBefore: React.createElement(index_1.Select, { defaultValue: this.props.search[0].field, style: { minWidth: 60 }, onChange: function (e) { return _this.queryField = e; } }, this.props.search.map(function (item) { return React.createElement(index_1.Select.Option, { value: item.field }, item.title); })), onSearch: function (value) { return _this.search(value); }, enterButton: true }));
        }
        if (this.props.title) {
            param.title.push(this.props.title);
        }
        var tableParam = {};
        if (this.props.showSizeChanger === false) {
            tableParam.showSizeChanger = false;
        }
        return React.createElement(index_1.Modal, __assign({}, this.props, param),
            React.createElement(index_1.DataTable, __assign({ _notUpdate: true, query: this.props.query, param: this.props.param, columns: this.props.columns }, tableParam, { ref: function (table) { return _this.table = table; } })));
    };
    return default_1;
}(React.Component));
exports.default = default_1;
