Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
function queryCouponList(urls, queryParams, paraUrls,state) {
    var pageNumber = 1, pageSize = 10;
    // 默认查询第一页 query查询时保存当前条件
    //var pageCount = 0;
    // var sum = parseInt(total);
    try {
        pageNumber = $('#datatable').datagrid('getPager').pagination("options").pageNumber;
        pageSize = $('#datatable').datagrid('getPager').pagination("options").pageSize;
    } catch (e) {
        pageNumber = 1, pageSize = 10;
    }
    $('#datatable')
        .datagrid(
            {
                title: "信息列表",
                iconCls: 'icon-search',
                pageNumber: pageNumber,
                pageSize: pageSize,
                pageList: [5, 10, 15, 20, 25, 30, 35, 40, 45, 50],
                nowrap: true,
                striped: true,
                border: true,
                noheader: true,
                url: urls,
                loadMsg: '数据加载中......',
                queryParams: queryParams,
                remoteSort: false,
                fitColumns: true,
                singleSelect: false,
                columns: [[

                    {
                        field: 'ORDER_CODE',
                        title: '案件编号',
                        sortable: 'false',
                        align: 'center',
                        width: 10
                    }, {
                        field: 'CREATE_TIME',
                        title: '案件创建时间',
                        sortable: 'false',
                        align: 'center',
                        width: 10,
                        formatter: function (value, row, index) {
                            return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                        }
                    }
                    , {
                        field: 'VIN_NO',
                        title: 'VIN码',
                        sortable: 'false',
                        align: 'center',
                        width: 10
                    }

                    , {
                        field: 'NAME',
                        title: '服务商名称',
                        sortable: 'false',
                        align: 'center',
                        width: 15
                    }
                    , {
                        field: 'CODE',
                        title: '服务商代码',
                        sortable: 'false',
                        align: 'center',
                        width: 10
                    }
                    , {
                        field: 'SERVICE_NAME',
                        title: '服务类型',
                        sortable: 'false',
                        align: 'center',
                        width: 10
                    }
                    , {
                        field: 'STATE',
                        title: '维修信息',
                        sortable: 'false',
                        align: 'center',
                        width: 10,
                        formatter: function (value, row, index) {
                            var str = '';
                            if(state == '0') {
                                str = '<a href="' + paraUrls + row.ID + '&state=' + state +'&tid=' + row.TID + '" name="opera"' +
                                    ' class="easyui-linkbutton" >查看详情</a>';
                            }else if(state == '1'){
                                    if (row.STATE == '1') {
                                        str = '<a href="' + paraUrls + row.ID + '&state=' + state +'&tid='+row.TID+'" name="opera"' +
                                            ' class="easyui-linkbutton" >查看详情</a>';
                                    }
                                   else if (row.STATE == '0') {
                                    str = '<a href="' + paraUrls + row.ID + '&state=' + state +'&tid='+row.TID +'" name="opera"' +
                                        ' class="easyui-linkbutton" >填写维修信息</a>';
                                   }else{
                                    str = '<a href="' + paraUrls + row.ID + '&state=' + state +'&tid='+row.TID +'" name="opera"' +
                                        ' class="easyui-linkbutton" >填写维修信息</a>';
                                   }
                            }
                            return str;
                        }
                    }
                ]],
                pagination: true,
                rownumbers: false,
                onLoadSuccess: function (data) {
                }

                ,
                toolbar: [],
                onCheck: function (rowIndex, rowData) {
                }

                ,
                onCheckAll: function (rows) {
                }
                ,
                onUncheck: function (rowIndex, rowData) {
                }
                ,
                onLoadSuccess: function (data) {
                }
                ,
                onUncheckAll: function (rows) {
                }
            })
    ;
    $('#datatable').datagrid('getPager').pagination({
        displayMsg: '',
    });

}

// 计算页面个数
function getPageCount(total, pageSize) {
    if (total % pageSize == 0) {
        return total / pageSize;
    } else {
        return parseInt(total / pageSize) + 1;
    }

}


