import { LightningElement, track, wire, api } from 'lwc'; import {CurrentPageReference,NavigationMixin} from 'lightning/navigation'; import { getObjectInfo } from 'lightning/uiObjectInfoApi'; import Maintenance_Contract__c from '@salesforce/schema/Maintenance_Contract__c'; import init from '@salesforce/apex/lexToAddMaintenanceContractController.init'; import searchMc from '@salesforce/apex/lexToAddMaintenanceContractController.searchMc'; import exchangeMc from '@salesforce/apex/lexToAddMaintenanceContractController.exchangeMc'; export default class lexToAddMaintenanceContract extends LightningElement { sobjectType = 'Maintenance_Contract__c'; @track labelMap = {}; @api recordId; contractType; textOpts; text1; cond1 = 'equals'; val1; IsLoading = true; allDatas = []; allColumns = []; selectedDatas = []; selectedColumns = []; searchHospital; @wire(getObjectInfo, { objectApiName: Maintenance_Contract__c }) getMcInfo({data,error}){ if(data){ this.labelMap ={ 'Name' : data.fields.Name.label, 'Management_Code__c' : data.fields.Management_Code__c.label, 'Hospital__c' : data.fields.Hospital__c.label, 'Service_Contract_Staff__c' : data.fields.Service_Contract_Staff__c.label, } this.textOpts = [{ label: this.labelMap.Management_Code__c, value: 'S:Management_Code__c' }, { label:this.labelMap.Name, value: 'S:Name' }]; this.text1 = 'S:Management_Code__c'; this.allColumns =[ { type: "button", typeAttributes: { label: '选择', name: 'Select', title: '选择', disabled: false, value: '选择', iconPosition: 'left' , }}, { label: this.labelMap.Name,fieldName:'Name', type: 'text'}, { label: this.labelMap.Management_Code__c, fieldName:"Management_Code__c", type: 'text'}, { label: this.labelMap.Hospital__c, fieldName: 'Hospital__c', type: 'text'}, { label: this.labelMap.Service_Contract_Staff__c, fieldName: 'Service_Contract_Staff__c', type: 'text'}]; this.selectedColumns =[ { type: "button", typeAttributes: { label: '删除', name: 'Delete', title: '删除', disabled: false, value: '删除', iconPosition: 'left' , }}, { label: this.labelMap.Name,fieldName:'Name', type: 'text'}, { label: this.labelMap.Management_Code__c, fieldName:"Management_Code__c", type: 'text'}, { label: this.labelMap.Hospital__c, fieldName: 'Hospital__c', type: 'text'}, { label: this.labelMap.Service_Contract_Staff__c, fieldName: 'Service_Contract_Staff__c', type: 'text'}]; } } equalOpts = [{ label: '等于', value: 'equals' }, { label:'包含', value: 'contains' }]; //==================服务打包合同的id================ ParamIdStr = ''; // url 参数Id getQueryVariable(variable){ var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i { console.log(result); var searchResultDatas = []; for(let i=0;imc.Id ===mcObj.Id)) { searchResultDatas.push(mcObj); } } this.allDatas = searchResultDatas; this.IsLoading = false; }).catch(error => { console.log("error"); console.log(error); }); } connectedCallback(){ var selectedDatasTemp = []; var allDatasTemp = []; var contractType = this.getQueryVariable('contractType'); var paramId = this.getQueryVariable('id'); if (paramId == null || paramId == '') { return ; } this.recordId = paramId; if (contractType) { this.contractType = contractType; } console.log(this.recordId); console.log(this.contractType); init({ recordId: this.recordId, contractType:this.contractType }).then(result => { console.log(result); console.log('1 = 1'); for(let i=0;i { console.log("error"); console.log(error.message); }); } callRowAction(event) { const recId = event.detail.row.Id; const actionName = event.detail.action.name; if (actionName === 'Delete') { this.handleDeleteRow(recId); } else if(actionName === 'Select') { this.handleSelectRow(recId); } } handleSelectRow(recId) { console.log('select recId:'+recId); let tempSelected = []; let tempNotSelected = []; this.selectedDatas.forEach((obj)=>{ tempSelected.push(obj); }); this.allDatas.forEach((obj)=>{ if(obj.Id ===recId) { tempSelected.push(obj); } else { tempNotSelected.push(obj); } }); this.selectedDatas = tempSelected; this.allDatas = tempNotSelected; } handleDeleteRow(recId) { console.log('delete recId:'+recId); let tempSelected = []; let tempNotSelected = []; this.allDatas.forEach((obj)=>{ tempNotSelected.push(obj); }); this.selectedDatas.forEach((obj)=>{ if(obj.Id ===recId) { tempNotSelected.push(obj); } else { tempSelected.push(obj); } }); this.selectedDatas = tempSelected; this.allDatas = tempNotSelected; } //获取选中MC saveMc() { this.IsLoading = true; var selectedIds = []; for (let i = 0; i < this.selectedDatas.length; i++) { selectedIds.push(this.selectedDatas[i].Id); } exchangeMc({ selectedMcs:selectedIds, recordId:this.recordId }).then(result=>{ this.IsLoading = false; if(result == '1') { alert('合同添加成功'); window.location = '/'+this.recordId; // window.open('/'+this.recordId, '_self'); } else { alert(result); } console.log('exchangeMc:') console.log(result); }); } }