/* 备品智能化 add by dzk 自动分配确认画面 */ import { api, LightningElement, track, wire } from 'lwc'; import lwcCSS from '@salesforce/resourceUrl/lwcCSS'; import {loadStyle} from 'lightning/platformResourceLoader'; import initRenApply from '@salesforce/apex/AutomaticAssignController.initRenApply'; import selectRenApply from '@salesforce/apex/AutomaticAssignController.selectRenApply'; import getAssetLocationOptions from '@salesforce/apex/AutomaticAssignController.getAssetLocationOptions'; import getDemopurpose1PicklistOptions from '@salesforce/apex/AutomaticAssignController.getDemopurpose1PicklistOptions'; import getProcategoryPicklistOptions from '@salesforce/apex/AutomaticAssignController.getProcategoryPicklistOptions'; import autoConfirmation from '@salesforce/apex/AutomaticAssignController.autoConfirmation'; import autoConfirmationConfirm from '@salesforce/apex/AutomaticAssignController.autoConfirmationConfirm'; import { ShowToastEvent } from 'lightning/platformShowToastEvent'; import LightningConfirm from 'lightning/confirm'; import IFTradeComplianceAlert2 from '@salesforce/label/c.IFTradeComplianceAlert2'; export default class lexAutomaticAssign extends LightningElement { @track data = []; @track selectAll = false; @track mainNotLink; @track mainLink = false; @track mainPartialLink = false; @track subNotLink = false; @track subLink = false; @track noAccessory = false; @track subPartialLink = false; @track RentalApp = ''; @track ProCode = ''; @track UseReason = '全部'; @track UserSalesdept = '全部'; @track Procategory = ''; @track AssetLocation = ''; @track searchResults = []; @track selectedRows =[]; @track RequestOwner = ''; @track showSpinner = false; @track showProfile = false; @track retrievedDataCount = 0; selectOptions1 = []; selectUseReason = []; selectProcategory = []; selectAssetLocation = []; selectUserSalesdept = [ { label: '全部', value: '全部'}, { label: '医疗西南营业本部', value: '医疗西南营业本部' }, { label: '医疗西北营业本部', value: '医疗西北营业本部' }, { label: '医疗华南营业本部', value: '医疗华南营业本部' }, { label: '医疗华东营业本部', value: '医疗华东营业本部' }, { label: '医疗华北营业本部', value: '医疗华北营业本部' }, { label: '医疗东北营业本部', value: '医疗东北营业本部' }, { label: '医疗产品培训本部', value: '医疗产品培训本部' }, { label: '消化·呼吸内镜事业本部', value: '消化·呼吸内镜事业本部' }, { label: '外科事业本部', value: '外科事业本部' }, { label: 'Solution本部', value: 'Solution本部' }, { label: 'MA本部', value: 'MA本部' }, ]; connectedCallback() { Promise.all([ loadStyle(this, lwcCSS) ]); } // 页面数据初始化显示 @wire(initRenApply, {}) wiredRenApplyMethod({ data, error }) { this.showSpinner = true; if (data) { if(data.userProfileCheck === false){ this.showToast('当前用户无权限查看。'); this.showSpinner = false; this.showProfile = true; this.retrievedDataCount = 0; }else{ this.data = data.RentalApplySet; this.retrievedDataCount = this.data.length; this.showSpinner = false; } } else if (error) { this.data = []; this.showSpinner = false; this.retrievedDataCount = 0; console.log('RenApplyMethod错误------' + JSON.stringify(error)); } } handleSelect(event) { const itemId = event.target.dataset.id; const selected = event.target.checked; this.data = this.data.map((item) => { if (item.id === itemId) { return { ...item, selected: selected }; } return item; }); // 更新选中的数据集合 if (selected) { const selectedItem = this.data.find((item) => item.id === itemId); this.selectedRows = [...this.selectedRows, selectedItem]; } else { this.selectedRows = this.selectedRows.filter((item) => item.id !== itemId); } } //全选按钮 handleSelectAll(event) { this.selectAll = event.target.checked; this.data = this.data.map((row) => ({ ...row, selected: this.selectAll })); if(this.selectAll){ this.selectedRows = this.data; }else{ this.selectedRows = []; } } // 查询条件值变更 handleRentalAppChange(event) { this.RentalApp = event.target.value; } handleProCodeChange(event) { this.ProCode = event.target.value; } handleUseReasonChange(event) { this.UseReason = event.target.value; } handleProcategoryChange(event) { this.Procategory = event.target.value; } handleAssetLocationChange(event) { this.AssetLocation = event.target.value; } handleUserSalesdeptChange(event) { this.UserSalesdept = event.target.value; } handleRequestOwnerChange(event) { this.RequestOwner = event.target.value; } // 获取用户.办事处选项列表 @wire(getAssetLocationOptions) wiredAssetLocationOptions({ data, error }) { if (data) { this.selectAssetLocation = data.map(option => { return { label: option, value: option }; }); } else if (error) { console.error('获取用户.办事处选项列表' + error); } } // 获取备品借出申请.使用目的1选项列表 @wire(getDemopurpose1PicklistOptions) wiredDemopurpose1PicklistOptions({ data, error }) { if (data) { this.selectUseReason = data.map(option => { return { label: option, value: option }; }); } else if (error) { console.error('获取备品借出申请.使用目的1选项列表' + error); } } // 获取备品借出申请.产品分类选项列表 @wire(getProcategoryPicklistOptions) wiredProcategoryPicklistOptions({ data, error }) { if (data) { this.selectProcategory = data.map(option => { return { label: option, value: option }; }); } else if (error) { console.error('获取备品借出申请.产品分类选项列表' + error); } } // 根据条件对数据进行查询 handleSearch(event) { this.showSpinner = true; selectRenApply({ UseReason: this.UseReason, UserSalesdept: this.UserSalesdept, RentalApp: this.RentalApp, ProCode: this.ProCode, Procategory: this.Procategory, AssetLocation: this.AssetLocation, RequestOwner: this.RequestOwner }).then(result => { // 处理 Apex 方法的返回结果 this.data = result; this.showSpinner = false; this.selectedRows = []; this.retrievedDataCount = this.data.length; }).catch(error => { // 处理错误 console.error('selectAppSetData发生错误:', error); }); } handleButtonClick(event) { this.showSpinner = true; const dataId = event.currentTarget.dataset.id; const selectedItem = this.data.find((item) => item.id === dataId); if(selectedItem.selected == false){ let msg = '请选择确认分配的数据。'; this.showToast(msg); this.showSpinner = false; }else{ this.selectedRows = [...this.selectedRows, selectedItem]; this.autoConfirmation(this.selectedRows); } } handleAllButtonClick(event) { this.showSpinner = true; if(this.selectedRows.length === 0){ let msg = '请选择确认分配的数据。'; this.showToast(msg); this.showSpinner = false; }else{ this.autoConfirmation(this.selectedRows); } } //自动分配按钮 async autoConfirmation(selectedRows){ await autoConfirmation({ recordId: JSON.stringify(selectedRows)}).then(result => { // 处理 Apex 方法的返回结果 // 20240122 ljh 贸易合规2 start if(result == ''){ // 继续分配 autoConfirmationConfirm({ recordId: JSON.stringify(selectedRows)}).then(result => { if(result == 'Success'){ const event = new ShowToastEvent({ title: '', message: '分配成功。', variant: "success" }); this.showSpinner = false; window.location.reload(); }else{ this.showSpinner = false; this.showToast(result); } }); }else if(result.startsWith('TrandeAlert')){ LightningConfirm.open({ message: '如下申请单'+result.slice(11)+'可能存在贸易合规风险,是否继续分配,'+ IFTradeComplianceAlert2 +'(一般需5-10个工作日)', //20240305 贸易合规二期邮件发送 话术修改 variant: 'headerless', label: 'this is the aria-label value', }).then(confirm=>{ if(!confirm){ console.log('zheli贸易合规'); this.showSpinner = false; // window.location.reload(); }else{ // 继续分配 autoConfirmationConfirm({ recordId: JSON.stringify(selectedRows)}).then(result => { if(result == 'Success'){ const event = new ShowToastEvent({ title: '', message: '分配成功。', variant: "success" }); this.showSpinner = false; window.location.reload(); }else{ this.showSpinner = false; this.showToast(result); } }); } }) // 20240122 ljh 贸易合规2 end }else{ this.showSpinner = false; this.showToast(result); } }).catch(error => { // 处理错误 console.error('selectAppSetData发生错误:', error); }); } // 清空检索条件 handleClear(event){ this.RentalApp = ''; this.ProCode = ''; this.RequestOwner = ''; this.UseReason = '全部'; this.UserSalesdept = '全部'; this.Procategory = ''; this.AssetLocation = ''; } showToast(msg) { const event = new ShowToastEvent({ message: msg, variant: "error", mode: 'sticky' }); this.dispatchEvent(event); } }