buli
2023-06-09 f94d7f9cd1d2d467e7242245719192d7157e3ede
force-app/main/default/lwc/lexinventoryViewLWC/lexinventoryViewLWC.js
@@ -1,4 +1,4 @@
import { LightningElement, wire, api, track } from 'lwc';
import { LightningElement, wire, api, track } from "lwc";
import oninit from "@salesforce/apex/LexInventoryViewController.init";
import { ShowToastEvent } from "lightning/platformShowToastEvent";
import searchOrder from "@salesforce/apex/LexInventoryViewController.searchConsumableorderdetails";
@@ -9,8 +9,9 @@
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
export default class LexinventoryViewLWC extends NavigationMixin(LightningElement) {
export default class LexinventoryViewLWC extends NavigationMixin(
  LightningElement
) {
   //分页start
   @track sortBy = "";
   //@track sortDirection = "asc";
@@ -55,7 +56,6 @@
   //表头样式
   stylesLoaded = false;
   @track columns = [
      {
         label: "消耗品名称",
@@ -63,7 +63,7 @@
         type: "Name",
         sortable: true,
         hideDefaultActions: true,
         // initialWidth: 300,
      initialWidth: 300,
         wrapText: true,
         cellAttributes: { alignment: "left" }
      },
@@ -74,7 +74,7 @@
         cellAttributes: { alignment: "left" },
         hideDefaultActions: true,
         sortable: true,
         wrapText: true,
      wrapText: true
      },
      {
         label: "第四分类",
@@ -83,8 +83,7 @@
         initialWidth: 90,
         hideDefaultActions: true,
         wrapText: true,
         sortable: true,
      sortable: true
      },
      {
         label: "第五分类",
@@ -93,8 +92,7 @@
         initialWidth: 90,
         hideDefaultActions: true,
         wrapText: true,
         sortable: true,
      sortable: true
      },
   
      {
@@ -103,7 +101,7 @@
         cellAttributes: { alignment: "right" },
         initialWidth: 55,
         wrapText: true,
         hideDefaultActions: true,
      hideDefaultActions: true
      },
      {
         label: "单位",
@@ -111,7 +109,7 @@
         cellAttributes: { alignment: "left" },
         initialWidth: 55,
         wrapText: true,
         hideDefaultActions: true,
      hideDefaultActions: true
      },
      {
         label: "注册证编码号",
@@ -119,7 +117,7 @@
         cellAttributes: { alignment: "left" },
         wrapText: true,
         initialWidth: 155,
         hideDefaultActions: true,
      hideDefaultActions: true
      },
      {
         label: "注册有效期",
@@ -135,7 +133,7 @@
         cellAttributes: { alignment: "left" },
         initialWidth: 95,
         wrapText: true,
         hideDefaultActions: true,
      hideDefaultActions: true
      },
      {
         label: "使用期限",
@@ -145,7 +143,7 @@
         initialWidth: 105
      },
      {
         label:'有效期内库存',
      label: "有效期内库存",
         type: "customInventoryColor",
         // sortable: true,
         cellAttributes: {alignment: "right" },
@@ -153,7 +151,7 @@
         value: { fieldName:"limitCount"},
         upperlimit: { fieldName: "upperlimit" },
         lowerlimit: { fieldName: "lowerlimit" },
         boxPrice:{ fieldName: "BoxPiece" },
        boxPrice: { fieldName: "BoxPiece" }
         },
         hideDefaultActions: true,
         initialWidth:150
@@ -171,8 +169,6 @@
   sortDirection = "asc";
   sortedBy;
    renderedCallback() {
        if (!this.stylesLoaded) {
            Promise.all([loadStyle(this, WrappedHeaderTable)])
@@ -186,7 +182,6 @@
        }
    }
   connectedCallback() {
      this.loader = true;
      this.init();
@@ -199,25 +194,45 @@
         pageTokenLWC: this.currentPageToken,
         sortFieldLWC: this.sortBy,
         sortOrderLWC: this.sortDirection
      }).then((result) => {
    })
      .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.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));
         console.log("result 2= " + JSON.stringify(result.entity.pageRecords));
         console.log("result.entity.categoryOptionMap 2= " + JSON.stringify(result.entity.categoryOptionMap));
         console.log("result.entity.categoryOptionMap 2= " + JSON.stringify(result.entity.category4OptionMap));
         console.log("result.entity.categoryOptionMap 2= " + JSON.stringify(result.entity.category5OptionMap));
        console.log(
          "result.entity.categoryOptionMap 2= " +
            JSON.stringify(result.entity.categoryOptionMap)
        );
        console.log(
          "result.entity.categoryOptionMap 2= " +
            JSON.stringify(result.entity.category4OptionMap)
        );
        console.log(
          "result.entity.categoryOptionMap 2= " +
            JSON.stringify(result.entity.category5OptionMap)
        );
         if (result.status == "Success") {
            console.log('result.entity.paginatedAccounts = ' + JSON.stringify(result.entity.paginatedAccounts));
          console.log(
            "result.entity.paginatedAccounts = " +
              JSON.stringify(result.entity.paginatedAccounts)
          );
            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.totalPages = Math.ceil(
            result.entity.paginatedAccounts.totalRecords / this.pageSize
          );
          console.log("this.totalPages = " + this.totalPages);
            this.paginationVisibility = this.totalPages > 1 ? true : false;
            this.loader = false;
@@ -238,12 +253,14 @@
            let option1ValueTemp = [];
            for (var key in result.entity.categoryOptionMap) {
               let object = {};
               object['label'] = result.entity.categoryOptionMap[key];
               object['value'] = key;
            object["label"] = result.entity.categoryOptionMap[key];
            object["value"] = key;
               option1ValueTemp.push(object);
            }
            this.category3Options = option1ValueTemp;
            console.log(' this.optionscatone===>' + JSON.stringify(this.optionscatone));
          console.log(
            " this.optionscatone===>" + JSON.stringify(this.optionscatone)
          );
            let option2ValueTemp = [];
            for (var key in result.entity.category4OptionMap) {
               let object = {};
@@ -261,7 +278,7 @@
            }
            this.category5Options = option3ValueTemp;
            this.hasHos = result.entity.hasHos;
            console.log('this.hasHos'+this.hasHos);
          console.log("this.hasHos" + this.hasHos);
            //颜色标记
            
              //hasHos = true 医院特价
@@ -270,29 +287,33 @@
                        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);
            console.log(" this.columns" + this.columns);
               for (var j in this.data) {
                  this.data[j]["Name__c"] = this.data[j].Prod.Name__c;
                  this.data[j]["Category3__c"] = this.data[j].Prod.Category3__c;
                  this.data[j]["Category4__c"] = this.data[j].Prod.Category3__c;
                  this.data[j]["Category5__c"] = this.data[j].Prod.Category3__c;
                  this.data[j]["SFDA_Status__c"] = this.data[j].Prod.SFDA_Status__c;
                  this.data[j]["hospitalSpecialOffer__c"] = this.data[j].hospitalSpecialOffer;
                  console.log('this.data[j].hospitalSpecialOffer__c'+this.data[j].hospitalSpecialOffer);
              this.data[j]["hospitalSpecialOffer__c"] =
                this.data[j].hospitalSpecialOffer;
              console.log(
                "this.data[j].hospitalSpecialOffer__c" +
                  this.data[j].hospitalSpecialOffer
              );
               }
                }
            this.showSpinner = false;
         } else {
            // this.showToast("Error",'Error', result.msg);
            this.showMyToast('初始化失败',result.msg,'error');
          this.showMyToast("初始化失败", result.msg, "error");
         }
      }).catch((error) => {
      })
      .catch((error) => {
         this.loader = false;
         this.showSpinner = false;
         console.log("error = " + JSON.stringify(error));
@@ -333,17 +354,17 @@
                this.CategoryThree = value;
                //调用后台显示第四五分类
                this.showAllCate();
                if (this.CategoryThree == '') {
                    this.CategoryFour = '';
                    this.CategoryFive = '';
        if (this.CategoryThree == "") {
          this.CategoryFour = "";
          this.CategoryFive = "";
                }
                break;
            case "CategoryFour":
                this.Category4 = value;
                //调用后台显示第五分类
                this.showCate();
                if (this.CategoryFour == '') {
                    this.CategoryFive = '';
        if (this.CategoryFour == "") {
          this.CategoryFive = "";
                }
                break;
            case "CategoryFive":
@@ -352,12 +373,12 @@
        }
    }
   showAllCate() {
        categoryAllload({
            category3LWC: this.CategoryThree,
         agencyProTypeLWC:this.agencyProType
        }).then((result) => {
    })
      .then((result) => {
            result = JSON.parse(JSON.stringify(result));
            console.log("result = " + JSON.stringify(result));
            if (result.status == "Success") {
@@ -370,7 +391,9 @@
                    object["value"] = key;
                    this.category4Options.push(object);
                }
                console.log("this.category4Options = " + JSON.stringify(this.category4Options));
          console.log(
            "this.category4Options = " + JSON.stringify(this.category4Options)
          );
                //第5分类
                for (var key in result.entity.category5OptionMap) {
                    let object = {};
@@ -380,9 +403,10 @@
                }
            } else {
                console.log("result = " + JSON.stringify(result));
                this.showMyToast(result.msg,'','error');
          this.showMyToast(result.msg, "", "error");
            }
        }).catch((error) => {
      })
      .catch((error) => {
            console.log("error" + JSON.stringify(error));
        });
    }
@@ -399,7 +423,7 @@
         agencyProType: this.agencyProType,
         userWorkLocation: this.userWorkLocation,
         pageSizeLWC: this.pageSize,
         pageTokenLWC: this.currentPageToken,
      pageTokenLWC: this.currentPageToken
         // sortFieldLWC: this.sortBy,
         // sortOrderLWC: this.sortDirection
      })
