import { LightningElement, wire, api, track } from "lwc"; import { ShowToastEvent } from "lightning/platformShowToastEvent"; import init from "@salesforce/apex/LexConsumableAccountController.init"; import changelistView from "@salesforce/apex/LexConsumableAccountController.changelistView"; import accountInit from "@salesforce/apex/LexConsumableAccountInfoController.init"; //table css import { loadStyle } from "lightning/platformResourceLoader"; import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable"; const columns = [ { label: "客户名", fieldName: "NameUrl", hideDefaultActions: true, wrapText: true, initialWidth: 345, sortable: true, type: "url", typeAttributes: { label: { fieldName: "Name", }, }, }, { label: "省", fieldName: "StateMasterUrl", hideDefaultActions: true, initialWidth: 80, wrapText: true, sortable: true, type: "url", typeAttributes: { label: { fieldName: "StateMasterName", }, target: "_blank", }, }, { label: "销售本部医院", fieldName: "Salesdepartment_HP__c", initialWidth: 115, hideDefaultActions: true, sortable: true, wrapText: true, }, { label: "创建日期", fieldName: "CreatedDate", hideDefaultActions: true, sortable: true, wrapText: true, type: "date", typeAttributes: { timeZone: "Asia/Shanghai", day: "numeric", month: "numeric", year: "numeric", }, initialWidth: 100, }, { label: "有效/无效", fieldName: "Is_Active__c", hideDefaultActions: true, sortable: true, wrapText: true, initialWidth: 91, }, { label: "客户记录类型", fieldName: "RecordTypeName", hideDefaultActions: true, sortable: true, wrapText: true, initialWidth: 130, }, { label: "政府等级", fieldName: "Grade__c", hideDefaultActions: true, sortable: true, wrapText: true, initialWidth: 86, }, { label: "OCSM分类(医院)", fieldName: "OCM_Category__c", hideDefaultActions: true, sortable: true, wrapText: true, initialWidth: 150, }, { label: "市", fieldName: "CityMasterNameUrl", hideDefaultActions: true, sortable: true, wrapText: true, type: "url", typeAttributes: { label: { fieldName: "CityMasterName", }, target: "_blank", }, }, { label: "县/区", fieldName: "Town__c", hideDefaultActions: true, sortable: true, wrapText: true, }, { label: "客户电话", fieldName: "Phone", hideDefaultActions: true, sortable: true, wrapText: true, }, ]; const topColumns = [ { label: "客户名", fieldName: "NameUrl", hideDefaultActions: true, wrapText: true, type: "url", typeAttributes: { label: { fieldName: "Name", }, }, }, { label: "市", fieldName: "CityMasterNameUrl", hideDefaultActions: true, wrapText: true, type: "url", typeAttributes: { label: { fieldName: "CityMasterName", }, target: "_blank", }, }, { label: "县/区", fieldName: "Town__c", hideDefaultActions: true, wrapText: true, }, { label: "销量占比", fieldName: "proportion", hideDefaultActions: true, wrapText: true, initialWidth: 100, cellAttributes: { alignment: "right" }, }, { label: "操作", fieldName: "Town__c", type:'weeklyReport', initialWidth:150, typeAttributes: { recordId: { fieldName: "Id" }, hospitalName : { fieldName: "Name" }, isShowButton : { fieldName: "isShowButton" }, }, hideDefaultActions: true, } ]; export default class LexConsumableAccount extends LightningElement { columns = columns; topColumns = topColumns; @track isShowSpinner = true; @track pageRecords = []; @track accountId = ""; @track agencyProType = ""; @track agencyProTypestr = ""; @track listViewOptions = [ { label: "01. 医院_Hospital", value: "01. 医院_Hospital", }, { label: "61. 医院_Hospital草案中的医院", value: "61. 医院_Hospital草案中的医院", }, { label: "62. 医院_Hospital申请中的医院", value: "62. 医院_Hospital申请中的医院", }, { label: "63. 医院_Hospital上周创建的医院", value: "63. 医院_Hospital上周创建的医院", }, ]; @track viewOption = "01. 医院_Hospital"; @track isShowAccountInfo = false; @track topAccountData = []; //前端排序 defaultSortDirection = "asc"; sortDirection = "asc"; sortedBy; //分页start @track sortBy = ""; @track pageSize = 10; error; records; currentPageToken = 0; nextPageToken = this.pageSize; @track totalRecords = 0; @track loader = false; @track pageNumber = 1; @track paginationVisibility = false; @track totalPages = 1; pageSizeOptions = [10, 25, 50, 100]; @track recordStart = 0; @track recordEnd = 0; //end @track AccId = ""; @track printUrl = ""; @track accountDataInfo = { name: "", ownerName: "", site: "", isActive: "", aliasName2: "", banOnUseReason: "", grade: "", attributeType: "", oCMCategory: "", specialityType: "", stateMasterName: "", phone: "", cityMasterName: "", phoneCall: "", town: "", fax: "", street: "", postalCode: "", address: "", parentName: "", }; 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"); }); } } //获取链接参数 getQueryString(name) { console.log("getQueryString name " + name); let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); let r = window.location.search.substr(1).match(reg); if (r != null) { return decodeURIComponent(r[2]); } return null; } connectedCallback() { this.AccId = this.getQueryString("AccId"); this.AccId = this.AccId == null ? "" : this.AccId; if (this.AccId != "") { console.log("this.AccId = " + this.AccId); accountInit({ accId: this.AccId, }).then((r) => { r = JSON.parse(JSON.stringify(r)); console.log("r = " + JSON.stringify(r)); if (r.status == "Success") { this.accountDataInfo.name = r.entity.obj.Name; this.accountDataInfo.ownerName = r.entity.obj.Owner == null ? "" : r.entity.obj.Owner.Name; this.accountDataInfo.site = r.entity.obj.site; this.accountDataInfo.isActive = r.entity.obj.Is_Active__c; this.accountDataInfo.aliasName2 = r.entity.obj.Alias_Name2__c; this.accountDataInfo.banOnUseReason = r.entity.obj.Ban_On_Use_Reason__c; this.accountDataInfo.grade = r.entity.obj.Grade__c; this.accountDataInfo.attributeType = r.entity.obj.Attribute_Type__c; this.accountDataInfo.oCMCategory = r.entity.obj.OCM_Category__c; this.accountDataInfo.specialityType = r.entity.obj.Speciality_Type__c; this.accountDataInfo.stateMasterName = r.entity.obj.State_Master__r == null ? "" : r.entity.obj.State_Master__r.Name; this.accountDataInfo.phone = r.entity.obj.Phone; this.accountDataInfo.cityMasterName = r.entity.obj.City_Master__r == null ? "" : r.entity.obj.City_Master__r.Name; this.accountDataInfo.phoneCall = r.entity.obj.PhoneCall__c; this.accountDataInfo.town = r.entity.obj.Town__c; this.accountDataInfo.fax = r.entity.obj.Fax; this.accountDataInfo.street = r.entity.obj.Street__c; this.accountDataInfo.postalCode = r.entity.obj.Postal_Code__c; this.accountDataInfo.address = r.entity.obj.Address__c; this.accountDataInfo.parentName = r.entity.obj.Parent == null ? "" : r.entity.obj.Parent.Name; console.log( "this.accountDataInfo = " + JSON.stringify(this.accountDataInfo) ); this.printUrl = "/lexconsumableaccountinfoprint?AccId=" + this.AccId; this.isShowAccountInfo = true; this.isShowSpinner = false; } else { console.log("r = " + JSON.stringify(r)); this.showMyToast('Error', r.msg, 'Error'); } }).catch((error) => { console.log("error = " + JSON.stringify(error)); this.showMyToast('Error', '初始化失败', 'Error'); }); } else { init({ pageSizeLWC: this.pageSize, pageTokenLWC: this.currentPageToken, }).then((r) => { r = JSON.parse(JSON.stringify(r)); console.log("r = " + JSON.stringify(r)); if (r.status == "Success") { //分页 this.nextPageToken = r.entity.paginatedAccounts.nextPageToken; this.totalRecords = r.entity.paginatedAccounts.totalRecords; this.recordStart = r.entity.paginatedAccounts.recordStart; this.recordEnd = r.entity.paginatedAccounts.recordEnd; this.totalPages = Math.ceil( r.entity.paginatedAccounts.totalRecords / this.pageSize ); console.log("this.totalPages = " + this.totalPages); this.paginationVisibility = this.totalPages > 1 ? true : false; this.pageRecords = r.entity.pageRecords; this.accountId = r.entity.accountId; this.agencyProType = r.entity.agencyProType; this.agencyProTypestr = r.entity.agencyProTypestr; console.log("this.agencyProTypestr = " + this.agencyProTypestr); for (var i in this.pageRecords) { this.pageRecords[i]["NameUrl"] = "/lexconsumableaccount?AccId=" + this.pageRecords[i].Id; this.pageRecords[i]["StateMasterName"] = this.pageRecords[i].State_Master__r.Name; this.pageRecords[i]["StateMasterUrl"] = "/" + this.pageRecords[i].State_Master__c; this.pageRecords[i]["CityMasterName"] = this.pageRecords[i].City_Master__r.Name; this.pageRecords[i]["CityMasterNameUrl"] = "/" + this.pageRecords[i].City_Master__c; this.pageRecords[i]["RecordTypeName"] = this.pageRecords[i].RecordType.Name; } console.log( "this.listViewOptions = " + JSON.stringify(this.listViewOptions) ); //top10客户 this.topAccountData = r.entity.acList; console.log( "this.topAccountData = " + JSON.stringify(this.topAccountData) ); let proportionTest = 11; let proportionTest1 = 16; for (var i in this.topAccountData) { this.topAccountData[i]["NameUrl"] = "/lexconsumableaccount?AccId=" + this.topAccountData[i].Id; this.topAccountData[i]["StateMasterName"] = this.topAccountData[i].State_Master__r.Name; this.topAccountData[i]["StateMasterUrl"] = "/" + this.topAccountData[i].State_Master__c; this.topAccountData[i]["CityMasterName"] = this.topAccountData[i].City_Master__r.Name; this.topAccountData[i]["CityMasterNameUrl"] = "/" + this.topAccountData[i].City_Master__c; this.topAccountData[i]["RecordTypeName"] = this.topAccountData[i].RecordType.Name; this.topAccountData[i]["isShowButton"] = true; this.topAccountData[i]["proportion"] = proportionTest + '%'; if(proportionTest1 == 16){ this.topAccountData[i]["proportion"] = proportionTest1 + '%'; proportionTest1--; } proportionTest--; } //其他 this.topAccountData.push({ Name : '...', NameUrl : '/lexconsumableaccount', proportion : '30%', CityMasterName : '...', CityMasterNameUrl:'/lexconsumableaccount', Town__c:'...', isShowButton : false }) this.isShowSpinner = false; } else { console.log("r = " + JSON.stringify(r)); this.showMyToast('Error', r.msg, 'Error'); } }).catch((error) => { console.log("error = " + JSON.stringify(error)); this.showMyToast('Error', '销量前十客户初始化失败', 'Error'); }); } } dataChange(event) { let fieldName = event.target.getAttribute("data-field"); let value = event.detail.value; console.log("fieldName = " + fieldName + " value = " + value); switch (fieldName) { case "viewOption": this.viewOption = value; this.changelistView(); break; } } changelistView() { this.isShowSpinner = true; changelistView({ filterNameLwc: this.viewOption, accountIdLwc: this.accountId, agencyProTypeLwc: this.agencyProType, pageSizeLWC: this.pageSize, pageTokenLWC: this.currentPageToken, sortFieldLWC: this.sortBy, sortOrderLWC: this.sortDirection, }) .then((r) => { r = JSON.parse(JSON.stringify(r)); console.log("r = " + JSON.stringify(r)); if (r.status == "Success") { //分页 this.nextPageToken = r.entity.paginatedAccounts.nextPageToken; this.totalRecords = r.entity.paginatedAccounts.totalRecords; this.recordStart = r.entity.paginatedAccounts.recordStart; this.recordEnd = r.entity.paginatedAccounts.recordEnd; this.totalPages = Math.ceil( r.entity.paginatedAccounts.totalRecords / this.pageSize ); console.log("this.totalPages = " + this.totalPages); this.paginationVisibility = this.totalPages > 1 ? true : false; this.pageRecords = r.entity.pageRecords; console.log("this.pageRecords = " + JSON.stringify(this.pageRecords)); for (var i in this.pageRecords) { this.pageRecords[i]["NameUrl"] = "/lexconsumableaccount?AccId=" + this.pageRecords[i].Id; this.pageRecords[i]["StateMasterName"] = this.pageRecords[i].State_Master__r.Name; this.pageRecords[i]["StateMasterUrl"] = "/" + this.pageRecords[i].State_Master__c; this.pageRecords[i]["CityMasterName"] = this.pageRecords[i].City_Master__r.Name; this.pageRecords[i]["CityMasterNameUrl"] = "/" + this.pageRecords[i].City_Master__c; this.pageRecords[i]["RecordTypeName"] = this.pageRecords[i].RecordType.Name; } this.isShowSpinner = false; } else { this.showMyToast('Error', r.msg, 'Error'); } }).catch((error) => { console.log('error = ' + JSON.stringify(error.message)) }); } showMyToast(title, message, variant) { this.isShowSpinner = false; console.log('show custom message'); var iconName = ''; var content = ''; if (variant.toLowerCase() == 'success') { iconName = 'utility:check'; } else { iconName = 'utility:error'; } if (message != '') { content = '