buli
2023-07-14 5b5c1e16deaa3a9d6d0ed1ffca390655ed103df7
force-app/main/default/lwc/lexOverdueStock/lexOverdueStock.js
@@ -5,8 +5,9 @@
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
//table css
import { loadStyle } from 'lightning/platformResourceLoader';
import WrappedHeaderTable from '@salesforce/resourceUrl/lexdatatable';
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
//过期库存一览
const columns = [
@@ -15,7 +16,7 @@
        fieldName: 'iscount',
        type: 'checkbox',
        hideDefaultActions: true,
        initialWidth: 80
    initialWidth: 80,
    },
    {
        label: '消耗品名称',
@@ -25,12 +26,14 @@
        initialWidth: 350,
        hideDefaultActions: true
    },
    {
        label: '单位',
        fieldName: 'boxPiece',
        hideDefaultActions: true
    hideDefaultActions: true,
        // initialWidth: 250,
    },
    {
        label: '过期数量',
@@ -39,6 +42,7 @@
        cellAttributes: { alignment: 'right' }
        // initialWidth: 250,
    },
    {
        label: '销存数量',
@@ -51,6 +55,7 @@
];
//销存明细
const column = [
    {
        label: '消耗品名称',
        fieldName: 'Name__c',
@@ -70,15 +75,16 @@
        label: 'BarCode',
        fieldName: 'Bar_Code__c',
        wrapText: true,
        hideDefaultActions: true
    hideDefaultActions: true,
        // initialWidth: 500,
    },
    {
        label: '使用期限',
        fieldName: 'Sterilization_limit__c',
        hideDefaultActions: true
    hideDefaultActions: true,
        // initialWidth : 250
    },
  }
  ,
    {
        label: '销存原因',
        fieldName: 'diffReason',
@@ -88,55 +94,58 @@
    }
];
export default class LexOverdueStock extends NavigationMixin(LightningElement) {
    columns = columns;
    column = column;
  columns = columns
  column = column
    @track data = [];
    @track overduePageRecords = [];
    @track iSinventory = false;
  @track iSinventory = false
    //加载框
    // @track casesSpinner = true;
    @track showSpinner = true;
    //显示口
    @track showbutton = false;
  @track showbutton = false
    @track showTable = false;
    @track showTables = false;
    //销存一览数据
    @track accountName;
    @track agencyProType;
    @track userWorkLocation;
    @track barcode = '';
    @track orderDetZaiku;
  @track barcode = ''
  @track orderDetZaiku
    @track selectedRows = [];
    @track codPageRecordsLWC;
    @track Id;
    @track overdueList = [];
    renderedCallback() {
        if (!this.stylesLoaded) {
            Promise.all([loadStyle(this, WrappedHeaderTable)])
                .then(() => {
                    console.log('Custom styles loaded');
          console.log("Custom styles loaded");
                    this.stylesLoaded = true;
                })
                .catch((error) => {
                    console.error('Error loading custom styles');
          console.error("Error loading custom styles");
                });
        }
    }
    //初始化
    connectedCallback() {
        console.log('初始化');
        this.showSpinner = true;
        init()
            .then((result) => {
    init().then((result) => {
                result = JSON.parse(JSON.stringify(result));
                console.log('result =' + JSON.stringify(result));
                console.log('result 1=' + result.entity.codPageRecords);
                if ((result.status = 'Success')) {
      if (result.status = 'Success') {
                    this.data = JSON.parse(result.entity.codPageRecords);
                    this.codPageRecordsLWC = result.entity.codPageRecords;
                    console.log('this.data' + this.data);
@@ -144,8 +153,7 @@
                    this.agencyProType = result.entity.agencyProType;
                    this.userWorkLocation = result.entity.userWorkLocation;
                    for (var i in this.data) {
                        this.data[i]['key'] =
                            this.data[i]['prodid'] + this.data[i]['boxPiece'];
          this.data[i]["key"] = this.data[i]["prodid"] + this.data[i]["boxPiece"];
                    }
                    this.showTable = true;
                    // this.casesSpinner = false;
@@ -154,8 +162,7 @@
                    this.showMyToast('初始化失败', result.msg, 'error');
                    this.showSpinner = false;
                }
            })
            .catch((error) => {
    }).catch((error) => {
                console.log('error = ' + JSON.stringify(error));
                this.showSpinner = false;
            });
@@ -167,20 +174,15 @@
        console.log('code' + this.barcode);
        console.log(' this.accountName' + this.accountName);
        console.log(' this.barcode' + this.barcode);
        const selectedRows = this.template
            .querySelector('c-lex-custom-lightning-datatable')
            .getSelectedRows();
    const selectedRows = this.template.querySelector('c-lex-custom-lightning-datatable').getSelectedRows();
        console.log('selectedRows========> ' + JSON.stringify(selectedRows));
        for (var i in this.data) {
            this.data[i]['check'] = false;
      this.data[i]["check"] = false;
        }
        for (var i in this.data) {
            for (var j in selectedRows) {
                if (
                    this.data[i].prodid + this.data[i]['boxPiece'] ==
                    selectedRows[j].prodid + selectedRows[j]['boxPiece']
                ) {
                    this.data[i]['check'] = true;
        if (this.data[i].prodid + this.data[i]["boxPiece"] == selectedRows[j].prodid + selectedRows[j]["boxPiece"]) {
          this.data[i]["check"] = true;
                }
            }
        }
@@ -190,100 +192,61 @@
            userWorkLocationLWC: this.userWorkLocation,
            barcodeLWC: this.barcode,
            codPageRecordsLWC: JSON.stringify(this.data)
        })
            .then((result) => {
    }).then((result) => {
                result = JSON.parse(JSON.stringify(result));
                if (result.status == 'Success') {
                    this.overduePageRecords = JSON.parse(
                        result.entity.overduePageRecords
                    );
        this.overduePageRecords = JSON.parse(result.entity.overduePageRecords);
                    this.overdueList = result.entity.overdueList;
                    this.iSinventory = result.entity.iSinventory;
                    console.log('result录入' + JSON.stringify(result));
                    console.log(
                        'overdueList==>' + JSON.stringify(this.overdueList)
                    );
        console.log('overdueList==>' + JSON.stringify(this.overdueList));
                    for (let i in this.overduePageRecords) {
                        if (this.overduePageRecords[i].Prod != null) {
                            this.overduePageRecords[i]['Name__c'] =
                                this.overduePageRecords[i].Prod.Name__c;
            this.overduePageRecords[i]['Name__c'] = this.overduePageRecords[i].Prod.Name__c;
                        }
                        this.overduePageRecords[i]['Bar_Code__c'] =
                            this.overduePageRecords[
                                i
                            ].orderdetails2.Bar_Code__c;
                        this.overduePageRecords[i]['Box_Piece__c'] =
                            this.overduePageRecords[
                                i
                            ].orderdetails2.Box_Piece__c;
                        this.overduePageRecords[i]['Sterilization_limit__c'] =
                            this.overduePageRecords[
                                i
                            ].orderdetails2.Sterilization_limit__c;
          this.overduePageRecords[i]['Bar_Code__c'] = this.overduePageRecords[i].orderdetails2.Bar_Code__c;
          this.overduePageRecords[i]['Box_Piece__c'] = this.overduePageRecords[i].orderdetails2.Box_Piece__c;
          this.overduePageRecords[i]['Sterilization_limit__c'] = this.overduePageRecords[i].orderdetails2.Sterilization_limit__c;
                    }
                    this.data = JSON.parse(result.entity.codPageRecords);
                    console.log(' this.data' + JSON.stringify(this.data));
                    for (var i in this.data) {
                        this.data[i]['key'] =
                            this.data[i]['prodid'] + this.data[i]['boxPiece'];
          this.data[i]["key"] = this.data[i]["prodid"] + this.data[i]["boxPiece"];
                    }
                    for (var i in this.data) {
                        if (this.data[i]['check']) {
                            this.selectedRows.push(
                                this.data[i].prodid + this.data[i]['boxPiece']
                            );
                            console.log('selectedRows:' + this.selectedRows);
            this.selectedRows.push(this.data[i].prodid + this.data[i]["boxPiece"]);
            console.log("selectedRows:" + this.selectedRows);
                        }
                    }
                    this.showSpinner = false;
                    this.showTable = true;
                } else {
                    if (result.status == 'Success1') {
                        this.overduePageRecords = JSON.parse(
                            result.entity.overduePageRecords
                        );
          this.overduePageRecords = JSON.parse(result.entity.overduePageRecords);
                        this.overdueList = result.entity.overdueList;
                        this.iSinventory = result.entity.iSinventory;
                        console.log('result录入' + JSON.stringify(result));
                        console.log(
                            'overdueList==>' + JSON.stringify(this.overdueList)
                        );
          console.log('overdueList==>' + JSON.stringify(this.overdueList));
                        for (let i in this.overduePageRecords) {
                            if (this.overduePageRecords[i].Prod != null) {
                                this.overduePageRecords[i]['Name__c'] =
                                    this.overduePageRecords[i].Prod.Name__c;
              this.overduePageRecords[i]['Name__c'] = this.overduePageRecords[i].Prod.Name__c;
                            }
                            this.overduePageRecords[i]['Bar_Code__c'] =
                                this.overduePageRecords[
                                    i
                                ].orderdetails2.Bar_Code__c;
                            this.overduePageRecords[i]['Box_Piece__c'] =
                                this.overduePageRecords[
                                    i
                                ].orderdetails2.Box_Piece__c;
                            this.overduePageRecords[i][
                                'Sterilization_limit__c'
                            ] =
                                this.overduePageRecords[
                                    i
                                ].orderdetails2.Sterilization_limit__c;
            this.overduePageRecords[i]['Bar_Code__c'] = this.overduePageRecords[i].orderdetails2.Bar_Code__c;
            this.overduePageRecords[i]['Box_Piece__c'] = this.overduePageRecords[i].orderdetails2.Box_Piece__c;
            this.overduePageRecords[i]['Sterilization_limit__c'] = this.overduePageRecords[i].orderdetails2.Sterilization_limit__c;
                        }
                        this.data = JSON.parse(result.entity.codPageRecords);
                        console.log(' this.data' + JSON.stringify(this.data));
                        for (var i in this.data) {
                            this.data[i]['key'] =
                                this.data[i]['prodid'] +
                                this.data[i]['boxPiece'];
            this.data[i]["key"] = this.data[i]["prodid"] + this.data[i]["boxPiece"];
                        }
                        for (var i in this.data) {
                            if (this.data[i]['check']) {
                                this.selectedRows.push(
                                    this.data[i].prodid +
                                        this.data[i]['boxPiece']
                                );
                                console.log(
                                    'selectedRows:' + this.selectedRows
                                );
              this.selectedRows.push(this.data[i].prodid + this.data[i]["boxPiece"]);
              console.log("selectedRows:" + this.selectedRows);
                            }
                        }
                        this.showSpinner = false;
@@ -294,16 +257,18 @@
                        this.showMyToast(result.msg, '', 'error');
                        this.showSpinner = false;
                        this.showTable = true;
                    }
                    // this.showMyToast('获取失败', result.msg, 'error');
                    // this.showSpinner = false;
                }
            })
            .catch((error) => {
    }).catch((error) => {
                this.showSpinner = false;
                console.log('error = ' + JSON.stringify(error));
            });
    }
    //获取当前输入值
    handleChange(event) {
@@ -316,31 +281,25 @@
        let selectedRowsEvent = event.detail.selectedRows;
        this.selectedRows = [];
        for (var i in selectedRowsEvent) {
            this.selectedRows.push(
                selectedRowsEvent[i].prodid + this.data[i]['boxPiece']
            );
              this.selectedRows.push(selectedRowsEvent[i].prodid+this.data[i]["boxPiece"]);
        }
        console.log('this.selectedRows==>' + this.selectedRows);
    }
    //保存
    saveConfirm() {
        console.log('进入销存确认');
        this.showSpinner = true;
        //查询有哪些选择了的然后check
        const selectedRows = this.template
            .querySelector('c-lex-custom-lightning-datatable')
            .getSelectedRows();
      const selectedRows = this.template.querySelector('c-lex-custom-lightning-datatable').getSelectedRows();
        console.log('selectedRows========> ' + JSON.stringify(selectedRows));
        for (var i in this.data) {
            this.data[i]['check'] = false;
         this.data[i]["check"] = false;
        }
        for (var i in this.data) {
            for (var j in selectedRows) {
                if (
                    this.data[i].prodid + this.data[i]['boxPiece'] ==
                    selectedRows[j].prodid + selectedRows[j]['boxPiece']
                ) {
                    this.data[i]['check'] = true;
            if (this.data[i].prodid+this.data[i]["boxPiece"] == selectedRows[j].prodid+ selectedRows[j]["boxPiece"]) {
               this.data[i]["check"] = true;
                }
            }
        }
@@ -349,8 +308,7 @@
            saveCodPageRecords: JSON.stringify(this.data),
            // saveoverdueList:JSON.stringify(this.overdueList)
            saveoverdueList: this.overdueList
        })
            .then((result) => {
    }).then((result) => {
                result = JSON.parse(JSON.stringify(result));
                console.log('result保存 = ' + JSON.stringify(result));
                if (result.status == 'Success') {
@@ -366,6 +324,7 @@
                } else {
                    this.showMyToast('销存失败', result.msg, 'error');
                    this.showSpinner = false;
                }
            })
            .catch((error) => {
@@ -384,17 +343,11 @@
            iconName = 'utility:error';
        }
        if (message != '') {
            content =
                '<h2><strong>' +
                title +
                '<strong/></h2><h5>' +
                message +
                '</h5>';
      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);
    this.template.querySelector('c-common-toast').showToast(variant, content, iconName, 10000);
    }
}