donate.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. myApp.controller("donate", ["$scope", "$http", "NgTableParams", function($scope, $http, NgTableParams) {
  2. window.hub.stop();
  3. var self = this;
  4. var source = [];
  5. $scope.loading();
  6. $scope.paginationConf = {
  7. currentPage: 1,
  8. itemsPerPage: 10,
  9. pagesLength: 25,
  10. perPageOptions: [1, 5, 10, 15, 20, 30, 40, 50, 100, 200],
  11. rememberPerPage: 'perPageItems',
  12. onChange: function() {
  13. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  14. }
  15. };
  16. this.GetPageData = function(page, size) {
  17. $scope.loading();
  18. $http.post("/donate/getpagedata", {
  19. page,
  20. size
  21. }).then(function(res) {
  22. $scope.paginationConf.totalItems = res.data.TotalCount;
  23. $("div[ng-table-pagination]").remove();
  24. self.tableParams = new NgTableParams({
  25. count: 50000
  26. }, {
  27. filterDelay: 0,
  28. dataset: res.data.Data
  29. });
  30. source = angular.copy(res.data.Data);
  31. $scope.loadingDone();
  32. });
  33. };
  34. self.del = function(row) {
  35. swal({
  36. title: "确认删除这条打赏记录吗?",
  37. text: row.NickName,
  38. showCancelButton: true,
  39. confirmButtonColor: "#DD6B55",
  40. confirmButtonText: "确定",
  41. cancelButtonText: "取消",
  42. showLoaderOnConfirm: true,
  43. animation: true,
  44. allowOutsideClick: false
  45. }).then(function() {
  46. $scope.request("/donate/delete", {
  47. id: row.Id
  48. }, function(data) {
  49. window.notie.alert({
  50. type: 1,
  51. text: data.Message,
  52. time: 4
  53. });
  54. });
  55. _.remove(self.tableParams.settings().dataset, function(item) {
  56. return row === item;
  57. });
  58. self.tableParams.reload().then(function(data) {
  59. if (data.length === 0 && self.tableParams.total() > 0) {
  60. self.tableParams.page(self.tableParams.page() - 1);
  61. self.tableParams.reload();
  62. }
  63. });
  64. }, function() {
  65. }).catch(swal.noop);
  66. }
  67. $scope.save = function (row) {
  68. if (row==null) {
  69. row = {
  70. NickName: "",
  71. DonateTime: "",
  72. Amount: "",
  73. Email: "",
  74. QQorWechat: "",
  75. Via:""
  76. };
  77. }
  78. swal({
  79. title: '添加打赏记录',
  80. html: '<div class="input-group"><span class="input-group-addon">昵称: </span><input type="text" id="name" class="form-control input-lg" placeholder="请输入昵称" value="' + row.NickName+'"></div>' +
  81. '<div class="input-group"><span class="input-group-addon">打赏时间: </span><input id="date" type="text" class="form-control input-lg date datainp dateicon" readonly placeholder="请输入打赏时间" value="' + row.DonateTime +'"></div> ' +
  82. '<div class="input-group"><span class="input-group-addon">打赏金额: </span><input id="amount" type="text" class="form-control input-lg" placeholder="请输入金额" value="' + row.Amount +'"></div>' +
  83. '<div class="input-group"><span class="input-group-addon">打赏方式: </span><input id="via" type="text" class="form-control input-lg" placeholder="请输入打赏方式" value="' + row.Via +'"></div>' +
  84. '<div class="input-group"><span class="input-group-addon">Email: </span><input type="email" id="email" class="form-control input-lg" placeholder="请输入Email" value="' + row.Email +'"></div>' +
  85. '<div class="input-group"><span class="input-group-addon">QQ或微信: </span><input type="text" id="qq" class="form-control input-lg" placeholder="请输入QQ或微信" value="' + row.QQorWechat +'"></div>',
  86. showCloseButton: true,
  87. confirmButtonColor: "#DD6B55",
  88. confirmButtonText: "确定",
  89. cancelButtonText: "取消",
  90. showLoaderOnConfirm: true,
  91. animation: true,
  92. allowOutsideClick: false,
  93. preConfirm: function () {
  94. return new Promise(function (resolve, reject) {
  95. row.NickName = $("#name").val();
  96. row.DonateTime = $("#date").val();
  97. row.Amount = $("#amount").val();
  98. row.Via = $("#via").val();
  99. row.Email = $("#email").val();
  100. row.QQorWechat = $("#qq").val();
  101. $http.post("/donate/save", row).then(function (res) {
  102. if (res.data.Success) {
  103. resolve(res.data);
  104. } else {
  105. reject(res.data.Message);
  106. }
  107. }, function (error) {
  108. reject("服务请求失败!");
  109. });
  110. });
  111. }
  112. }).then(function (result) {
  113. if (result) {
  114. if (result.Success) {
  115. swal(result.Message, "", "success");
  116. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  117. } else {
  118. swal(result.Message, "", "error");
  119. }
  120. }
  121. }).catch(swal.noop);
  122. $(".date").jeDate({
  123. isinitVal: true,
  124. format: "YYYY-MM-DD",
  125. okfun: function (elem) {
  126. $("#date").val(elem.val);
  127. }
  128. });
  129. }
  130. $scope.loadingDone();
  131. }]);