123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- layui.use([ 'layer', 'table', 'element','form','laydate'], function(){
- var layer = layui.layer //弹层
- ,$ = layui.jquery
- ,table = layui.table //表格
- ,element = layui.element //元素操作
- ,form = layui.form,
- laydate = layui.laydate;
- // console.log($('select[name=input_news] option'));
- var cols1 = [ //表头
- // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left',align:'center'},
- {type:'numbers',fixed:"left",title:'序号'}
- ,{field:'name', title:'名字',width:150,align:'center',totalRowText:'合计'}
- ,{field:'total', title:'总数',width:150,align:'center',totalRow:true}
- ];
- $.each($('select[name=input_news] option'),function(k,v){
- if(v.value != '' && v.value != null){
- var obj = {field:"news_name_"+v.value, title:v.text,width:150,align:'center',totalRow:true};
- cols1.push(obj);
- }
- });
- // laydate.render({
- // elem: '#date1'
- // });
- // laydate.render({
- // elem: '#date2'
- // });
- //年月选择器
- laydate.render({
- elem: '#date1'
- ,type: 'month'
- });
- //第一个实例
- var tableIns = table.render({
- elem: '#userlist'
- ,url: '/news/statisticaform' //数据接口
- ,where:{token:csrfToken}
- ,method:'post'
- ,id:'tablerReload'
- ,totalRow:true
- ,text:'数据加载中'
- ,cols: [cols1],done:function (res, curr, count) {
- var date= new Date();
- var year=date.getFullYear();//获取年
- var month=date.getMonth()+1;//获取月
- var day=date.getDate();//获取日
- var date_time = year+'-'+month+'-'+day;
- this.elem.next().find('td[data-field="time"]:contains("'+date_time+'")').parent('tr').css({"color": "#ccc"});
- }
- });
- tableIns.reload('tablerReload'); //重新加载
- var $ = layui.$, active = {
- reset:function(){
- // table.reload('tablerReload');
- window.location.reload();
- },
- reload:function () {
- var form = pfgs_serialize($('form'));
- // console.log(form);
- // var a = compareTime(form.start_time,form.end_time);
- // if(a === false) {
- // layer.msg('开始时间不能大于结束时间');
- // return ;
- // }
- table.reload('tablerReload',{
- where:{
- date_month:form.start_time
- }
- })
- }
- };
- //
- // function compareTime(a, b) {
- // var arr = a.split("-"); //log [2016,04,06]
- // var start = new Date(arr[0], (arr[1] - 1), arr[2]);
- // var starts = start.getTime(); //输出时间戳进行对比
- // var arrs = b.split("-");
- // var end = new Date(arrs[0], (arrs[1] - 1), arrs[2]);
- // var ends = end.getTime();
- // if (starts > ends) return false ;
- // }
- $('.demoTable .layui-btn').on('click', function(){
- var type = $(this).data('type');
- active[type] ? active[type].call(this) : '';
- });
- });
- function Layui_SetDataTableRowColor(TabDivId,RowIndex, ColorString)
- {
- try
- {
- var div = document.getElementById(TabDivId);
- if(div != null) //找到对象了
- {
- var table_main = div.getElementsByClassName('layui-table-main'); //通过class获取table_main
- if (table_main != null && table_main.length > 0)
- {
- var table = table_main[0].getElementsByClassName('layui-table'); //通过class获取table
- if (table != null && table.length > 0) {
- var trs = table[0].querySelectorAll("tr");
- if (trs != null && trs.length > 0) {
- trs[RowIndex].style.color = ColorString;
- }
- }
- }
- }
- }
- catch(e)
- {
- console.log(e.message);
- }
- }
|