statistica.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. layui.use([ 'layer', 'table', 'element','form','laydate'], function(){
  2. var layer = layui.layer //弹层
  3. ,$ = layui.jquery
  4. ,table = layui.table //表格
  5. ,element = layui.element //元素操作
  6. ,form = layui.form,
  7. laydate = layui.laydate;
  8. // console.log($('select[name=input_news] option'));
  9. var cols1 = [ //表头
  10. // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
  11. {type:'numbers',fixed:"left",title:'序号'}
  12. ,{field:'name', title:'名字',width:150,align:'center',totalRowText:'合计'}
  13. ,{field:'total', title:'总数',width:150,align:'center',totalRow:true}
  14. ];
  15. $.each($('select[name=input_news] option'),function(k,v){
  16. if(v.value != '' && v.value != null){
  17. var obj = {field:"news_name_"+v.value, title:v.text,width:150,align:'center',totalRow:true};
  18. cols1.push(obj);
  19. }
  20. });
  21. // laydate.render({
  22. // elem: '#date1'
  23. // });
  24. // laydate.render({
  25. // elem: '#date2'
  26. // });
  27. //年月选择器
  28. laydate.render({
  29. elem: '#date1'
  30. ,type: 'month'
  31. });
  32. //第一个实例
  33. var tableIns = table.render({
  34. elem: '#userlist'
  35. ,url: '/news/statisticaform' //数据接口
  36. ,where:{token:csrfToken}
  37. ,method:'post'
  38. ,id:'tablerReload'
  39. ,totalRow:true
  40. ,text:'数据加载中'
  41. ,cols: [cols1],done:function (res, curr, count) {
  42. var date= new Date();
  43. var year=date.getFullYear();//获取年
  44. var month=date.getMonth()+1;//获取月
  45. var day=date.getDate();//获取日
  46. var date_time = year+'-'+month+'-'+day;
  47. this.elem.next().find('td[data-field="time"]:contains("'+date_time+'")').parent('tr').css({"color": "#ccc"});
  48. }
  49. });
  50. tableIns.reload('tablerReload'); //重新加载
  51. var $ = layui.$, active = {
  52. reset:function(){
  53. // table.reload('tablerReload');
  54. window.location.reload();
  55. },
  56. reload:function () {
  57. var form = pfgs_serialize($('form'));
  58. // console.log(form);
  59. // var a = compareTime(form.start_time,form.end_time);
  60. // if(a === false) {
  61. // layer.msg('开始时间不能大于结束时间');
  62. // return ;
  63. // }
  64. table.reload('tablerReload',{
  65. where:{
  66. date_month:form.start_time
  67. }
  68. })
  69. }
  70. };
  71. //
  72. // function compareTime(a, b) {
  73. // var arr = a.split("-"); //log [2016,04,06]
  74. // var start = new Date(arr[0], (arr[1] - 1), arr[2]);
  75. // var starts = start.getTime(); //输出时间戳进行对比
  76. // var arrs = b.split("-");
  77. // var end = new Date(arrs[0], (arrs[1] - 1), arrs[2]);
  78. // var ends = end.getTime();
  79. // if (starts > ends) return false ;
  80. // }
  81. $('.demoTable .layui-btn').on('click', function(){
  82. var type = $(this).data('type');
  83. active[type] ? active[type].call(this) : '';
  84. });
  85. });
  86. function Layui_SetDataTableRowColor(TabDivId,RowIndex, ColorString)
  87. {
  88. try
  89. {
  90. var div = document.getElementById(TabDivId);
  91. if(div != null) //找到对象了
  92. {
  93. var table_main = div.getElementsByClassName('layui-table-main'); //通过class获取table_main
  94. if (table_main != null && table_main.length > 0)
  95. {
  96. var table = table_main[0].getElementsByClassName('layui-table'); //通过class获取table
  97. if (table != null && table.length > 0) {
  98. var trs = table[0].querySelectorAll("tr");
  99. if (trs != null && trs.length > 0) {
  100. trs[RowIndex].style.color = ColorString;
  101. }
  102. }
  103. }
  104. }
  105. }
  106. catch(e)
  107. {
  108. console.log(e.message);
  109. }
  110. }