import { LightningElement,wire,track,api} from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
|
import init from '@salesforce/apex/lexToAddMaintenanceContractController.initUploadToRecognition';
|
import updateColunm from '@salesforce/apex/otherButtonMaintenanceContractCtl.updateColunm';
|
import up2sap from '@salesforce/apex/LexOtherButtonMc.up2sap';
|
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import {loadStyle} from 'lightning/platformResourceLoader';
|
import lexSendNfm103 from '@salesforce/resourceUrl/lexSendNfm103';
|
|
export default class lexUploadToRecognition extends LightningElement {
|
@api recordId;
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
}
|
}
|
}
|
|
connectedCallback(){
|
Promise.all([
|
loadStyle(this,lwcCSS),
|
loadStyle(this, lexSendNfm103)
|
]);
|
init({
|
recordId: this.recordId
|
}).then(returnData => {
|
if(returnData) {
|
console.log(returnData);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
debugger
|
this.IsLoading = false;
|
var records = returnData
|
var msg = '';
|
var j =0;
|
for(var i=0;i<records.length;i++) {
|
j = i+1;
|
var fooResult = this.foo(records[i]);
|
if(fooResult != '1') {
|
msg += '【'+j+'】'+records[i].Name+': ' + fooResult +'\n';
|
console.log(msg);
|
console.log('record'+i+records[i]);
|
}
|
|
}
|
}
|
if(msg ) {
|
this.showToast(msg,'error');
|
return;
|
}
|
|
if(!confirm('请确认是否要上传认款合同。')){
|
return;
|
}
|
for(var i=0;i<records.length;i++) {
|
var rst = this.up2sapJs( records[i].Id);
|
if(rst!='1') {
|
this.showToast('上传认款合同失败','error');
|
return;
|
}
|
}
|
this.showToast('上传认款合同成功','success');
|
|
});
|
}
|
|
foo(mc){
|
var resultMsg = '';
|
// var resultMsg = '【'+mc.Name+'】';
|
if(mc.Contract_quotation_or_not__c == '还没做报价'){
|
resultMsg +="您还没有做合同报价,不能上传认款合同。";
|
return resultMsg ;
|
}else if(!mc.Decided_Estimation__c) {
|
resultMsg += '合同报价还没有decide,不能上传认款合同。';
|
return resultMsg ;
|
}else if (mc.Maintenance_Contract_No__c=='' || mc.Maintenance_Contract_No__c==null) {
|
resultMsg +="合同号码为空,不能上传认款合同。";
|
return resultMsg ;
|
}else if (mc.upload_to_sap_time__c != '' && mc.upload_to_sap_time__c != null) {
|
resultMsg +="已经上传SAP,不能再次上传认款合同。";
|
return resultMsg ;
|
}else if(mc.upload_to_RM_time__c != '' && mc.upload_to_RM_time__c != null){
|
resultMsg +="已经上传认款合同,不能再次上传认款合同。";
|
return resultMsg ;
|
}else{
|
if(mc.old_Is_RecognitionModel__c=='false' || mc.old_Is_RecognitionModel__c==false){
|
resultMsg +="经销商为空或经销商不是先款对象,不需要上传认款合同。";
|
return resultMsg ;
|
}else if(mc.Payment_Plan_Sum_First__c == '' || mc.Payment_Plan_Sum_First__c == null ){
|
resultMsg +="第一次计划付款金额不能为空。";
|
return resultMsg ;
|
}else{
|
return '1';
|
|
|
}
|
}
|
return resultMsg;
|
}
|
|
async up2sapJs (mcid) {
|
var resultMsg = '1';
|
await updateColunm({
|
mcid: mcid
|
}).then(result => {
|
if (result != '1') {
|
resultMsg = '2';
|
return resultMsg ;
|
// this.ShowToastEvent('上传认款合同失败,因为 来年合同相关信息修改失败', "error");
|
// this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
})
|
await up2sap({
|
mcid: mcid
|
}).then(rtn => {
|
if (rtn == '1') {
|
resultMsg ="1";
|
} else {
|
resultMsg ='3';
|
}
|
return resultMsg ;
|
})
|
|
}
|
showToast(msg,type) {
|
if(type == 'success'){
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type
|
});
|
this.dispatchEvent(event);
|
}else{
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type,
|
mode: 'sticky'
|
});
|
this.dispatchEvent(event);
|
}
|
}
|
}
|
|
// old js
|
//zhangzhengmei 2023/06/28 start
|
/*var executeFoo = function() {
|
|
var mcpid = '{!MaintanceContractPack__c.Id}';
|
console.log('mcpid ='+mcpid);
|
var sql = "select Id,Name,Decided_Estimation__c,Contract_quotation_or_not__c,Maintenance_Contract_No__c,upload_to_sap_time__c,upload_to_RM_time__c,old_Is_RecognitionModel__c,Payment_Plan_Sum_First__c from Maintenance_Contract__c where MaintanceContractPack__c='" + mcpid + "'";
|
var sqlResult = sforce.connection.query(sql);
|
var records = sqlResult.getArray("records");
|
var msg = '';
|
for(var i=0;i<records.length;i++) {
|
j = i+1;
|
var fooResult = foo(records[i]);
|
if(fooResult != '1') {
|
msg += '【'+j+'】'+records[i].Name+': ' + foo(records[i]) +'\n';
|
console.log(msg);
|
console.log('record'+i+records[i]);
|
}
|
|
}
|
if(msg ) {
|
alert(msg);
|
return;
|
}
|
|
if(!confirm('请确认是否要上传认款合同。')){
|
return;
|
}
|
for(var i=0;i<records.length;i++) {
|
var rst = up2sapJs( records[i].Id);
|
if(rst!='1') {
|
alert('上传认款合同失败');
|
return;
|
}
|
}
|
alert('上传认款合同成功');
|
|
}
|
executeFoo();
|
function foo(mc){
|
var resultMsg = '';
|
// var resultMsg = '【'+mc.Name+'】';
|
if(mc.Contract_quotation_or_not__c == '还没做报价'){
|
resultMsg +="您还没有做合同报价,不能上传认款合同。";
|
return resultMsg ;
|
}else if(!mc.Decided_Estimation__c) {
|
resultMsg += '合同报价还没有decide,不能上传认款合同。';
|
return resultMsg ;
|
}else if (mc.Maintenance_Contract_No__c=='' || mc.Maintenance_Contract_No__c==null) {
|
resultMsg +="合同号码为空,不能上传认款合同。";
|
return resultMsg ;
|
}else if (mc.upload_to_sap_time__c != '' && mc.upload_to_sap_time__c != null) {
|
resultMsg +="已经上传SAP,不能再次上传认款合同。";
|
return resultMsg ;
|
}else if(mc.upload_to_RM_time__c != '' && mc.upload_to_RM_time__c != null){
|
resultMsg +="已经上传认款合同,不能再次上传认款合同。";
|
return resultMsg ;
|
}else{
|
if(mc.old_Is_RecognitionModel__c=='false' || mc.old_Is_RecognitionModel__c==false){
|
resultMsg +="经销商为空或经销商不是先款对象,不需要上传认款合同。";
|
return resultMsg ;
|
}else if(mc.Payment_Plan_Sum_First__c == '' || mc.Payment_Plan_Sum_First__c == null ){
|
resultMsg +="第一次计划付款金额不能为空。";
|
return resultMsg ;
|
}else{
|
return '1';
|
|
|
}
|
}
|
return resultMsg;
|
}
|
function up2sapJs (mcid) {
|
sforce.connection.sessionId = '{!$Api.Session_ID}';
|
var resultMsg = '1';
|
var result = sforce.apex.execute("MaintenanceContractSetColunmWebService","updateColunm",{mcid: mcid});
|
if (result != '1'){
|
resultMsg = '2';
|
return resultMsg ;
|
//"上传认款合同失败,因为 来年合同相关信息修改失败";
|
}
|
//上传认款合同
|
var rtn = sforce.apex.execute("MaintenanceContractWebService", "up2sap", {mcid: mcid});
|
if (rtn == '1') {
|
resultMsg ="1";
|
} else {
|
resultMsg ='3';
|
}
|
return resultMsg ;
|
}*/
|
|
|
//zhangzhengmei 2023/06/28 end
|