| | |
| | | import { NavigationMixin } from 'lightning/navigation'; |
| | | import { ShowToastEvent } from 'lightning/platformShowToastEvent'; |
| | | |
| | | import NAME_FIELD from '@salesforce/schema/Repair__c.Incharge_Staff__c'; |
| | | import MY_CUSTOM_OBJECT from '@salesforce/schema/Repair__c'; |
| | | |
| | | import search from '@salesforce/apex/lexBatchSelectRepairLWCController.search'; |
| | | import showPDF from '@salesforce/apex/lexBatchSelectRepairLWCController.showPDF'; |
| | | |
| | | /* |
| | | const actions = [ |
| | | { label: 'Show details', name: 'show_details' }, |
| | | { label: 'Delete', name: 'delete' }, |
| | | ];*/ |
| | | |
| | | const columns = [ |
| | | { label: '状态1', fieldName: 'Status1__c'}, |
| | | { label: '状态2', fieldName: 'Status2__c' }, |
| | | { label: 'RS修理单号', fieldName: 'Name' }, |
| | | { label: 'SAP修理单号', fieldName: 'SAP_Service_Repair_No__c' }, |
| | | // { label: '型号', fieldName: 'deliveredProductName' }, |
| | | { label: '型号', fieldName: 'deliveredProductUrl',type:'url', |
| | | typeAttributes:{ |
| | | label:{ |
| | |
| | | { label: '机身编号', fieldName: 'SerialNumber__c' }, |
| | | { label: '医院名称', fieldName: 'HP_Name__c' }, |
| | | { label: '省份', fieldName: 'State_Hospital__c' }, |
| | | // { label: '修理委托者', fieldName: 'Incharge_Staff_Name' }, |
| | | { label: '修理委托者', fieldName: 'inchargeStaffUrl',type:'url', |
| | | typeAttributes:{ |
| | | label:{ |
| | |
| | | { label: '服务方式', fieldName: 'On_site_repair__c' }, |
| | | { label: '有无维修合同对象', fieldName: 'Number_of_EffectiveContract__c' }, |
| | | { label: '无偿区别标志', fieldName: 'NewProductGuaranteeObject__c' } |
| | | /* { |
| | | type: 'action', |
| | | typeAttributes: { rowActions: actions }, |
| | | },*/ |
| | | ]; |
| | | |
| | | // 批量选择修理LWC |
| | | export default class lexBatchSelectRepairLWC extends LightningElement { |
| | | // Expose a field to make it available in the template |
| | | nameField = NAME_FIELD; |
| | | |
| | | // Flexipage provides recordId and objectApiName |
| | | @api recordId; |
| | | @api objectApiName; |
| | | |
| | | data = []; |
| | | columns = columns; |
| | |
| | | |
| | | searchObj = {}; |
| | | repair = {}; |
| | | selectedRepairs; |
| | | |
| | | /* @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; |
| | | } |
| | | } |
| | | }*/ |
| | | selectedRepairs = []; |
| | | |
| | | connectedCallback(){ |
| | | // console.log(this.recordId); |
| | | } |
| | | //状态1 |
| | | handleStatus1Change(event){ |
| | | /*console.log(event); |
| | | console.log(event.detail);*/ |
| | | this.searchObj.Status1 = event.detail.value; |
| | | // console.log(JSON.stringify(this.searchObj)); |
| | | } |
| | | //状态2 |
| | | handleStatus2Change(event){ |
| | | this.searchObj.Status2 = event.detail.value; |
| | | // console.log(this.searchObj); |
| | | } |
| | | //服务方式 |
| | | handleSiteChange(event){ |
| | | this.searchObj.onSiteRepair = event.detail.value; |
| | | // console.log(this.searchObj); |
| | | } |
| | | //RS修理单号 RepairName |
| | | handleRepairNameChange(event){ |
| | | this.searchObj.RepairName = event.detail.value; |
| | | // console.log(this.searchObj); |
| | | } |
| | | //SAP修理单号 SAPRepairNo |
| | | handleSAPRepairNoChange(event){ |
| | | this.searchObj.SAPRepairNo = event.detail.value; |
| | | // console.log(this.searchObj); |
| | | } |
| | | //维修中心 workLocationSelect |
| | | handleWorkLocationChange(event){ |
| | |
| | | //FSE申请日 repair.Aware_date__c |
| | | handleAwareDateDStart(event){ |
| | | this.repair.Aware_date__c = event.detail.value; |
| | | console.log(this.repair.Aware_date__c); |
| | | } |
| | | // repair.Aware_date2__c |
| | | handleAwareDateDEnd(event){ |
| | | this.repair.Aware_date2__c = event.detail.value; |
| | | // console.log(this.repair.Aware_date2__c); |
| | | } |
| | | // 修理委托者 repair.Incharge_Staff__c |
| | | handleInchargeStaffChange(event){ |
| | | this.repair.Incharge_Staff__c = event.detail.value; |
| | | // console.log(this.repair.Aware_date2__c); |
| | | this.repair.Incharge_Staff__c = event.detail.value[0]; |
| | | } |
| | | |
| | | //检索 |
| | | searchRepair(event) { |
| | | console.log(this.repair.Aware_date__c); |
| | | if (JSON.stringify(this.repair) != "{}") { |
| | | console.log('this.repair'); |
| | | this.searchObj.repair = this.repair; |
| | | // fse 时间条件 |
| | | /*if (!(this.repair.Aware_date__c != null && this.repair.Aware_date2__c != null) || this.repair.Aware_date__c > this.repair.Aware_date2__c) { |
| | | const event = new ShowToastEvent({ |
| | | title: 'error', |
| | | message: 'FSE申请日输入有误', |
| | | variant:'error', |
| | | }); |
| | | this.dispatchEvent(event); |
| | | return; |
| | | }*/ |
| | | } |
| | | let jsonStr = JSON.stringify(this.searchObj); |
| | | if (jsonStr === "{}") { |
| | |
| | | }); |
| | | this.dispatchEvent(event); |
| | | }else{ |
| | | console.log(jsonStr); |
| | | search({ |
| | | json: jsonStr |
| | | }).then(result => { |
| | | console.log(result.repairData); |
| | | console.log('length:'+result.repairData.length); |
| | | if (result.repairData.length == 0 || result.repairData.length == 200) { |
| | | if (!result.repairData || result.repairData && (result.repairData.length == 0 || result.repairData.length == 200)) { |
| | | const event = new ShowToastEvent({ |
| | | title: 'warning', |
| | | message: result.status, |
| | | variant:'warning', |
| | | }); |
| | | this.dispatchEvent(event); |
| | | if (!result.repairData || result.repairData && result.repairData.length == 0) { |
| | | result.repairData = []; |
| | | } |
| | | } |
| | | let returnArr = []; |
| | | result.repairData.forEach(function(v){ |
| | | let objRepair = v.repair; |
| | | //添加修理委托者和型号名称 |
| | | objRepair.deliveredProductName = objRepair.Delivered_Product__r.Name; |
| | | objRepair.deliveredProductName = objRepair.Delivered_Product__r ? objRepair.Delivered_Product__r.Name : ''; |
| | | objRepair.deliveredProductUrl = "/"+objRepair.Delivered_Product__c; |
| | | objRepair.inchargeStaffName = objRepair.Incharge_Staff__r.Name; |
| | | objRepair.inchargeStaffName = objRepair.Incharge_Staff__r ? objRepair.Incharge_Staff__r.Name : ''; |
| | | objRepair.inchargeStaffUrl = "/"+objRepair.Incharge_Staff__c; |
| | | // console.log(objRepair); |
| | | returnArr.push(objRepair); |
| | | }); |
| | | /*console.log('arr'); |
| | | console.log(arr); |
| | | console.log(arr.length);*/ |
| | | this.data = returnArr; |
| | | // console.log(this.data); |
| | | }).catch(error => { |
| | | console.log("error"); |
| | | console.log(error); |
| | |
| | | fieldNameArr.push(v.fieldName); |
| | | } |
| | | }); |
| | | console.log(fieldNameArr); |
| | | fieldNameArr.forEach(v=>{ |
| | | console.log(v); |
| | | // console.log(this.data[0].v); |
| | |
| | | }else{ |
| | | doc += '<th></th>' |
| | | } |
| | | // fieldNameArr.forEach(fieldName =>{ |
| | | // doc += '<th>'+record.fieldName+'</th>'; |
| | | // }); |
| | | doc += '</tr>'; |
| | | doc += '</tr>'; |
| | | }); |
| | | doc += '</table>'; |
| | | var element = 'data:application/vnd.ms-excel,' + encodeURIComponent(doc); |
| | |
| | | downloadElement.click(); |
| | | } |
| | | |
| | | // this method validates the data and creates the csv file to download this.data的所有字段 |
| | | downloadCSVFile1() { |
| | | console.log("downloadCSVFile1"); |
| | | let rowEnd = '\n'; |
| | | let csvString = ''; |
| | | // this set elminates the duplicates if have any duplicate keys |
| | | let rowData = new Set(); |
| | | let columnsData = new Set(); |
| | | let columnsLabelData = new Set(); |
| | | |
| | | // getting keys from data |
| | | this.data.forEach(function (record) { |
| | | Object.keys(record).forEach(function (key) { |
| | | rowData.add(key); |
| | | }); |
| | | }); |
| | | console.log(rowData); |
| | | |
| | | // Array.from() method returns an Array object from any object with a length property or an iterable object. |
| | | rowData = Array.from(rowData); |
| | | console.log(rowData); |
| | | |
| | | // splitting using ',' |
| | | csvString += rowData.join(','); |
| | | csvString += rowEnd; |
| | | console.log(csvString); |
| | | this.columns.forEach(function(v){ |
| | | columnsLabelData.add(v.label); |
| | | if (v['typeAttributes']) { |
| | | columnsData.add(v['typeAttributes'].label.fieldName); |
| | | }else{ |
| | | columnsData.add(v.fieldName); |
| | | } |
| | | }); |
| | | console.log("columnsData"); |
| | | console.log(columnsLabelData); |
| | | console.log(columnsData); |
| | | console.log(rowData[1]); |
| | | console.log(Array.from(columnsData)); |
| | | console.log(Array.from(columnsData).hasOwnProperty(rowData[1])); |
| | | console.log(this.data[0].Name); |
| | | console.log(this.data[0][rowData[1]]); |
| | | // main for loop to get the data based on key value |
| | | for(let i=0; i < this.data.length; i++){ |
| | | let colValue = 0; |
| | | |
| | | // validating keys in data |
| | | for(let key in rowData) { |
| | | if(rowData.hasOwnProperty(key)) { |
| | | // Key value |
| | | // Ex: Id, Name |
| | | let rowKey = rowData[key]; |
| | | // add , after every value except the first. |
| | | if(colValue > 0){ |
| | | csvString += ','; |
| | | } |
| | | // If the column is undefined, it as blank in the CSV file. |
| | | let value = this.data[i][rowKey] === undefined ? '' : this.data[i][rowKey]; |
| | | csvString += '"'+ value +'"'; |
| | | colValue++; |
| | | } |
| | | } |
| | | csvString += rowEnd; |
| | | } |
| | | |
| | | // Creating anchor element to download |
| | | let downloadElement = document.createElement('a'); |
| | | |
| | | // This encodeURI encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters). |
| | | downloadElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csvString); |
| | | downloadElement.target = '_self'; |
| | | // CSV File Name |
| | | downloadElement.download = 'Account Data.csv'; |
| | | // below statement is required if you are using firefox browser |
| | | document.body.appendChild(downloadElement); |
| | | // click() Javascript function to download CSV file |
| | | downloadElement.click(); |
| | | } |
| | | //导出为Excel |
| | | downloadCSVFile() { |
| | | console.log("downloadCSVFile"); |
| | | let rowEnd = '\n'; |
| | | let csvString = ''; |
| | | // this set elminates the duplicates if have any duplicate keys |
| | | //表格标题 |
| | | let columnsData = new Set(); |
| | | //表格字段 |
| | | let rowData = new Set(); |
| | | |
| | | // getting keys from data |
| | | this.columns.forEach(function(v){ |
| | | columnsData.add(v.label); |
| | | if (v['typeAttributes']) { |
| | | rowData.add(v['typeAttributes'].label.fieldName); |
| | | }else{ |
| | | rowData.add(v.fieldName); |
| | | } |
| | | }); |
| | | console.log(columnsData); |
| | | console.log(rowData); |
| | | // Array.from() method returns an Array object from any object with a length property or an iterable object. |
| | | rowData = Array.from(rowData); |
| | | columnsData = Array.from(columnsData); |
| | | // getting keys from data |
| | | /* console.log("rowData"); |
| | | rowData.forEach(function(v){ |
| | | console.log(v); |
| | | }); |
| | | console.log("columnsData"); |
| | | columnsData.forEach(function(v){ |
| | | console.log(v); |
| | | }); */ |
| | | |
| | | // splitting using ',' |
| | | csvString += columnsData.join(','); |
| | | csvString += rowEnd; |
| | | // console.log(csvString); |
| | | // main for loop to get the data based on key value |
| | | for(let i=0; i < this.data.length; i++){ |
| | | let colValue = 0; |
| | | |
| | | // validating keys in data |
| | | for(let key in rowData) { |
| | | if(rowData.hasOwnProperty(key)) {//del |
| | | // Key value |
| | | // Ex: Id, Name |
| | | let rowKey = rowData[key]; |
| | | // add , after every value except the first. |
| | | if(colValue > 0){ |
| | | csvString += ','; |
| | | } |
| | | // If the column is undefined, it as blank in the CSV file. |
| | | let value = this.data[i][rowKey] === undefined ? '' : this.data[i][rowKey]; |
| | | csvString += '"'+ value +'"'; |
| | | colValue++; |
| | | } |
| | | } |
| | | csvString += rowEnd; |
| | | } |
| | | |
| | | // Creating anchor element to download |
| | | let downloadElement = document.createElement('a'); |
| | | |
| | | // This encodeURI encodes special characters, except: , / ? : @ & = + $ # (Use encodeURIComponent() to encode these characters). |
| | | downloadElement.href = 'data:text/csv;charset=utf-8,' + encodeURI(csvString); |
| | | downloadElement.target = '_self'; |
| | | // CSV File Name |
| | | downloadElement.download = '修理明细表.csv'; |
| | | // below statement is required if you are using firefox browser |
| | | document.body.appendChild(downloadElement); |
| | | // click() Javascript function to download CSV file |
| | | downloadElement.click(); |
| | | } |
| | | //获取选中Repair |
| | | getSelectedRows(event) { |
| | | const selectedRows = event.detail.selectedRows; |
| | | console.log(selectedRows); |
| | | //Repair__c selectedRepairs |
| | | // Display that fieldName of the selected rows |
| | | let selectedRepairsArr = []; |
| | |
| | | |
| | | //跳转到pdf页面 |
| | | skipPage() { |
| | | console.log("selectedRows"); |
| | | // console.log(jsonStr); |
| | | if (this.selectedRepairs.length <= 0 ) { |
| | | const event = new ShowToastEvent({ |
| | | title: 'error', |
| | |
| | | let jsonStr = JSON.stringify(this.selectedRepairs); |
| | | showPDF({ |
| | | json: jsonStr |
| | | }).then(result => { |
| | | console.log(result); |
| | | if (result.indexOf("https://ocsm") != -1) { |
| | | window.open(result, "维修委托书PDF", ""); |
| | | }else{ |
| | | const event = new ShowToastEvent({ |
| | | title: 'error', |
| | | message: result, |
| | | variant:'error', |
| | | }); |
| | | this.dispatchEvent(event); |
| | | } |
| | | }).catch(error => { |
| | | console.log("error"); |
| | | console.log(error); |
| | | }).finally(() => { |
| | | |
| | | }); |
| | | } |
| | | }).then(result => { |
| | | if (result.indexOf("https://ocsm") != -1) { |
| | | window.open(result, "维修委托书PDF", ""); |
| | | }else{ |
| | | const event = new ShowToastEvent({ |
| | | title: 'error', |
| | | message: result, |
| | | variant:'error', |
| | | }); |
| | | this.dispatchEvent(event); |
| | | } |
| | | }).catch(error => { |
| | | console.log("error"); |
| | | console.log(error); |
| | | }).finally(() => { |
| | | |
| | | }); |
| | | } |
| | | |
| | | } |