endorsement.js 10.5 KB
/**
 * Created by chenbiao on 2017/8/23.
 */

/*进场时间筛选框*/
//进场时间初始化
$('#endor-daterange-btnsta').val(moment().subtract('days',6).format('YYYY-MM-DD'));
$('#endor-daterange-btnend').val(moment().subtract('days', 0).format('YYYY-MM-DD'));
//开始日期
$("#endor-daterange-btnsta").datetimepicker({
    endDate: moment().subtract('days', 0).format('YYYY-MM-DD'),
    format: 'yyyy-mm-dd',
    autoclose: true,
    startView: 2,
    //maxDate:moment().subtract('months', 3),
    minView: 2,
    forceParse: false,
    locale: "zh-CN",
    language: 'zh-CN',
    pickerPosition: "bottom-right"
}).on("click", function () {
    $("#endor-daterange-btnsta").datetimepicker("setEndDate", $("#endor-daterange-btnend").val())
});
//结束日期
$("#endor-daterange-btnend").datetimepicker({
    endDate: moment().subtract('days', 0).format('YYYY-MM-DD'),
    //startDate:startVal,
    format: 'yyyy-mm-dd',
    weekStart: 1,
    autoclose: true,
    startView: 2,
    minView: 2,
    forceParse: false,
    locale: "zh-CN",
    language: 'zh-CN',
    pickerPosition: "bottom-right"
}).on("click", function () {
    $("#endor-daterange-btnend").datetimepicker("setStartDate", $("#endor-daterange-btnsta").val())
});

