/*
|
* @Date: 2023-05-16 13:32:13
|
* @Author: @zyh
|
* @LastEditTime: 2023-11-13 18:30:31
|
* @Descripttion:
|
*/
|
import { LightningElement, wire, track, api } from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { NavigationMixin } from 'lightning/navigation';
|
import init from '@salesforce/apex/lexRentalApply_FromRepCtl.init';
|
import userInfo from '@salesforce/apex/lexRentalApply_FromRepCtl.UserInfo_Owner';
|
import rentalApp from '@salesforce/apex/lexRentalApply_FromRepCtl.rentalApp';
|
import qureySoql from '@salesforce/apex/ControllerUtil.qureySoql';
|
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
import { loadStyle } from 'lightning/platformResourceLoader'
|
|
export default class LexEquipmentRentalApply_FromRepair2 extends NavigationMixin(LightningElement) {
|
@api recordId; //OpportunityId
|
stauts1;
|
repairId;
|
repairName;
|
hospital;
|
repairDepartment;
|
repairAccount;
|
inspectionDate;
|
shippedDate;
|
assetModelNo;
|
qisRepairId;
|
qisId;
|
qisRepairName;
|
repairSource;
|
maintenanceContract;
|
purpose2;
|
newProductGuaranteeObject;
|
ifCheckFixture;
|
IsLoading = true;
|
isFormalStuff;
|
userId;
|
firstName;
|
lastName;
|
rtnJSON;
|
records;
|
dataFields;
|
|
@wire(CurrentPageReference)
|
getStateParameters(currentPageReference) {
|
console.log(111);
|
console.log(currentPageReference);
|
|
if (currentPageReference) {
|
const urlValue = currentPageReference.state.recordId;
|
if (urlValue) {
|
let str = `${urlValue}`;
|
console.log("str");
|
console.log(str);
|
this.recordId = str;
|
}
|
}
|
}
|
|
connectedCallback() {
|
console.log(this.recordId);
|
|
this.IsLoading = false;
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
this.initRepairToApply();
|
}
|
async initRepairToApply(){
|
await rentalApp({
|
recordId: this.recordId
|
}).then(result => {
|
console.log('rentalApp============', result);
|
if (result.length > 0) {
|
const evt = new ShowToastEvent({
|
// title : 'Error',
|
message: '同一个型号的修理记录不能重复申请备品',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
this.dispatchEvent(new CloseActionScreenEvent());
|
return;
|
}
|
// init({
|
// recordId: this.recordId
|
// }).then(result => {
|
// console.log('init============' + result);
|
// console.log(result);
|
// if (result != null) {
|
// userInfo({}).then(result => {
|
// this.userId = result.id;
|
// this.isFormalStuff = result.isFormalStuff;
|
// this.firstName = result.firstName;
|
// this.lastName = result.lastName;
|
// })
|
// this.stauts1 = result.stauts1;
|
// this.repairId = result.repairId;
|
// this.repairName = result.repairName;
|
// this.hospital = result.hospital;
|
// this.inspectionDate = result.inspectionDate;
|
// this.shippedDate = result.shippedDate;
|
// this.qisId = result.qisId;
|
// this.newProductGuaranteeObject = result.newProductGuaranteeObject;
|
// this.maintenanceContract = result.maintenanceContract;
|
// this.repairSource = result.repairSource;
|
// this.ifCheckFixture = result.ifCheckFixture;
|
// this.repairDepartment = result.repairDepartment;
|
// this.repairAccount = result.repairAccount;
|
|
// if (this.qisId != '' && this.qisId != null) {
|
// console.log('qureySoql1===row');
|
// qureySoql({
|
// soql: "select Delivered_Product__r.Product2.Asset_Model_No__c,QIS_ID__r.Repair__c,QIS_ID__r.Repair__r.Name from Repair__c where id ='" + this.recordId + "'"
|
// }).then(result => {
|
// console.log('qureySoql============' + result);
|
// this.rtnJSON = result;
|
// this.records = JSON.parse(this.rtnJSON);
|
// this.repairToApply();
|
|
// }).catch(error => {
|
// console.log("error");
|
// console.log(error);
|
// }).finally(() => {
|
|
// });
|
// } else {
|
// console.log('qureySoql2===row');
|
// console.log("select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'");
|
// qureySoql({
|
// soql: "select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'"
|
// }).then(result => {
|
// console.log('qureySoql============' + result);
|
// this.rtnJSON = result;
|
// console.log('rtnJSON111111===row' + this.rtnJSON);
|
// this.records = JSON.parse(this.rtnJSON);
|
// this.repairToApply();
|
|
// }).catch(error => {
|
// console.log("error");
|
// console.log(error);
|
// }).finally(() => {
|
|
// });
|
// }
|
// // this.repairToApply();
|
// this.dispatchEvent(new CloseActionScreenEvent());
|
// // window.location.reload();
|
// }
|
// }).catch(error => {
|
// console.log("error");
|
// console.log(error);
|
// }).finally(() => {
|
|
// });
|
}).catch(error => {
|
console.log("error11");
|
console.log(error);
|
}).finally(() => {
|
|
});
|
await userInfo({}).then(result => {
|
this.userId = result.id;
|
this.isFormalStuff = result.isFormalStuff;
|
// this.firstName = result.firstName;
|
this.lastName = result.lastName;
|
})
|
await init({
|
recordId: this.recordId
|
}).then(result => {
|
console.log('init============' + result);
|
console.log(result);
|
if (result != null) {
|
// userInfo({}).then(result => {
|
// this.userId = result.id;
|
// this.isFormalStuff = result.isFormalStuff;
|
// // this.firstName = result.firstName;
|
// this.lastName = result.lastName;
|
// })
|
this.stauts1 = result.stauts1;
|
this.repairId = result.repairId;
|
this.repairName = result.repairName;
|
this.hospital = result.hospital;
|
this.inspectionDate = result.inspectionDate;
|
this.shippedDate = result.shippedDate;
|
this.qisId = result.qisId;
|
this.newProductGuaranteeObject = result.newProductGuaranteeObject;
|
this.maintenanceContract = result.maintenanceContract;
|
this.repairSource = result.repairSource;
|
this.ifCheckFixture = result.ifCheckFixture;
|
this.repairDepartment = result.repairDepartment;
|
this.repairAccount = result.repairAccount;
|
|
if (this.qisId != '' && this.qisId != null) {
|
console.log('qureySoql1===row');
|
qureySoql({
|
soql: "select Delivered_Product__r.Product2.Asset_Model_No__c,QIS_ID__r.Repair__c,QIS_ID__r.Repair__r.Name from Repair__c where id ='" + this.recordId + "'"
|
}).then(result => {
|
console.log('qureySoql============' + result);
|
this.rtnJSON = result;
|
this.records = JSON.parse(this.rtnJSON);
|
this.repairToApply();
|
|
}).catch(error => {
|
console.log("error");
|
console.log(error);
|
}).finally(() => {
|
|
});
|
} else {
|
console.log('qureySoql2===row');
|
console.log("select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'");
|
qureySoql({
|
soql: "select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId + "'"
|
}).then(result => {
|
console.log('qureySoql============' + result);
|
this.rtnJSON = result;
|
console.log('rtnJSON111111===row' + this.rtnJSON);
|
this.records = JSON.parse(this.rtnJSON);
|
this.repairToApply();
|
|
}).catch(error => {
|
console.log("error");
|
console.log(error);
|
}).finally(() => {
|
|
});
|
}
|
// this.repairToApply();
|
this.dispatchEvent(new CloseActionScreenEvent());
|
// window.location.reload();
|
}
|
}).catch(error => {
|
console.log("error");
|
console.log(error);
|
}).finally(() => {
|
|
});
|
}
|
repairToApply() {
|
console.log('草案中============' + this.stauts1);
|
if (this.inspectionDate != null) {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '从修理做备品借出申请时,修理的[最终检测日]必须为空',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
console.log('草案中1============' + this.stauts1);
|
return;
|
}
|
|
if (this.isFormalStuff == true) {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '试用期内,不能申请',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
console.log('草案中2============' + this.stauts1);
|
return;
|
}
|
if (this.shippedDate != null) {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '从修理做备品借出申请时,修理的[RC修理品返送日]必须为空',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
console.log('草案中3============' + this.stauts1);
|
return;
|
}
|
if (this.isFormalStuff == true) {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '试用期内,不能申请',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
console.log('草案中4============' + this.stauts1);
|
return;
|
} else if (this.stauts1 == '0.删除') {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '修理的状态为删除,不可借用备品',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
console.log('草案中5============' + this.stauts1);
|
return;
|
} else if (this.stauts1 == '0.取消') {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '修理的状态为取消,不可借用备品',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
console.log('草案中6============' + this.stauts1);
|
return;
|
} else if (this.stauts1 == '5.完毕') {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '修理的状态为完毕,不可借用备品',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
console.log('草案中7============' + this.stauts1);
|
return;
|
} else if (this.stauts1 != '草案中') {
|
console.log('草案中============' + this.stauts1 + this.qisId);
|
// var rtnJSON;
|
// if(this.qisId != '' && this.qisId != null){
|
// console.log('qureySoql1===row');
|
// qureySoql({
|
// soql: 'select Delivered_Product__r.Product2.Asset_Model_No__c,QIS_ID__r.Repair__c,QIS_ID__r.Repair__r.Name from Repair__c where id =' + this.recordId
|
// }).then(result => {
|
// console.log('qureySoql============' + result);
|
// rtnJSON = result;
|
// }).catch(error => {
|
// console.log("error");
|
// console.log(error);
|
// }).finally(() => {
|
|
// });
|
// }else{
|
// console.log('qureySoql2===row');
|
// console.log("select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId +"'");
|
// qureySoql({
|
// soql: "select Delivered_Product__r.Product2.Asset_Model_No__c from Repair__c where id ='" + this.recordId +"'"
|
// }).then(result => {
|
// console.log('qureySoql============' + result);
|
// this.rtnJSON = result;
|
// console.log('rtnJSON111111===row'+ this.rtnJSON);
|
// this.records = JSON.parse(this.rtnJSON);
|
// }).catch(error => {
|
// console.log("error");
|
// console.log(error);
|
// }).finally(() => {
|
|
// });
|
// }
|
console.log('rtnJSON===row' , this.records);
|
console.log('202===row');
|
console.log('202===row'+this.records.length);
|
// var records = JSON.parse(this.rtnJSON);
|
var AssetModelNo = '';
|
// var qisRepairId = '';
|
// var qisRepairName = '';
|
if (this.records.length > 0) {
|
console.log('records.lenth===row');
|
AssetModelNo = this.records[0].Delivered_Product__r.Product2.Asset_Model_No__c;
|
console.log('records.lenth===qisId' + this.qisId);
|
console.log('records.lenth===qisIdtest' + this.qisId != '' && this.qisId != null);
|
// console.log('records.lenth===records' + this.records[0].QIS_ID__c);
|
// console.log('records.lenth===records' + this.records[0].QIS_ID__r.Repair__r.Name);
|
|
if (this.qisId != '' && this.qisId != null) {
|
this.qisRepairId = this.records[0].QIS_ID__r.Repair__c;
|
this.qisRepairName = this.records[0].QIS_ID__r.Repair__r.Name;
|
}
|
}
|
var isKeepRepair = false;
|
if (this.newProductGuaranteeObject == '2: 服务多年保修' && (AssetModelNo == 'LTF-190-10-3D' || AssetModelNo == 'LTF-S190-5' || AssetModelNo == 'CYF-VHA' || AssetModelNo == 'CYF-VA2' || AssetModelNo == 'CYF-5A' || AssetModelNo == 'LTF-S190-10' || AssetModelNo == 'OER-AW' || AssetModelNo == 'URF-V' || AssetModelNo == 'URF-V2' || AssetModelNo == 'URF-P6')) {
|
isKeepRepair = true;
|
}
|
var purpose2 = '';
|
if (this.repairSource != 'QIS转修理') {
|
if (this.newProductGuaranteeObject == '8: 市场多年保修') {
|
purpose2 = '市场多年保修';
|
} else if (this.maintenanceContract != null && this.maintenanceContract != '') {
|
purpose2 = "保修用户";
|
} else if (this.ifCheckFixture) {
|
purpose2 = "故障排查";
|
} else {
|
if (isKeepRepair) {
|
purpose2 = '保修用户';
|
} else {
|
purpose2 = '一般用户';
|
}
|
}
|
} else {
|
purpose2 = '索赔QIS';
|
}
|
console.log('236===row' + purpose2);
|
console.log('236===row');
|
console.log('236===row' + this.repairName);
|
// const defaultValues = encodeDefaultFieldValues({
|
// // RecordTypeId : '',
|
// Name : '*',
|
// Hospital__c : this.hospital,
|
// Strategic_dept__c : this.repairDepartment,
|
// Account__c : this.repairAccount,
|
// Demo_purpose1__c : '维修代用',
|
// demo_purpose2__c : purpose2,
|
// Person_In_Charge__c : this.lastName + ' ' + this.firstName,//备品出街担当
|
// applyUser__c : this.lastName + ' ' + this.firstName,//操作者
|
// // Repair__c : this.repairId,
|
// Loaner_received_staff__c : this.lastName + ' ' + this.firstName// 收件者姓名 (销售或FSE)
|
// });
|
let defaultValues = {
|
// RecordTypeId : '',
|
Name: '*',
|
//2023 7 11 update by 张赫阳 PIPL Start
|
RepairName: this.repairName,
|
//2023 7 11 update by 张赫阳 PIPL End
|
Hospital__c: this.hospital,
|
Strategic_dept__c: this.repairDepartment,
|
Account__c: this.repairAccount,
|
Demo_purpose1__c: '维修代用',
|
demo_purpose2__c: purpose2,
|
// Person_In_Charge__c : this.lastName + ' ' + this.firstName,//备品出街担当
|
Person_In_Charge__c: this.userId, //备品出街担当
|
// applyUser__c : this.lastName + ' ' + this.firstName,//操作者
|
applyUser__c: this.userId, //操作者
|
Repair__c: this.repairId,
|
// Loaner_received_staff__c: this.lastName + ' ' + this.firstName // 收件者姓名 (销售或FSE)
|
Loaner_received_staff__c: this.lastName // 收件者姓名 (销售或FSE)
|
// Loaner_received_staff__c : this.lastName// 收件者姓名 (销售或FSE)
|
}
|
console.log('236===row' + this.lastName + '==收件者姓名');
|
console.log('236===rowUserId' + this.userId);
|
console.log('236===rowRepairId' + this.repairId);
|
|
this.dataFields = defaultValues;
|
console.log('236===row' + this.dataFields);
|
if (purpose2 == '索赔QIS' && this.qisId != null && this.qisId != '') {
|
// const defaultValues = encodeDefaultFieldValues({
|
// RecordTypeId : '',
|
// Repair__c : this.repairName,
|
// Name : '*',
|
// Hospital__c : this.hospital,
|
// Strategic_dept__c : this.repairDepartment,
|
// Account__c : this.repairAccount,
|
// Demo_purpose1__c : '维修代用',
|
// demo_purpose2__c : purpose2,
|
// Person_In_Charge__c : this.lastName + ' ' + this.firstName,//备品出街担当
|
// applyUser__c : this.lastName + ' ' + this.firstName,//操作者
|
// Loaner_received_staff__c : this.lastName + ' ' + this.firstName,// 收件者姓名 (销售或FSE)
|
// QISRepair__c : this.qisRepairName,
|
// QIS_number__c : this.qisId
|
// });
|
let defaultValues = {
|
// RecordTypeId : '',
|
Repair__c: this.repairId,
|
//2023 7 11 update by 张赫阳 PIPL Start
|
RepairName: this.repairName,
|
//2023 7 11 update by 张赫阳 PIPL End
|
Name: '*',
|
Hospital__c: this.hospital,
|
Strategic_dept__c: this.repairDepartment,
|
Account__c: this.repairAccount,
|
Demo_purpose1__c: '维修代用',
|
demo_purpose2__c: purpose2,
|
Person_In_Charge__c: this.userId, //备品出街担当
|
applyUser__c: this.userId, //操作者
|
// Loaner_received_staff__c: this.lastName + ' ' + this.firstName, // 收件者姓名 (销售或FSE)
|
Loaner_received_staff__c: this.lastName, // 收件者姓名 (销售或FSE)
|
// Loaner_received_staff__c : this.lastName,// 收件者姓名 (销售或FSE)
|
// QISRepair__c: this.qisRepairName,
|
QISRepair__c: this.qisRepairId,
|
QIS_number__c: this.qisId
|
}
|
|
this.dataFields = defaultValues;
|
console.log('testzyh==='+this.qisRepairName);
|
}
|
// this[NavigationMixin.Navigate]({
|
// type: 'standard__objectPage',
|
// attributes: {
|
// objectApiName: 'Rental_Apply__c',
|
// actionName: 'new'
|
// },
|
// state:{
|
// defaultFieldValues: this.dataFields
|
// }
|
// });
|
//2023 7 11 update by 张赫阳 PIPL Start
|
debugger;
|
//2023 7 11 update by 张赫阳 PIPL End
|
this[NavigationMixin.Navigate]({
|
type: 'standard__objectPage',
|
attributes: {
|
objectApiName: 'Rental_Apply__c', // 要新建的对象API
|
actionName: 'new'
|
},
|
state: {
|
// defaultFieldValues:'Repair__c='+this.repairName// 要复制的字段API
|
// defaultFieldValues:this.dataFields// 要复制的字段API
|
defaultFieldValues: encodeDefaultFieldValues(this.dataFields) // 要复制的字段API
|
|
}
|
});
|
console.log('236===row' + this.dataFields);
|
|
} else {
|
const evt = new ShowToastEvent({
|
// 刘川 titl横展 start 2023年10月11日
|
// title : '',
|
// 刘川 title横展 end 2023年10月11日
|
message: '申请修理后,才可以新建备品借出申请',
|
variant: 'error',
|
mode: 'sticky'
|
});
|
this.dispatchEvent(evt);
|
// console.log('草案中6============' + this.stauts1);
|
return;
|
}
|
}
|
}
|