statistica.js 4.4 KB

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