(function ($) {
    $.extend({
        dyAjax: function (url, data, callback, type, async, isloading) {
            isloading = typeof (isloading) === 'undefined' ? true : isloading;
            let vm = {};
            let loading;
            if (isloading) {
                vm = new Vue({
                    el: '#loadingele',
                });
                loading = vm.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
            }

            $.ajax({
                async: async,
                contentType: "application/x-www-form-urlencoded",
                type: type ? type : "post",
                url: url,
                data: data,
                success: function (result, status, xhr) {
                    isloading ? loading.close() : {};
                    if (result.msg == "OK") {
                        callback(result.data);
                    } else if (result.msg == null) {
                        callback(result.data);
                    } else if (result.msg === "error") {

                    } else if (result.status === 500) {
                        vm.$message({
                            type: 'error',
                            message: result.msg
                        });
                    } else {
                        callback(result);
                    }
                },
                error: function (xhr, status, error) {
                    console.log(error)
                    if (status == "parsererror") {
                        vm.$message({
                            type: 'error',
                            message: xhr.responseText
                        });
                    }
                    isloading ? loading.close() : {};
                }
            });
        },
        dyjAjax: function (url, data, callback, async, isloading) {
            isloading = typeof (isloading) === 'undefined' ? true : isloading;
            let vm = {};
            let loading;
            if (isloading) {
                vm = new Vue({
                    el: '#loadingele',
                });
                loading = vm.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
            }

            $.ajax({
                async: async,
                contentType: "application/json",
                type: "post",
                url: url,
                data: JSON.stringify(data),
                success: function (result, status, xhr) {
                    isloading ? loading.close() : {};
                    if (result.msg == "OK") {
                        callback(result.data);
                    } else if (result.msg == null) {
                        callback(result.data);
                    } else if (result.msg === "error") {

                    } else if (result.status === 500) {
                        vm.$message({
                            type: 'error',
                            message: result.msg
                        });
                    } else {
                        callback(result);
                    }
                },
                error: function (xhr, status, error) {
                    console.log(error)
                    if (status == "parsererror") {
                        vm.$message({
                            type: 'error',
                            message: xhr.responseText
                        });
                    }
                    isloading ? loading.close() : {};
                }
            });
        }
    })
})(jQuery)