// 报价js 工具类 import LightningConfirm from 'lightning/confirm'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import { NavigationMixin } from 'lightning/navigation'; const toast = { // 提示信息 showToast: function(_this, variant, msg) { if (variant == 'success') { const event = new ShowToastEvent({ variant: variant, title: '', message: msg }); _this.dispatchEvent(event); }else{ const event = new ShowToastEvent({ variant: variant, title: '', message: msg, mode:'sticky' }); _this.dispatchEvent(event); } }, //确认框 handleConfirmClick: function(message) { console.log('handleConfirmClick'); const result = LightningConfirm.open({ message: message, variant: 'headerless', // variant: variant, // theme: 'shade', // setting theme would have no effect }); //Confirm has been closed //result is true if OK was clicked console.log(result); return result; //and false if cancel was clicked }, //页面对象跳转 navigateToOtherObj: function(recordId){ this.IsLoading = true; console.log('navigateToOtherObj'); this[NavigationMixin.Navigate]({ type:'standard__recordPage', attributes:{ recordId:recordId, objectApiName:'Account', actionName:'view' } }); }, }; const handleInfo = { //合同对象设备 参保修理金额 更新后触发 changeAsset(_this,cnt,checkedAssets,PageDisabled,approvalDate,allData) { //封装返回数据 var returnData = {}; // 提交后就页面不计算了 var isDisabled = PageDisabled; // 合同总理 var newCount = 0; var isresduce = 0; var oyearCount = 0; var firstCCount = 0; var conCCount = 0; // row金額合計 var repairSum = 0; var listSum = 0; // 新品合同 判断 var newCon = true; var contractStartDate = new Date(allData.estimate.Contract_Start_Date__c); //多年保续签合同数量 thh 20220316 start var GuranteeCount = 0; //多年保续签合同数量 thh 20220316 end //2022故障品加费 获取userInfo简档名称 是否为FSE start var isFSE = allData.isFSE; //2022故障品加费 获取userInfo简档名称 end // 预定开始日 var startdate = new Date(allData.estimate.Contract_Esti_Start_Date__c); // 预定开始日-6个月 startdate.setMonth(startdate.getMonth() - 6); //补充使用变量 // 申请日 当前日期 if(approvalDate != ''){ //申请日 approvalDate = new Date(approvalDate.toLocaleDateString()); if (Date.parse(approvalDate) < Date.parse(startdate)) { newCon = false; } } // 最高、最低价格合计 var downPriceSum = 0; var upPriceSum = 0; // 合同月数乗算 parseFloat(null.'',undefined) 为NAN 补充判断 var month = parseFloat(allData.estimate.Contract_Range__c); if (month == undefined || month == "" || isNaN(month)) { month = 1; } var month2 = 0; if (month > 12) { month2 = month - 12; month = 12; } for (var i = 0; i < cnt; i++) { //字段按钮 默认可用 checkedAssets[i].ShowAssetSituation = true; var strMoney = 0; var repairMoney = 0; // 行项目 最高、最低价格合计 // 续签价格取联动价格页面计算,首签或产品取 实际价格 // 下线价格 var downPrice = 0; // 上线价格 var upPrice = 0; // 12个月合同金额 var Price_YearTXT = 0; var isManual = checkedAssets[i].isManual; //return boolean var isnew = checkedAssets[i].mcae.IsNew__c; //return boolean var assetListmonth = checkedAssets[i].mcae.Estimate_List_Price__c; //市场多年保修价格开发 DC 2023/02/09 start var VMassetListmonth = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.Maintenance_Price_Year__c : '') : ''; //市场多年保修价格开发 DC 2023/02/09 end if (isManual) { var a = checkedAssets[i].mcae.Product_Manual__c ? checkedAssets[i].mcae.Product_Manual__c : ''; if (a != '') { strMoney = assetListmonth; var LastMContractRecord = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.RecordType_DeveloperName__c : '') : ''; Price_YearTXT = strMoney * 12; if (isnew) { newCount ++; strMoney = month * strMoney + month2 * strMoney / allData.isNewPriceAdj; } else { newCon = false; strMoney = month * strMoney + month2 * strMoney; } //补充空指针 var b = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.Maintenance_Contract_No_F__c : '') : ''; // var LastMContractRecord = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.RecordType_DeveloperName__c : '') : ''; if(b != ''){ conCCount ++; // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。) // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。 var lastendDate = new Date(checkedAssets[i].rec.CurrentContract_End_Date__c); var lastContRange = 0; if(LastMContractRecord == 'VM_Contract'){ newCount++; //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start GuranteeCount++; newCon = false; //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c); lastContRange = 36; }else{ lastContRange = checkedAssets[i].rec.CurrentContract_F__r.Contract_Range__c; } //最后结束日+1年 lastendDate.setMonth(lastendDate.getMonth() + 12); if (Date.parse(contractStartDate) > Date.parse(lastendDate) ) { oyearCount ++; } // 取联动价格 // 上一期合同实际报价月额 // * 1 避免 parseFloat(null) ->NAN var LastMContract_Price = parseFloat(checkedAssets[i].mcae.LastMContract_Price__c * 1); var Adjustment_ratio_Lower = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Lower__c * 1); var Adjustment_ratio_Upper = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Upper__c * 1); //计算惩罚率 var Punish = handleInfo.calculateNtoMRatio(_this,lastContRange,(month + month2),allData); if(Punish == 0){ return; } // 判断有无报价:没有按照标准价格实际联动 var Estimate_Num = checkedAssets[i].rec.CurrentContract_F__r.Estimate_Num__c ; if(Estimate_Num == 0){ if(LastMContractRecord == 'VM_Contract'){ // gzw 20220630 实际联动6个月价格区分 var nowdate = new Date(); lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c); nowdate = nowdate.setMonth(nowdate.getMonth() + 6); //市场多年保修价格开发 DC 2023/1/30 start var Maxcoefficient =0; var Mincoefficient =0; var ContractMonth = handleInfo.localParseFloat(allData.estimate.Contract_Range__c); var AssetRate = handleInfo.localParseFloat(checkedAssets[i].rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c); checkedAssets[i].mcae.Asset_Consumption_rate__c = AssetRate; if(AssetRate<= 50){ Maxcoefficient = (1-0.3); Mincoefficient = (1-0.4); }else if(AssetRate>50 &&AssetRate<=60){ Maxcoefficient = (1-0.2); Mincoefficient = (1-0.3); }else if(AssetRate>60 &&AssetRate<=70){ Maxcoefficient = (1-0.15); Mincoefficient = (1-0.25); }else if(AssetRate>70 &&AssetRate<=80){ Maxcoefficient = (1-0.1); Mincoefficient = (1-0.2); }else if(AssetRate>80 &&AssetRate<=90){ Maxcoefficient = (1-0.05); Mincoefficient = (1-0.15); }else if(AssetRate>90 &&AssetRate<=100){ Maxcoefficient = 1; Mincoefficient = (1-0.05); }else if(AssetRate>100 &&AssetRate<=110){ Maxcoefficient = (1+0.05); Mincoefficient = 1; }else if(AssetRate>110 &&AssetRate<=120){ Maxcoefficient = (1+0.1); Mincoefficient = 1; }else if(AssetRate>120 &&AssetRate<=130){ Maxcoefficient = (1+0.2); Mincoefficient = (1+0.1); }else if(AssetRate>130 &&AssetRate<=140){ Maxcoefficient = (1+0.25); Mincoefficient = (1+0.15); }else if(AssetRate>140){ Maxcoefficient = (1+0.3); Mincoefficient = (1+0.2); } //市场多年保修价格开发 DC 2023/1/30 end if(nowdate < Date.parse(lastendDate)){ // 市场多年保修价格开发 start DC 2023/01/19 //市场多年保设备小于2年半 var AssetModelNo = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Asset_Model_No__c : 0; var Category4 = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Category4__c : ''; //设备设备消费率小于1.4 if(AssetRate<140){ upPrice = VMassetListmonth * ContractMonth /12; if((AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF'))|| Category4 =='URF'){ downPrice = upPrice; }else{ downPrice = upPrice * 0.8; } }else{ upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12; downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12; } // 市场多年保修价格开发 end DC 2023/01/19 }else{ //市场多年保修价格开发 DC 2023/1/30 start 设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数 upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12; downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12; //市场多年保修价格开发 DC 2023/1/30 end } // gzw 20220630 实际联动6个月价格区分 }else{ upPrice = strMoney; downPrice = strMoney * 0.8; } }else{ upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100); downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100); } }else{ upPrice = strMoney; downPrice = strMoney * 0.8; } // 上下限四舍五入 upPrice = upPrice.toFixed(2); downPrice = downPrice.toFixed(2); // 12个月合同金额 if (!isDisabled) { // 实际联动价格 start //*1 转化为Number类型 checkedAssets[i].mcae.Adjustment_Lower_price__c = (downPrice*1).toFixed(2); checkedAssets[i].mcae.Adjustment_Upper_price__c = (upPrice*1).toFixed(2); // 实际联动价格 end } checkedAssets[i].mcae.Estimate_List_Price_Page__c = strMoney * 1; //Repair_Price__c null Number类型 .trim() repairMoney = (checkedAssets[i].mcae.Repair_Price__c == undefined ? null : checkedAssets[i].mcae.Repair_Price__c ) *1; } else { // TODO 一時的な対応、なんで別行の金額リフレッシュされた? checkedAssets[i].mcae.Estimate_List_Price_Page__c = ''; // 12个月合同金额 if (!isDisabled) { // 实际联动价格 start checkedAssets[i].mcae.Adjustment_Lower_price__c = ''; checkedAssets[i].mcae.Adjustment_Upper_price__c = ''; // 实际联动价格 end } } } else { // 所有设备按安装日、发货日(最早的),距离合同开始日6个月内都是新品合同 var isNewDate = new Date( checkedAssets[i].rec.isNewDate_use__c); isNewDate.setMonth(isNewDate.getMonth() + 6); if (Date.parse(contractStartDate) > Date.parse(isNewDate)) { newCon = false; } strMoney = assetListmonth ; Price_YearTXT = strMoney * 12; if (isnew) { strMoney = month * strMoney + month2 * strMoney / allData.isNewPriceAdj; } else { strMoney = month * strMoney + month2 * strMoney; } var b = checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.Maintenance_Contract_No_F__c : ''; var LastMContractRecord = checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.RecordType_DeveloperName__c : ''; if(b != ''){ conCCount ++; // 1.合同期不满一年时,合同期超过一半才可开始续签报价。(eg:11个月的合同从6个月后才可报价。) // 2.一年以上的合同,在结束前6个月开始可以开放续签报价。 var lastendDate = new Date(checkedAssets[i].rec.CurrentContract_End_Date__c); var lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F__r.Contract_End_Date__c); var lastContRange = 0; if(LastMContractRecord == 'VM_Contract'){ newCount++; //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 start GuranteeCount++; newCon = false; //多年保续签合同数量,多年保续签到服务合同时视为首签设备 thh 20220316 end lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c) ; lastContRange = 36; }else{ lastContRange = checkedAssets[i].rec.CurrentContract_F__r.Contract_Range__c; } //最后结束日+1年 lastendDate.setMonth(lastendDate.getMonth() + 12); if (Date.parse(contractStartDate) > Date.parse(lastendDate)) { oyearCount ++; } // 取联动价格 // 上一期合同实际报价月额 var LastMContract_Price = parseFloat(checkedAssets[i].mcae.LastMContract_Price__c * 1); var Adjustment_ratio_Lower = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Lower__c * 1); var Adjustment_ratio_Upper = parseFloat(checkedAssets[i].mcae.Adjustment_ratio_Upper__c * 1); //计算惩罚率 var Punish = handleInfo.calculateNtoMRatio(_this, lastContRange,(month + month2),allData); if(Punish == 0){ return; } // 判断有无报价:没有按照标准价格实际联动 var Estimate_Num = checkedAssets[i].rec.CurrentContract_F__r.Estimate_Num__c ; if(Estimate_Num == 0){ if(LastMContractRecord == 'VM_Contract'){ // gzw 20220630 实际联动6个月价格区分 var nowdate = new Date(); lastendDate = new Date(checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c); nowdate = nowdate.setMonth(nowdate.getMonth() + 6); //市场多年保修价格开发 DC 2023/1/30 start var Maxcoefficient =0; var Mincoefficient =0; var ContractMonth = handleInfo.localParseFloat(allData.estimate.Contract_Range__c); var AssetRate = handleInfo.localParseFloat(checkedAssets[i].rec.CurrentContract_F_asset__r.Asset_Consumption_Rate__c); checkedAssets[i].mcae.Asset_Consumption_rate__c = AssetRate; if(AssetRate<= 50){ Maxcoefficient = (1-0.3); Mincoefficient = (1-0.4); }else if(AssetRate>50 &&AssetRate<=60){ Maxcoefficient = (1-0.2); Mincoefficient = (1-0.3); }else if(AssetRate>60 &&AssetRate<=70){ Maxcoefficient = (1-0.15); Mincoefficient = (1-0.25); }else if(AssetRate>70 &&AssetRate<=80){ Maxcoefficient = (1-0.1); Mincoefficient = (1-0.2); }else if(AssetRate>80 &&AssetRate<=90){ Maxcoefficient = (1-0.05); Mincoefficient = (1-0.15); }else if(AssetRate>90 &&AssetRate<=100){ Maxcoefficient = 1; Mincoefficient = (1-0.05); }else if(AssetRate>100 &&AssetRate<=110){ Maxcoefficient = (1+0.05); Mincoefficient = 1; }else if(AssetRate>110 &&AssetRate<=120){ Maxcoefficient = (1+0.1); Mincoefficient = 1; }else if(AssetRate>120 &&AssetRate<=130){ Maxcoefficient = (1+0.2); Mincoefficient = (1+0.1); }else if(AssetRate>130 &&AssetRate<=140){ Maxcoefficient = (1+0.25); Mincoefficient = (1+0.15); }else if(AssetRate>140){ Maxcoefficient = (1+0.3); Mincoefficient = (1+0.2); } //市场多年保修价格开发 DC 2023/1/30 end if(nowdate < Date.parse(lastendDate)){ // 市场多年保修价格开发 start DC 2023/01/19 //市场多年保设备小于2年半 var AssetModelNo = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Asset_Model_No__c : 0; var Category4 = checkedAssets[i].rec.Product2 ? checkedAssets[i].rec.Product2.Category4__c : ''; //设备设备消费率小于1.4 if(AssetRate<140){ upPrice = VMassetListmonth *ContractMonth / 12; if((AssetModelNo.includes('290')&&( Category4 =='BF'|| Category4=='BF扇扫'||Category4=='CF'))|| Category4 =='URF'){ downPrice = upPrice; }else{ downPrice = upPrice * 0.8; } }else{ upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12; downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12; } // 市场多年保修价格开发 end DC 2023/01/19 }else{ //市场多年保修价格开发 DC 2023/1/30 start 设备大于2年半 续签价格 = 定价 *消费率对应系数 / 12 *合同月数 upPrice = VMassetListmonth * ContractMonth *Maxcoefficient / 12; downPrice = VMassetListmonth * ContractMonth * Mincoefficient / 12; //市场多年保修价格开发 DC 2023/1/30 end } // gzw 20220630 实际联动6个月价格区分 }else{ upPrice = strMoney; downPrice = strMoney * 0.8; } }else{ upPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100); downPrice = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100); } }else{ if (isnew) { newCount ++; } else { newCon = false; firstCCount ++; } upPrice = strMoney; downPrice = strMoney * 0.8; } // 上下限四舍五入 upPrice = upPrice.toFixed(2); downPrice = downPrice.toFixed(2); if (!isDisabled) { // 实际联动价格 start checkedAssets[i].mcae.Adjustment_Lower_price__c = (downPrice*1).toFixed(2); checkedAssets[i].mcae.Adjustment_Upper_price__c = (upPrice*1).toFixed(2); // 实际联动价格 end } checkedAssets[i].mcae.Estimate_List_Price_Page__c = strMoney * 1; // let Repair_Price_Auto = checkedAssets[i].Repair_Price_Auto; // Repair_Price_Auto = Repair_Price_AutoPrice.value(); 避免下面条件误判 repairMoney = checkedAssets[i].mcae.Repair_Price__c == undefined ? null : checkedAssets[i].mcae.Repair_Price__c; let repairMoney1 = parseFloat(repairMoney * 1); //在该部分js代码 未使用变量 var ISReduced = allData.estimate.IS_Reduced_price_approval__c; var Repair_Price_pass1 = checkedAssets[i].mcae.Repair_Price_pass__c; var Repair_Price_pass2 = handleInfo.localParseFloat(Repair_Price_pass1); if (repairMoney1> 0 && repairMoney1<(Repair_Price_Auto*0.80) && Repair_Price_Auto != null && isFSE == true) { if (Repair_Price_pass1!=null && repairMoney1 0 && (repairMoney3 0 && GuranteeCount == allcount){ result = '市场多年保续签合同'; //如果所有设备的上期合同都是多年保合同,则合同种类为市场多年保续签合同 thh 20220315 end }else if (newCount > 0 && newCount == allcount && newCon == true) { result = '新品合同'; }else if (((newCount > 0 && newCount == allcount) ||(newCount + firstCCount == allcount)) && newCon == false) { result = '首签合同'; }else if(firstCCount > 0 && firstCCount == allcount){ result = '首签合同'; // 20220328 ljh update LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start // }else if(oyearCount > 0 && oyearCount == conCCount){ }else if(oyearCount > 0 && oyearCount == conCCount && allcount == oyearCount ){ // 20220328 ljh update LJPH-C8FB4P【委托】配合PBI设备覆盖率的数据准备 start result = '非续签合同(空白期一年以上)'; }else{ result = '续签合同'; } allData.estimate.New_Contract_Type_TxT__c = result; allData.typeresult = result; //剩余内容前端处理 allData.checkedAssets = checkedAssets; returnData.allData = allData; returnData.approvalDate = approvalDate; return returnData; }, calculateNtoMRatio(_this,lastContRange, month,allData){ var lastContRangeYear = Math.ceil(parseFloat(lastContRange* 1)/12); var currentMonthYear = Math.ceil(parseFloat(month* 1)/12); //if(!lastendDate || currentMonthYear <= lastContRangeYear){ // calculateNtoMRatio报价规则改善新增 +- // var rateF = allData.estimate.Consumption_rate_Forecast__c; // var coefficient = allData.coefficient; // if (handleInfo.localParseFloat(rateF) * handleInfo.localParseFloat(coefficient) < 100) { // return month; // } // 报价规则改善新增 if(currentMonthYear == lastContRangeYear || currentMonthYear == 1){ return month; }else if(month <= 24) { return 12+ (month- 12) *1.1; }else if(month <= 36) { return 25.2 + (month- 24) *1.21; }else if(month <= 48) { return 39.72 + (month- 36) *1.331; }else if(month <= 60) { return 55.692 + (month- 48) *1.4641; }else { toast.showToast(_this, 'error', '合同期最长只能选择60个月!'); return 0; } }, // 报价规则改善 20230310 start addMonths(yearMonthDay ,monthNum){ if (!yearMonthDay) { return ''; } console.log('yearMonthDay',yearMonthDay); yearMonthDay = yearMonthDay.replace(new RegExp("/", "g"),'-'); console.log('yearMonthDay',yearMonthDay); //lwc 日期显示:2022-12-12 var arr=yearMonthDay.split('-'); var year=parseInt(arr[0]); var month=parseInt(arr[1]); var day=parseInt(arr[2]); month=month+monthNum; if(month>12){//月份加 var yearNum=parseInt( (month-1)/12); month=month%12==0?12 :month%12; year+=yearNum; }else if(month<=0){//月份减 month=Math.abs( month); var yearNum=parseInt( (month+12)/12); year-=yearNum; } month=month<10?"0"+month :month; return year+"-"+month+"-"+day; }, //parseFloat 避免NAN localParseFloat(val){ val = val == undefined ? null : val; return parseFloat(val*1); }, seamlessRenew(_this,cnt,allData,checkedAssets,PageDisabled,IsContractEstiStartDateDisabled){ var returnData = {}; // 2023/09/18 原有值返回 returnData.IsContractEstiStartDateDisabled = IsContractEstiStartDateDisabled; var startdatetime = allData.estimate.Contract_Esti_Start_Date__c; allData.startdateaddsix4 = startdatetime; // 报价规则改善 20230309 start var isSeamlessRenew = 0; var isSeamlessRenew1 = 0; var isSeamlessRenew3 = 0; var isSeamlessRenew4 = 0; // 报价规则改善 20230309 end // 报价规则改善 20230310 start var downPriceSum = 0; var upPriceSum = 0; var tag1 = 0; var downPriceSum1 = 0; var upPriceSum1 = 0; var downPriceSum3 = 0; var upPriceSum3 = 0; var downPriceSum4 = 0; var upPriceSum4 = 0; // 报价规则改善 20230310 end // 报价规则改善 20230310 start var renewTenOFF = allData.estimate.renewTen_OFF__c; if (renewTenOFF == true) { returnData.IsContractEstiStartDateDisabled = true; } // 2023/09/06 报价规则改善新增 var contrNew = allData.estimate.New_Contract_Type_TxT__c; // 2023/09/20 新增条件 var pastime = allData.Past_Contract_end_day; if (contrNew =='新品合同' || contrNew =='首签合同' || pastime== '') { isSeamlessRenew++; allData.startdateaddsix1 = startdatetime; allData.startdateaddsix2 = startdatetime; allData.startdateaddsix3 = startdatetime; }else{ allData.startdateaddsix1 = handleInfo.addMonths(allData.Past_Contract_end_day ,6); allData.startdateaddsix2 = handleInfo.addMonths(allData.Past_Contract_end_day ,6); allData.startdateaddsix3 = handleInfo.addMonths(allData.Past_Contract_end_day ,12); } // 报价规则改善新增 var ProductCountAll = 0; var VMProductCountAll = 0; // 报价规则改善 20230310 end for (var i = 0; i < cnt; i++) { console.log('seamlessRenew i',i); // 报价规则改善 20230310 start var downPrice = checkedAssets[i].mcae.Adjustment_Lower_price__c; console.log('seamlessRenew downPrice',downPrice); var downPrice1 = 0; var upPrice = checkedAssets[i].mcae.Adjustment_Upper_price__c; var upPrice1 = 0; var downPrice3 = 0; var upPrice3 = 0; var downPrice4 = 0; var upPrice4 = 0; var Price_YearTXT = 0; var LastMContract_Price = handleInfo.localParseFloat(checkedAssets[i].mcae.LastMContract_Price__c); var isnew = checkedAssets[i].mcae.IsNew__c; // 合同月数乗算 var month = handleInfo.localParseFloat(allData.estimate.Contract_Range__c); // 0 == '' --true if (month == undefined || month == "") { month = 1; } var month2 = 0; if (month > 12) { month2 = month - 12; month = 12; } var b = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.Maintenance_Contract_No_F__c : '') : ''; if (b != '') { ProductCountAll++; } var LastMContractRecord = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.RecordType_DeveloperName__c : '') : ''; if (LastMContractRecord == 'VM_Contract') { VMProductCountAll++; } if(b != ''){ var lastContRange = 0; if(LastMContractRecord == 'VM_Contract'){ lastContRange = 36; }else{ lastContRange = checkedAssets[i].mcae.Asset_Consumption_rate__c; } } var Punish = handleInfo.calculateNtoMRatio(_this, lastContRange,(month + month2),allData); // 报价规则改善 20230310 end // if (!isDisabled) { var Adjustment_ratio_Lower = handleInfo.localParseFloat(checkedAssets[i].mcae.Adjustment_ratio_Lower__c ); var Adjustment_ratio_Upper = handleInfo.localParseFloat(checkedAssets[i].mcae.Adjustment_ratio_Upper__c ); var strMoney = checkedAssets[i].mcae.Estimate_List_Price__c; Price_YearTXT = strMoney * 12; console.log('isnew',isnew); if (isnew == true) { strMoney = month * strMoney + month2 * strMoney / allData.isNewPriceAdj; } else { strMoney = month * strMoney + month2 * strMoney; } console.log('strMoney',strMoney); // 服务合同报价规则改善 20230227 start var LastMContractID = checkedAssets[i].rec ? checkedAssets[i].rec.CurrentContract_F__c : ''; var ISStandardPricing = checkedAssets[i].rec ? checkedAssets[i].rec.IS_StandardPricing__c+'' : ''; // var ProductISStandardPricing = checkedAssets[i].ProductISStandardPricing+''; // // 缺少首签设备逻辑 if ((ISStandardPricing == 'true' || ProductISStandardPricing == 'true' ) && (LastMContractID == '' || LastMContractID == undefined) && LastMContractRecord != 'VM_Contract') { console.log('strMoney = >downprice'); tag1 = 1; upPrice = strMoney; downPrice = strMoney; // isSeamlessRenew+; checkedAssets[i].mcae.Adjustment_Lower_price__c = isNaN(strMoney*1) ? '' : (strMoney*1).toFixed(2); checkedAssets[i].mcae.Adjustment_Upper_price__c = isNaN(strMoney*1) ? '' : (strMoney*1).toFixed(2); } console.log('LastMContractID',LastMContractID); // classic != '',undefined 同样未进入逻辑 if (LastMContractID) { // 服务合同报价规则改善 20230227 end var startdate11 = allData.Past_Contract_end_day; var startdate1 = allData.estimate.Contract_Esti_Start_Date__c; // new Date('')会异常 var startdate = new Date(startdate1); console.log('startdate1',startdate1); console.log('startdate11',startdate11); var startdatesix1 = new Date(handleInfo.addMonths(startdate11,6)); console.log('startdatesix1',startdatesix1); startdatesix1.setDate(startdatesix1.getDate()-1); console.log('startdatesix1 setDate',startdatesix1); var startdatesix2 = new Date(handleInfo.addMonths(startdate11,6)); startdatesix2.setDate(startdatesix2.getDate()+1); var startdatesix3 = new Date(handleInfo.addMonths(startdate11,12)); startdatesix3.setDate(startdatesix3.getDate()+1); // 第一个日期 var result1 = handleInfo.Blankperiod(startdate,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,1,LastMContractRecord,checkedAssets,allData,PageDisabled); console.log('result1',result1); //todo 可能 null var arr=result1.split('/'); downPrice=parseInt(arr[0]); upPrice=parseInt(arr[1]); isSeamlessRenew=isSeamlessRenew+parseInt(arr[2]); // 第二个日期 var result2 = handleInfo.Blankperiod(startdatesix1,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,2,LastMContractRecord,checkedAssets,allData,PageDisabled); console.log('result2',result2); var arr2=result2.split( '/'); downPrice1=parseInt(arr2[0]); upPrice1=parseInt(arr2[1]); isSeamlessRenew1=isSeamlessRenew1+parseInt(arr2[2]); // 第三个日期 var result3 = handleInfo.Blankperiod(startdatesix2,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,2,LastMContractRecord,checkedAssets,allData,PageDisabled); var arr3=result3.split( '/'); downPrice3=parseInt(arr3[0]); upPrice3=parseInt(arr3[1]); isSeamlessRenew3=isSeamlessRenew3+parseInt(arr3[2]); // 第四个日期 var result4 = handleInfo.Blankperiod(startdatesix3,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,2,LastMContractRecord,checkedAssets,allData,PageDisabled); var arr4=result4.split( '/'); downPrice4=parseInt(arr4[0]); upPrice4=parseInt(arr4[1]); isSeamlessRenew4=isSeamlessRenew4+parseInt(arr4[2]); }else{ var assN = checkedAssets[i].rec ? checkedAssets[i].rec.Name : ''; if (assN !=null&&assN != '') { isSeamlessRenew++; isSeamlessRenew1++; isSeamlessRenew4++; isSeamlessRenew3++; } } //方法内定义变量 // 报价规则改善 20230308 end // 报价规则改善 20230310 start console.log('downPrice',downPrice); downPriceSum = downPriceSum + handleInfo.localParseFloat(downPrice); upPriceSum = upPriceSum + handleInfo.localParseFloat(upPrice); console.log('downPrice1',downPrice1); if (downPrice1 ==0) { downPriceSum1 = downPriceSum1 + handleInfo.localParseFloat(downPrice); }else{ downPriceSum1 = downPriceSum1 + handleInfo.localParseFloat(downPrice1); } if (upPrice1 ==0) { upPriceSum1 = upPriceSum1 + handleInfo.localParseFloat(upPrice); }else{ upPriceSum1 = upPriceSum1 + handleInfo.localParseFloat(upPrice1); } if (downPrice3 ==0) { downPriceSum3 = downPriceSum3 + handleInfo.localParseFloat(downPrice); }else{ downPriceSum3 = downPriceSum3 + handleInfo.localParseFloat(downPrice3); } if (upPrice3 ==0) { upPriceSum3 = upPriceSum3 + handleInfo.localParseFloat(upPrice); }else{ upPriceSum3 = upPriceSum3 + handleInfo.localParseFloat(upPrice3); } if (downPrice4 ==0) { downPriceSum4 = downPriceSum4 + handleInfo.localParseFloat(downPrice); }else{ downPriceSum4 = downPriceSum4 + handleInfo.localParseFloat(downPrice4); } if (upPrice4 ==0) { upPriceSum4 = upPriceSum4 + handleInfo.localParseFloat(upPrice); }else{ upPriceSum4 = upPriceSum4 + handleInfo.localParseFloat(upPrice4); } } // 报价规则改善 20230309 start if (isSeamlessRenew==0) { allData.Is_Blank_period = true; }else{ allData.Is_Blank_period = false; } //Past_Contract_end_day = null->startime1=Thu Jan 01 1970 08:00:00 GMT+0800 // result 目前未涉及其他逻辑,暂不处理 Past_Contract_end_day没有值转为''?-》invalid Date var startime1 = new Date(allData.Past_Contract_end_day); var startime2 = new Date(allData.estimate.Contract_Esti_Start_Date__c); var result = (startime2-startime1)/(3600*24*1000); // Is_Blank_period1,Cost_rate_ForecastF 定义变量未使用 var Is_Blank_period1 = allData.Is_Blank_period; var Cost_rate_ForecastF = allData.Cost_rate_ForecastF; // 2023/09/20 补充 价格处理(4个标准价格的最低/高价总额) var GuidePriceUp1 = allData.estimate.GuidePrice_Up1__c +''; var GuidePriceUp2 = allData.estimate.GuidePrice_Up2__c +''; var GuidePriceUp3 = allData.estimate.GuidePrice_Up3__c +''; // 2023/08/31 添加逻辑判断 页面可编辑时重新计算,不可编辑时,没有值则重新计算 if (!PageDisabled) { //round 为整数,toFixed 保留两位小数无意义 allData.estimate.GuidePrice_Up__c = Math.round(upPriceSum)*1; allData.estimate.GuidePrice_Down__c = Math.round(downPriceSum)*1; allData.estimate.GuidePrice_Up1__c = Math.round(upPriceSum1)*1; allData.estimate.GuidePrice_Down1__c = Math.round(downPriceSum1)*1; allData.estimate.GuidePrice_Up2__c = Math.round(upPriceSum3)*1; allData.estimate.GuidePrice_Down2__c = Math.round(downPriceSum3)*1; allData.estimate.GuidePrice_Up3__c = Math.round(upPriceSum4)*1; allData.estimate.GuidePrice_Down3__c = Math.round(downPriceSum4)*1; }else{ // 字符串.trim() if (GuidePriceUp1.trim() == '' || GuidePriceUp2.trim() == '' || GuidePriceUp3.trim() == '') { allData.estimate.GuidePrice_Up1__c = Math.round(upPriceSum1)*1; allData.estimate.GuidePrice_Down1__c = Math.round(downPriceSum1)*1; allData.estimate.GuidePrice_Up2__c = Math.round(upPriceSum3)*1; allData.estimate.GuidePrice_Down2__c = Math.round(downPriceSum3)*1; allData.estimate.GuidePrice_Up3__c = Math.round(upPriceSum4)*1; allData.estimate.GuidePrice_Down3__c = Math.round(downPriceSum4)*1; } } //未找到 id GuidePriceDown5 GuidePriceUp5 -- 该字段移到estimate对象上 // allData.GuidePriceDown4 = Math.round(downPriceSum1)*1; // allData.GuidePriceUp4 = Math.round(upPriceSum1)*1; // allData.GuidePriceDown3 = Math.round(downPriceSum3)*1; // allData.GuidePriceUp3 = Math.round(upPriceSum3)*1; // allData.GuidePriceDown2 = Math.round(downPriceSum4)*1; // allData.GuidePriceUp2 = Math.round(upPriceSum4)*1; allData.VMProductCountAll = VMProductCountAll; var allcount = VMProductCountAll; allData.ProductCountAll = ProductCountAll; var allcount1 = ProductCountAll; returnData.checkedAssets = checkedAssets; returnData.allData = allData; // 报价规则改善 20230309 end return returnData; }, Blankperiod(startdate,i,LastMContract_Price,Punish,Adjustment_ratio_Upper,Adjustment_ratio_Lower,strMoney,type,LastMContractRecord,checkedAssets,allData,PageDisabled){ console.log('开始时间='+startdate); var downPrice = 0; var upPrice = 0; var today = new Date(); var isSeamlessRenew = 0; console.log('lastendDate1',checkedAssets[i].rec.Id); if(LastMContractRecord == 'VM_Contract'){ var lastendDate1 = checkedAssets[i].rec ? checkedAssets[i].rec.CurrentContract_F_asset__r.endDateGurantee_Text__c : ''; }else{ var lastendDate1= checkedAssets[i].rec ? checkedAssets[i].rec.CurrentContract_End_Date__c : ''; } // 2023/09/06 var renewcontractstartdate = allData.renewcontractstartdate; var renewcontractstartdate1 = new Date(renewcontractstartdate); var Blank_period = checkedAssets[i].mcae.Blank_period__c; console.log('lastendDate1',lastendDate1); var lastendDate = new Date(lastendDate1); var lastendDateAddSix = new Date(lastendDate1); lastendDateAddSix.setMonth(lastendDateAddSix.getMonth() + 6); console.log('lastendDateAddSix',lastendDateAddSix); var lastendDateAddTw = new Date(lastendDate1); lastendDateAddTw.setMonth(lastendDateAddTw.getMonth() + 12); var lastendDateAddFiv = new Date(lastendDate1); lastendDateAddFiv.setDate(lastendDateAddFiv.getDate() + 15); console.log('结束时间+15天 lastendDateAddFiv',lastendDateAddFiv); // 2023/09/06 var renewtime = lastendDateAddFiv.getFullYear()+'/'+(lastendDateAddFiv.getMonth()+1)+'/'+lastendDateAddFiv.getDate(); if (renewcontractstartdate == '' ) { allData.renewcontractstartdate = renewtime; console.log('添加完成'); } // del 变量未使用 var renewcontractstartdate222 = allData.renewcontractstartdate; if (lastendDateAddFiv < renewcontractstartdate1 ) { allData.renewcontractstartdate = renewtime; } //add 空指针判断 if (lastendDate1 && lastendDate1.length !=0) { console.log('startdate',startdate.getFullYear()+'-'+startdate.getMonth()+'-'+startdate.getDate()); if (startdate == null) { // 2023/09/06 if (today<=lastendDateAddFiv) { Blank_period = '无缝续签'; } if (today>lastendDateAddFiv && today<=lastendDateAddSix) { Blank_period = '6个月以内非无缝续签'; } if (today>lastendDateAddSix && today<=lastendDateAddTw) { Blank_period = '6个月-12个月'; } if (today>lastendDateAddTw) { Blank_period = '12个月以上'; } }else{ if (startdate<=lastendDateAddFiv) { Blank_period = '无缝续签'; } if (startdate>lastendDateAddFiv && startdate<=lastendDateAddSix) { Blank_period = '6个月以内非无缝续签'; } if (startdate>lastendDateAddSix && startdate<=lastendDateAddTw) { Blank_period = '6个月-12个月'; } if (startdate>lastendDateAddTw) { Blank_period = '12个月以上'; } } checkedAssets[i].mcae.Blank_period__c = Blank_period; } console.log('Blank_period',Blank_period); var Blank_period1 = Blank_period; var aId = checkedAssets[i].recId; if (Blank_period1 != '无缝续签' && aId !=null && aId != '') { isSeamlessRenew++; } // 1.实绩连动价格和设备参保定价 逻辑查看 // 2023/09/15 逻辑调整 取refreshAsset 计算后值 start var b = checkedAssets[i].rec ? (checkedAssets[i].rec.CurrentContract_F__r ? checkedAssets[i].rec.CurrentContract_F__r.Maintenance_Contract_No_F__c : '') : ''; if(LastMContractRecord == 'VM_Contract'){ var upPrice1 = checkedAssets[i].mcae.Adjustment_Upper_price__c *1; var downPrice1 = checkedAssets[i].mcae.Adjustment_Lower_price__c *1; }else{ if (b != '') { var upPrice1 = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Upper/100); var downPrice1 = (LastMContract_Price * Punish) * (1 + Adjustment_ratio_Lower/100); } } // 2023/09/15 逻辑调整 取refreshAsset 计算后值 end // 定价8折 var downPrice2 = strMoney * 0.8; console.log('upPrice1',upPrice1); upPrice1 = upPrice1.toFixed(2); var upPrice2 = strMoney.toFixed(2); downPrice1 = downPrice1.toFixed(2); downPrice2 = downPrice2.toFixed(2); upPrice1 = parseInt(upPrice1); upPrice2 = parseInt(upPrice2); downPrice1 = parseInt(downPrice1); downPrice2 = parseInt(downPrice2); if (!Blank_period1) { downPrice = downPrice2; upPrice = upPrice2; } if (Blank_period1 && Blank_period1.length!=0 && Blank_period1 == '6个月以内非无缝续签' || Blank_period1 == '无缝续签' ) { if (type == 1 &&!PageDisabled) { checkedAssets[i].mcae.Adjustment_Lower_price__c = isNaN(downPrice1*1) ? '' : (downPrice1*1).toFixed(2); checkedAssets[i].mcae.Adjustment_Upper_price__c = isNaN(upPrice1*1) ? '' : (upPrice1*1).toFixed(2); } downPrice = downPrice1; upPrice = upPrice1; } console.log('upPrice2',upPrice2); console.log('downPrice1',downPrice1); console.log('downPrice2',downPrice2); console.log('type',type); // Blank_period1 != '无缝续签' && 条件无意义 if (Blank_period1 == '6个月-12个月') { if (downPrice1 9) ? month1 : ("0" + month1); day1 = (day1 < 10) ? ("0" + day1) : day1; var startime1 = year1 + "-" + month1 + "-" + day1; var year2 = startime2.getFullYear(); var month2 = startime2.getMonth(); var day2 = startime2.getDate(); month2 = (month2 > 9) ? month2 : ("0" + month2); day2 = (day2 < 10) ? ("0" + day2) : day2; var startime2 = year2 + "-" + month2 + "-" + day2; var result = daysBetween(startime1,startime2); // var result = (startime2-startime1)/(3600*24*1000); // gzw add 日期差时间取值造成数据不准问题 20231103修复 end var VMProductCountAll = allData.VMProductCountAll ; var ProductCountAll = allData.ProductCountAll; if (VMProductCountAll ==ProductCountAll) { result = 0; } var Is_Blank_period1 = allData.Is_Blank_period; //预测成本率计算 天修理实绩汇总*合同月数*30/申请报价金额 var MonthlyCostSUM = handleInfo.localParseFloat(allData.estimate.Monthly_Repair_Cost_SUM__c); var months = handleInfo.localParseFloat(allData.estimate.Contract_Range__c); console.log('MonthlyCostSUM',MonthlyCostSUM); console.log('months',months); var Cost_rate_ForecastF = ((MonthlyCostSUM*months*30)/(val*0.9))*0.75; console.log('Cost_rate_ForecastF',Cost_rate_ForecastF); var downprice = allData.estimate.GuidePrice_Down__c; var upprice = allData.estimate.GuidePrice_Up__c; var renewTenOFF = allData.estimate.renewTen_OFF__c; var AgreerenewTenOFF = allData.estimate.AgreeRenewTen_OFF__c; // 2023/09/06 报价规则改善新增 var Limit_PriceHidden2 = allData.isLimitPrice; var isFSE = allData.isFSE; console.log('Is_Blank_period1',Is_Blank_period1); console.log('downprice',downprice); // console.log('downprice replace',downprice.replace(",", "")); console.log('result',result); console.log('result localParseFloat',handleInfo.localParseFloat(result)); if (Is_Blank_period1 == true && (Cost_rate_ForecastF<1) && (0