123
chenjingwu
2024-04-11 278a7ae49ca7a23d71e8c1ecb0546b73ce2dfa2a
force-app/main/default/lwc/improvedForecastTime/improvedForecastTime.js
@@ -1,11 +1,16 @@
import { LightningElement, track  } from 'lwc';
import { api, wire,LightningElement } 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';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { CloseActionScreenEvent } from 'lightning/actions';
import { updateRecord } from 'lightning/uiRecordApi';
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
import {loadStyle} from 'lightning/platformResourceLoader';
import lexDateCss from '@salesforce/resourceUrl/lexDateCss';
export default class ImprovedForecastTime extends LightningElement {
    @api recordId;
    //显示与隐藏
    isAdvance = false;  //选着 提前 的标识
    isDelay = false; //选着 延后 的标识
@@ -14,6 +19,9 @@
        {label:"提前",value:"提前"},
        {label:"延后",value:"延后"},
    ]
    updateRecordView(recordId) {
        updateRecord({fields: { Id: recordId }});
    }
        
    handleRelationFn(event){
@@ -99,8 +107,12 @@
    //初始化
    connectedCallback(){
        this.oppId = this.getQueryVariable('id');
        Promise.all([
            loadStyle(this, lwcCSS),
            loadStyle(this, lexDateCss)
           ]);
        this.oppId = this.recordId;
        console.log('oppId--' + this.oppId);
        GetOppinformationcData({ParamIdStr:this.oppId}).then(response=>{
            this.opp=JSON.parse(response);
@@ -136,10 +148,10 @@
        if (error) {
            this.TongzhiIcon = "standard:first_non_empty";
            this.BgColorStyle = "background-color:#f88568";
            this.BgColorStyle = "background-color:#ba0517";
        }else{
            this.TongzhiIcon = "standard:account";
            this.BgColorStyle = "background-color:#69e669";
            this.BgColorStyle = "background-color:#DD7A01";
        }
        if (left) {
            this.IsLeftStyle = "left: 0.25rem"
@@ -147,7 +159,25 @@
            this.IsLeftStyle = ""
        }
    }
    showToast(msg,type) {
        if(type == 'success'){
          const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type
          });
          this.dispatchEvent(event);
        }else{
          const event = new ShowToastEvent({
            title: '',
            message: msg,
            variant: type,
            mode: 'sticky'
        });
        this.dispatchEvent(event);
        }
    }
    //关闭提示框
    CloseAlert(){
        this.closeOffRefresh();
@@ -212,24 +242,24 @@
        // 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);
            this.showToast("请选择日期/理由。","error");
        }
        else if(this.opp.Date_InAdvance_Delay == '提前' && (myDate5 >= myDate4 || myDate5 < myDate3)){
            this.Alert("请选择 “提前” 于当前预测OCSM签约日的日期 且 不早于今天。",false,true);
            this.showToast("请选择 “提前” 于当前预测OCSM签约日的日期 且 不早于今天。","error");
        }
        else if(this.opp.Date_InAdvance_Delay == '延后' && myDate5 <= myDate4){
            this.Alert("请选择 “延后” 于当前预测OCSM签约日的日期。",false,true);
            this.showToast("请选择 “延后” 于当前预测OCSM签约日的日期。","error");
        }
        else if(myDate7 < myDate5){
            this.Alert("预测发货日不能小于预测签约日。",false,true);
            this.showToast("预测发货日不能小于预测签约日。","error");
        }
        //20221226 lt DB202212359066增加限制-修改预测日最大日期 start
        else if(myDate5 > OrderDate){
            this.Alert("订货预测日请在未来三财年内。",false,true);
            this.showToast("订货预测日请在未来三财年内。","error");
        }
        else if(myDate7 > ShipmentsDate){
            this.Alert("发货预测日请在未来四财年内。",false,true);
            this.showToast("发货预测日请在未来四财年内。","error");
        }
        //20221226 lt DB202212359066增加限制-修改预测日最大日期 end
@@ -238,10 +268,19 @@
            SaveData({JsonData:JSON.stringify(this.opp)}).then((response)=>{
                if (response == '成功') {
                    this.OnLoading(false);
                    this.Alert("保存成功",false,true);
                    window.location.hash = "Refresh"+"=="+this.oppId;
                    this.showToast("保存成功","success");
                    // window.location.hash = "Refresh"+"=="+this.oppId;
                    const closeEvent = new CustomEvent('closeaction', {
                        bubbles: true, // 允许事件冒泡至父组件
                        composed: true, // 允许事件穿越 Shadow DOM 界限
                    });
                    setTimeout(() => {
                        window.location = '/' + this.recordId;
                    }, 2000);
                    this.dispatchEvent(closeEvent);
                }else{
                    this.Alert(response,true);
                    this.showToast(response,"error");
                    this.IsLoading = false;
                }
            });
        }