- /**
- * 用于控制数据的游标
- */
- var currentIndex = 0;
- var currentData = new Array();
- var dataVector = new Array();
- var isInit = false;
- var buttonTarget;
- /**
- * 同步当前数据
- */
- function setCurrent(){
- currentData = dataVector[currentIndex];
- currentNode = nodeVector[currentIndex];
- }
- /**
- * 同步当前数据,且同时显示当前数据
- */
- function setCurrentItems(){
- setCurrent();
- showItems(currentIndex);
- }
- /**
- * 同步当前保额保费
- */
- function setCurrentDatas(name, count){
- currentData.ScenarioName = name;
- currentData.totalFee = count;
- currentData.PlanNo = 0;
- currentData.PlanInsurance = 0;
- }
- /**
- * 初始化
- */
- function initItems(){
- if(isInit == false){
- dataVector[0] = currentData;
- viewVector[0] = currentView;
- nodeVector[0] = currentNode;
- dataVector.SumAmount = 0;
- dataVector.SumPremium = 0;
- setCurrentDatas("", 0);
- fm.text_itemkindpage_Index.value = 1;
- isInit = true;
- }
- }
- /**
- * 下一个页面
- */
- function nextItems(){
- if(currentIndex < dataVector.length - 1){
- hideItems(currentIndex);
- currentIndex++;
- setCurrentItems();
- }else{
- alert("您已经到最后一页,没有下一页!");
- }
- }
- /**
- * 跳转到指定页数
- * @param index
- */
- function toPointItems(target){
- var index = parseNumber(target.value) - 1;
- if(index >= 0 && index <= dataVector.length - 1){
- target.value = "";
- hideItems(currentIndex);
- currentIndex = index;
- setCurrentItems();
- }else{
- alert("您所指定的页数不在显示范围之内!")
- }
- }
- /**
- * 上一个页面
- */
- function previousItems(){
- if(currentIndex > 0){
- hideItems(currentIndex);
- currentIndex--;
- setCurrentItems();
- }else{
- alert("您已经到第一页,没有上一页!");
- }
- }
- /**
- * 默认初始化时调用一次,每次调用增加一个页数据对象
- */
- function insertItems()
- {
- currentView = new Array();
- viewVector[viewVector.length] = currentView;
- currentNode = new Array();
- nodeVector[nodeVector.length] = currentNode;
- currentData = new Array();
- setCurrentDatas("", 0);
- dataVector[dataVector.length] = currentData;
- hideItems(currentIndex);
- currentIndex = dataVector.length - 1;
- showItems(currentIndex);
- fm.ScenarioName.value = "";
- }
- function handlePlanName(){
- currentData.ScenarioName = fm.ScenarioName.value;
- fm.ScenarioPlanName.value += fm.ScenarioName.value + ",";
- console.log('fm.ScenarioPlanName.value:' + fm.ScenarioPlanName.value);
- }
- /**
- * 删除:至少保证一条记录
- */
- function removeItems(){
- var index = currentIndex;
- if(dataVector.length > 1){
- clearView(index);
- }
- }
- /**
- * 删除一页的数据和显示,从中间删除
- */
- function deleteItems(index){
- if(index < dataVector.length){
- viewVector.splice(index,1);
- nodeVector.splice(index,1);
- dataVector.splice(index,1);
- }
- }
- /**
- * 设置input的可见性
- */
- function showItems(index){
- fm.text_itemkindpage_Index.value = currentIndex + 1;
- fm.ProgramNumber.value = currentIndex + 1;
- fm.ScenarioName.value = currentData.ScenarioName;
- fm.TotalNumber.value = nodeVector.length;
- fm.PlanNo.value = currentData.PlanNo;
- fm.PlanInsurance.value = currentData.PlanInsurance;
- fm.SumAmount.value = countSumAmount('PlanNo');
- fm.SumPremium.value= countSumAmount('PlanInsurance');
- if(index < nodeVector.length){
- for(var i = 0; i < nodeVector[index].length; i++){
- if(nodeVector[currentIndex] && nodeVector[index][i]){
- nodeVector[index][i].style.display= "inline";
- }
- }
- }
- }
- /**
- *
- *
- * @param pageCode
- * @param dataPageCode
- */
- function insertOneRow(pageCode, dataPageCode) {
- var oTBODY = document.getElementById(pageCode).tBodies.item(0);
- var oTBODYData = document.getElementById(dataPageCode).tBodies.item(0);
- var rowsCount = oTBODYData.rows.length;
- var node = oTBODYData.rows[0].cloneNode(true)
- for (var i = 0; i < rowsCount; i++) {
- oTBODY.appendChild(node);
- }
- return node;
- }
- /**
- * 删除最后一页数据的算法。
- * @param index
- */
- function clearView(index){
- var currentView = viewVector[index];
- for(var i=0; i < currentView.length; i++){
- if(currentView[i].parentNode){
- deleteItemKindSub(currentView[i],1,1);
- }
- }
- currentView.length = 0;//删除数据
- deleteItems(index);
- if(index < viewVector.length){
- currentIndex = index;
- setCurrentItems();
- }else{
- currentIndex = viewVector.length - 1;
- setCurrentItems();
- }
- }
- /**
- * "none","inline"
- * @param visible
- */
- function hideItems(currentIndex){
- console.log('nodeVector.length:' + nodeVector.length);
- if(currentIndex < nodeVector.length){
- for(var i=0; i < nodeVector[currentIndex].length; i++){
- if(nodeVector[currentIndex] && nodeVector[currentIndex][i])
- nodeVector[currentIndex][i].style.display= "none";
- }
- }
- }
- /**
- * 准备存放数据的节点对象
- */
- var itemData = new Array();
- /**
- * 操作节点的按钮,可以用来作删除操作
- */
- var viewVector = new Array();
- /**
- * 操作当前页的节点
- */
- var currentView = new Array();
- /**
- * 节点的句柄,控制可见性的
- */
- var nodeVector = new Array();
- /**
- * 当前节点
- */
- var currentNode = new Array();
- /**
- * 记录被克隆的对象的指针
- * @param target
- */
- function addButton(target){
- currentView[currentView.length] = target;
- buttonTarget = target;
- }
- /**
- * 记录克隆出来的对象在页面上的可显示的node
- */
- function addNode(target){
- initItems();
- var itemData = {};
- currentData[currentData.length] = itemData;
- currentNode[currentNode.length] = target;
- }
- function parseNumber(numField){
- var num;
- if(numField == ""){
- num = 0;
- }else{
- num = parseFloat(numField);
- }
- return num;
- }
- /**
- * 依次统计dataVector里面的字段的累积和,field可以是保额,也可以是保费
- * @param field
- * @returns {Number}
- */
- function countSumAmount(field){
- var countResult = 0;
- var filedNumber;
- for(var i = 0; i < dataVector.length; i++){
- filedNumber = dataVector[i][field];
- if(filedNumber > 0){
- countResult += filedNumber;
- }
- }
- console.log(field + ", =" + countResult);
- dataVector[field] = countResult;
- return countResult;
- }
- /**
- * 依次统计currentData里面字段的累积和,field可以是保额, 也可以是保费
- * @param field
- * @returns {Number}
- */
- function countNodeAmount(field){
- var countResult = 0;
- var filedNumber;
- for(var i = 0; i < currentData.length; i++){
- filedNumber = currentData[i][field];
- if(filedNumber > 0){
- countResult += filedNumber;
- }
- }
- console.log(field + ", =" + countResult);
- currentData.field = countResult;
- return countResult;
- }
- function setPlanModeNameMain(target) {
- for(var i = 0; i< currentNode.length; i++){
- if(currentNode[i] == target.parentNode.parentNode){
- console.log("......ok");
- currentData[i].nodeSum = parseNumber(target.value);
- }
- }
- fm.PlanNo.value = countNodeAmount('nodeSum');
- currentData.PlanNo = parseNumber(fm.PlanNo.value);
- fm.SumAmount.value = countSumAmount('PlanNo');
- }
- function setPlanInsurance(target, count){
- for(var i = 0; i< currentNode.length; i++){
- if(currentNode[i] == target.parentNode.parentNode){
- console.log("......ok");
- if(count > 0){
- currentData[i].nodeFee = parseNumber(count);
- }
- }
- }
- fm.PlanInsurance.value = countNodeAmount('nodeFee');
- }
- /**
- * 当一个条款里面的保额、保费、费率改变时,进行相应的数据更改
- * @param target
- */
- function setAmountSub(target){
- var targetName = target.name;
- console.log('targetName:' + targetName);
- if(targetName == 'PlanFinalRateSub'){
- var count = countFees(target);
- currentData.AmountSub = count;
- $(target).parent().next().children(":input").attr("value",count);
- setPlanInsurance(target, count);
- //fm.PlanInsurance.value = parseNumber(fm.PlanInsurance.value) + parseNumber(count);
- }else if(targetName == 'AmountSub'){
- var count = countFeeRate(target);
- currentData.PlanFinalRateSub = count;
- $(target).parent().prev().children(":input").attr("value",count);
- setPlanInsurance(target, target.value);
- //fm.PlanInsurance.value = parseNumber(fm.PlanInsurance.value) + parseNumber(target.value);
- }
- currentData.PlanInsurance = parseNumber(fm.PlanInsurance.value);
- fm.SumPremium.value= countSumAmount('PlanInsurance');
- }
- /**
- * 当一个方案里面的保费改变时通知总保费进行相应的改变
- */
- function onPlanInsuranceChange(){
- checkcalculatefeeandsumpremium();
- setFeeRatios();
- }
- /**
- * 如果计算费率,传来的是最后的费
- * @param target
- */
- function countFeeRate(target){
- var totalFee = $(target).parent().prev().prev().children(":input").val();
- var targetValue = target.value;
- var resultValue = parseNumber(targetValue) / parseNumber(totalFee);
- return resultValue;
- }
- /**
- * 如果计算的是最后的费,传来的是费率
- * @param target
- */
- function countFees(target){
- var totalFee = $(target).parent().prev().children(":input").val();
- var targetValue = target.value;
- var resultValue = parseNumber(targetValue) * parseNumber(totalFee);
- return resultValue.toFixed(2);
- }
- function checkCalculate() {
- return true;
- }
- function insertItemKindMain() {
- var intRowsCount = getRowsCount("ItemKindMain");
- insertRow("ItemKindMain", "ItemKindMain_Data");
- fm.StartDateMain[intRowsCount + 1].value = fm.StartDate.value;
- fm.EndDateMain[intRowsCount + 1].value = fm.EndDate.value;
- resetItemKindNo();
- }
- //该片段来自于http://www.codesnippet.cn/detail/0708201513373.html
来源: http://www.codesnippet.cn/detail/0708201513373.html