buli
2023-07-11 80a3f59e2d3df07805bc67e329300b8de90a5b3a
force-app/main/default/lwc/lexProductLimitEdit/lexProductLimitEdit.js
@@ -1,9 +1,11 @@
import { LightningElement, wire, api, track } from 'lwc';
import oninit from "@salesforce/apex/LexProductLimitEditController.init";
import save from "@salesforce/apex/LexUpAccountProLimit.upAccount";
import oninit from '@salesforce/apex/LexProductLimitEditController.init';
import save from '@salesforce/apex/LexUpAccountProLimit.upAccount';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from "lightning/navigation";
export default class InventoryEditingLWC extends  NavigationMixin(LightningElement){
import { NavigationMixin } from 'lightning/navigation';
export default class LexProductLimitEdit extends NavigationMixin(
    LightningElement
) {
    @track invRecords = [];
    @track accountid;
    @track upstring = '';
@@ -11,8 +13,8 @@
    @track showSpinner = true;
    //获取链接参数
   getQueryString(name) {
      console.log("getQueryString name " + name);
      let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        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]);
@@ -24,26 +26,26 @@
        this.showSpinner = true;
        console.log('  === connectedCallback === ');
        //获取accountid userPro_Type
      this.accountid = this.getQueryString("accountid");
        this.accountid = this.accountid == null ? "" : this.accountid;
        this.userPro_Type = this.getQueryString("userPro_Type");
      this.userPro_Type = this.userPro_Type == null ? "" : this.userPro_Type;
        this.accountid = this.getQueryString('accountid');
        this.accountid = this.accountid == null ? '' : this.accountid;
        this.userPro_Type = this.getQueryString('userPro_Type');
        this.userPro_Type = this.userPro_Type == null ? '' : this.userPro_Type;
             //获取数据
             oninit({
                accountid:this.accountid,
                userPro_Type:this.userPro_Type
             }).then((result) => {
        })
            .then((result) => {
                result = JSON.parse(JSON.stringify(result));
                console.log('result'+JSON.stringify(result));
                if(result.status == 'Success'){
                    console.log('11===>'+result.entity.product_Limit);
                    console.log('11===>'+typeof(result.entity.product_Limit));
                    console.log('11===>' + typeof result.entity.product_Limit);
                    let str =  result.entity.product_Limit;
                    var arr  = str.split(',');
                    console.log('arr==>'+ arr);
                    console.log('arr==>'+ arr.length);
                    console.log('arr==>'+ typeof(arr));
                    console.log('arr==>' + typeof arr);
                    for(var i in arr){ 
                        var arry = arr[i].split('|');
                        this.invRecords.push({ 
@@ -53,18 +55,19 @@
                        });
                    }
                    this.showSpinner = false;
                    console.log('this.invRecords'+JSON.stringify(this.invRecords));
                    console.log(
                        'this.invRecords' + JSON.stringify(this.invRecords)
                    );
                }else{
                    this.showSpinner = false;
                    console.log("error = " + JSON.stringify(error));
                    console.log('error = ' + JSON.stringify(error));
                }
            }).catch((error) => {
            })
            .catch((error) => {
                this.showSpinner = false;
            console.log("error = " + JSON.stringify(error));
                console.log('error = ' + JSON.stringify(error));
         });
        // this.inventoryTempRecords();
    }
    addRow(){
@@ -73,7 +76,7 @@
            inventory1: '',
            inventory2: '',
            id: ++this.keyIndex
        }
        };
        this.invRecords = [...this.invRecords, Object.create(objRow)];
    }
    removeRow(event){
@@ -89,32 +92,59 @@
        console.log('保存');
        console.log('this.invRecords'+JSON.stringify(this.invRecords));
        for(var i in this.invRecords){
            console.log('inven'+this.invRecords[i]["inventory1"]);
            console.log('数字'+this.isNum(this.invRecords[i]["inventory1"]));
            if(this.isNum(this.invRecords[i]["inventory1"]) == false || this.isNum(this.invRecords[i]["inventory2"]==false)){
                // alert("输入格式不正确,请输入数字!");
                this.showMyToast('保存失败','输入格式不正确,请输入数字','error');
            console.log('inven1' + this.invRecords[i]['inventory1']);
            console.log('数字1' + this.isNum(this.invRecords[i]['inventory1']));
            console.log('inven2' + this.invRecords[i]['inventory2']);
            console.log('数字2' + this.isNum(this.invRecords[i]['inventory2']));
            if (
                this.invRecords[i]['inventory1'] == '' ||
                this.invRecords[i]['inventory1'] == null ||
                this.invRecords[i]['inventory2'] == null ||
                this.invRecords[i]['inventory2'] == ''
            ) {
                this.showMyToast(
                    '保存失败',
                    '输入格式不正确,请输入数字',
                    'error'
                );
                this.showSpinner = false;
                return;
            }
            if(this.invRecords[i]["inventory1"] == ''||this.invRecords[i]["inventory1"] == null ||this.invRecords[i]["inventory2"] == null ||
            this.invRecords[i]["inventory2"] == ''){
                // alert('请输入' +this.invRecords[i]["productNumber"] + '库存上下限信息!');
                this.showMyToast('保存失败','请输入' +this.invRecords[i]["productNumber"] + '库存上下限信息','error');
            if (
                this.isNum(this.invRecords[i]['inventory1']) == false ||
                this.isNum(this.invRecords[i]['inventory2']) == false
            ) {
                this.showMyToast(
                    '保存失败',
                    '输入格式不正确,请输入数字',
                    'error'
                );
                this.showSpinner = false;
                return;
            }
            if(Number(this.invRecords[i]["inventory1"])>Number(this.invRecords[i]["inventory2"])){
                // alert( this.invRecords[i]["productNumber"]  + '库存下限大于上限!');
                this.showMyToast('保存失败',this.invRecords[i]["productNumber"]  + '库存下限大于上限','error');
            if (
                Number(this.invRecords[i]['inventory1']) >
                Number(this.invRecords[i]['inventory2'])
            ) {
                this.showMyToast(
                    '保存失败',
                    this.invRecords[i]['productNumber'] + '库存下限大于上限',
                    'error'
                );
                this.showSpinner = false;
                return;
            }
        }
            let dataStr = ''
        let dataStr = '';
            for(var i in this.invRecords){
                dataStr = dataStr+this.invRecords[i]["productNumber"] +'|'+this.invRecords[i]["inventory1"]+'|'+this.invRecords[i]["inventory2"]+',';
            dataStr =
                dataStr +
                this.invRecords[i]['productNumber'] +
                '|' +
                this.invRecords[i]['inventory1'] +
                '|' +
                this.invRecords[i]['inventory2'] +
                ',';
            }
            console.log('dataStr==>'+dataStr);
            this.upstring = dataStr.substring(0, dataStr.lastIndexOf(','));
@@ -123,7 +153,8 @@
                accountId: this.accountid, 
                productLimit: this.upstring,
                userPro_Type:this.userPro_Type
            }).then((result) => {
        })
            .then((result) => {
                result = JSON.parse(JSON.stringify(result));
                console.log('result===>'+JSON.stringify(result));
                if(result.status == 'Success'){
@@ -133,14 +164,13 @@
                    setTimeout(() => {
                        this.toLexToppage();
                    }, 500);
                }else{
                    this.showMyToast('保存失败',result.msg,'error');
                    this.showSpinner = false;
                }
            }).catch((error) => {
            console.log("error = " + JSON.stringify(error));
            })
            .catch((error) => {
                console.log('error = ' + JSON.stringify(error));
                this.showSpinner = false;
         });
            
@@ -150,21 +180,24 @@
    handleProductChange(event){ 
        if (event.target.name == 'productNumber') {
            this.invRecords[event.currentTarget.dataset.index].productNumber = event.target.value;
            this.invRecords[event.currentTarget.dataset.index].productNumber =
                event.target.value;
            console.log('===>invrecords'+JSON.stringify(this.invRecords));
        }
        else if (event.target.name == 'inventory1') {
            this.invRecords[event.currentTarget.dataset.index].inventory1 = event.target.value;
        }
        else if (event.target.name == 'inventory2') {
            this.invRecords[event.currentTarget.dataset.index].inventory2 = event.target.value;
        } else if (event.target.name == 'inventory1') {
            this.invRecords[event.currentTarget.dataset.index].inventory1 =
                event.target.value;
            console.log('===>invrecords' + JSON.stringify(this.invRecords));
        } else if (event.target.name == 'inventory2') {
            this.invRecords[event.currentTarget.dataset.index].inventory2 =
                event.target.value;
            console.log('===>invrecords' + JSON.stringify(this.invRecords));
        }
    }
    
//数字验证
isNum(num){
    var reNum =/^[0-9]+$/;
    return (reNum.test(num));
        return reNum.test(num);
    }
    showMyToast(title, message, variant) {
        console.log('show custom message');
@@ -176,11 +209,18 @@
           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);
        }
        toLexToppage(){
            this[NavigationMixin.Navigate]({