buli
2023-06-05 cb95755fe8496d8af6d40b05c4bbd4b6df2e77ab
force-app/main/default/lwc/lexinventoryViewLWC/lexinventoryViewLWC.js
@@ -1,16 +1,20 @@
import { LightningElement, wire, api, track } from 'lwc';
import oninit from "@salesforce/apex/LexInventoryViewController.init";
import oninit2 from "@salesforce/apex/LexInventoryViewController.init2";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import searchOrder from "@salesforce/apex/LexInventoryViewController.searchConsumableorderdetails";
import categoryAllload from "@salesforce/apex/LexInventoryViewController.categoryAllload";
import { NavigationMixin } from "lightning/navigation";
//table css
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
export default class LexinventoryViewLWC extends NavigationMixin(LightningElement) {
   //分页start
   @track sortBy = "";
   //@track sortDirection = "asc";
   @track pageSize = 5;
   @track pageSize = 10;
   error;
   records;
   currentPageToken = 0;
@@ -20,7 +24,7 @@
   @track pageNumber = 1;
   @track paginationVisibility = false;
   @track totalPages = 1;
   pageSizeOptions = [5, 10, 25, 50, 75, 100];
   pageSizeOptions = [10,25,50,100];
   @track recordStart = 0;
   @track recordEnd = 0;
   //end
@@ -48,7 +52,8 @@
   @track showSpinners = false;
   //医院特价
   @track hasHos = false;
   //表头样式
   stylesLoaded = false;
   @track columns = [
@@ -58,13 +63,15 @@
         type: "Name",
         sortable: true,
         hideDefaultActions: true,
         initialWidth: 250,
         // initialWidth: 300,
         wrapText: true,
         cellAttributes: { alignment: "left" }
      },
      {
         label: "第三分类",
         fieldName: "Category3__c",
         initialWidth: 90,
         cellAttributes: { alignment: "left" },
         hideDefaultActions: true,
         sortable: true,
         wrapText: true,
@@ -72,6 +79,8 @@
      {
         label: "第四分类",
         fieldName: "Category4__c",
         cellAttributes: { alignment: "left" },
         initialWidth: 90,
         hideDefaultActions: true,
         wrapText: true,
         sortable: true,
@@ -80,6 +89,8 @@
      {
         label: "第五分类",
         fieldName: "Category5__c",
         cellAttributes: { alignment: "left" },
         initialWidth: 90,
         hideDefaultActions: true,
         wrapText: true,
         sortable: true,
@@ -89,50 +100,71 @@
      {
         label: "规格",
         fieldName: "packing_list",
         cellAttributes: { alignment: "right" },
         initialWidth: 55,
         wrapText: true,
         hideDefaultActions: true,
      },
      {
         label: "单位",
         fieldName: "BoxPiece",
         cellAttributes: { alignment: "left" },
         initialWidth: 55,
         wrapText: true,
         hideDefaultActions: true,
      },
      {
         label: "注册证编码号",
         fieldName: "approbation_No",
         cellAttributes: { alignment: "left" },
         wrapText: true,
         initialWidth: 100,
         initialWidth: 155,
         hideDefaultActions: true,
      },
      {
         label: "注册有效期",
         fieldName: "expiration_Date",
         cellAttributes: { alignment: "left" },
         wrapText: true,
         hideDefaultActions: true,
         initialWidth: 150
         initialWidth: 100
      },
      {
         label: "CFDA状态",
         fieldName: "SFDA_Status__c",
         cellAttributes: { alignment: "left" },
         initialWidth: 95,
         wrapText: true,
         hideDefaultActions: true,
      },
      {
         label: "使用期限",
         fieldName: "guaranteeperiod",
         cellAttributes: { alignment: "left" },
         hideDefaultActions: true,
         initialWidth: 100
         initialWidth: 105
      },
      {
         label: "有效期内库存",
         fieldName: "limitCount",
         label:'有效期内库存',
         type: "customInventoryColor",
         // sortable: true,
         cellAttributes: {alignment: "right" },
         typeAttributes: {
         value: { fieldName:"limitCount"},
         upperlimit: { fieldName: "upperlimit" },
         lowerlimit: { fieldName: "lowerlimit" },
         boxPrice:{ fieldName: "BoxPiece" },
         },
         hideDefaultActions: true,
         sortable: true,
         initialWidth:150
      },
      {
         label: "过期库存",
         fieldName: "overlimitCount",
         hideDefaultActions: true,
         cellAttributes: { alignment: "right" },
         initialWidth:80
      }
   ];
   defaultSortDirection = "asc";
@@ -140,6 +172,21 @@
   sortedBy;
    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.loader = true;
      this.init();
@@ -154,6 +201,8 @@
         sortOrderLWC: this.sortDirection
      }).then((result) => {
         result = JSON.parse(JSON.stringify(result));
         console.log("result.pageRecords = " + JSON.stringify(result.entity.pageRecords));
         console.log("result.consumableorderdetailsRecords = " + JSON.stringify(result.entity.consumableorderdetailsRecords));
         console.log("result.status = " + result.status);
         console.log("result = " + JSON.stringify(result));
         console.log("result 1= " + JSON.stringify(result.entity));
@@ -213,13 +262,18 @@
            this.category5Options = option3ValueTemp;
            this.hasHos = result.entity.hasHos;
            console.log('this.hasHos'+this.hasHos);
            //颜色标记
              //hasHos = true 医院特价
              if (this.hasHos) {
                    let object1 = {
                        label: "医院特价",
                        fieldName: "hospitalSpecialOffer__c",
                        hideDefaultActions: true,
                  type:'boolean'
                  type:'boolean',
                  cellAttributes: { alignment: "left" },
                  initialWidth:80
                    };
                    this.columns.push(object1);
               console.log(' this.columns'+  this.columns);
@@ -235,31 +289,14 @@
                }
            this.showSpinner = false;
         } else {
            this.loader = false;
            console.log("Error:" + result.errorMsg);
            const evt = new ShowToastEvent({
               title: "解析失败",
               message: result.errorMsg,
               variant: "error"
            });
            this.dispatchEvent(evt);
            this.showSpinner = false;
            // this.showToast("Error",'Error', result.msg);
            this.showMyToast('初始化失败',result.msg,'error');
         }
      }).catch((error) => {
         this.loader = false;
         this.showSpinner = false;
         console.log("error = " + JSON.stringify(error));
      });
   }
   handlePaginatorChange(event) {
      this.recordsToDisplay = event.detail.recordsToDisplay;
      this.preSelected = event.detail.preSelected;
      if (this.recordsToDisplay && this.recordsToDisplay > 0) {
         this.rowNumberOffset = this.recordsToDisplay[0].rowNumber - 1;
      } else {
         this.rowNumberOffset = 0;
      }
   }
   handleChange(event) {
@@ -343,7 +380,7 @@
                }
            } else {
                console.log("result = " + JSON.stringify(result));
                this.showToast("Error", result.msg);
                this.showMyToast(result.msg,'','error');
            }
        }).catch((error) => {
            console.log("error" + JSON.stringify(error));
@@ -377,12 +414,8 @@
               console.log('this.totalPages = ' + this.totalPages);
               this.paginationVisibility = this.totalPages > 1 ? true : false;
               console.log('this.sortDirection = ' + this.sortDirection);
               const evt = new ShowToastEvent({
                  title: "搜索成功",
                  message: result.msg,
                  variant: "Success"
               });
               this.dispatchEvent(evt);
               // this.showToast("Success",'搜索成功', result.msg);
               this.showMyToast('搜索成功',result.msg,'success');
               this.data = result.entity.pageRecords;
               console.log('搜索Data==>'+JSON.stringify(this.data));
               for (var i in this.data) {
@@ -397,12 +430,8 @@
               console.log('this.data = ' + JSON.stringify(this.data));
               this.showTable = true;
            } else {
               const evt = new ShowToastEvent({
                  title: "",
                  message: result.msg,
                  variant: "Success"
               });
               this.dispatchEvent(evt);
               // this.showToast("Error",'Error', result.msg);
               this.showMyToast('搜索失败',result.msg,'error');
            }
         })
         .catch((error) => {
@@ -413,7 +442,7 @@
      this[NavigationMixin.Navigate]({
         type: 'standard__webPage',
         attributes: {
            url: '/lexInventory'
            url: '/lexinventory'
         }
      });
   }
@@ -423,7 +452,7 @@
      this[NavigationMixin.Navigate]({
         type: 'standard__webPage',
         attributes: {
            url: '/lexoverdueStock'
            url: '/lexoverduestock'
         }
      });
@@ -441,7 +470,7 @@
      this[NavigationMixin.Navigate]({
         type: 'standard__webPage',
         attributes: {
            url: '/lexCancelRemoveBox'
            url: '/lexcancelremovebox'
         }
      });
@@ -467,12 +496,23 @@
         orderDetZaikuListLWC: JSON.stringify(this.orderDetZaikuList),
         accountName: this.accountName,
         agencyProType: this.agencyProType,
         userWorkLocation: this.userWorkLocation
         userWorkLocation: this.userWorkLocation,
         pageSizeLWC: this.pageSize,
         pageTokenLWC: this.currentPageToken,
      })
         .then((result) => {
            console.log("result搜索 = " + JSON.stringify(result));
            result = JSON.parse(JSON.stringify(result));
            if (result.status == "Success") {
               this.nextPageToken = result.entity.paginatedAccounts.nextPageToken;
               this.totalRecords = result.entity.paginatedAccounts.totalRecords;
               this.recordStart = result.entity.paginatedAccounts.recordStart;
               this.recordEnd = result.entity.paginatedAccounts.recordEnd;
               this.totalPages = Math.ceil(result.entity.paginatedAccounts.totalRecords / this.pageSize);
               console.log('this.totalPages = ' + this.totalPages);
               this.paginationVisibility = this.totalPages > 1 ? true : false;
               console.log('this.sortDirection = ' + this.sortDirection);
               this.data = result.entity.pageRecords;
               for (var i in this.data) {
@@ -484,20 +524,12 @@
               }
               this.showSpinner = false;
               this.showTable = true;
               const evt = new ShowToastEvent({
                  title: "搜索成功",
                  message: result.msg,
                  variant: "Success"
               });
               this.dispatchEvent(evt);
               this.showMyToast('搜索成功',result.msg,'success');
               // this.showToast("Success",'搜索成功', result.msg);
               this.showSpinner = false;
            } else {
               const evt = new ShowToastEvent({
                  title: "",
                  message: result.msg,
                  variant: "Success"
               });
               this.dispatchEvent(evt);
               // this.showToast("Error", 'Error',result.msg);
               this.showMyToast('搜索失败',result.msg,'error');
            }
         })
         .catch((error) => {
@@ -545,6 +577,15 @@
      this.sortDirection = sortDirection;
      this.sortedBy = sortedBy;
   }
   handlePaginatorChange(event) {
      this.recordsToDisplay = event.detail.recordsToDisplay;
      this.preSelected = event.detail.preSelected;
      if (this.recordsToDisplay && this.recordsToDisplay > 0) {
         this.rowNumberOffset = this.recordsToDisplay[0].rowNumber - 1;
      } else {
         this.rowNumberOffset = 0;
      }
   }
   handlePrevious() {
      this.currentPageToken = Number(this.currentPageToken) - Number(this.pageSize);
@@ -578,6 +619,38 @@
   get nextButtonDisabled() {
      return this.nextPageToken === undefined;
   }
   showMyToast(title, message, variant) {
        console.log('show custom message');
        var iconName = '';
        var content = '';
        if(variant == 'success'){
           iconName = 'utility:check';
        }else{
           iconName = 'utility:error';
        }
        if(message != ''){
           content = '<h2><strong>'+title+'<strong/></h2><h5>'+message+'</h5>';
        }else{
           content = '<h2><strong>'+title+'<strong/></h2>';
        }
        this.template.querySelector('c-common-toast').showToast(variant,content,iconName,10000);
   // showToast(type,title,msg) {
   //    this.showSpinner = false;
   //    let mode = '';
   //    if (type.toLowerCase() != 'success') {
   //       mode = 'sticky';
   //    } else {
   //       mode = 'dismissable';
   //    }
   //    const event = new ShowToastEvent({
   //       title: title,
   //       variant: type,
   //       message: msg,
   //       mode: mode
   //    });
   //    this.dispatchEvent(event);
   // }
   }
}