import { LightningElement, track, wire, api } from 'lwc';
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
|
import { updateRecord } from 'lightning/uiRecordApi';
|
import LightningConfirm from 'lightning/confirm';
|
import init from '@salesforce/apex/AddSubmitApprovalProcessController.init';
|
import submitApproval from '@salesforce/apex/AddSubmitApprovalProcessController.submitApproval';
|
import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare';
|
import changeAddApprovalStatus from '@salesforce/apex/AddSubmitApprovalProcessController.changeAddApprovalStatus';
|
|
export default class lexAddSubmitApprovalProcess extends LightningElement {
|
@api recordId;
|
IsLoading = true;
|
RecordTypeId;
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference){
|
if(currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if(urlValue) {
|
let str = `${urlValue}`;
|
this.recordId = str;
|
}
|
}
|
}
|
|
connectedCallback(){
|
init({
|
recordId: this.recordId
|
}).then(result=>{
|
if(result.addApprovalStatus != '草案中' || result.detailSize == 0){
|
this.ToastShow('没有需要审批的追加附属品','warning');
|
return;
|
}
|
// if (!confirm("一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?")) {
|
// this.dispatchEvent(new CloseActionScreenEvent());
|
// return;
|
// }
|
const SUBMIT = LightningConfirm.open({
|
message: "一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?",
|
variant: 'headerless',
|
label: '提示信息',
|
// setting theme would have no effect
|
});
|
|
if(SUBMIT==false){
|
this.dispatchEvent(new CloseActionScreenEvent());
|
return;
|
}
|
|
// 希望到货日不能早于申请提交日-0418追加
|
//if ('{!Rental_Apply__c.Request_shipping_day__c}' < '{!TODAY()}') {
|
// alert('希望到货日不能早于申请提交日');
|
// return;
|
// }
|
console.log(JSON.stringify(result));
|
if(result.repairId != null){
|
if(result.demoPurpose1 == '维修代用' && result.demoPurpose2 == '一般用户'){
|
if(result.repairEstimatedDateFormula == null){
|
this.ToastShow('一般维修无报价日,不可借用备品','warning');
|
return;
|
}else if(result.repairEstimatedDateFormula <'2019-07-01' && result.agreedDate == null){
|
this.ToastShow('报价日在2019/7/1之前且户同意日为空,不可借用备品','warning');
|
return;
|
}
|
}
|
//备品申请 过去历史转移
|
if(result.recordTypeId != result.demoRequestPastDataId && result.newProductGuaranteeObject=='2: 服务多年保修' && (result.assetModelNo=='CV-V1' ||result.assetModelNo=='CV-V1(A)'||result.assetModelNo=='CV-V1(B)'||result.assetModelNo=='GIF-LV1'||result.assetModelNo=='CF-LV1L'||result.assetModelNo=='CF-LV1I'||result.assetModelNo=='MAJ-1910') &&(result.demoPurpose2=='一般用户'||result.demoPurpose2=='再修理')){
|
this.ToastShow('奥辉设备,保修期内不提供备品.','warning');
|
return;
|
}
|
}
|
|
if(result.campaignId!=null || result.campaignId!=''){
|
if(result.campaignStatus == '草案中'){
|
this.ToastShow('学会状态为草案中,不能提交','warning');
|
return;
|
}
|
if(result.campaignStatus == '申请中'){
|
this.ToastShow('学会状态为申请中,不能提交','warning');
|
return;
|
}
|
if(result.campaignStatus == '已结束'){
|
this.ToastShow('学会状态为已结束,不能提交','warning');
|
return;
|
}
|
if(result.campaignStatus == '已提交报告'){
|
this.ToastShow('学会状态为已提交报告,不能提交','warning');
|
return;
|
}
|
if(result.campaignStatus == '取消申请中'){
|
this.ToastShow('学会状态为取消申请中,不能提交','warning');
|
return;
|
}
|
if(result.campaignStatus == '取消'){
|
this.ToastShow('学会状态为取消,不能提交','warning');
|
return;
|
}
|
}
|
|
if(result.qISNumber!=null || result.qISNumber!=''){
|
if(result.nextAction=='送回'){
|
this.ToastShow('QIS 已送回,不能再申请备品了','warning');
|
return;
|
}
|
}
|
|
//share
|
var userAccess = new Array();
|
userAccess.push(result.applyUserId + '_Edit');
|
|
//SWAG-BZMA8W 去掉 服务经理部长共享 start
|
//update lxy DLIU-BZNBG9 去掉服务经理部长共享
|
//userAccess.push('{!Rental_Apply__c.JingliApprovalManagerId__c}_Read');
|
//userAccess.push('{!Rental_Apply__c.SalesManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
|
//update lxy DLIU-BZNBG9 去掉服务经理部长共享
|
//userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerId__c}_Read');
|
//SWAG-BZMA8W 去掉 服务经理部长共享 end
|
//userAccess.push('{!Rental_Apply__c.BuchangApprovalManagerSalesId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
|
//userAccess.push('{!Rental_Apply__c.ZongjianApprovalManagerId__c}_Read');//20210727 ljh SFDC-C54C33 update 共享触发器完成
|
//userAccess.push('{!Rental_Apply__c.Status__c}_Read');
|
|
console.log('参数==='+result.rentalApplyId+' '+userAccess+' '+result.ownerId);
|
setSObjectShare({
|
sobjectName:'Rental_Apply__Share',
|
rowCause:'ApplyUserShare__c',
|
parentId:result.rentalApplyId,
|
userAccess:userAccess,
|
ownerId:result.ownerId
|
}).then(res=>{
|
|
if(res!='OK'){
|
this.ToastShow(res,'warning');
|
return;
|
}else{
|
console.log('setSObjectShareSuccess====OK');
|
//追加备品申请状态确认,已经提交过的申请,不能重复提交Status__c
|
if (result.rentalApplyStatus != '已批准' && result.rentalApplyStatus != '已出库指示') {
|
this.ToastShow('请备品申请状态确认,申请状态已批准后才可以提交追加审批','warning');
|
return;
|
}
|
|
changeAddApprovalStatus({
|
recordId: this.recordId,
|
status: '填写完毕'
|
}).then(changeResult=>{
|
if(changeResult == '更新成功'){
|
submitApproval({
|
recordId: this.recordId
|
}).then(submitApprovalRes=>{
|
if(submitApprovalRes == 'OK'){
|
this.ToastShow('提交追加待审批','success');
|
this.updateRecordView(this.recordId);
|
}else{
|
this.ToastShow('追加待审批失败','ERROR');
|
}
|
})
|
}else{
|
this.ToastShow(changeResult,'error');
|
}
|
})
|
}
|
}).catch(err=>{
|
console.log('setSObjectShareErr===='+err);
|
})
|
|
}).catch(err=>{
|
console.log('====1111====',err);
|
})
|
}
|
|
ToastShow(msg,type){
|
const evt = new ShowToastEvent({
|
title : msg,
|
message: '',
|
variant: type
|
});
|
this.dispatchEvent(evt);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
|
updateRecordView(recordId) {
|
updateRecord({fields: { Id: recordId }});
|
}
|
}
|