function toCompairTime(a, b) {
    var arr = a.split("-");
    var starttime = new Date(arr[0], arr[1], arr[2]);
    var starttimes = starttime.getTime();
    var arrs = b.split("-");
    var lktime = new Date(arrs[0], arrs[1], arrs[2]);
    var lktimes = lktime.getTime();

    if (starttimes >= lktimes) {

        return false;
    }
    else
        return true;
}

// 2.向select选项中 加入一个Item
function jsAddItemToSelect(objSelect, listfirst, idList) {

    // jsRemoveItemFromSelect(objSelect, idList);
//判断是否存在
    if (listfirst != null && listfirst.length > 0) {
        objSelect.options.add(new Option('请选择', 0));
        for (var i = 0; i < listfirst.length; i++) {
            var objItemValue = idList[i];
            //  alert(objItemValue);
            var objItemText = listfirst[i];
            //alert(objItemText);
            var varItem = new Option(objItemText, objItemValue);
            objSelect.options.add(varItem);
        }
    }

    //alert("成功加入");
}



function jsRemoveItemFromSelect(objSelect) {
//判断是否存在
    var optionList = objSelect.options
    for (var i = 0; i < optionList.length; i++) {
        alert(optionList.length);
        optionList.remove(i);
    }
}
// 1.判断select选项中 是否存在Value="paraValue"的Item
function jsSelectIsExitItem(objSelect, objItemValue) {
    var isExit = false;
    for (var i = 0; i < objSelect.options.length; i++) {
        if (objSelect.options[i].value == objItemValue) {
            isExit = true;
            break;
        }
    }
    return isExit;
}

// 求援完成确定
function completionOfRescue(code, special_organize, servicesname) {
    var path = $("#paths").val();
    $(".order_print").show();
    var param = {};
    param["code"] = code;
    var result = ajaxgetresultpost(path + '/casesInfo/completionOfRescue.do', param);
    var specialOrganize = special_organize == "undefined" || special_organize == null ? '' : special_organize;
    var servicesName = servicesname == "undefined" || servicesname == null ? '' : servicesname;

    var s = ' <tr> <th colspan="3"><span class="printList"></span>案件信息</th> </tr>' +
        ' <tr> <td><span>案件编号：</span>' + result.code + '</td> ' +
        '<td><span>服务内容：</span>' + servicesName + '</td></tr>' +
        ' <tr><td><span>经销商代码：</span>' + result.contract_company_code + '</td>' +
        '<td><span>经销商名称：</span>' + specialOrganize + '</td></tr>' +
        ' <tr><td><span>车架号：</span>' + result.frame_code + '</td> ' +
        '<td><span>车&nbsp;&nbsp;型：</span>' + result.style + '</td> </tr>' +
        ' <tr><td><span>故障描述：</span>' + result.trouble_leve2 + '</td> </tr> ' +
        '<tr><td><span>事发地：</span>' + result.depart_address + '</td> </tr> ' +
        '<tr><td><span>目的地：</span>' + result.dest_address + '</td> <td></td> </tr> ';
    $(".PrintCase").html(s);


    // 救援详情
    var ss = '<tr> <th colspan="2"><span class="printList"></span>救援详情</th> </tr>' +
        '<tr><td>接案时间：</td><td>' + result.accept_time + '</td> </tr> ' +
        '<tr><td>到达时间：</td><td>' + result.arrive_time + '</td> </tr> ' +
        '<tr><td>完成时间：</td><td>' + result.finish_time + '</td> </tr> '
    $(".saveDetail").html(ss);

    // 签名
    //alert(result.csignaturePath,result.cksignaturePath);
    var sss = ' <tr> <th> <div class=" signList "><span class=" printSignList ">' +
        '</span>车主签字</div> <img src="' + result.csignaturePath + ' "' + ' class=" signImg " />' +
        ' </th> <th> <div class=" signList "><span class=" printSignList ">' +
        '</span>车主/接车人签字</div> <img src=" ' + result.cksignaturePath + ' " class=" signImg " /> </th> </tr>';
    $(".sign").html(sss);
}

