所需的事件:页面打开后加载事件,点击onchange事件
一、页面打开对其绑定事件 _private.checkboxOnClick();
二、页面打开对以有的勾选框进行加载 _private.loadComleteEvent();
三、onchange事件:
大纲:点击选中,点击补选中
重要点:每次点击后获取未选中的行id 并对选中的以及未选中行进行标签性保存其属性,下次页面打开时调用该属性反写勾选框
代码实现:
checkboxOnClick: function () {
$("input[type=checkbox]").click(function () {//对界面上类型未checkbox的进行绑定点击事件
waf.dataBinder.storeField(_self.getCurrentModel()); //直接获取界面数据
var allRowId = _private.getAllRowId();//获取所有行id
if ($(this).prop("checked")) { //当这个按钮被选中触发
//初始化金额
var amt = 0;
var arr = new Array();
var arrId = new Array();
var arrIdcb = new Array();
$("#section2 :checkbox[checked]").each(function (i) { //遍历这个表格中所有被选中的行 取其id集合
arrId[i] = $("#section2 :checkbox[checked]").get(i).id;
arrId[i] = arrId[i].split("_"); //此处需要进行截取 因为直接获取出来的id为那个checkBox的id需要从中 取出对应的行id
arrIdcb[i] = arrId[i][0]; //此处取出最上方全选的id 与其他的第0位不一样 以此进行过滤
arrId[i] = arrId[i][arrId[i].length - 1]; //截取出选中的行id
arr[i] = $(this).val();
});
//对两个数据进行相减获取剩下的行id
var a = {};
for (i = 0; i < arrId.length; i++) {
if (!a[arrId[i]]) {
a[arrId[i]] = true;
}
}
for (i = 0; i < allRowId.length; i++) {
if (a[allRowId[i]]) {
allRowId.splice(i, 1); /*从一个数组中第i位移除一个或多个元素*/
i--;
}
}
if (allRowId.length > 0) {
for (i = 0; i < allRowId.length; i++) {
waf("#editGrid0").wafGrid("setCell", allRowId[i], "remark", "0");
}
}
if (arrId.length > 0) {
for (ii = 0; ii < arrId.length; ii++) {
if (arrIdcb[ii] == "cb") { //过滤掉顶部全选的id
continue;
} else {
waf("#editGrid0").wafGrid("setCell", arrId[ii], "remark", "1"); //表格中用于存储勾选框的状态以便下次调用
var griAmt = waf("#editGrid0").wafGrid("getCell", arrId[ii], "returnableAmt");//获取改行的可退金额 //j进行自己的操作
amt += griAmt;
}
}
waf("#beingReturnAmt").wafNumberField("setValue", amt);//可退金额
var withdrawnAmt = waf("#withdrawnAmt").wafNumberField("getValue");
if ((withdrawnAmt != null && withdrawnAmt != "" && withdrawnAmt != undefined) && (amt != null && amt != "" && amt != undefined)) {
waf("#haveVertifiAmt").wafNumberField("setValue", withdrawnAmt - amt);
} else {
waf("#haveVertifiAmt").wafNumberField("setValue", "0.00");
}
} else {
waf("#beingReturnAmt").wafNumberField("setValue", "0.00");//可退金额
var withdrawnAmt = waf("#withdrawnAmt").wafNumberField("getValue");
waf("#haveVertifiAmt").wafNumberField("setValue", withdrawnAmt);
}
} else { //补选中
//初始化金额
var amt = 0;
var arr1 = new Array();
var arrId1 = new Array();
var arrId1cb = new Array();
$("#section2 :checkbox[checked]").each(function (i) {
arrId1[i] = $("#section2 :checkbox[checked]").get(i).id;
arrId1[i] = arrId1[i].split("_");
arrId1cb[i] = arrId1[i][0];
arrId1[i] = arrId1[i][arrId1[i].length - 1];
arr1[i] = $(this).val();
});
//对两个数据进行相减获取剩下的行id
var a = {};
for (i = 0; i < arrId1.length; i++) {
if (!a[arrId1[i]]) {
a[arrId1[i]] = true;
}
}
for (i = 0; i < allRowId.length; i++) {
if (a[allRowId[i]]) {
allRowId.splice(i, 1); /*从一个数组中第i位移除一个或多个元素*/
i--;
}
}
if (allRowId.length > 0) {
for (i = 0; i < allRowId.length; i++) {
waf("#editGrid0").wafGrid("setCell", allRowId[i], "remark", "0");
}
}
//金额进行赋值
if (arrId1.length > 0) {
for (ii = 0; ii < arrId1.length; ii++) {
if (arrId1cb[ii] == "cb") {
continue;
} else {
var griAmt = waf("#editGrid0").wafGrid("getCell", arrId1[ii], "returnableAmt");//获取改行的可退金额
amt += griAmt;
}
}
waf("#beingReturnAmt").wafNumberField("setValue", amt);//可退金额
var withdrawnAmt = waf("#withdrawnAmt").wafNumberField("getValue");
if ((withdrawnAmt != null && withdrawnAmt != "" && withdrawnAmt != undefined) && (amt != null && amt != "" && amt != undefined)) {
waf("#haveVertifiAmt").wafNumberField("setValue", withdrawnAmt - amt);
} else {
waf("#haveVertifiAmt").wafNumberField("setValue", "0.00");
}
} else {
waf("#beingReturnAmt").wafNumberField("setValue", "0.00");//可退金额
var withdrawnAmt = waf("#withdrawnAmt").wafNumberField("getValue");
waf("#haveVertifiAmt").wafNumberField("setValue", withdrawnAmt);
}
}
// }
});
}
网友评论