import { LightningElement, api, track } from 'lwc';
|
import { loadStyle } from "lightning/platformResourceLoader";
|
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
|
import selectInfrastructureProjectById from '@salesforce/apex/infrastructureProjectRelatedOpController.selectInfrastructureProjectById';
|
import selectoppByAccountId from '@salesforce/apex/infrastructureProjectRelatedOpController.selectoppByAccountId';
|
import selectoppByOpportunityNoc from '@salesforce/apex/infrastructureProjectRelatedOpController.selectoppByOpportunityNoc';
|
import saveOppInfrastructureProject from '@salesforce/apex/infrastructureProjectRelatedOpController.saveOppInfrastructureProject';
|
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
|
import lwcCSS from '@salesforce/resourceUrl/lwcCSS';
|
|
export default class InfrastructureProjectRelatedOpp extends LightningElement {
|
@api
|
infproid;
|
// InfProId = '';
|
@track
|
IsLoading = false;
|
@track
|
InfPro = {Id:'',Name:'',OCSM_Hospital__c:'',OCSM_Hospital__r:{}};
|
@track
|
jzDataToOpp={};
|
stylesLoaded = false;
|
renderedCallback(){
|
if (!this.stylesLoaded) {
|
Promise.all([loadStyle(this, WrappedHeaderTable)])
|
.then(() => {
|
console.log("Custom styles loaded");
|
this.stylesLoaded = true;
|
})
|
.catch((error) => {
|
console.error("Error loading custom styles");
|
});
|
}
|
}
|
connectedCallback() {
|
this.IsLoading = true;
|
// this.InfProId = this.getQueryVariable('Id');
|
selectInfrastructureProjectById({InfProId:this.infproid}).then(res=>{
|
debugger
|
this.InfPro = res;
|
this.InfPro.url = '/'+res.OCSM_Hospital__c;
|
selectoppByAccountId({OCSMHospital:this.InfPro.OCSM_Hospital__c}).then(opp=>{
|
debugger
|
this.jzDataToOpp = opp;
|
this.IsLoading = false;
|
});
|
});
|
Promise.all([
|
loadStyle(this, lwcCSS)
|
]);
|
}
|
getQueryVariable(variable) { //id字符串
|
var query = window.location.search.substring(1);
|
var vars = query.split("&");
|
for (var i = 0; i < vars.length; i++) {
|
var pair = vars[i].split("=");
|
if (pair[0] == variable) {
|
return pair[1];
|
}
|
}
|
return '';
|
}
|
SelectedOppValue = [];
|
saveValue = [];
|
Selectedopp(event){
|
let arr = event.detail.rows;
|
this.SelectedOppValue = arr;
|
this.saveValue = [];
|
var selectId = new Map();
|
if(this.SelectedOppValue){
|
this.SelectedOppValue.forEach(itm=>{
|
selectId.set(itm.Id,itm.Id);
|
});
|
this.jzDataToOpp.forEach(item=>{
|
if(selectId.has(item.Id)){
|
item.Infrastructure_Project__c = this.infproid;
|
this.saveValue.push(item);
|
}else{
|
item.Infrastructure_Project__c = null;
|
}
|
});
|
}
|
debugger
|
}
|
OppValue;
|
jzOppsearchChange(event){
|
if(this.OppValue != event.target.value){
|
this.OppValue = event.target.value;
|
}
|
}
|
jzOppsearchbutton(){
|
debugger
|
this.IsLoading = true;
|
selectoppByOpportunityNoc({OCSMHospital:this.InfPro.OCSM_Hospital__c,OpportunityNoc:this.OppValue}).then(rvalue=>{
|
debugger
|
this.jzDataToOpp = rvalue;
|
this.IsLoading = false;
|
});
|
}
|
saveOpp(){
|
this.IsLoading = true;
|
var saveValuec = JSON.stringify(this.saveValue);
|
saveOppInfrastructureProject({saveValuec:saveValuec}).then(res=>{
|
debugger
|
if(res != 'success'){
|
this.showToast(res,'error');
|
}else{
|
this.showToast("保存成功",'success');
|
setTimeout(() => {
|
window.location.href = '/'+this.infproid
|
},4000)
|
// window.location.hash = "Refresh"+"=="+this.infproid;
|
}
|
this.IsLoading = false;
|
});
|
}
|
showToast(msg,type) {
|
if(type == "success"){
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type
|
});
|
this.isTrue = false;
|
this.dispatchEvent(event);
|
}else{
|
const event = new ShowToastEvent({
|
message: msg,
|
variant: type,
|
mode:"sticky"
|
});
|
this.dispatchEvent(event);
|
}
|
}
|
initDataTableToOpp = {
|
columns: [
|
{
|
label: '状态1',
|
fieldName: 'StageName__c',
|
editable: false,
|
cellAttributes: {
|
class: {},
|
alignment: 'left'
|
},
|
hideDefaultActions: true,
|
initialWidth:60
|
},
|
{
|
label: '询价名称',
|
fieldName: 'Name',
|
type: 'text',
|
cellAttributes: {
|
alignment: 'left'
|
},
|
hideDefaultActions: true,
|
},
|
{
|
label: '询价编码',
|
fieldName: 'Opportunity_No__c',
|
cellAttributes: {
|
alignment: 'left'
|
},
|
hideDefaultActions: true,
|
},
|
{
|
label: '询价阶段',
|
fieldName: 'Opportunity_stage__c',
|
cellAttributes: {
|
alignment: 'left'
|
},
|
hideDefaultActions: true,
|
}
|
],
|
sortInterfaces: false,
|
searchColumns: []
|
};
|
getTableDataToOpp(){
|
}
|
|
}
|