JS前端動態新增表格--包括合併指定單元格
阿新 • • 發佈:2018-12-30
var newRow = "";//全域性變數
var pubSum=1;//計數新增記錄次數
var panelTitle=$("#title").val();
var currExtBJ="";
var existMatterPrice=$("#matter_price").val();
var isDisplay=$("#isDisplay").val();
var existMatter_bjsj=$("#matter_bjsj").val();
var matter_stotal=$("#matter_stotal").val();
var matter_hjje=$("#matter_hjje").val();
var currentCount=$("#currentCount").val();
var matterSize=$("#listMatterSize").val();
var len=parseInt($("#_listsize").val());//標的物的個數
var len1=parseInt($("#_listsize1").val());//有幾條資料
var currUnit=$("#currUnit").val();//計價單位
var currCurrency=$("#currCurrency").val();//計價單位
var bidding=$("#bidding").val();//bidding
var biddings=$("#biddings").val();//bidding
var phase_Id=$("#phase_Id").val();//bidding
var matterArr=$("#matterStr").val().split(",");
var matterIdArr=$("#matterIdStr").val().split(",");
var matterCountArr=$("#matterCountStr").val().split(",");
var matterSpecStr=$("#matterSpecStr").val().split(",");
var matter_hjjeArr=matter_hjje.split(",");
var existMatterPriceArr=existMatterPrice.split(",");
var matter_stotalArr=matter_stotal.split(",");
var bjsj=getNowFormatDate();
var isValid=true;
var count_Str=$("#count_Str").val();
var result=new Array();//創建出一個結果陣列
result=deDuplication(count_Str);//創建出一個結果陣列
if(Number(currentCount)>0){
pubSum=currentCount;//如果已經存在報價則需要進行賦值
}
var bjcs=Number(Math.ceil(len1/len));//已經存在的報價次數
$(function(){
/*if(currentCount!=''){
pubSum=currentCount;
loadBjRecord();
disExistBj(bjcs,matterSize);
}else{
loadBjRecord();
}*/
if(panelTitle=='2'){
renamePanel("定標意見");
}else if(panelTitle=='3'){
renamePanel("定標意見簽報");
}else if(panelTitle=='4'){
renamePanel("定標意見稽核");
}else if(panelTitle=='5'){
renamePanel("上傳定標意見");
}
if(result.length>1){
for(var i=0;i<result.length;i++){
if(Number(result[i])){
addrows(result[i]);
disExistBj(result[i],matterSize);
}
}
}else{
addrows(pubSum);
}
});
/**
* 去除重複字串,得到當前所有的報價次數
*/
function deDuplication(str){
var strArr=str.split(",");//把字串分割成一個數組
strArr.sort();//排序
var result=new Array();//創建出一個結果陣列
var tempStr="";
for(var i in strArr)
{
if(strArr[i] != tempStr)
{
result.push(strArr[i]);
tempStr=strArr[i];
}
else
{
continue;
}
}
return result;
}
/**
* 禁用已經報價的單價的輸入框
* @param currCount
* @param matSize
*/
function disExistBj(currCount,matSize){
//id=\"matter_"+pubSum+"_Price_"+i+"\"
for(var i=0;i<matSize;i++){
$("#matter_"+currCount+"_"+matterIdArr[i]+"_Price").attr("readOnly","true");
}
//談判記錄以後禁用刪除報價功能 mod by bjj at 2017.02.21
if(isDisplay=="false"){
$("#del_"+currCount).attr("disabled", true);
}
}
/**
* 判斷當前報價是否已經儲存過,如果已經儲存過,則不能再重複儲存
* @param
*/
function isReadOnly(currCount,matSize){
for(var i=0;i<matSize;i++){
if($("#matter_"+currCount+"_"+matterIdArr[i]+"_Price").prop("readonly"))
{
warningAlert('第'+chinaNum(currCount)+'次報價已經完成,不允許重複儲存,若要修改,請重新新增報價!');
return false;
}else{
return true;
}
}
}
function dosave1(action){
save();
}
function doprint(action){
window.open(contextPath+action+"&bidding="+$("#uBidding_bidding").val());
//window.open("http://127.0.0.1:9020/pcecp/inet/panel/exec?panelId=EditNegotiateRecord&operate=print&bidding="+$("#uBidding_bidding").val());
}
function doadd1(action){
try{
addBjRecord();
}catch(e){alert(e.description)}
}
function dosubmit(action){
jskb();
}
/**
* 澄清
* @param action
*/
function dosubmit1(action){
//openRightPanel('澄清',basePath+'/inet/chengqing/toChengqingList.do?bidding='+bidding+'&phaseId='+phase_Id+'&biddings='+biddings);
openRightPanel('澄清',basePath+'/inet/chengqing/toChengqingList.do?bidding='+bidding+'&phaseId='+phase_Id+'&singleBiddings='+biddings);
}
/**
* 流標
* @param action
*/
function dosubmit2(action){
toLiubiao(biddings);
}
/*//來源於/inet/emulative/negotiateRecord.jsp
$(function(){
setbjTime("bjtime0");
});*/
/**
* 儲存
*/
function save(){
var matterSize=$("#listMatterSize").val();
var udpIdValue=$("#udpIdValue").val();
var matterUdp_id=$("#matterUdp_id").val();
var bjsj=getNowFormatDate();
if(!isReadOnly(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
return;
}
if(!validate(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
return;
}
/*var action = getButtonUrl("save");*/
$.ajax({
type:"POST",
async:false,
//url:'<%=basePath%>/inet/emulativeNegotiate/saveNegoRecord.do',
//url:basePath+action+"&requestType=ajax",
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=save'+"&requestType=ajax",
data: $("#sidbidderForm").serialize(),
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag==1){
/*successAlert("儲存成功!");
reloadList();*/
$.messager.alert('提示資訊','儲存成功!','info',function(){
reloadList();
});
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});
}
/**
* 談判記錄提交之前的各種判斷 add by bjj at 20170208 */
function validate(bjIndex,priceIndex){
var flag=true;
//$("#matter_"+bjIndex+"_Price_"+priceIndex).val();
//matter_0_Price_0
for(var i =0;i<priceIndex;i++){
var matterPrice=$("#matter_"+bjIndex+"_"+matterIdArr[i]+"_Price").val();
if(matterPrice==''){
flag=false;
warningAlert('第'+chinaNum(bjIndex)+'次報價第'+(i+1)+'個標的物的單價填寫不完整,請填寫!');
return false;
}
if(isNaN(matterPrice)){
warningAlert('第'+chinaNum(bjIndex)+'次報價第'+(i+1)+'個標的物的單價為非法資料,請修改!');
return false;
}
}
if(isValid){
//其它校驗:談判小組結論、上傳附件檢驗
var cghother=$("#cghother").val();
if(cghother==''){
warningAlert('請填寫談判小結論!');
return false;
}
//其它校驗:談判小組結論、上傳附件檢驗
var uploadButton_filename= $("#uploadButton_filename").val()
if(uploadButton_filename==''){
warningAlert('請上傳談判紀要!');
return false;
}
}
if(!flag){
return flag;
}
return flag;
}
/**
* 提交
*/
function jskb(){
var matterSize=$("#listMatterSize").val();
var udpIdValue=$("#udpIdValue").val();
var matterUdp_id=$("#matterUdp_id").val();
var bjsj=getNowFormatDate();
if(!validate(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
return;
}
var action = getButtonUrl("save");
$.ajax({
type:"POST",
async:false,
//url:'<%=basePath%>/inet/emulativeNegotiate/saveNegoRecord.do',
//url:basePath+action+"&requestType=ajax",
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=save'+"&requestType=ajax",
data: $("#sidbidderForm").serialize(),
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag==1){
goNext(BIDDINGS,"11","","確定要完成談判記錄嗎?");
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});
}
function reloadList(){
refreshPage();
//openRightThreePanel('談判記錄表','<%=path%>/inet/emulativeNegotiate/toNegoRecordMain.do?biddings=${biddings}');
}
/**
* 設定報價時間 add by bjj at 20170208
* @param id
*/
function setbjTime(id){
var d=new Date();
var year=d.getFullYear();
var month=d.getMonth()+1;
var day=d.getDate();
var hour=d.getHours();
var minutes=d.getMinutes();
var second=d.getSeconds();
if($("#"+id).val()==""){
var time=year+"-"+month+"-"+day+" "+hour+":"+minutes+":"+second;
$("#"+id).val(time);
}
}
/**
* 新增報價記錄
* @param flag
*/
function addBjRecord(){//sidbidders[${size.index}].bidder
if(pubSum=='1'){
isValid=false;
}
$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=isToSave'+"&requestType=ajax",
data:{"bidding":bidding,"currentCount":currExtBJ},
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag!=0){
if(validate(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
pubSum++;
currExtBJ+=pubSum+',';
addrows(pubSum);
}
}else{
warningAlert('請先儲存上次報價,再進行新增!');
}
}
})
}
/**
* 每次新增完畢後就需要進行合併單元格
* @param addSum
*/
function addrows(addSum)
{
newRow="";//追加之前需要清空,必須要清空,否決會進行重複的新增
//var cs=Number(Math.ceil(len1/len))+Number(pubSum);
for(var i =0;i<matterSize;i++){
$("#matter_bjcs").val('');
//newRow += "<tr style=\"background:white;\"><td>第"+chinaNum(Number(addSum))+"次<input type=\"hidden\" name=\"matter_bjcs\" id=\"matter_bjcs\" class=\"form-control\" value=\""+bjcs+"\"/></td><td>"+$("#sname0").html()+"</td><td>"+matterArr[i]+"</td><td>"+matterSpecStr[i]+"</td><td><input type=\"hidden\" name=\"matter_"+i+"\" id=\"matter_"+i+"\" class=\"form-control\" value=\""+matterCountArr[i]+"\" />"+matterCountArr[i]+"</td><td><input class=\"easyui-validatebox\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price_"+i+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price_"+i+"\" maxlength=\"66\" data-options=\"required:true\" onchange=\"onmouseToCompute("+addSum+","+i+","+matterSize+")\" value=\""+(typeof(existMatterPriceArr[i])=="undefined"?'':existMatterPriceArr[i])+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:#CCCCCC 1px solid;\"/></td><td><input type=\"text\" name=\"matter_total_"+addSum+"_"+i+"\" id=\"matter_total_"+addSum+"_"+i+"\" class=\"form-control\" value=\""+(typeof(matter_stotalArr[i])=="undefined"?'':matter_stotalArr[i])+"\"/></td></td><td><input type=\"text\" name=\"matter_amount_"+addSum+"_"+i+"\" id=\"matter_amount_"+addSum+"_"+i+"\" class=\"form-control\" value=\""+matter_hjjeArr[0]+"\"/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"text\" name=\"matter_bjsj_"+addSum+"_"+i+"\" id=\"matter_bjsj_"+addSum+"_"+i+"\" class=\"form-control\" value=\""+bjsj+"\"/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"button\" value=\"刪除此次報價\" onclick=\"del1("+matterSize+","+addSum+");\" class=\"btn btn-primary\"><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td></tr>";
if(addSum==1){
newRow += "<tr style=\"background:white;\"><td>第"+chinaNum(Number(addSum))+"次<input type=\"hidden\" name=\"matter_bjcs\" id=\"matter_bjcs\" class=\"form-control\" value=\""+bjcs+"\"/></td><td>"+$("#sname0").html()+"</td><td>"+matterArr[i]+"</td><td>"+matterSpecStr[i]+"</td><td><input type=\"hidden\" name=\"matter_"+i+"\" id=\"matter_"+i+"\" class=\"form-control\" value=\""+matterCountArr[i]+"\" />"+matterCountArr[i]+"</td><td><input class=\"easyui-validatebox\" readonly=\"true\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" maxlength=\"66\" data-options=\"required:true\" onchange=\"onmouseToCompute("+addSum+","+i+","+matterSize+")\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\"/></td><td><input type=\"text\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/></td></td><td><input type=\"text\" name=\"matter_amount_"+addSum+"_"+i+"\" id=\"matter_amount_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"text\" readonly=\"true\" name=\"matter_bjsj_"+addSum+"_"+i+"\" id=\"matter_bjsj_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;\" value=\""+bjsj+"\" /><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td style=\"min-width:90px;\"><input type=\"button\" id=\"del_"+addSum+"\" value=\"刪除此次報價\" style=\"display:none;\" onclick=\"del1("+matterSize+","+addSum+");\" class=\"btn btn-primary\"><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td></tr>";
}else{
newRow += "<tr style=\"background:white;\"><td>第"+chinaNum(Number(addSum))+"次<input type=\"hidden\" name=\"matter_bjcs\" id=\"matter_bjcs\" class=\"form-control\" value=\""+bjcs+"\"/></td><td>"+$("#sname0").html()+"</td><td>"+matterArr[i]+"</td><td>"+matterSpecStr[i]+"</td><td><input type=\"hidden\" name=\"matter_"+i+"\" id=\"matter_"+i+"\" class=\"form-control\" value=\""+matterCountArr[i]+"\" />"+matterCountArr[i]+"</td><td><input class=\"easyui-validatebox\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" maxlength=\"66\" data-options=\"required:true\" onchange=\"onmouseToCompute("+addSum+","+i+","+matterSize+")\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:#CCCCCC 1px solid;max-width: 110px;\"/></td><td><input type=\"text\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/></td></td><td><input type=\"text\" name=\"matter_amount_"+addSum+"_"+i+"\" id=\"matter_amount_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"text\" readonly=\"true\" name=\"matter_bjsj_"+addSum+"_"+i+"\" id=\"matter_bjsj_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;\" value=\""+bjsj+"\" /><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"button\" id=\"del_"+addSum+"\" value=\"刪除此次報價\" onclick=\"del1("+matterSize+","+addSum+");\" class=\"btn btn-primary\"><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td></tr>";
}
}
$("#dg tr:last").after(newRow);
var tab = document.getElementById("dg") ;
SpanGrid(tab,0,2);//合併報價次數
SpanGrid(tab,1,2);//合併供應商
SpanGrid(tab,7,2);//合併合計金額
SpanGrid(tab,9,2);//合併刪除
SpanGrid(tab,8,2);//合併刪除
if(existMatterPrice.length>2){
evaluate(addSum,existMatterPrice,matter_stotal);
}
$("#addedBJcs").val(addSum);//儲存當前新增的新增次數
}
/**
* 賦值
*/
function evaluate(addSum,existMPrice,existMStotal){
var matterPriceArr=existMPrice.split(',');
var matterTotalArr=existMStotal.split(',');
var existMatter_bjsjArr=existMatter_bjsj.split(',');
/*for(var i =0;i<matterPriceArr.length;i++){
var matterPriArr=matterPriceArr[i].split('&');
var matterTolArr=matterTotalArr[i].split('&');
$("#matter_"+addSum+"_"+matterPriArr[1]+"_Price").val(matterPriArr[0]);//儲存當前新增的新增次數
$("#matter_"+addSum+"_"+matterTolArr[1]+"_total").val(matterTolArr[0]);//儲存當前新增的新增次數
}*/
/*for(var j =1;j<=addSum;j++){
for(var i =0;i<len;i++){
var index=(j*len)-len+i;
alert(matterPriceArr[index]);
var matterPriArr=matterPriceArr[index].split('&');
var matterTolArr=matterTotalArr[index].split('&');
//單價
$("#matter_"+j+"_"+matterPriArr[1]+"_Price").val(matterPriArr[0]);//儲存當前新增的新增次數
//總價(萬元)
$("#matter_"+j+"_"+matterTolArr[1]+"_total").val(matterTolArr[0]);//儲存當前新增的新增次數
//合計金額(萬元)
$("#matter_amount_"+j+"_0").val(matter_hjjeArr[index]);//儲存當前新增的新增次數
//報價時間
$("#matter_bjsj_"+j+"_0").val(existMatter_bjsjArr[index]);//儲存當前新增的新增次數
}
}*/
var indexArr=0;
if(indexOfArr(result,addSum)!=-1){
indexArr=Number(indexOfArr(result,addSum)+1);//定位當前報價的報價陣列中的位置,沒有的則不給賦值
for(var i =0;i<len;i++){
var index=(indexArr*len)-len+i;
/*alert(matterPriceArr[index]);*/
var matterPriArr=matterPriceArr[index].split('&');
var matterTolArr=matterTotalArr[index].split('&');
//單價
$("#matter_"+addSum+"_"+matterPriArr[1]+"_Price").val(matterPriArr[0]);//儲存當前新增的新增次數
//總價(萬元)
$("#matter_"+addSum+"_"+matterTolArr[1]+"_total").val(matterTolArr[0]);//儲存當前新增的新增次數
//合計金額(萬元)
$("#matter_amount_"+addSum+"_0").val(matter_hjjeArr[index]);//儲存當前新增的新增次數
//報價時間
$("#matter_bjsj_"+addSum+"_0").val(existMatter_bjsjArr[index]);//儲存當前新增的新增次數
}
}
}
/**
* 定位當前報價的報價陣列中的位置,沒有的則不給賦值
* @param arr
* @param str
* @returns
*/
function indexOfArr(arr, str){
// 如果可以的話,呼叫原生方法
if(arr && arr.indexOf){
return arr.indexOf(str);
}
var len = arr.length;
for(var i = 0; i < len; i++){
// 定位該元素位置
if(arr[i] == str){
return i;
}
}
// 陣列中不存在該元素
return -1;
}
function getRandom(){
var count=3000;
var originalArray=new Array;//原陣列
//給原陣列originalArray賦值
for (var i=0;i<count;i++){
originalArray[i]=i+1;
}
originalArray.sort(
function(){
return 0.5 - Math.random();
});
return originalArray[0];
}
/**
* 滑鼠離開就計算
* bjIndex 報價次數Index
* priceIndex 單價Index
* matter_total_"+pubSum+"_"+i+"
* matterSize 計算合計金額時有用
*/
function onmouseToCompute(bjIndex,priceIndex,matterSize){
var matterCountStr=$("#matter_"+priceIndex).val();
var matterPriceStr=$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price").val();
if(!isNaN(matterPriceStr)){
//檢查單價資料的是否是小數,是小數則最多保留六位小數
if(isFloat(matterPriceStr)){
if(Number(currCurrency)==2){
matterPriceStr=hadelFolat(matterPriceStr,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price",Number(6));
}else{
matterPriceStr=hadelFolat(matterPriceStr,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price",Number(2));
}
$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price").val(matterPriceStr);
}
$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total").val(Number(matterCountStr)*Number(matterPriceStr));
var currentMatterTotal=$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total").val();
//檢查單個標的物的總價資料的是否是小數,是小數則最多保留六位小數
if(isFloat(currentMatterTotal)){
if(Number(currCurrency)==2){
matterPriceStr=hadelFolat(currentMatterTotal,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total",Number(6));
}else{
matterPriceStr=hadelFolat(currentMatterTotal,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total",Number(2));
}
}
var hjje=0;
for(var i =0;i<matterSize;i++){
hjje+=Number($("#matter_"+bjIndex+"_"+matterIdArr[i]+"_total").val());
}
$("#matter_amount_"+bjIndex+"_0").val(hjje);
var currentMatterHjje=$("#matter_amount_"+bjIndex+"_0").val();
//檢查單個標的物的總價資料的是否是小數,是小數則最多保留六位小數
if(isFloat(currentMatterHjje)){
if(Number(currCurrency)==2){
matterPriceStr=hadelFolat(currentMatterHjje,"matter_amount_"+bjIndex+"_0",Number(6));
}else{
matterPriceStr=hadelFolat(currentMatterHjje,"matter_amount_"+bjIndex+"_0",Number(2));
}
}
}else{
warningAlert('第'+chinaNum(bjIndex+1)+'次報價第'+(priceIndex+1)+'個標的物的單價為非法資料,無法計算總價,請修改!');
$("#matter_"+bjIndex+"_Price_"+priceIndex).val('');
$("#matter_total_"+bjIndex+"_"+priceIndex).val('');
}
}
/**
*
* @param num 源資料+返回資料
* @param inputId 要賦值的Input的Id
* @param fiex 保留的小數位數
* @returns
*/
function hadelFolat(num,inputId,fiex){
if(isFloat(num)){
var str=num.split(".");
if(str[1].length>fiex)//小數部分大於6
{
num=Number(num).toFixed(fiex);
$("#"+inputId).val(num);
}
}
return parseFloat(num);
}
/**
* 頁面載入進來後預設加載出來第一次報價
*/
function defaultTable(){
addrows(0);
}
/**
* 合併同類項
* @param tabObj 表格
* @param cellindex 合併同類型的單元格
* @param beginRow 開始合併的行數
*/
function SpanGrid(tabObj, cellindex, beginRow) {
var colIndex = cellindex;
var rowBeginIndex = beginRow;
if (tabObj != null) {
var i, j, m;
var intSpan;
var strTemp;
m = 0;
for (i = rowBeginIndex; i < tabObj.rows.length; i++) {
intSpan = 1;
m++;
strTemp = tabObj.rows[i].cells[colIndex].innerText;
for (j = i + 1; j < tabObj.rows.length; j++) {
if (strTemp == tabObj.rows[j].cells[colIndex].innerText) {
intSpan++;
tabObj.rows[i].cells[colIndex].rowSpan = intSpan;
tabObj.rows[j].cells[colIndex].style.display = "none";
}
else {
break;
}
}
}
i = j - 1;
}
}
function del(curr){
if(!confirm("確定要刪除此次報價嗎?")){
return ;
}
$("#timetable"+curr).remove();
$("#table"+curr).remove();
}
function del1(index,currCount){
if(currCount==1){
warningAlert("第一條談判記錄為基礎報價記錄,不能刪除!");
return;
}
if(!confirm("確定要刪除此次報價嗎?")){
return ;
}
$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=delete'+"&requestType=ajax",
data: {"currCount":currCount,"bidding":$("#bidding").val()},
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag==1){
//successAlert("刪除成功!");
$.messager.alert('提示資訊','刪除成功!','info',function(){
//save();
reloadList();
});
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});
/*$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/emulativeNegotiate/delRecord.do',
data: {"currCount":currCount,"bidding":$("#bidding").val()},
cache:false,
success:function(dataStr){
if(dataStr=="true"){
//successAlert("刪除成功!");
$.messager.alert('提示資訊','刪除成功!','info',function(){
//save();
reloadList();
});
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});*/
}
function vali(){
var flag=true;
$("[name$='.stotal']").each(function(){
if($(this).val()==""){
warningAlert("投標總價不能為空!");
flag=false;
return false;
}
})
return flag;
}
/**
* 獲取當前時間 add by bjj at 20170208
* @returns {String}
*/
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}
/**
* 上傳檔案回顯 add by bjj at 20170208
*/
function myUploadSuccessExpand(){
var att='qbfzsm';
var attchId=$("#uploadButton_fileid").val();
/*var attchName=$("#uploadButton_filename").val();
alert(attchName);
if(attchName.length>30)
attchName=attchName.substring(0,30)+"...";*/
//更新下面檔案的顯示名稱。
$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=saveAttch'+"&requestType=ajax",
data:{"bidding":bidding,"attchId":attchId,"att":att},
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag!=0){
var nameArr=data.flag.split('&');
var attchName=nameArr[1];
if(attchName.length>30)
{
attchName=attchName.substring(0,30)+"...";
}
//更新下面檔案的顯示名稱。
/*$("#fileTitleNew").html("<span title="+$("#uploadButton_filename").val()+" id=\"fileTitle\" class=\"attchSpan\"><a id=\"aFileName\">"+attchName+"</a></span>");
$("#uploadSpan").html("<input type=\"button\" id=\"downFileButton\" value=\"檢視\" class=\"generic_button\" onclick=\"javascript:downFile('"+attchId+"')\"/> <font color=\"red\">注:點選右側檢視按鈕可以下載檢視</font>");*/
$("#fileTitleNew").html("<a id=\"aFileName\" title="+attchName+" style=\"font-size:12px;color:blue;\" onclick=\"javascript:downFile('"+attchId+"')\">"+attchName+"</a>");
/*$("#uploadSpan").html("<input type=\"button\" id=\"downFileButton\" value=\"檢視\" class=\"generic_button\" onclick=\"javascript:downFile('"+attchId+"')\"/> <font color=\"red\">注:點選右側檢視按鈕可以下載檢視</font>");*/
}else{
//errorAlert("檔案儲存業務表失敗!");
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
})
}
/**
* 是否小float 型別的小數
* @param oNum
* @returns {Boolean}
*/
function isFloat(oNum)//判斷是否為浮點數的函式
{
var r= /^[+-]?[1-9]?[0-9]*\.[0-9]*$/;
return r.test(oNum);
}
var pubSum=1;//計數新增記錄次數
var panelTitle=$("#title").val();
var currExtBJ="";
var existMatterPrice=$("#matter_price").val();
var isDisplay=$("#isDisplay").val();
var existMatter_bjsj=$("#matter_bjsj").val();
var matter_stotal=$("#matter_stotal").val();
var matter_hjje=$("#matter_hjje").val();
var currentCount=$("#currentCount").val();
var matterSize=$("#listMatterSize").val();
var len=parseInt($("#_listsize").val());//標的物的個數
var len1=parseInt($("#_listsize1").val());//有幾條資料
var currUnit=$("#currUnit").val();//計價單位
var currCurrency=$("#currCurrency").val();//計價單位
var bidding=$("#bidding").val();//bidding
var biddings=$("#biddings").val();//bidding
var phase_Id=$("#phase_Id").val();//bidding
var matterArr=$("#matterStr").val().split(",");
var matterIdArr=$("#matterIdStr").val().split(",");
var matterCountArr=$("#matterCountStr").val().split(",");
var matterSpecStr=$("#matterSpecStr").val().split(",");
var matter_hjjeArr=matter_hjje.split(",");
var existMatterPriceArr=existMatterPrice.split(",");
var matter_stotalArr=matter_stotal.split(",");
var bjsj=getNowFormatDate();
var isValid=true;
var count_Str=$("#count_Str").val();
var result=new Array();//創建出一個結果陣列
result=deDuplication(count_Str);//創建出一個結果陣列
if(Number(currentCount)>0){
pubSum=currentCount;//如果已經存在報價則需要進行賦值
}
var bjcs=Number(Math.ceil(len1/len));//已經存在的報價次數
$(function(){
/*if(currentCount!=''){
pubSum=currentCount;
loadBjRecord();
disExistBj(bjcs,matterSize);
}else{
loadBjRecord();
}*/
if(panelTitle=='2'){
renamePanel("定標意見");
}else if(panelTitle=='3'){
renamePanel("定標意見簽報");
}else if(panelTitle=='4'){
renamePanel("定標意見稽核");
}else if(panelTitle=='5'){
renamePanel("上傳定標意見");
}
if(result.length>1){
for(var i=0;i<result.length;i++){
if(Number(result[i])){
addrows(result[i]);
disExistBj(result[i],matterSize);
}
}
}else{
addrows(pubSum);
}
});
/**
* 去除重複字串,得到當前所有的報價次數
*/
function deDuplication(str){
var strArr=str.split(",");//把字串分割成一個數組
strArr.sort();//排序
var result=new Array();//創建出一個結果陣列
var tempStr="";
for(var i in strArr)
{
if(strArr[i] != tempStr)
{
result.push(strArr[i]);
tempStr=strArr[i];
}
else
{
continue;
}
}
return result;
}
/**
* 禁用已經報價的單價的輸入框
* @param currCount
* @param matSize
*/
function disExistBj(currCount,matSize){
//id=\"matter_"+pubSum+"_Price_"+i+"\"
for(var i=0;i<matSize;i++){
$("#matter_"+currCount+"_"+matterIdArr[i]+"_Price").attr("readOnly","true");
}
//談判記錄以後禁用刪除報價功能 mod by bjj at 2017.02.21
if(isDisplay=="false"){
$("#del_"+currCount).attr("disabled", true);
}
}
/**
* 判斷當前報價是否已經儲存過,如果已經儲存過,則不能再重複儲存
* @param
*/
function isReadOnly(currCount,matSize){
for(var i=0;i<matSize;i++){
if($("#matter_"+currCount+"_"+matterIdArr[i]+"_Price").prop("readonly"))
{
warningAlert('第'+chinaNum(currCount)+'次報價已經完成,不允許重複儲存,若要修改,請重新新增報價!');
return false;
}else{
return true;
}
}
}
function dosave1(action){
save();
}
function doprint(action){
window.open(contextPath+action+"&bidding="+$("#uBidding_bidding").val());
//window.open("http://127.0.0.1:9020/pcecp/inet/panel/exec?panelId=EditNegotiateRecord&operate=print&bidding="+$("#uBidding_bidding").val());
}
function doadd1(action){
try{
addBjRecord();
}catch(e){alert(e.description)}
}
function dosubmit(action){
jskb();
}
/**
* 澄清
* @param action
*/
function dosubmit1(action){
//openRightPanel('澄清',basePath+'/inet/chengqing/toChengqingList.do?bidding='+bidding+'&phaseId='+phase_Id+'&biddings='+biddings);
openRightPanel('澄清',basePath+'/inet/chengqing/toChengqingList.do?bidding='+bidding+'&phaseId='+phase_Id+'&singleBiddings='+biddings);
}
/**
* 流標
* @param action
*/
function dosubmit2(action){
toLiubiao(biddings);
}
/*//來源於/inet/emulative/negotiateRecord.jsp
$(function(){
setbjTime("bjtime0");
});*/
/**
* 儲存
*/
function save(){
var matterSize=$("#listMatterSize").val();
var udpIdValue=$("#udpIdValue").val();
var matterUdp_id=$("#matterUdp_id").val();
var bjsj=getNowFormatDate();
if(!isReadOnly(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
return;
}
if(!validate(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
return;
}
/*var action = getButtonUrl("save");*/
$.ajax({
type:"POST",
async:false,
//url:'<%=basePath%>/inet/emulativeNegotiate/saveNegoRecord.do',
//url:basePath+action+"&requestType=ajax",
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=save'+"&requestType=ajax",
data: $("#sidbidderForm").serialize(),
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag==1){
/*successAlert("儲存成功!");
reloadList();*/
$.messager.alert('提示資訊','儲存成功!','info',function(){
reloadList();
});
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});
}
/**
* 談判記錄提交之前的各種判斷 add by bjj at 20170208 */
function validate(bjIndex,priceIndex){
var flag=true;
//$("#matter_"+bjIndex+"_Price_"+priceIndex).val();
//matter_0_Price_0
for(var i =0;i<priceIndex;i++){
var matterPrice=$("#matter_"+bjIndex+"_"+matterIdArr[i]+"_Price").val();
if(matterPrice==''){
flag=false;
warningAlert('第'+chinaNum(bjIndex)+'次報價第'+(i+1)+'個標的物的單價填寫不完整,請填寫!');
return false;
}
if(isNaN(matterPrice)){
warningAlert('第'+chinaNum(bjIndex)+'次報價第'+(i+1)+'個標的物的單價為非法資料,請修改!');
return false;
}
}
if(isValid){
//其它校驗:談判小組結論、上傳附件檢驗
var cghother=$("#cghother").val();
if(cghother==''){
warningAlert('請填寫談判小結論!');
return false;
}
//其它校驗:談判小組結論、上傳附件檢驗
var uploadButton_filename= $("#uploadButton_filename").val()
if(uploadButton_filename==''){
warningAlert('請上傳談判紀要!');
return false;
}
}
if(!flag){
return flag;
}
return flag;
}
/**
* 提交
*/
function jskb(){
var matterSize=$("#listMatterSize").val();
var udpIdValue=$("#udpIdValue").val();
var matterUdp_id=$("#matterUdp_id").val();
var bjsj=getNowFormatDate();
if(!validate(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
return;
}
var action = getButtonUrl("save");
$.ajax({
type:"POST",
async:false,
//url:'<%=basePath%>/inet/emulativeNegotiate/saveNegoRecord.do',
//url:basePath+action+"&requestType=ajax",
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=save'+"&requestType=ajax",
data: $("#sidbidderForm").serialize(),
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag==1){
goNext(BIDDINGS,"11","","確定要完成談判記錄嗎?");
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});
}
function reloadList(){
refreshPage();
//openRightThreePanel('談判記錄表','<%=path%>/inet/emulativeNegotiate/toNegoRecordMain.do?biddings=${biddings}');
}
/**
* 設定報價時間 add by bjj at 20170208
* @param id
*/
function setbjTime(id){
var d=new Date();
var year=d.getFullYear();
var month=d.getMonth()+1;
var day=d.getDate();
var hour=d.getHours();
var minutes=d.getMinutes();
var second=d.getSeconds();
if($("#"+id).val()==""){
var time=year+"-"+month+"-"+day+" "+hour+":"+minutes+":"+second;
$("#"+id).val(time);
}
}
/**
* 新增報價記錄
* @param flag
*/
function addBjRecord(){//sidbidders[${size.index}].bidder
if(pubSum=='1'){
isValid=false;
}
$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=isToSave'+"&requestType=ajax",
data:{"bidding":bidding,"currentCount":currExtBJ},
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag!=0){
if(validate(pubSum,matterSize)){//校驗每次報價的單價是否填寫完畢
pubSum++;
currExtBJ+=pubSum+',';
addrows(pubSum);
}
}else{
warningAlert('請先儲存上次報價,再進行新增!');
}
}
})
}
/**
* 每次新增完畢後就需要進行合併單元格
* @param addSum
*/
function addrows(addSum)
{
newRow="";//追加之前需要清空,必須要清空,否決會進行重複的新增
//var cs=Number(Math.ceil(len1/len))+Number(pubSum);
for(var i =0;i<matterSize;i++){
$("#matter_bjcs").val('');
//newRow += "<tr style=\"background:white;\"><td>第"+chinaNum(Number(addSum))+"次<input type=\"hidden\" name=\"matter_bjcs\" id=\"matter_bjcs\" class=\"form-control\" value=\""+bjcs+"\"/></td><td>"+$("#sname0").html()+"</td><td>"+matterArr[i]+"</td><td>"+matterSpecStr[i]+"</td><td><input type=\"hidden\" name=\"matter_"+i+"\" id=\"matter_"+i+"\" class=\"form-control\" value=\""+matterCountArr[i]+"\" />"+matterCountArr[i]+"</td><td><input class=\"easyui-validatebox\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price_"+i+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price_"+i+"\" maxlength=\"66\" data-options=\"required:true\" onchange=\"onmouseToCompute("+addSum+","+i+","+matterSize+")\" value=\""+(typeof(existMatterPriceArr[i])=="undefined"?'':existMatterPriceArr[i])+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:#CCCCCC 1px solid;\"/></td><td><input type=\"text\" name=\"matter_total_"+addSum+"_"+i+"\" id=\"matter_total_"+addSum+"_"+i+"\" class=\"form-control\" value=\""+(typeof(matter_stotalArr[i])=="undefined"?'':matter_stotalArr[i])+"\"/></td></td><td><input type=\"text\" name=\"matter_amount_"+addSum+"_"+i+"\" id=\"matter_amount_"+addSum+"_"+i+"\" class=\"form-control\" value=\""+matter_hjjeArr[0]+"\"/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"text\" name=\"matter_bjsj_"+addSum+"_"+i+"\" id=\"matter_bjsj_"+addSum+"_"+i+"\" class=\"form-control\" value=\""+bjsj+"\"/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"button\" value=\"刪除此次報價\" onclick=\"del1("+matterSize+","+addSum+");\" class=\"btn btn-primary\"><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td></tr>";
if(addSum==1){
newRow += "<tr style=\"background:white;\"><td>第"+chinaNum(Number(addSum))+"次<input type=\"hidden\" name=\"matter_bjcs\" id=\"matter_bjcs\" class=\"form-control\" value=\""+bjcs+"\"/></td><td>"+$("#sname0").html()+"</td><td>"+matterArr[i]+"</td><td>"+matterSpecStr[i]+"</td><td><input type=\"hidden\" name=\"matter_"+i+"\" id=\"matter_"+i+"\" class=\"form-control\" value=\""+matterCountArr[i]+"\" />"+matterCountArr[i]+"</td><td><input class=\"easyui-validatebox\" readonly=\"true\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" maxlength=\"66\" data-options=\"required:true\" onchange=\"onmouseToCompute("+addSum+","+i+","+matterSize+")\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\"/></td><td><input type=\"text\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/></td></td><td><input type=\"text\" name=\"matter_amount_"+addSum+"_"+i+"\" id=\"matter_amount_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"text\" readonly=\"true\" name=\"matter_bjsj_"+addSum+"_"+i+"\" id=\"matter_bjsj_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;\" value=\""+bjsj+"\" /><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td style=\"min-width:90px;\"><input type=\"button\" id=\"del_"+addSum+"\" value=\"刪除此次報價\" style=\"display:none;\" onclick=\"del1("+matterSize+","+addSum+");\" class=\"btn btn-primary\"><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td></tr>";
}else{
newRow += "<tr style=\"background:white;\"><td>第"+chinaNum(Number(addSum))+"次<input type=\"hidden\" name=\"matter_bjcs\" id=\"matter_bjcs\" class=\"form-control\" value=\""+bjcs+"\"/></td><td>"+$("#sname0").html()+"</td><td>"+matterArr[i]+"</td><td>"+matterSpecStr[i]+"</td><td><input type=\"hidden\" name=\"matter_"+i+"\" id=\"matter_"+i+"\" class=\"form-control\" value=\""+matterCountArr[i]+"\" />"+matterCountArr[i]+"</td><td><input class=\"easyui-validatebox\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_Price"+"\" maxlength=\"66\" data-options=\"required:true\" onchange=\"onmouseToCompute("+addSum+","+i+","+matterSize+")\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:#CCCCCC 1px solid;max-width: 110px;\"/></td><td><input type=\"text\" name=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" id=\"matter_"+addSum+"_"+matterIdArr[i]+"_total"+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/></td></td><td><input type=\"text\" name=\"matter_amount_"+addSum+"_"+i+"\" id=\"matter_amount_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;max-width: 110px;\" readonly='true'/><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"text\" readonly=\"true\" name=\"matter_bjsj_"+addSum+"_"+i+"\" id=\"matter_bjsj_"+addSum+"_"+i+"\" style=\"text-align: center;width:160px;height:26px;line-height:26px ;color:black;border:none;\" value=\""+bjsj+"\" /><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td><td><input type=\"button\" id=\"del_"+addSum+"\" value=\"刪除此次報價\" onclick=\"del1("+matterSize+","+addSum+");\" class=\"btn btn-primary\"><span style=\"display:none\">("+chinaNum(Math.ceil(len1/len)+addSum)+")</span></td></tr>";
}
}
$("#dg tr:last").after(newRow);
var tab = document.getElementById("dg") ;
SpanGrid(tab,0,2);//合併報價次數
SpanGrid(tab,1,2);//合併供應商
SpanGrid(tab,7,2);//合併合計金額
SpanGrid(tab,9,2);//合併刪除
SpanGrid(tab,8,2);//合併刪除
if(existMatterPrice.length>2){
evaluate(addSum,existMatterPrice,matter_stotal);
}
$("#addedBJcs").val(addSum);//儲存當前新增的新增次數
}
/**
* 賦值
*/
function evaluate(addSum,existMPrice,existMStotal){
var matterPriceArr=existMPrice.split(',');
var matterTotalArr=existMStotal.split(',');
var existMatter_bjsjArr=existMatter_bjsj.split(',');
/*for(var i =0;i<matterPriceArr.length;i++){
var matterPriArr=matterPriceArr[i].split('&');
var matterTolArr=matterTotalArr[i].split('&');
$("#matter_"+addSum+"_"+matterPriArr[1]+"_Price").val(matterPriArr[0]);//儲存當前新增的新增次數
$("#matter_"+addSum+"_"+matterTolArr[1]+"_total").val(matterTolArr[0]);//儲存當前新增的新增次數
}*/
/*for(var j =1;j<=addSum;j++){
for(var i =0;i<len;i++){
var index=(j*len)-len+i;
alert(matterPriceArr[index]);
var matterPriArr=matterPriceArr[index].split('&');
var matterTolArr=matterTotalArr[index].split('&');
//單價
$("#matter_"+j+"_"+matterPriArr[1]+"_Price").val(matterPriArr[0]);//儲存當前新增的新增次數
//總價(萬元)
$("#matter_"+j+"_"+matterTolArr[1]+"_total").val(matterTolArr[0]);//儲存當前新增的新增次數
//合計金額(萬元)
$("#matter_amount_"+j+"_0").val(matter_hjjeArr[index]);//儲存當前新增的新增次數
//報價時間
$("#matter_bjsj_"+j+"_0").val(existMatter_bjsjArr[index]);//儲存當前新增的新增次數
}
}*/
var indexArr=0;
if(indexOfArr(result,addSum)!=-1){
indexArr=Number(indexOfArr(result,addSum)+1);//定位當前報價的報價陣列中的位置,沒有的則不給賦值
for(var i =0;i<len;i++){
var index=(indexArr*len)-len+i;
/*alert(matterPriceArr[index]);*/
var matterPriArr=matterPriceArr[index].split('&');
var matterTolArr=matterTotalArr[index].split('&');
//單價
$("#matter_"+addSum+"_"+matterPriArr[1]+"_Price").val(matterPriArr[0]);//儲存當前新增的新增次數
//總價(萬元)
$("#matter_"+addSum+"_"+matterTolArr[1]+"_total").val(matterTolArr[0]);//儲存當前新增的新增次數
//合計金額(萬元)
$("#matter_amount_"+addSum+"_0").val(matter_hjjeArr[index]);//儲存當前新增的新增次數
//報價時間
$("#matter_bjsj_"+addSum+"_0").val(existMatter_bjsjArr[index]);//儲存當前新增的新增次數
}
}
}
/**
* 定位當前報價的報價陣列中的位置,沒有的則不給賦值
* @param arr
* @param str
* @returns
*/
function indexOfArr(arr, str){
// 如果可以的話,呼叫原生方法
if(arr && arr.indexOf){
return arr.indexOf(str);
}
var len = arr.length;
for(var i = 0; i < len; i++){
// 定位該元素位置
if(arr[i] == str){
return i;
}
}
// 陣列中不存在該元素
return -1;
}
function getRandom(){
var count=3000;
var originalArray=new Array;//原陣列
//給原陣列originalArray賦值
for (var i=0;i<count;i++){
originalArray[i]=i+1;
}
originalArray.sort(
function(){
return 0.5 - Math.random();
});
return originalArray[0];
}
/**
* 滑鼠離開就計算
* bjIndex 報價次數Index
* priceIndex 單價Index
* matter_total_"+pubSum+"_"+i+"
* matterSize 計算合計金額時有用
*/
function onmouseToCompute(bjIndex,priceIndex,matterSize){
var matterCountStr=$("#matter_"+priceIndex).val();
var matterPriceStr=$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price").val();
if(!isNaN(matterPriceStr)){
//檢查單價資料的是否是小數,是小數則最多保留六位小數
if(isFloat(matterPriceStr)){
if(Number(currCurrency)==2){
matterPriceStr=hadelFolat(matterPriceStr,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price",Number(6));
}else{
matterPriceStr=hadelFolat(matterPriceStr,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price",Number(2));
}
$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_Price").val(matterPriceStr);
}
$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total").val(Number(matterCountStr)*Number(matterPriceStr));
var currentMatterTotal=$("#matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total").val();
//檢查單個標的物的總價資料的是否是小數,是小數則最多保留六位小數
if(isFloat(currentMatterTotal)){
if(Number(currCurrency)==2){
matterPriceStr=hadelFolat(currentMatterTotal,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total",Number(6));
}else{
matterPriceStr=hadelFolat(currentMatterTotal,"matter_"+bjIndex+"_"+matterIdArr[priceIndex]+"_total",Number(2));
}
}
var hjje=0;
for(var i =0;i<matterSize;i++){
hjje+=Number($("#matter_"+bjIndex+"_"+matterIdArr[i]+"_total").val());
}
$("#matter_amount_"+bjIndex+"_0").val(hjje);
var currentMatterHjje=$("#matter_amount_"+bjIndex+"_0").val();
//檢查單個標的物的總價資料的是否是小數,是小數則最多保留六位小數
if(isFloat(currentMatterHjje)){
if(Number(currCurrency)==2){
matterPriceStr=hadelFolat(currentMatterHjje,"matter_amount_"+bjIndex+"_0",Number(6));
}else{
matterPriceStr=hadelFolat(currentMatterHjje,"matter_amount_"+bjIndex+"_0",Number(2));
}
}
}else{
warningAlert('第'+chinaNum(bjIndex+1)+'次報價第'+(priceIndex+1)+'個標的物的單價為非法資料,無法計算總價,請修改!');
$("#matter_"+bjIndex+"_Price_"+priceIndex).val('');
$("#matter_total_"+bjIndex+"_"+priceIndex).val('');
}
}
/**
*
* @param num 源資料+返回資料
* @param inputId 要賦值的Input的Id
* @param fiex 保留的小數位數
* @returns
*/
function hadelFolat(num,inputId,fiex){
if(isFloat(num)){
var str=num.split(".");
if(str[1].length>fiex)//小數部分大於6
{
num=Number(num).toFixed(fiex);
$("#"+inputId).val(num);
}
}
return parseFloat(num);
}
/**
* 頁面載入進來後預設加載出來第一次報價
*/
function defaultTable(){
addrows(0);
}
/**
* 合併同類項
* @param tabObj 表格
* @param cellindex 合併同類型的單元格
* @param beginRow 開始合併的行數
*/
function SpanGrid(tabObj, cellindex, beginRow) {
var colIndex = cellindex;
var rowBeginIndex = beginRow;
if (tabObj != null) {
var i, j, m;
var intSpan;
var strTemp;
m = 0;
for (i = rowBeginIndex; i < tabObj.rows.length; i++) {
intSpan = 1;
m++;
strTemp = tabObj.rows[i].cells[colIndex].innerText;
for (j = i + 1; j < tabObj.rows.length; j++) {
if (strTemp == tabObj.rows[j].cells[colIndex].innerText) {
intSpan++;
tabObj.rows[i].cells[colIndex].rowSpan = intSpan;
tabObj.rows[j].cells[colIndex].style.display = "none";
}
else {
break;
}
}
}
i = j - 1;
}
}
function del(curr){
if(!confirm("確定要刪除此次報價嗎?")){
return ;
}
$("#timetable"+curr).remove();
$("#table"+curr).remove();
}
function del1(index,currCount){
if(currCount==1){
warningAlert("第一條談判記錄為基礎報價記錄,不能刪除!");
return;
}
if(!confirm("確定要刪除此次報價嗎?")){
return ;
}
$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=delete'+"&requestType=ajax",
data: {"currCount":currCount,"bidding":$("#bidding").val()},
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag==1){
//successAlert("刪除成功!");
$.messager.alert('提示資訊','刪除成功!','info',function(){
//save();
reloadList();
});
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});
/*$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/emulativeNegotiate/delRecord.do',
data: {"currCount":currCount,"bidding":$("#bidding").val()},
cache:false,
success:function(dataStr){
if(dataStr=="true"){
//successAlert("刪除成功!");
$.messager.alert('提示資訊','刪除成功!','info',function(){
//save();
reloadList();
});
}else{
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
});*/
}
function vali(){
var flag=true;
$("[name$='.stotal']").each(function(){
if($(this).val()==""){
warningAlert("投標總價不能為空!");
flag=false;
return false;
}
})
return flag;
}
/**
* 獲取當前時間 add by bjj at 20170208
* @returns {String}
*/
function getNowFormatDate() {
var date = new Date();
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}
/**
* 上傳檔案回顯 add by bjj at 20170208
*/
function myUploadSuccessExpand(){
var att='qbfzsm';
var attchId=$("#uploadButton_fileid").val();
/*var attchName=$("#uploadButton_filename").val();
alert(attchName);
if(attchName.length>30)
attchName=attchName.substring(0,30)+"...";*/
//更新下面檔案的顯示名稱。
$.ajax({
type:"POST",
async:false,
url:basePath+'/inet/panel/exec?panelId=SingleEditNegotiateRecord&operate=saveAttch'+"&requestType=ajax",
data:{"bidding":bidding,"attchId":attchId,"att":att},
cache:false,
success:function(dataStr){
var data=eval("(" +dataStr+")");
if(data.flag!=0){
var nameArr=data.flag.split('&');
var attchName=nameArr[1];
if(attchName.length>30)
{
attchName=attchName.substring(0,30)+"...";
}
//更新下面檔案的顯示名稱。
/*$("#fileTitleNew").html("<span title="+$("#uploadButton_filename").val()+" id=\"fileTitle\" class=\"attchSpan\"><a id=\"aFileName\">"+attchName+"</a></span>");
$("#uploadSpan").html("<input type=\"button\" id=\"downFileButton\" value=\"檢視\" class=\"generic_button\" onclick=\"javascript:downFile('"+attchId+"')\"/> <font color=\"red\">注:點選右側檢視按鈕可以下載檢視</font>");*/
$("#fileTitleNew").html("<a id=\"aFileName\" title="+attchName+" style=\"font-size:12px;color:blue;\" onclick=\"javascript:downFile('"+attchId+"')\">"+attchName+"</a>");
/*$("#uploadSpan").html("<input type=\"button\" id=\"downFileButton\" value=\"檢視\" class=\"generic_button\" onclick=\"javascript:downFile('"+attchId+"')\"/> <font color=\"red\">注:點選右側檢視按鈕可以下載檢視</font>");*/
}else{
//errorAlert("檔案儲存業務表失敗!");
errorAlert('當前網路不穩定,請重新整理瀏覽器後重試!');
}
}
})
}
/**
* 是否小float 型別的小數
* @param oNum
* @returns {Boolean}
*/
function isFloat(oNum)//判斷是否為浮點數的函式
{
var r= /^[+-]?[1-9]?[0-9]*\.[0-9]*$/;
return r.test(oNum);
}