import { LightningElement, track } from 'lwc';
|
import GetOppinformationcData from '@salesforce/apex/ImprovedForecastTimeController.GetOppinformationcData';
|
import getReason from '@salesforce/apex/ImprovedForecastTimeController.getReason';
|
import SaveData from '@salesforce/apex/ImprovedForecastTimeController.SaveData';
|
import SystemModstamp from '@salesforce/schema/Account.SystemModstamp';
|
|
export default class ImprovedForecastTime extends LightningElement {
|
|
//显示与隐藏
|
isAdvance = false; //选着 提前 的标识
|
isDelay = false; //选着 延后 的标识
|
|
RelateOption=[
|
{label:"提前",value:"提前"},
|
{label:"延后",value:"延后"},
|
]
|
|
handleRelationFn(event){
|
|
var value = event.target.value;
|
this.opp.Date_InAdvance_Delay = value;
|
debugger
|
// this.opp.Predicted_date_ChangeReason__c = '';
|
//SWAG-CJR4PC【委托】调查-修改预测日提前理由错误 fy start
|
this.opp.Predicted_date_ChangeReason = ''
|
this.opp.Close_Forecasted_Date= '';
|
this.opp.CloseDate= '';
|
//SWAG-CJR4PC【委托】调查-修改预测日提前理由错误 fy end
|
if (value == "提前") {
|
this.isAdvance = true;
|
this.isDelay = false;
|
|
}
|
if (value == "延后") {
|
this.isAdvance = false;
|
this.isDelay = true;
|
}
|
|
}
|
|
handleRelationFn1(event){
|
var value = event.target.value;
|
this.opp.Predicted_date_ChangeReason = value;
|
}
|
flg=true;
|
handleRelationFn2(event){
|
var value = event.target.value;
|
this.opp.Close_Forecasted_Date = value;
|
this.flg=false;
|
debugger
|
this.CloseDateAssignment(value);
|
}
|
//给预测发货日赋值
|
CloseDateAssignment(value){
|
debugger
|
var value=this.addDay(30,value);
|
this.opp.CloseDate = value;
|
this.flg=true;
|
}
|
//加天数
|
addDay(dayNumber, value1) {
|
var date = new Date(value1);
|
var ms = dayNumber * (1000 * 60 * 60 * 24)
|
|
var newDate = new Date(date.getTime() + ms);
|
var value=newDate.toLocaleDateString();
|
var value2=value.split('/');
|
if(value2[1].length == 1){
|
value2[1]='0'+value2[1];
|
}
|
if(value2[2].length == 1){
|
value2[2]='0'+value2[2];
|
}
|
value=value2[0]+'-'+value2[1]+'-'+value2[2];
|
return value;
|
}
|
handleRelationFn3(event){
|
var value = event.target.value;
|
this.opp.CloseDate = value;
|
}
|
//从url上取得ID
|
getQueryVariable(variable)
|
{
|
var query = window.location.search.substring(1);
|
var vars = query.split("&");
|
for (var i=0;i<vars.length;i++) {
|
var pair = vars[i].split("=");
|
if(pair[0] == variable){return pair[1];}
|
}
|
return(false);
|
}
|
|
oppId = '';
|
opp = {};
|
Date_InAdvance_Delay = '';
|
|
AdvanceReasons = [];
|
DelayReasons = [];
|
|
//初始化
|
connectedCallback(){
|
this.oppId = this.getQueryVariable('id');
|
|
GetOppinformationcData({ParamIdStr:this.oppId}).then(response=>{
|
this.opp=JSON.parse(response);
|
|
if(this.opp.Date_InAdvance_Delay == '提前'){
|
this.isAdvance = true;
|
this.isDelay = false;
|
}
|
if(this.opp.Date_InAdvance_Delay == '延后'){
|
this.isAdvance = false;
|
this.isDelay = true;
|
}
|
});
|
|
getReason().then(response=>{
|
var options = JSON.parse(response);
|
this.AdvanceReasons = options['提前'];
|
this.DelayReasons = options['延后'];
|
});
|
|
}
|
|
//提示
|
SaveShowText="保存成功";//提示框的文本
|
Tongzhishow=false; //提示显示的标识
|
TongzhiIcon = 'standard:account' //提示框的图标
|
IsLeftStyle = "" //提示框的样式
|
BgColorStyle = ""
|
|
//弹框提示 content 内容 error 是否是错误提示框 left 是否居左
|
Alert(content,error = false,left = false){
|
this.SaveShowText = content;
|
this.Tongzhishow = true;
|
|
if (error) {
|
this.TongzhiIcon = "standard:first_non_empty";
|
this.BgColorStyle = "background-color:#f88568";
|
}else{
|
this.TongzhiIcon = "standard:account";
|
this.BgColorStyle = "background-color:#69e669";
|
}
|
if (left) {
|
this.IsLeftStyle = "left: 0.25rem"
|
}else{
|
this.IsLeftStyle = ""
|
}
|
}
|
|
//关闭提示框
|
CloseAlert(){
|
this.closeOffRefresh();
|
}
|
closeOffRefresh(){
|
if (this.Tongzhishow == true) {
|
this.Tongzhishow = false;
|
}
|
if (this.SaveShowText != "") {
|
this.SaveShowText = "";
|
}
|
}
|
//加载
|
IsLoading = false;
|
OnLoading(flag) {
|
this.IsLoading = flag;
|
}
|
//保存数据逻辑
|
saveFn(){
|
debugger
|
var myDate = new Date(); //今天日期
|
var myDate1 = new Date(this.opp.Close_Forecasted_Check); //当前预测日期
|
var myDate2 = new Date(this.opp.Close_Forecasted_Date); //改变的预测日期
|
var myDate3 = new Date(myDate.toLocaleDateString()); //今天日期 格式化
|
var myDate4 = new Date(myDate1.toLocaleDateString()); //当前预测日期 格式化
|
var myDate5 = new Date(myDate2.toLocaleDateString()); //改变的预测日期 格式化
|
|
var myDate6 = new Date(this.opp.CloseDate);
|
var myDate7 = new Date(myDate6.toLocaleDateString()); //发货日期
|
|
//20221226 lt DB202212359066增加限制-修改预测日最大日期 start
|
var date1 = new Date();
|
var year = date1.getFullYear();
|
var month = date1.getMonth() + 1;
|
if(month > 3){
|
year = year + 1;
|
}
|
|
var strDate = "-03-31";
|
var Odate = year + 3;
|
var Sdate = year + 4;
|
var Odate1 = Odate + strDate;
|
var Sdate1 = Sdate + strDate;
|
var Odate2 = new Date(Odate1);
|
var Sdate2 = new Date(Sdate1);
|
|
// //订货预测日
|
var OrderDate = new Date(Odate2.toLocaleDateString());
|
// //发货预测日
|
var ShipmentsDate = new Date(Sdate2.toLocaleDateString());
|
|
//20221226 lt DB202212359066增加限制-修改预测日最大日期 end
|
|
console.warn('myDatevalue:='+myDate);
|
console.warn('今天日期'+myDate3);
|
console.warn('当前预测日期'+myDate4);
|
console.warn('1111111111'+myDate2);
|
console.warn('改变的预测日期'+myDate5);
|
|
//SWAG-CJR4PC【委托】调查-修改预测日提前理由错误 fy start
|
// if(this.opp.Date_InAdvance_Delay == undefined || this.opp.Predicted_date_ChangeReason == undefined || myDate5 == undefined){
|
// if(this.opp.Date_InAdvance_Delay == '' ||this.opp.Date_InAdvance_Delay == undefined || this.opp.Predicted_date_ChangeReason == '' ||this.opp.Predicted_date_ChangeReason == undefined|| myDate5 == '' || myDate5 == undefined){
|
if(!this.opp.Date_InAdvance_Delay || !this.opp.Predicted_date_ChangeReason || !this.opp.Close_Forecasted_Date){
|
//SWAG-CJR4PC【委托】调查-修改预测日提前理由错误 fy end
|
this.Alert("请选择日期/理由。",false,true);
|
}
|
else if(this.opp.Date_InAdvance_Delay == '提前' && (myDate5 >= myDate4 || myDate5 < myDate3)){
|
this.Alert("请选择 “提前” 于当前预测OCSM签约日的日期 且 不早于今天。",false,true);
|
}
|
else if(this.opp.Date_InAdvance_Delay == '延后' && myDate5 <= myDate4){
|
this.Alert("请选择 “延后” 于当前预测OCSM签约日的日期。",false,true);
|
}
|
else if(myDate7 < myDate5){
|
this.Alert("预测发货日不能小于预测签约日。",false,true);
|
}
|
|
//20221226 lt DB202212359066增加限制-修改预测日最大日期 start
|
else if(myDate5 > OrderDate){
|
this.Alert("订货预测日请在未来三财年内。",false,true);
|
}
|
else if(myDate7 > ShipmentsDate){
|
this.Alert("发货预测日请在未来四财年内。",false,true);
|
}
|
//20221226 lt DB202212359066增加限制-修改预测日最大日期 end
|
|
else{
|
this.OnLoading(true);
|
SaveData({JsonData:JSON.stringify(this.opp)}).then((response)=>{
|
if (response == '成功') {
|
this.OnLoading(false);
|
this.Alert("保存成功",false,true);
|
window.location.hash = "Refresh"+"=="+this.oppId;
|
}else{
|
this.Alert(response,true);
|
}
|
});
|
}
|
}
|
|
}
|