ArtJS(原创)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ArtJS(原创)相关的知识,希望对你有一定的参考价值。
/*
方法目录;
【IE7 8 不支持trim()方法的弥补】
【 终止冒泡】
【数字千分位】
【js运算的替代方法(js3.3/1.1不等于3浮点计算有bug)】
【日期加减天数,两日期相减】
【页面如果想使用终止冒泡,则在页面调用此方法;类ArtJS_stopMaopao点击会终止冒泡;类ArtJs_removeAfterDomClick dom点击会remove或者hide】
【元素下方呈现带有三角形的div】
【table实现类似excel搜索】
【table排序】
【弥补layer.msg只能同一时间使用一个,第二个会覆盖第一个的效果】
*/
; (function (a, $) {
//【IE7 8 不支持trim()方法】
String.prototype.trim = function () {
return this.replace(/^\s\s*/, ‘‘).replace(/\s\s*$/, ‘‘);
}
var ArtJS = {};
/*
【 终止冒泡】
对于 动态元素的事件绑定(比如 live ),stopMaopao无效果,需要在方法内使用return false;即可。
使用冒泡,则使用冒泡的元素内部的同样的事件,只能冒泡到当前元素上就会终止冒泡。所以内部元素的live不会冒泡到document起作用(直接在元素上onclick能起作用)。不过可以使用, on(delegate) 的方式,使事件监听不冒泡到document对象而是冒泡到使用冒泡的元素身上即可。{live是把动态元素事件的监听放到document上;delegate是把动态元素事件的监听放到指定的对象上,高版本的jquery推荐使用on}
使用时候的注意点:event参数需要来自于要使用终止冒泡的方法绑定时候的参数中;
情况1-> <input type=‘button‘ value=‘按钮‘ onclick=‘btnClick(event,其他参数)‘/>
情况2-> <input type=‘button‘ value=‘按钮‘ id=‘testbtn‘/> $(‘#testbtn‘).click(funtion(event,其他参数){})
情况3-> $(‘#testbtn‘).live(‘click‘,function(其他参数){ 逻辑代码; return false;})
return false 就可以终止冒泡。
*/
ArtJS.stopMaopao = function (event) {
var evt = event || window.event;
if (evt.stopPropagation) { //W3C阻止冒泡方法
evt.stopPropagation();
} else {
evt.cancelBubble = true; //IE阻止冒泡方法
}
}
/*
【数字千分位】
数字千位分,只负责把数字类型的数据转换成千位分的字符串。如需要小数和四舍五入等则在千位分之前进行处理。
*/
ArtJS.toThousandSplit = function (num) {
//1.先去除空格,判断是否空值和非数
num = num + "";
num = num.replace(/[^\d.]/g, "");
num = num.replace(/^\./g, ""); //第一个不能是.
num = num.replace(".", "f").replace(/\./g, "").replace("f", "."); //仅保留第一个小数点
if (num == "") {
return "";
}
//2.针对是否有小数点,分情况处理
var index = num.indexOf(".");
if (index == -1) {//无小数点
var reg = /(-?\d+)(\d{3})/;
while (reg.test(num)) {
num = num.replace(reg, "$1,$2");
}
} else {
var intPart = num.substring(0, index);
var pointPart = num.substring(index + 1, num.length);
var reg = /(-?\d+)(\d{3})/;
while (reg.test(intPart)) {
intPart = intPart.replace(reg, "$1,$2");
}
num = intPart + "." + pointPart;
}
return num;
}
ArtJS.deThousandSplit = function (numStr) {
numStr = numStr.replace(/[ ]/g, ""); //去除空格
numStr = numStr.replace(/,/gi, ‘‘);
return numStr;
}
ArtJS.autoThousandSplit = function (val) {
val = val.toString();
if (val.indexOf(",") > -1) {
return nameSpace.duyupu.deThousandSplit(val);
} else {
return nameSpace.duyupu.toThousandSplit(val);
}
}
//【js运算的替代方法(js3.3/1.1不等于3浮点计算有bug)】
ArtJS.A = function (arg1, arg2) {
var r1, r2, m;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2))
return (T(arg1, m) + T(arg2, m)) / m
}
//减
ArtJS.M = function (arg1, arg2) {
var r1, r2, m, n;
try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
m = Math.pow(10, Math.max(r1, r2));
//动态控制精度长度
n = (r1 >= r2) ? r1 : r2;
return ((T(arg1, m) - T(arg2, m)) / m).toFixed(n);
}
//乘
ArtJS.T = function (arg1, arg2) {
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
try { m += s1.split(".")[1].length } catch (e) { }
try { m += s2.split(".")[1].length } catch (e) { }
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
//除
ArtJS.D = function (arg1, arg2) {
var t1 = 0, t2 = 0, r1, r2;
try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
with (Math) {
r1 = Number(arg1.toString().replace(".", ""))
r2 = Number(arg2.toString().replace(".", ""))
return (r1 / r2) * pow(10, t2 - t1);
}
}
//【日期加减天数,两日期相减】
//日期加天数
ArtJS.dateAddDays = function (primaryDay, addDays) {
var primaryDay = primaryDay.split("-");
if (primaryDay[1].indexOf("0") == 0) {
primaryDay[1] = parseInt(primaryDay[1].replace("0", ""));
}
primaryDay[1] = primaryDay[1] - 1;
var nDate = new Date(primaryDay[0], primaryDay[1], primaryDay[2]); // new Date(年,月,日) 出来的日期,月份加1
var millSeconds = Math.abs(nDate) + (addDays * 24 * 60 * 60 * 1000);
var rDate = new Date(millSeconds);
var year = rDate.getFullYear();
var month = rDate.getMonth() + 1;
if (month < 10) month = "0" + month;
var date = rDate.getDate();
if (date < 10) date = "0" + date;
return (year + "-" + month + "-" + date);
}
//日期减天数
ArtJS.dateRemoveDays = function (primaryDay, addDays) {
var primaryDay = primaryDay.split("-");
if (primaryDay[1].indexOf("0") == 0) {
primaryDay[1] = parseInt(primaryDay[1].replace("0", ""));
}
primaryDay[1] = primaryDay[1] - 1;
var nDate = new Date(primaryDay[0], primaryDay[1], primaryDay[2]);
var millSeconds = Math.abs(nDate) - (addDays * 24 * 60 * 60 * 1000);
var rDate = new Date(millSeconds);
var year = rDate.getFullYear();
var month = rDate.getMonth() + 1;
if (month < 10) month = "0" + month;
var date = rDate.getDate();
if (date < 10) date = "0" + date;
return (year + "-" + month + "-" + date);
}
//两日期相减
ArtJS.twoDateMinus = function (date1, date2) {
var d1 = date1.split("-");
if (d1[1].indexOf("0") == 0) {
d1[1] = parseInt(d1[1].replace("0", ""));
}
d1[1] = d1[1] - 1;
var rd1 = new Date(d1[0], d1[1], d1[2]);
var d2 = date2.split("-");
if (d2[1].indexOf("0") == 0) {
d2[1] = parseInt(d2[1].replace("0", "") - 1);
}
d2[1] = d2[1] - 1;
var rd2 = new Date(d2[0], d2[1], d2[2]);
var millSeconds = Math.abs(Math.abs(rd1) - Math.abs(rd2));
return Math.abs(millSeconds / (24 * 60 * 60 * 1000));
}
/*
Example:
var now = new Date();
var y = now.getFullYear();//获取时间中的年份
var m = now.getMonth()+1;//获取时间中的月份 月份 0-11 所以,需要加1
var d = now.getDate();//获取时间中的几号
//转换成可以用来加减,处理的格式 年-月-日
var formatNow = y + "-" + m + "-" + d;
var result = ArtJS.dateAddDays(formatNow, 11);
alert(result);
ArtJS.twoDateMinus(‘2016-09-30‘,‘2016-10-1‘)
*/
//【页面如果想使用终止冒泡,则在页面调用此方法;ArtJS_stopMaopao点击会终止冒泡;ArtJs_removeAfterDomClick dom点击会remove】添加类 ArtJS_stopMaopao 就会终止冒泡到 document
ArtJS.setStopMaopaoAfterDomClickRemove = function () {
setStopMaopaoAfterDomClick("ArtJS_stopMaopao", "ArtJs_removeAfterDomClick", "remove");
}
//内部方法,
function setStopMaopaoAfterDomClick(stopMaopaoClass, documentClickHideClass, removeOrHide) {
if ($.fn.on == null) {
$("." + stopMaopaoClass).live(‘click‘, function (event) {
ArtJS.stopMaopao(event);
});
}
else {
$(document).on(‘click‘, "." + stopMaopaoClass, function (event) {
ArtJS.stopMaopao(event);
});
}
$(document).click(function () {
if (documentClickHideClass != null) {
var dom = $("." + documentClickHideClass);
if (dom.length > 0) {
if (removeOrHide == "remove") {
dom.remove();
}
else {
dom.hide();
}
}
}
});
}
ArtJS.setStopMaopaoAfterDomClickHide = function () {
setStopMaopaoAfterDomClick("ArtJS_stopMaopao", "ArtJs_removeAfterDomClick", ‘hide‘);
}
//【下方呈现带有三角形的div】
ArtJS.showWithTriDiv = function (single, cont) {
var those = $(single);
if ($("#triangleDiv_add").length > 0) {
$("#triangleDiv_add").remove();
}
var left = $(single).offset().left;
var top = $(single).offset().top + $(single).outerHeight() + 10;
$("body").append("<div id=‘triangleDiv_add‘ class=‘ArtJS_stopMaopao ArtJs_removeAfterDomClick‘ style=‘ position: absolute;border-radius: 4px;border: 1px solid #545050;box-shadow: 1px 1px 5px #d1d1d1; -webkit-box-shadow: 1px 1px 5px gray;left:" + left + "px;top:" + top + "px;‘><em style=‘position: absolute; left: 10px;margin-top: -11px;width: 0; height: 0; border-right: 10px solid transparent; border-left: 10px solid transparent;border-bottom: 10px solid #1e242b; z-index: 5;‘></em><i style=‘position: absolute;left: 10px; margin-top: -10px;width: 0; height: 0;border-right: 10px solid transparent; border-left: 10px solid transparent;border-bottom: 10px solid white;z-index: 5;‘></i><div style=‘ padding: 20px;overflow: auto; max-height: 300px; word-wrap: break-word; word-break: break-all;white-space: normal;‘>" + cont + "</div></div>");
}
//【弥补layer.msg只能同一时间使用一个,第二个会覆盖第一个的效果】
ArtJS.msg=function (cont,time,cssParam) {
$("#addedMsg").remove();
$(‘body‘).append("<div id=‘addedMsg‘ style=‘display:table;‘>" + cont + "</div>");
var defaultParam = { "z-index": 5000, "color": "white", "background-color": "#AD8585", "padding": "10px", "position": "fixed", "left": "50%", "top": "50%" };
var css = $.extend({}, defaultParam, cssParam);
var $msg = $("#addedMsg");
if (cssParam != null && cssParam.right != null) {
}
else {
css["margin-top"] = (0 - $msg.width() / 2) + "px";
}
if (cssParam != null && cssParam.right != null) {
}
else {
css["margin-left"] = (0 - $msg.width() / 2) + "px";
}
setTimeout(function () {
$("#addedMsg").remove();
}, time);
$msg.css(css);
}
a.ArtJS = ArtJS;
//===============================
// 【excel搜索】 依赖 json2.js jquery.js my97datepickeer
$.fn.useExcelFilter = function (submitOrAjaxSearch, cssObj) {
var those = this;
var defaultMainCss = { "width": "220px", "height": "350px", "position": "absolute", "z-index": "888", "border": "1px solid gray", "background-color": "white", "border-radius": "4px", "display": "none" };
$(".useExcelFilter_Main_div").remove(); //如果有先删除
var realMainCss = {}; $.extend(realMainCss, defaultMainCss, cssObj);
$("body").append("<div class=‘useExcelFilter_Main_div‘><div class=‘useExcelFilter_Main_div_cont‘ style=‘margin-left:20px; margin-right:20px;‘></div><div class=‘useExcelFilter_Main_div_bottom‘ style=‘position:absolute;bottom:15px;margin:0px auto;width:100%;text-align:center‘><span style=‘color:white;padding-top:3px;padding-bottom:3px;padding-left:5px;padding-right:5px;border-radius:4px;cursor:pointer;color: #fff; background-color: #337ab7;border-color: #2e6da4;‘ id=‘excel_sure‘>确定</span> <span style=‘background-color:red;color:white;padding-top:3px;padding-bottom:3px;padding-left:5px;padding-right:5px;border-radius:4px;cursor:pointer; color: #333; background-color:#E0C3C3; border-color: #ccc;‘ id=‘excel_sure_not‘ >取消</span></div></div>");
$(‘body‘).append("<style>.excel_li:hover,.useExcelFilter_Main_div_sortul li:hover{cursor:pointer;} .useExcelFilter_Main_div_ul{color:black;}.Excel_unsearched{display:none;} .useExcelFilter_Main_div_ul li{word-break: keep-all;white-space:nowrap;}</style>");
$(".useExcelFilter_Main_div").css(realMainCss);
$(".useExcelFilter_Main_div").click(function (event) {
var evt = event || window.event;
if (evt.stopPropagation) { //W3C阻止冒泡方法
evt.stopPropagation();
} else {
evt.cancelBubble = true; //IE阻止冒泡方法
}
});
$(this).click(function (event) {
var that = this;
if ($(that).hasClass("excelclicked")) {
$(".useExcelFilter_Main_div").hide();
return;
}
$(those).removeClass("excelclicked");
$(that).addClass("excelclicked");
var jsonDataMark = $(that).attr("jsonDataMark");
var jsonDataType = $(that).attr("jsonDataType");
var excelJsonStr = $("#excelJsonStr").val();
var excelJson = $.parseJSON(excelJsonStr);
var thisObjJson = null;
if (excelJson != null) {
thisObjJson = excelJson[jsonDataMark];
}
// var uls = "<ul class=‘useExcelFilter_Main_div_sortul‘ style=‘border-bottom:1px solid gray;‘><li>升序 ↑</li><li>降序 ↓</li></ul>";
var uls = "";
//字符串
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "1") {
uls = uls + "<input type=‘text‘ style=‘box-shadow:none; height:30px;margin-top:20px; padding:5px 2px;width:100%;‘ placeholder=‘搜索‘ id=‘excel_search_text‘/><div style=‘overflow-y:auto;height:" + (parseFloat(realMainCss.height.replace(‘px‘, ‘‘)) - 110) + "px;margin-top:10px;‘><ul class=‘useExcelFilter_Main_div_ul‘><li onclick=‘$(this).find(\":checkbox\").click()‘ class=‘excel_li fisrtli‘><input type=‘checkbox‘ class=‘excel_cb_all excel_cb‘/> <span>全选</span></li>";
$.each(thisObjJson, function (a, b) {
if (b.isChecked) {
uls = uls + "<li class=‘excel_li‘ onclick=‘$(this).find(\":checkbox\").click()‘><input type=‘checkbox‘ class=‘excel_cb‘ value=‘" + b.dbVal + "‘ checked=‘checked‘/> <span>" + b.showVal + "</span></li>";
}
else {
uls = uls + "<li class=‘excel_li‘ onclick=‘$(this).find(\":checkbox\").click()‘><input type=‘checkbox‘ class=‘excel_cb‘ value=‘" + b.dbVal + "‘ /> <span>" + b.showVal + "</span></li>";
}
});
uls = uls + "</ul></div>";
}
//金钱类型
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "2") {
uls = uls + "<div style=‘margin-top:20px;color:black;‘ class=‘execle_money_div‘>金额范围 <span style=‘color:white;padding-left:5px;padding-right:5px;border-radius:4px;cursor:pointer; color: #333; background-color:#E0C3C3; border-color: #ccc;‘ id=‘excel_typeclear‘>清空</span><br/><input type=‘text‘ style=‘width:100%;height:30px;box-shadow:none;‘ placeholder=‘¥‘ class=‘inputmoney‘ value=‘" + thisObjJson[0].moneyMin + "‘/> <br/> ↓<input type=‘text‘ style=‘width:100%;height:30px;box-shadow:none;‘ placeholder=‘¥‘ class=‘inputmoney‘ value=‘" + thisObjJson[0].moneyMax + "‘/></div>";
}
//时间类型
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "3") {
uls = uls + "<div style=‘margin-top:20px;color:black;‘ class=‘execle_date_div‘>日期范围 <span style=‘color:white;padding-left:5px;padding-right:5px;border-radius:4px;cursor:pointer; color: #333; background-color:#E0C3C3; border-color: #ccc;‘ id=‘excel_typeclear‘>清空</span><br/><input type=‘text‘ style=‘width:100%;height:30px;box-shadow:none;‘ class=‘Wdate‘onFocus=‘WdatePicker()‘ value=‘" + thisObjJson[0].timeMin + "‘/> <br/> ↓<input type=‘text‘ style=‘width:100%;height:30px;box-shadow:none;‘ class=‘Wdate‘ onFocus=‘WdatePicker()‘ value=‘" + thisObjJson[0].timeMax + "‘ /></div>";
}
//添加前移除已经存在的
$(".useExcelFilter_Main_div_cont").find("div,input,ul").remove().end().append(uls);
//字符串
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "1") {
if ($(".excel_cb:not(‘.excel_cb_all‘)").length == $(".excel_cb:not(‘.excel_cb_all‘):checked").length) {
$(".excel_cb_all").attr("checked", "checked");
}
else {
$(".excel_cb_all").removeAttr("checked");
}
//全选按钮
$(".excel_cb").click(function (event) {
if ($(this).hasClass("excel_cb_all")) {
if ($(this).is(":checked")) {
$(".excel_cb").attr("checked", "checked");
}
else {
$(".excel_cb").removeAttr("checked");
}
}
var evt = event || window.event;
if (evt.stopPropagation) { //W3C阻止冒泡方法
evt.stopPropagation();
} else {
evt.cancelBubble = true; //IE阻止冒泡方法
}
});
//搜索框keyup
$("#excel_search_text").keyup(function () {
var xcont = $(this).val();
if (xcont == "") {
$(".useExcelFilter_Main_div_ul li").removeClass("Excel_unsearched");
return;
}
var lis = $(".excel_li").not(".fisrtli");
$.each(lis, function (c, d) {
if ($(d).find("span").text().indexOf(xcont) >= 0) {
$(d).removeClass("Excel_unsearched");
}
else {
$(d).addClass("Excel_unsearched");
}
});
});
}
//金钱类型
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "2") {
$(".inputmoney").keyup(function () {
var num = $(this).val();
//1.先去除空格,判断是否空值和非数
num = num + "";
num = num.replace(/[^\d.]/g, ""); //非数字和.的替换掉
num = num.replace(/^\./g, ""); //第一个不能是.
num = num.replace(".", "f").replace(/\./g, "").replace("f", "."); //仅保留第一个小数点
if (num == "") {
return;
}
//2.针对是否有小数点,分情况处理
var index = num.indexOf(".");
if (index == -1) {//无小数点
var reg = /(-?\d+)(\d{3})/;
while (reg.test(num)) {
num = num.replace(reg, "$1,$2");
}
} else {
var intPart = num.substring(0, index);
var pointPart = num.substring(index + 1, num.length);
var reg = /(-?\d+)(\d{3})/;
while (reg.test(intPart)) {
intPart = intPart.replace(reg, "$1,$2");
}
num = intPart + "." + pointPart;
}
$(this).val(num);
});
$(".inputmoney").focusout(function () {
var num = $(this).val();
//1.先去除空格,判断是否空值和非数
num = num + "";
num = num.replace(/[^\d.]/g, ""); //非数字和.的替换掉
num = num.replace(/^\./g, ""); //第一个不能是.
num = num.replace(".", "f").replace(/\./g, "").replace("f", "."); //仅保留第一个小数点
if (num == "") {
return;
}
//2.针对是否有小数点,分情况处理
var index = num.indexOf(".");
if (index == -1) {//无小数点
var reg = /(-?\d+)(\d{3})/;
while (reg.test(num)) {
num = num.replace(reg, "$1,$2");
}
} else {
var intPart = num.substring(0, index);
var pointPart = num.substring(index + 1, num.length);
var reg = /(-?\d+)(\d{3})/;
while (reg.test(intPart)) {
intPart = intPart.replace(reg, "$1,$2");
}
num = intPart + "." + pointPart;
}
$(this).val(num);
});
$("#excel_typeclear").click(function () {
$(".useExcelFilter_Main_div").find(":text").val("");
});
}
//时间类型
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "3") {
$("#excel_typeclear").click(function () {
$(".useExcelFilter_Main_div").find(":text").val("");
});
}
$(".useExcelFilter_Main_div").css({ "left": $(that).offset().left, "top": ($(that).offset().top + $(that).outerHeight()) });
$(".useExcelFilter_Main_div").show();
$("#excel_sure_not").unbind(‘click‘).click(function () {
$(document).click();
});
//
$("#excel_sure").unbind(‘click‘).click(function () {
//字符串
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "1") {
var checkedCBs = $(".excel_cb:not(‘.excel_cb_all‘):visible:checked");
var str = ‘,‘;
$.each(checkedCBs, function (m, n) {
str = str + $(n).val() + ",";
});
$.each(thisObjJson, function (h, m) {
if (str.indexOf("," + m.dbVal + ",") >= 0) {
m.isChecked = true;
}
else {
m.isChecked = false;
}
});
$("#excelJsonStr").val(JSON.stringify(excelJson));
submitOrAjaxSearch();
}
//金钱
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "2") {
var inputMoney = $(".execle_money_div").find(".inputmoney");
thisObjJson[0].moneyMin = $(inputMoney[0]).val();
thisObjJson[0].moneyMax = $(inputMoney[1]).val();
debugger;
$("#excelJsonStr").val(JSON.stringify(excelJson));
submitOrAjaxSearch();
}
//时间
if (thisObjJson != null && thisObjJson.length > 0 && jsonDataType == "3") {
var inputDate = $(".execle_date_div").find(":text");
thisObjJson[0].timeMin = $(inputDate[0]).val();
thisObjJson[0].timeMax = $(inputDate[1]).val();
$("#excelJsonStr").val(JSON.stringify(excelJson));
submitOrAjaxSearch();
}
$(document).click();
});
//终止冒泡
var evt = event || window.event;
if (evt.stopPropagation) { //W3C阻止冒泡方法
evt.stopPropagation();
} else {
evt.cancelBubble = true; //IE阻止冒泡方法
}
});
$(document).click(function (event) {
$(".useExcelFilter_Main_div").hide();
$(those).removeClass("excelclicked");
});
}
/*
<input type="hidden" name="excelJsonStr" value=‘<%=excelJsonStr %>‘ id=‘excelJsonStr‘ />
<td>
<div align="center" style=‘width: 80px;‘ >
销售人员
<img src="../images/excel.png" paixu="order_type" style=" cursor:pointer" class=‘useWidthSort‘ jsonDataMark =‘xiaoShou‘ jsonDataType="1"/>
</div>
</td>
<td>
<div align="center" style=‘width: 150px;‘ >
发票申请人
<img src="../images/excel.png" paixu="order_type" style=" cursor:pointer" class=‘useWidthSort‘ jsonDataMark =‘shenQingRen‘ jsonDataType="1"/>
</div>
</td>
<td >
<div align="center" style=‘width: 120px;‘ >
申请日期
<img src="../images/excel.png" paixu="order_type" style=" cursor:pointer" class=‘useWidthSort‘ jsonDataMark =‘shenDate‘ jsonDataType="3"/>
</div>
</td>
<td>
<div align="center" style=‘width: 110px;‘ >
认款金额 <img src="../images/excel.png" paixu="order_type" style=" cursor:pointer" class=‘useWidthSort‘ jsonDataMark =‘renKuanMoney‘ jsonDataType="2"/></div>
</td>
后台
//后台接受从前台传递过来的excle数据值
string excelJsonStr = Request["excelJsonStr"];
System.Web.Script.Serialization.javascriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
jsonModel4 jm = null;
if (!string.IsNullOrEmpty(excelJsonStr))
{
jm = js.Deserialize<jsonModel4>(excelJsonStr);
//销售
var xiaoShous = jm.xiaoShou.Where(t => t.isChecked == true);
//申请人
var shenWingRens = jm.shenQingRen.Where(t => t.isChecked == true);
//认款金额
List<basicExcelModel4> renMoney = jm.renKuanMoney.Where(t => t.moneyMin != "" || t.moneyMax != "").ToList();
//申请日期
List<basicExcelModel4> shenDate = jm.shenDate.Where(t => t.timeMin != "" || t.timeMax != "").ToList();
StringBuilder sbb = new StringBuilder();
#region 销售
foreach (var item in xiaoShous)
{
sbb.Append(item.dbVal + ",");
}
if (sbb.ToString() != "")
{
sb.Append(" and fpxsid in (" + sbb.ToString().Trim(‘,‘) + ")");
}
else//什么也没选 空
{
sb.Append(" and fpxsid in (-1)");
}
#endregion
sbb = new StringBuilder();
#region 申请人
foreach (var item in shenWingRens)
{
sbb.Append(item.dbVal + ",");
}
if (sbb.ToString() != "")
{
sb.Append(" and fpxzid in (" + sbb.ToString().Trim(‘,‘) + ")");
}
else//什么也没选 空
{
sb.Append(" and fpxzid in (-1)");
}
#endregion
sbb = new StringBuilder();
#region 认款金额
if (renMoney.Count>0)
{
string moneyMin = renMoney[0].moneyMin;
string moneyMax = renMoney[0].moneyMax;
if (moneyMin != "")
{
sb.Append(" and fapUsedMoney >=" + moneyMin.Replace(",", ""));
}
if (moneyMax != "")
{
sb.Append(" and fapUsedMoney <=" + moneyMin.Replace(",", ""));
}
}
#endregion
sbb = new StringBuilder();
#region 申请日期
if (shenDate.Count>0)
{
string dateMin = shenDate[0].timeMin;
string dateMax = shenDate[0].timeMax;
if (dateMin!="")
{
sb.Append(" and fpcreateddate >= ‘" + dateMin+"‘");
}
if (dateMax != "")
{
sb.Append(" and fpcreateddate <= ‘" + dateMax + "‘");
}
}
#endregion
}
else
{
MakeJsonStr();
}
void MakeJsonStr()
{
//要被序列化的对象
jsonModel4 jm = new jsonModel4();
//excel 销售
List<basicExcelModel4> xiaosohu = new List<basicExcelModel4>();
//excel 申请人
List<basicExcelModel4> xz = new List<basicExcelModel4>();
//获取excle数据源
DataSet ds = FapiaoManageRule.GetExcel();
if (ds != null && ds.Tables.Count > 0)
{
var rows = ds.Tables[0].Rows;
foreach (DataRow item in rows)
{
xiaosohu.Add(new basicExcelModel4()
{
dbVal = item["fpxsid"].ToString(),
isChecked = true,
showVal = item["xsname"].ToString()
});
}
var rows2 = ds.Tables[1].Rows;
foreach (DataRow item in rows2)
{
xz.Add(new basicExcelModel4() { dbVal = item["fpxzid"].ToString(), isChecked = true, showVal = item["xzname"].ToString() });
}
}
jm = new jsonModel4();
jm.xiaoShou = xiaosohu;
jm.shenQingRen = xz;
jm.renKuanMoney = new List<basicExcelModel4>() { new basicExcelModel4() { } };
jm.shenDate = new List<basicExcelModel4>() { new basicExcelModel4() { } };
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
excelJsonStr = js.Serialize(jm);
}
class jsonModel4
{
public List<basicExcelModel4> xiaoShou { get; set; }
public List<basicExcelModel4> shenQingRen { get; set; }
public List<basicExcelModel4> renKuanMoney { set; get; }
public List<basicExcelModel4> shenDate { set; get; }
}
class basicExcelModel4
{
//1 字符串
public string dbVal = "";
public string showVal = "";
public bool isChecked = false;
//2 金钱
public string moneyMin = "";
public string moneyMax = "";
// 3 时间
public string timeMin = "";
public string timeMax = "";
}
*/
//【排序】
//【排序】
$.fn.useSort = function (afterDeal) {
var those = this;
//点击排序
$(this).click(function () {
var that = this;
var sort = $(that).attr("sort"); //排序标记
var sortStr = "";
debugger;
//如果是 升序排序
if (sort.indexOf("asc") >= 0) {
sortStr = sort.replace("asc", "desc");
$(that).attr("sort", sortStr);
}
//倒叙,或者 还没有排序
else {
sortStr = sort.replace("desc", "") + " asc ";
$(that).attr("sort", sortStr);
}
var focusedSorts = $(".focusedSort").not(that);
if (focusedSorts.length > 0) {
$.each(focusedSorts, function (x, y) {
$(y).attr("sort", $(y).attr("sort").replace("desc", "").replace("asc", ""));
});
}
focusedSorts.removeClass("focusedSort");
$(that).addClass("focusedSort");
$("#hiddenSortStr").val(sortStr);
afterDeal(that);
});
}
/*
<input type="hidden" name="hiddenSortStr" value="" id=‘hiddenSortStr‘/>
$(".sortIcon").useSort(afterDealsort);
function afterDealsort(a) {
var sort = $(a).attr("sort");
$.each($(".sortIcon"), function () {
$(this).attr("src", "../images/details_open.png");
});
if (sort.indexOf("asc")>=0) {
$(a).attr("src", "../images/details_close.png");
}
else {
$(a).attr("src", "../images/details_open.png");
}
ajaxGetData();
}
后台
private string GetSort()
{
string sort = " order by a.statu asc, sort asc, a.autoid desc";
string hiddenSortStr = Request["hiddenSortStr"];
if (!string.IsNullOrEmpty(hiddenSortStr))
{
string sortField = hiddenSortStr.Replace("asc", "").Replace("desc", "").Trim();
string sortType = hiddenSortStr.IndexOf("asc")>=0 ?"asc":"desc";
switch (sortField)
{
case "zhuangtai":
if (sortType == "desc")
{
sort = " order by t.astatu desc, sort asc, aid desc";
}
else
{
sort = " order by t.astatu asc, sort asc, aid desc";
}
break;
case "liushui":
sort = " order by a.waternumber " + sortType;
break;
case "daoqi":
sort = " order by b.endDate " + sortType;
break;
case "kaishouju":
sort = " order by a.ksjdate " + sortType;
break;
case "shouju":
sort = " order by a.sydsjh " + sortType;
break;
}
}
return sort;
}
*/
})(window, jQuery);
/*
把window作为参数传入,据说好处 1 提高性能; 2 可以把window定义成a; 压缩js文件减少代码;
*/
|
以上是关于ArtJS(原创)的主要内容,如果未能解决你的问题,请参考以下文章