import { LightningElement,wire,track,api} from 'lwc';
|
import { CurrentPageReference } from "lightning/navigation";
|
import { CloseActionScreenEvent } from 'lightning/actions';
|
import { NavigationMixin } from 'lightning/navigation';
|
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
|
|
import init from '@salesforce/apex/lexNewRepairAuraController.init';
|
|
export default class lexNewRepairLWC extends NavigationMixin(LightningElement) {
|
|
// Flexipage provides recordId
|
@api recordId;
|
// @api recordId;
|
@api urlStr;
|
@api objectApiName;
|
|
/* @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;
|
}
|
}
|
}*/
|
|
objectName = 'Repair__c';
|
uiPageLayoutView;
|
isNewMode;
|
//属性默认值
|
defaultValue = {};
|
isLoading = true;
|
activeSections;
|
isSaveAndNew = false;
|
//更新操作时 不显示保存新建
|
hasRecordId = false;
|
recordIdStr;
|
recordTypeId = '';
|
|
connectedCallback(){
|
console.log(this.recordId);
|
console.log(JSON.parse(this.urlStr));
|
if (!this.recordId) {
|
this.hasRecordId = true;
|
// urlStr 传参处理
|
let urlObj = JSON.parse(this.urlStr);
|
if (urlObj.hasOwnProperty("CF00N10000009H1rR_lkid") || urlObj.hasOwnProperty("retURL") ) {
|
console.log('urlObj.hasOwnProperty:',urlObj);
|
// init 向Controller发送请求获取数据
|
init({
|
recordId : this.recordId,urlStr : this.urlStr
|
}).then(result => {
|
console.log("result");
|
console.log(result);
|
this.defaultValue = result;
|
//返回结果赋值
|
if (result.status) {
|
this.recordTypeId = result.recordTypeId;
|
}
|
}).catch(error => {
|
console.log("error");
|
console.log(error);
|
}).finally(() => {
|
});
|
}
|
}
|
}
|
//获取Layout字段
|
handleRecordEditFormLoad(event) {
|
if (event.detail.layout == undefined) {
|
return;
|
}
|
console.log('Layout => ', JSON.stringify(event.detail.layout));
|
this.uiPageLayoutView = event.detail.layout;
|
console.log('Layout1 => ',this.uiPageLayoutView);
|
|
//页面内容初始化 del
|
//to del ! err: Delivered_Product 02i10000004tNXIAA2 Hospital 0011000001g11rDAAQ
|
// this.defaultValue['Delivered_Product'] = '02i10000004tMKgAAM';
|
// // this.defaultValue['Delivered_Product'] = '02i10000004tNXIAA2';
|
// this.defaultValue['Account'] = '0011000001g11rDAAQ';
|
// this.defaultValue['SalesOfficeCode_selection'] = '北京';
|
// this.defaultValue['On_site_repair'] = 'RC修理';
|
// this.defaultValue['Repair_Detail'] = 'testLwcSaveAndNew';
|
// this.defaultValue['Hospital'] = '0011000001g0R8vAAE';
|
// // this.defaultValue['Hospital'] = '0011000001g11rDAAQ';
|
// // 0011000000V9SG5AAN
|
// this.defaultValue['work_location_select'] = '北京办事处';
|
|
const inputFields = this.template.querySelectorAll('lightning-input-field');
|
if (inputFields) {
|
inputFields.forEach(field => {
|
let fieldName = field.name.replace("__c","");
|
if (this.defaultValue.hasOwnProperty(fieldName)) {
|
field.value= this.defaultValue[fieldName];
|
}
|
});
|
}
|
|
let checkedSections = new Set();
|
if (this.uiPageLayoutView.sections.length > 0) {
|
for(const tabs of this.uiPageLayoutView.sections){
|
checkedSections.add(tabs.id);
|
}
|
this.activeSections = Array.from(checkedSections);
|
}
|
this.isLoading = false;
|
this.recordIdStr = this.recordId;
|
|
}
|
//保存 保存新建提交事件
|
handleSubmit(event){
|
this.isLoading = true;
|
console.log("handleSubmit");
|
event.preventDefault(); // stop the form from submitting
|
const fields = event.detail.fields;
|
/*console.log("fields");
|
console.log(fields);*/
|
this.template.querySelector('lightning-record-edit-form').submit(fields);
|
// console.log("success");
|
}
|
handleSubmitAndNew(event){
|
this.isSaveAndNew = true;
|
}
|
//成功后跳转
|
handleSucess(event){
|
// console.log("handleSucess");
|
const updatedRecord = event.detail.id;
|
console.log('onsuccess: ', updatedRecord);
|
if (this.isSaveAndNew) {
|
// console.log("isSaveAndNew");
|
window.location.reload();
|
}else if (event.detail.id) {
|
// console.log("NavigationMixin");
|
this[NavigationMixin.Navigate]({
|
type:'standard__recordPage',
|
attributes:{
|
recordId:updatedRecord,
|
objectApiName:this.objectName,
|
actionName:'view'
|
}
|
});
|
}
|
this.isLoading = false;
|
}
|
//对象验证,属性验证
|
handleError(event) {
|
console.log("handleError event");
|
console.log(JSON.stringify(event.detail));
|
}
|
handleCancel(event) {
|
window.location.href = "https://ocsm--partial.sandbox.lightning.force.com/lightning/o/Repair__c/list?filterName=Recent&0.source=alohaHeader";
|
}
|
|
|
showToast(theTitle, theMessage, theVariant) {
|
const event = new ShowToastEvent({
|
title: theTitle,
|
message: theMessage,
|
variant: theVariant
|
});
|
this.dispatchEvent(event);
|
}
|
|
}
|