import { LightningElement , wire, api} from 'lwc';
|
import { CurrentPageReference,NavigationMixin } from 'lightning/navigation';
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { updateRecord } from 'lightning/uiRecordApi';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
|
import init from '@salesforce/apex/ConsumApplyApprovalProcessController.initSubmitApprovalProcessController';
|
import selectCampaignById from '@salesforce/apex/ConsumApplyApprovalProcessController.selectCampaignById';
|
import selectReportById from '@salesforce/apex/ConsumApplyApprovalProcessController.selectReportById';
|
import selectEquipmentById from '@salesforce/apex/ConsumApplyApprovalProcessController.selectEquipmentById';
|
import approvalCheck from '@salesforce/apex/ConsumApplyApprovalProcessController.approvalCheck';
|
import setSObjectShare from '@salesforce/apex/ConsumApplyApprovalProcessController.setSObjectShare';
|
import updateConsumApply from '@salesforce/apex/ConsumApplyApprovalProcessController.updateConsumApply';
|
// import setSObjectShare from '@salesforce/apex/ControllerUtil.setSObjectShare';
|
|
|
export default class LexConsumApplySubmitApprovalProcess extends LightningElement {
|
|
@api recordId;
|
id;
|
shippingDays;//希望到货日前7个工作日
|
shippingDay;//希望到货日
|
campaign ;//学会
|
qISNumber;//QIS
|
qISIDLine;//QIS的ID值
|
status;// 状态
|
minApprovalDate;//最小可以提交申请日期
|
applyUser;//操作者
|
jingliManager;//CL6 经理级(服务)
|
salesManager;//CL6 经理级
|
buchangManager;//CL5 总监级(服务)
|
buchangManagerSale;//CL5 总监级
|
zongjianManager;//CL4 高级总监
|
owner;//所有人
|
IsLoading = true;
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
console.log("str:"+str);
|
this.recordId = str;
|
}
|
}
|
}
|
|
|
connectedCallback(){
|
init({recordId : this.recordId}).then( result => {
|
console.log('result'+result);
|
if(result!= null){
|
this.IsLoading = false;
|
this.id = result.id;
|
this.shippingDays = result.shippingDays;
|
this.shippingDay = result.shippingDay;
|
this.campaign = result.campaign;
|
this.qISNumber = result.qISNumber;
|
this.qISIDLine = result.qISIDLine;
|
this.status = result.status;
|
this.minApprovalDate = result.minApprovalDate;
|
this.applyUser = result.applyUser;
|
this.jingliManager = result.jingliManager;
|
this.salesManager = result.salesManager;
|
this.buchangManager = result.buchangManager;
|
this.buchangManagerSale = result.buchangManagerSale;
|
this.zongjianManager = result.zongjianManager;
|
this.owner = result.owner;
|
|
var date = new Date();
|
var day = date.getDate();
|
|
console.log('shipingDays'+this.shippingDays);
|
if(this.shippingDays < day){
|
this.showToast('此申请已不满足(希望到货日-7工作日)前完成审批的情况,请重新修改申请。','error');
|
}
|
|
if(!confirm('一旦提交此记录以待批准,根据您的设置您可能不再能够编辑此记录或将他从批准过程中调回。是否继续?\n\n※ 需要在'
|
+this.shippingDays+'前完成审批,否则申请单自动取消。')){
|
console.log('2222222222');
|
this.IsLoading = false;
|
this.showToast('已取消','error')
|
}
|
|
|
console.log('3333333333333');
|
if(this.shippingDay < day){
|
this.showToast('希望到货日不能早于申请提交日','error');
|
}
|
|
if(this.campaign != null && this.campaign != ''){
|
console.log('qqqqqqqqqqqqqq');
|
var dataList = new Array();
|
selectCampaignById({recordId: this.campaign}).then(data =>{
|
console.log('iiiiiiiiiiii');
|
dataList = data;
|
var interval = dataList[0].Status;
|
if (interval == '草案中') {
|
this.showToast('学会状态为草案中,不能提交','error');
|
}
|
if (interval == '申请中') {
|
this.showToast('学会状态为申请中,不能提','error');
|
}
|
if (interval == '已结束') {
|
this.showToast('学会状态为已结束,不能提交','error');
|
}
|
if (interval == '已提交报告') {
|
this.showToast('学会状态为已提交报告,不能提交','error');
|
}
|
if (interval == '取消申请中') {
|
this.showToast('学会状态为取消申请中,不能提交','error');
|
}
|
if (interval == '取消') {
|
this.showToast('学会状态为取消,不能提交','error');
|
}
|
})
|
}
|
console.log('9888888888');
|
if(this.qISNumber != null && this.qISNumber != ''){
|
var resList = new Array();
|
selectReportById({recordId:this.qISIDLine}).then(res=>{
|
resList = res;
|
var interval = resList[0].next_action__c;
|
if (interval == '送回') {
|
this.showToast('QIS 已送回,不能再申请备品了','error');
|
}
|
})
|
}
|
|
console.log('wwwwwwwwwww');
|
var userAccess = new Array();
|
userAccess.push(this.applyUser+'_Edit');
|
userAccess.push(this.jingliManager+'_Read');
|
userAccess.push(this.salesManager+'_Read');
|
userAccess.push(this.buchangManager+'_Read');
|
userAccess.push(this.buchangManagerSale+'_Read');
|
userAccess.push(this.zongjianManager+'_Read');
|
|
console.log('yyyyyyyyyy');
|
setSObjectShare({applyUser:this.applyUser,
|
parentId:this.Id,
|
userAccess:userAccess,
|
ownerId:this.owner}).then(res=>{
|
if(res!='OK'){
|
this.showToast(rtn,'error');
|
}
|
})
|
// var rtn = setSObjectShare(Consum_Apply__Share,this.applyUser,this.Id,userAccess,this.owner);
|
// if(rtn != 'OK'){
|
// this.showToast(rtn,'error');
|
// }
|
|
//没有this.status == '引当完了'状态
|
if(this.status == '填写完毕' || this.status == '申请中' || this.status == '已批准'
|
|| this.status == '已出库指示' || this.status == '删除' || this.status == '取消'){
|
this.showToast('请备品申请状态确认,已经提交过的申请,不能重复提交','error');
|
}
|
console.log('eeeeeeeeee');
|
if(this.minApprovalDate > day){
|
this.showToast('申请提交日到预计使用日必须在22个工作日以内才可以','error');
|
}
|
var raesList = new Array();
|
|
console.log('ttttttttt');
|
selectEquipmentById({recordId:this.id}).then(raes=>{
|
raesList = raes;
|
if(raesList.length > 0){
|
this.showToast('有没有明细的耗材备品配套一览,不能提交','error');
|
}
|
})
|
|
console.log('99999999999'+this.id);
|
approvalCheck({recordId:this.id}).then(re1=>{
|
if(re1 != '1'){
|
this.showToast(re1,'error');
|
}
|
})
|
|
updateConsumApply({recordId:this.id}).then(re1=>{
|
if(re1 != '1'){
|
this.showToast(re1,'error');
|
}else{
|
this.showToast('已提交','success');
|
}
|
})
|
}else{
|
console.log('444444444444');
|
this.IsLoading = false;
|
this.showToast('result为空','error')
|
}
|
|
})
|
|
}
|
|
|
|
|
|
updateRecordView() {
|
updateRecord({fields: { Id: this.recordId }});
|
}
|
|
showToast(msg,type) {
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type
|
});
|
if(type == 'success'){
|
this.updateRecordView();
|
}
|
this.dispatchEvent(event);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
}
|
}
|