table-tool.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * Created by Administrator on 2017/2/27 0027.
  3. */
  4. // 表格选中
  5. $('#dateTable tbody').on('click', 'tr input[type="checkbox"]', function () {
  6. var obj = $(this).parent().parent();
  7. if (this.checked) {
  8. obj.addClass('selected');
  9. } else {
  10. obj.removeClass('selected');
  11. }
  12. });
  13. // 全选和反选
  14. $('#dateTable thead').on('click', 'tr input[type="checkbox"]', function () {
  15. var obj = $("#dateTable tbody input[type='checkbox']:checkbox");
  16. var allTr = $("#dateTable tbody tr");
  17. if (this.checked) {
  18. obj.prop("checked", true);
  19. allTr.addClass('selected');
  20. } else {
  21. obj.prop("checked", false);
  22. allTr.removeClass('selected');
  23. }
  24. });
  25. // 删除公共方法 deleteAll(ids,请求url,操作成功跳转url,操作失败跳转url)
  26. function deleteAll(ids,url,sUrl,eUrl){
  27. // ids不能为空
  28. if(ids == null || ids == ''){
  29. layer.msg('请选择要删除的数据',{time:2000});
  30. return false;
  31. }else{
  32. layer.confirm('确认删除选中数据?', {
  33. title: '删除',
  34. btn: ['确认', '取消'] // 可以无限个按钮
  35. }, function(index, layero){
  36. // 确认
  37. $.post(url,{ids:ids},function(res){
  38. // 大于0表示删除成功
  39. if(res.status > 0){
  40. // 提示信息并跳转
  41. layer.msg(res.msg,{time:2000},function(){
  42. location.href = sUrl;
  43. })
  44. }else{
  45. // 提示信息并跳转
  46. layer.msg(res.msg,{time:2000},function(){
  47. location.href = eUrl;
  48. })
  49. }
  50. });
  51. }, function(index){
  52. // 关闭
  53. layer.close(index);
  54. });
  55. }
  56. }
  57. // 转换时间戳为日期时间(时间戳,显示年月日时分,加8小时显示正常时间区)
  58. function UnixToDate(unixTime, isFull, timeZone) {
  59. if (unixTime == '' || unixTime == null) {
  60. return '';
  61. }
  62. if (typeof (timeZone) == 'number') {
  63. unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
  64. }
  65. var time = new Date(unixTime * 1000);
  66. var ymdhis = "";
  67. var year, month, date, hours, minutes, seconds;
  68. if (time.getUTCFullYear() < 10) {
  69. year = '0' + time.getUTCFullYear();
  70. } else {
  71. year = time.getUTCFullYear();
  72. }
  73. if ((time.getUTCMonth() + 1) < 10) {
  74. month = '0' + (time.getUTCMonth() + 1);
  75. } else {
  76. month = (time.getUTCMonth() + 1);
  77. }
  78. if (time.getUTCDate() < 10) {
  79. date = '0' + time.getUTCDate();
  80. } else {
  81. date = time.getUTCDate();
  82. }
  83. ymdhis += year + "-";
  84. ymdhis += month + "-";
  85. ymdhis += date;
  86. if (isFull === true) {
  87. if (time.getUTCHours() < 10) {
  88. hours = '0' + time.getUTCHours();
  89. } else {
  90. hours = time.getUTCHours();
  91. }
  92. if (time.getUTCMinutes() < 10) {
  93. minutes = '0' + time.getUTCMinutes();
  94. } else {
  95. minutes = time.getUTCMinutes();
  96. }
  97. if (time.getUTCSeconds() < 10) {
  98. seconds = '0' + time.getUTCSeconds();
  99. } else {
  100. seconds = time.getUTCSeconds();
  101. }
  102. ymdhis += " " + hours + ":";
  103. ymdhis += minutes;
  104. // ymdhis += seconds;
  105. }
  106. return ymdhis;
  107. }
  108. // 批量删除 返回需要的 ids
  109. function getIds(o,str){
  110. var obj = o.find('tbody tr td:first-child input[type="checkbox"]:checked');
  111. var list = '';
  112. obj.each(function(index,elem){
  113. list += $(elem).attr(str)+',';
  114. });
  115. // 去除最后一位逗号
  116. list = list.substr(0,(list.length-1));
  117. return list;
  118. }