@@ -410,28 +434,31 @@
               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.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);
          console.log("this.sortDirection = " + this.sortDirection);
               // this.showToast("Success",'搜索成功', result.msg);
               this.showMyToast('搜索成功',result.msg,'success');
          this.showMyToast("搜索成功", result.msg, "success");
               this.data = result.entity.pageRecords;
               console.log('搜索Data==>'+JSON.stringify(this.data));
          console.log("搜索Data==>" + JSON.stringify(this.data));
               for (var i in this.data) {
                  this.data[i]["Name__c"] = this.data[i].Prod.Name__c;
                  this.data[i]["Category3__c"] = this.data[i].Prod.Category3__c;
                  this.data[i]["Category4__c"] = this.data[i].Prod.Category3__c;
                  this.data[i]["Category5__c"] = this.data[i].Prod.Category3__c;
                  this.data[i]["SFDA_Status__c"] = this.data[i].Prod.SFDA_Status__c;
                  this.data[i]["hospitalSpecialOffer__c"] = this.data[i].hospitalSpecialOffer;
            this.data[i]["hospitalSpecialOffer__c"] =
              this.data[i].hospitalSpecialOffer;
               }
               this.data = [...this.data];
               console.log('this.data = ' + JSON.stringify(this.data));
          console.log("this.data = " + JSON.stringify(this.data));
               this.showTable = true;
            } else {
               // this.showToast("Error",'Error', result.msg);
               this.showMyToast('搜索失败',result.msg,'error');
          this.showMyToast("搜索失败", result.msg, "error");
            }
         })
         .catch((error) => {
@@ -440,54 +467,51 @@
   }
   inventoryCount() {
      this[NavigationMixin.Navigate]({
         type: 'standard__webPage',
      type: "standard__webPage",
         attributes: {
            url: '/lexinventory'
        url: "/lexinventory"
         }
      });
   }
   handleExpired() {
      console.log('过期库存呢销存');
    console.log("过期库存呢销存");
      this[NavigationMixin.Navigate]({
         type: 'standard__webPage',
      type: "standard__webPage",
         attributes: {
            url: '/lexoverduestock'
        url: "/lexoverduestock"
         }
      });
   }
   removeBox() {
      this[NavigationMixin.Navigate]({
         type: 'standard__webPage',
      type: "standard__webPage",
         attributes: {
            url: '/lexremovebox'
        url: "/lexremovebox"
         }
      });
   }
   cancelremoveBox() {
      this[NavigationMixin.Navigate]({
         type: 'standard__webPage',
      type: "standard__webPage",
         attributes: {
            url: '/lexcancelremovebox'
        url: "/lexcancelremovebox"
         }
      });
   }
   clearAll() {
      this.showSpinner = true;
      this.showTable = false;
      this.Name = '';
      this.CategoryThree = '';
      this.CategoryFour = '';
      this.CategoryFive = '';
    this.Name = "";
    this.CategoryThree = "";
    this.CategoryFour = "";
    this.CategoryFive = "";
      this.template.querySelectorAll("lightning-combobox").forEach((each) => {
         each.value = null;
      });
      console.log(' this.CategoryThree' + this.CategoryThree);
      console.log('数据列表' + this.data);
    console.log(" this.CategoryThree" + this.CategoryThree);
    console.log("数据列表" + this.data);
      searchOrder({
         category1: this.Name,
         Category3: this.CategoryThree,
@@ -498,21 +522,22 @@
         agencyProType: this.agencyProType,
         userWorkLocation: this.userWorkLocation,
         pageSizeLWC: this.pageSize,
         pageTokenLWC: this.currentPageToken,
      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.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);
          console.log("this.sortDirection = " + this.sortDirection);
               this.data = result.entity.pageRecords;
               for (var i in this.data) {
@@ -524,12 +549,12 @@
               }
               this.showSpinner = false;
               this.showTable = true;
               this.showMyToast('搜索成功',result.msg,'success');
          this.showMyToast("搜索成功", result.msg, "success");
               // this.showToast("Success",'搜索成功', result.msg);
               this.showSpinner = false;
            } else {
               // this.showToast("Error", 'Error',result.msg);
               this.showMyToast('搜索失败',result.msg,'error');
          this.showMyToast("搜索失败", result.msg, "error");
            }
         })
         .catch((error) => {
@@ -558,8 +583,8 @@
      this.sortBy = event.detail.fieldName;
      this.sortDirection = event.detail.sortDirection;
      this.currentPageToken = 0;
      console.log('this.sortBy = ' + this.sortBy)
      console.log('this.sortDirection = ' + this.sortDirection)
    console.log("this.sortBy = " + this.sortBy);
    console.log("this.sortDirection = " + this.sortDirection);
      // if('limitCount' != this.sortBy)
      //    this.searchOrderDetail();
      // else{
@@ -572,7 +597,9 @@
      // }
      const { fieldName: sortedBy, sortDirection } = event.detail;
      const cloneData = [...this.data];
      cloneData.sort(this.sortByMethod(sortedBy, sortDirection === 'asc' ? 1 : -1));
    cloneData.sort(
      this.sortByMethod(sortedBy, sortDirection === "asc" ? 1 : -1)
    );
      this.data = cloneData;
      this.sortDirection = sortDirection;
      this.sortedBy = sortedBy;
@@ -588,12 +615,14 @@
   }
   handlePrevious() {
      this.currentPageToken = Number(this.currentPageToken) - Number(this.pageSize);
    this.currentPageToken =
      Number(this.currentPageToken) - Number(this.pageSize);
      this.searchOrderDetail();
   }
   handleNext() {
      this.currentPageToken = Number(this.currentPageToken) + Number(this.pageSize);
    this.currentPageToken =
      Number(this.currentPageToken) + Number(this.pageSize);
      this.searchOrderDetail();
   }
   handleFirst() {
@@ -602,7 +631,8 @@
   }
   handleLast() {
      this.currentPageToken = this.totalPages > 1 ? (this.totalPages - 1) * this.pageSize : 0;
    this.currentPageToken =
      this.totalPages > 1 ? (this.totalPages - 1) * this.pageSize : 0;
      this.searchOrderDetail();
   }
@@ -620,21 +650,23 @@
      return this.nextPageToken === undefined;
   }
   showMyToast(title, message, variant) {
        console.log('show custom message');
        var iconName = '';
        var content = '';
        if(variant == 'success'){
           iconName = 'utility:check';
    console.log("show custom message");
    var iconName = "";
    var content = "";
    if (variant == "success") {
      iconName = "utility:check";
        }else{
           iconName = 'utility:error';
      iconName = "utility:error";
        }
        if(message != ''){
           content = '<h2><strong>'+title+'<strong/></h2><h5>'+message+'</h5>';
    if (message != "") {
      content =
        "<h2><strong>" + title + "<strong/></h2><h5>" + message + "</h5>";
        }else{
           content = '<h2><strong>'+title+'<strong/></h2>';
      content = "<h2><strong>" + title + "<strong/></h2>";
        }
        this.template.querySelector('c-common-toast').showToast(variant,content,iconName,10000);
    this.template
      .querySelector("c-common-toast")
      .showToast(variant, content, iconName, 10000);
   // showToast(type,title,msg) {
   //    this.showSpinner = false;