donate.js 4.3 KB

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