//隐藏显示 查询条件 搜索框 hide-common-style
documentBindFunc.on('click',".ITD-search-morebtn",function(){
    $(".hide-common-style").toggleClass("display-none");
});
(function () {
    var cacheParkData ;
    var fun = {
        init: function () {
            //初始化停车状态下拉框
            fn.getParkStatus(fun.initParkStatus);
            fun.createTableData();
        },
        //生成表格数据
        createTableData: function () {
            $('#recordtable').bootstrapTable('destroy').bootstrapTable({
                striped: true,//表格显示条纹
                pagination: true, //启动分页
                pageNumber: 1, //当前第几页
                pageSize: 10,  //每页显示的记录数
                pageList: [10, 15, 20],  //记录数可选列表
                sidePagination: 'server',//表示服务端分页
                queryParamsType: 'limit',
                method: 'POST',//请求方法
                paginationPreText: '<',
                paginationNextText: '>',
                fixedColumns:true,
                fixedNumber:1,
                leftFixedColumns: true,
                leftFixedNumber: 1,
                // rightFixedColumns: true,
                // rightFixedNumber: 1,
                ajax: tableLoadRequest,//自定义ajax加载数据
                // uniqueId:'id',
                columns: [

                    {
                        field: 'carNumber',
                        title: '车牌号',
                        width: '10%',
                        align:"left",
                        formatter: function (value, row, index) {
                            if (undefined != value && null != value) {
                                if (value.length > 8) {
                                    return '无牌车'
                                } else {
                                    return value;
                                }
                            }
                        }
                    },
                    {field: 'plName', title: '停车场名称', width: '10%', align:"left"},
                    {
                        field: 'parkInTime',
                        title: '进场时间',
                        width: '15%',
                        align:"left",
                        formatter: fun.inDatatimeFormatter
                    },
                    {
                        field: 'parkOutTime',
                        title: '出场时间',
                        width: '15%',
                        align:"left",
                        formatter: fun.outDatatimeFormatter
                    },

                    {
                        field: 'parkingDuration',
                        title: '停车时长',
                        width: '10%',
                        align:"left",
                        formatter: fun.parkingDurationFormatter
                    },
                    {
                        field: 'parkState',
                        title: '状态',
                        width: '10%',
                        align:"left",
                        formatter: fun.inOutStateFormatter
                    },
                ]
            });

        },
        /*获取查询参数*/
        getQueryParam: function () {
            /*停车状态*/
            var parkStatus = JSON.parse($("#parkStatus").val());
            console.log(parkStatus)
            if(parkStatus.length == 0 ||parkStatus==null ||parkStatus==undefined){
            	parkStatus = null;
            }else{
            	parkStatus = parkStatus[0];
            }
            /*进场开始时间*/
            var beginInTime = null;
            /*进场结束*/
            var endInTime = null;
            /*出场开始时间*/
            var beginOutTime = null;
            /*出场结束时间*/
            var endOutTime = null;
            /*解析进场时间*/
            var times1 = $('#endor-daterange-btnsta').val();
            var times2 = $('#endor-daterange-btnend').val();
            if (null != times1 && times1.trim().length > 0) {
                beginInTime = times1;
            }
            if (null != times2 && times2.trim().length > 0) {
                endInTime = times2;
            }
            /*var dateEntranceRange = $('#timeinStartDate input').val();
            if (null != dateEntranceRange && dateEntranceRange.trim().length > 0) {
                var times = dateEntranceRange.split('  -  ');
                beginInTime = times[0];
                endInTime = times[1];
            }*/

            /*解析出场时间*/
            var times3 = $('#endor-daterange-timeoutsta').val();
            var times4 = $('#endor-daterange-timeoutend').val();
            if (null != times3 && times3.trim().length > 0) {
                beginOutTime = times3;
            }
            if (null != times4 && times4.trim().length > 0) {
                endOutTime = times4;
            }
            
           /* var dateExitRange = $('#timeoutStartDate input').val();
            if (null != dateExitRange && dateExitRange.trim().length > 0) {
                var times = dateExitRange.split('  -  ');
                beginOutTime = times[0];
                endOutTime = times[1];
            }*/

            /*车牌号*/
            var carNum = $('#carNumber').val();
            carNum = carNum == null || carNum.length == 0 ? null : carNum.trim();
            var req = {
                parkState: parkStatus,
                beginInTime: beginInTime,
                endInTime: endInTime,
                beginOutTime: beginOutTime,
                endOutTime: endOutTime,
                carNumber: carNum
            };

            return req;
        },
       
        //停车状态下来框
        initParkStatus: function (data) {
            if (null == data) {
                return;
            }
            $("#parkStatus").empty();
            var html = '<option value="[]" selected >所有状态</option>';
            $.each(data, function (index, item) {
                html += '<option value="[' + item.codeValue + ']">' + item.codeValueName + '</option>'
            });
            $("#parkStatus").append(html);
            $('#parkStatus').selectpicker('refresh');
        },
        inDatatimeFormatter: function (value, row, index) {
            if (value == null) {
                return "";
            } else {
                return "<div class='imgClick'>" + DateUtils.long2String(value, 7) + "</div>";
            }
        },
        outDatatimeFormatter: function (value, row, index) {
            if (value == null) {
                return "";
            } else {
                return DateUtils.long2String(value, 7);
            }
        },
        parkingDurationFormatter: function (value, row, index) {
            if (value == null) {
                return "";
            } else {
                return formatSeconds(value);
            }
        },
        inOutStateFormatter: function (value, row, index) {
            if (value == 10) {
                return "在场";
            } else if(value == 20){
                return "离场";
            }else{
            	return "未知";
            }
        },
        imageformatter: function (value, row, index) {
            return "<span onClick='' id='inParkimage'></span>";

        }
    };


    //初始执行
    fun.init();
    documentBindFunc.on('click', '#queryBtn', function () {
        fun.createTableData();
    });

    /**
     * 自定义table AJAX请求
     * @param {Object} params
     */
    function tableLoadRequest(params) {
        var req = fun.getQueryParam();
        //设置请求参数
        var pageNum = (params.data.offset / params.data.limit) + 1;

        //条件查询
        req.baseRequest = {
            pageNum: pageNum,
            pageSize: params.data.limit
        };
        req.sysCode = sysComm.sysCode;
        var opt = {
            method: 'post',
            url: dataUrl.util.queryPageParkOrderByIllegalCar(),
            async: false,
            data: JSON.stringify(req),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function (res) {
                if (res.code == '8888') {
                    console.log(res.data);
                    params.success(res.data);
                }
            }
        };
        sysAjax(opt);
    }
})
();


function formatSeconds(value) {
    var theTime = parseInt(value);// 秒
    var theTime1 = 0;// 分
    var theTime2 = 0;// 小时
    var theTime3 = 0;//天
    if (theTime < 60) {
        return theTime + '秒';
    }
    if (theTime > 60) {
        theTime1 = parseInt(theTime / 60);
        theTime = parseInt(theTime % 60);


    }

    if (theTime1 > 60) {
        theTime2 = parseInt(theTime1 / 60);
        theTime1 = parseInt(theTime1 % 60);
    }

    if (theTime2 > 24) {
        theTime3 = parseInt(theTime2 / 24);
        theTime2 = parseInt(theTime2 % 24);
    }

    var result = '';
    if (theTime1 == 0 && theTime2 == 0 && theTime3 == 0) {
        result = parseInt(theTime) + "秒"
    }

    if (theTime1 > 0) {
        result = "" + parseInt(theTime1) + "分钟" + result;
    }
    if (theTime2 > 0) {
        result = "" + parseInt(theTime2) + "小时" + result;
    }

    if (theTime3 > 0) {
        result = "" + parseInt(theTime3) + "天" + result;
    }
    return result;
};