myApp.controller("donate", ["$scope", "$http", "NgTableParams", function($scope, $http, NgTableParams) { window.hub.stop(); var self = this; var source = []; $scope.loading(); $scope.paginationConf = { currentPage: 1, itemsPerPage: 10, pagesLength: 25, perPageOptions: [1, 5, 10, 15, 20, 30, 40, 50, 100, 200], rememberPerPage: 'perPageItems', onChange: function() { self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage); } }; this.GetPageData = function(page, size) { $scope.loading(); $http.post("/donate/getpagedata", { page, size }).then(function(res) { $scope.paginationConf.totalItems = res.data.TotalCount; $("div[ng-table-pagination]").remove(); self.tableParams = new NgTableParams({ count: 50000 }, { filterDelay: 0, dataset: res.data.Data }); source = angular.copy(res.data.Data); $scope.loadingDone(); }); }; self.del = function(row) { swal({ title: "确认删除这条打赏记录吗?", text: row.NickName, showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "确定", cancelButtonText: "取消", showLoaderOnConfirm: true, animation: true, allowOutsideClick: false }).then(function() { $scope.request("/donate/delete", { id: row.Id }, function(data) { window.notie.alert({ type: 1, text: data.Message, time: 4 }); }); _.remove(self.tableParams.settings().dataset, function(item) { return row === item; }); self.tableParams.reload().then(function(data) { if (data.length === 0 && self.tableParams.total() > 0) { self.tableParams.page(self.tableParams.page() - 1); self.tableParams.reload(); } }); }, function() { }).catch(swal.noop); } $scope.save = function (row) { if (row==null) { row = { NickName: "", DonateTime: "", Amount: "", Email: "", QQorWechat: "", Via:"" }; } swal({ title: '添加打赏记录', html: '
昵称:
' + '
打赏时间:
' + '
打赏金额:
' + '
打赏方式:
' + '
Email:
' + '
QQ或微信:
', showCloseButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "确定", cancelButtonText: "取消", showLoaderOnConfirm: true, animation: true, allowOutsideClick: false, preConfirm: function () { return new Promise(function (resolve, reject) { row.NickName = $("#name").val(); row.DonateTime = $("#date").val(); row.Amount = $("#amount").val(); row.Via = $("#via").val(); row.Email = $("#email").val(); row.QQorWechat = $("#qq").val(); $http.post("/donate/save", row).then(function (res) { if (res.data.Success) { resolve(res.data); } else { reject(res.data.Message); } }, function (error) { reject("服务请求失败!"); }); }); } }).then(function (result) { if (result) { if (result.Success) { swal(result.Message, "", "success"); self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage); } else { swal(result.Message, "", "error"); } } }).catch(swal.noop); $(".date").jeDate({ isinitVal: true, format: "YYYY-MM-DD", okfun: function (elem) { $("#date").val(elem.val); } }); } $scope.loadingDone(); }]);