var loadFlag = true;
var grid = null;
var hoverId = "";
function gridRefresh() {
}
$(document).ready(function () {
grid = mini.get("m_grid");
if (grid != null) {
grid.pageSize = _page_size;
if (loadFlag) {
grid.load();
}
grid._OnRowMouseOver = function (e) {
var row = grid.getRow(e.record._index);
row.rowCls = "mini-grid-row mini-grid-row-hover";
hoverId = e.record.ID;
if ($("#op_" + hoverId).length > 0) $("#op_" + hoverId).show();
}
grid._OnRowMouseOut = function (e) {
var row = grid.getRow(e.record._index);
row.rowCls = "mini-grid-row";
if ($("#op_" + hoverId).length > 0) $("#op_" + hoverId).hide();
}
}
//查询过滤
$("#sp_date_filter").find("a").bind({
click: function () {
var t = $(this).html();
var _dt = GetCurDate();
switch (t) {
case "前一天":
{
_dt = mini.get("txtEdate").getValue();
_dt.setDate(_dt.getDate() - 1);
mini.get("txtEdate").setValue(_dt);
break;
}
case "后一天":
{
_dt = mini.get("txtEdate").getValue();
_dt.setDate(_dt.getDate() + 1);
mini.get("txtEdate").setValue(_dt);
break;
}
case "昨天": {
if (mini.get("txtSdate") != null) mini.get("txtSdate").setValue(null);
_dt.setDate(_dt.getDate() - 1);
mini.get("txtEdate").setValue(_dt);
break;
}
case "明天": {
if (mini.get("txtSdate") != null) mini.get("txtSdate").setValue(null);
_dt.setDate(_dt.getDate() + 1);
mini.get("txtEdate").setValue(_dt);
break;
}
case "今天": {
set_SearchCurDay(_dt);
break;
}
case "所有": {
mini.get("txtSdate").setValue(null);
mini.get("txtEdate").setValue(null);
break;
}
case "本月": {
set_SearchCurMonth(_dt);
break;
}
case "上月":
case "上一月": {
set_SearchPrevMonth(_dt);
break;
}
case "下月":
case "下一月": {
set_SearchNextMonth(_dt);
break;
}
}
view_search();
}
});
//过滤
$("#txtKey").keydown(function (e) {
if (e.which == 13) {
view_search();
}
});
//if (/msie [1-7].0/.test(navigator.userAgent.toLowerCase())) {
//} else {
// $("#m_toolbar").css({ position: "fixed", width: "100%", "z-Index": "999", top: "0px" });
// var h = $("#m_toolbar").height();
// h = parseInt(h) + 1;
// $(".mini-fit").css({ "margin-top": h + "px" });
// $(".report_div").css({ "margin-top": "40px" });
//}
});
function FillCurDay() {
var hd = $("#hDate").val();
var dt = null;
if (hd != "") dt = formatTdate(hd);
else dt = GetCurDate();
cur_dtime = formatTdate(dt, "yyyy-MM-dd");
mini.get("txtEdate").setValue(dt);
}
function FillCurMonth() {
var hd = $("#hDate").val();
var dt = null;
if (hd != "") dt = formatTdate(hd);
else dt = GetCurDate();
cur_dtime = formatTdate(dt, "yyyy-MM-dd");
set_SearchCurMonth(dt);
//mini.get("txtEdate").setValue(dt);
}
function set_SearchCurDay(_dt) {
if (mini.get("txtSdate") != undefined) mini.get("txtSdate").setValue(null);
mini.get("txtEdate").setValue(_dt);
}
function set_SearchPrevMonth(_dt) {
if (mini.get("txtSdate") == undefined) {
_dt = mini.get("txtEdate").getValue();
_dt.setMonth(_dt.getMonth() - 1);
mini.get("txtEdate").setValue(_dt);
} else {
if (mini.get("txtEdate").getValue() != "") _dt = mini.get("txtEdate").getValue();
var e = new Date(_dt.getTime());
_dt.setMonth(_dt.getMonth() - 1);
var s = new Date(_dt.getFullYear(), _dt.getMonth(), 1);
e.setDate(0);
mini.get("txtSdate").setValue(s);
mini.get("txtEdate").setValue(e);
}
}
function set_SearchCurMonth(_dt) {
if (mini.get("txtSdate") != undefined) {
var s = new Date(_dt.getFullYear(), _dt.getMonth(), 1);
mini.get("txtSdate").setValue(s);
}
mini.get("txtEdate").setValue(_dt);
}
function set_SearchNextMonth(_dt) {
if (mini.get("txtSdate") == undefined) {
_dt = mini.get("txtEdate").getValue();
_dt.setMonth(_dt.getMonth() + 1);
mini.get("txtEdate").setValue(_dt);
} else {
if (mini.get("txtEdate").getValue() != "") _dt = mini.get("txtEdate").getValue();
var e = new Date(_dt.getTime());
_dt.setMonth(_dt.getMonth() + 1);
var s = new Date(_dt.getFullYear(), _dt.getMonth(), 1);
e.setMonth(e.getMonth() + 2);
e.setDate(-1);
mini.get("txtSdate").setValue(s);
mini.get("txtEdate").setValue(e);
}
}
function getColumns(columns) {
columns = grid.getBottomColumns().clone();
for (var i = columns.length - 1; i >= 0; i--) {
var column = columns[i];
if (!column.field) {
columns.removeAt(i);
} else {
var c = { header: column.header, field: column.field };
columns[i] = c;
}
}
return columns;
}
function getColumnsHeader(columns) {
columns = grid.getBottomColumns().clone();
var arr = new Array();
for (var i = columns.length - 1; i >= 0; i--) {
var column = columns[i];
if (!column.field) {
columns.removeAt(i);
} else {
arr.push(column.header);
}
}
return arr.join(",");
}
String.prototype.asCurrency = function () {
var f1 = this;
var f2 = (Math.round((f1 - 0) * 100)) / 100;
f2 = Math.floor(f2) == f2 ? f2 + ".00" : (Math.floor(f2 * 10) == f2 * 10) ? f2 + '0' : f2;
f2 = String(f2);
r = /(\d+)(\d{3})/;
fs = String(f2);
while (r.test(f2)) {
f2 = f2.replace(r, '$1' + ',' + '$2');
}
return ('¥' + f2); // TODO 没考虑金额为负的情况
}
//格式化时间
function formatDateFn(e) {
if (e.value == "") return "未确定";
var dt = GetCurDate();
var result = formatTdate(e.value, "yyyy-MM-dd");
var res = e.record;
if (getTaskMinute(res.DispatchTime) > -3) {
e.rowCls = "flag_row";
return "" + result + "";
}
if (result == dt.format("yyyy-MM-dd")) {
return "" + result + "";
}
return result;
}
function getLastDay(dt) {
var new_year = dt.getFullYear(); //取当前的年份
var new_month = dt.getMonth() + 1;//取下一个月的第一天,方便计算(最后一天不固定)
if (new_month > 12) //如果当前大于12月,则年份转到下一年
{
new_month -= 12; //月份减
new_year++; //年份增
}
var new_date = new Date(new_year, new_month, 1); //取当年当月中的第一天
return (new Date(new_date.getTime() - 1000 * 60 * 60 * 24));//获取当月最后一天日期
}
function getTaskMinute(dt2) {
var dt = GetCurDate();
return (dt2 - dt) / (1000 * 60)
}
function getDayMinute(dt2) {
var dt = GetCurDate();
return (dt2.getTime() - dt.getTime()) / (1000 * 60 * 60 * 24);
}
function getDiffDay(dt2) {
var dt = GetCurDate();
return Math.floor((dt.getTime() - dt2.getTime()) / (1000 * 60 * 60 * 24));
}
//工程名称
function ennameFn(e) {
//#6F5315
return "" + e.value + "";
}
function bodyFn(e) {
return "" + e.value + "";
}
$(document).keydown(function (e) {
switch (e.which) {
case 8://back
{
var targ = null;
if (e.target) targ = e.target;
else targ = e.srcElement;
if ((targ.type == "textarea" && (targ.getAttribute("readonly") == null || targ.getAttribute("readonly") == "")) || targ.type == "text") return true;
else return false;
break;
}
case 27://ESC
{
if (opCloseFn != undefined) opCloseFn();
break;
}
case 13://回车
{
hideKB();
break;
}
}
});
function getColumns(columns) {
columns = grid.getBottomColumns().clone();
for (var i = columns.length - 1; i >= 0; i--) {
var column = columns[i];
if (!column.field) {
columns.removeAt(i);
} else {
var c = { header: column.header, field: column.field };
columns[i] = c;
}
}
return columns;
}
function fDouble(v) {
if (v == undefined || v == "") return 0;
var m = parseFloat(v);
if (m == 0) return 0;
return Math.round(parseFloat(m) * 100) / 100;
}